Skip to content

When identical bytes leave a database handle stale

What should happen if another component replaces a database underneath an open writer, but supplies exactly the same bytes? RustEditor tested this with Tosumu's main database and write-ahead log held in its in-memory Resource Space. A resource has an identity and a version as well as contents. Replacing it advances the version even when every byte matches.

What the consumer tested

The experiment opened a database and tried to replace, rename, and delete its backing resources through the host. Each operation returned Busy while the database was open. A second test deliberately went through the lower-level resource API. It started with a fresh database for each case.

Change through the raw resource API Next database operation Observed result
Replace the main resource with a copy of its existing bytes Write a key Stale backing
Rename the main resource Write a key Stale backing
Delete the main resource Write a key Stale backing

All three raw changes succeeded. In each case the test recorded the adapter's write counter immediately after the change, called db.put, and checked both the error and the counter. Tosumu surfaced TosumuError::Io carrying the adapter's Fault::StaleBacking. The counter stayed at its pre-put value. The retained September 26, 2026 native run passed all twelve adapter tests, including this one.

Why the identical copy matters

Comparing the file contents before and after replacement would show equality. RustEditor could still tell that the handle referred to an earlier version of the resource. That distinction gives a storage adapter a useful failure to communicate: the caller needs to re-establish which resource it owns before it can safely write again. The raw change had already happened by the time the adapter reported it.

Page authentication answers a different question about the bytes read by the pager. This experiment exercised the resource-version check. It leaves two separate questions open: what happens when altered page bytes reach the pager, and what a freshly opened handle can establish after an entire authentic database is rolled back. The latter depends on which evidence survives the rollback. Tosumu's safety and limits.

Evidence

The negative control is named raw_resource_space_has_no_database_lease_but_adapter_detects_each_bypass. Its companion test exercises the host's refusal while a handle is open. Both belong to RustEditor's experimental adapter.