Upstream deletes from the container are dropped as stale: tombstoneIsStale compares revs from different peers' rev spaces
Summary
Deletes made inside the container (rm, and therefore mv) are never applied to the Durable Object's VFS once the DO's local revision counter is ahead of computerd's. tombstoneIsStale compares revisions from two unrelated counters.
Environment
@cloudflare/computer0.3.1 withcomputer-computerd-linux-x64:0.3.1.withWorkspaceContainer+CloudflareContainerBackend, standard-1.- Same code on
main(e5e28a7).
What happens
- A workspace has some history. Local writes via
ws.fs.writeFilebumpvfs_meta.rev, and so does every file pulled back from the container, becauselinkStagedChunksSyncstamps it with a fresh local rev. ws.runtime.exec('rm x', { backend: 'linux' }).- The container's
lsno longer showsx, andresult()reportssync.status: 'complete',pulled: 0. xis still in the DO's VFS. It is never re-pushed, because it did not change locally, so the two sides stay diverged. Amv a barrives as "b created, a still present".
Files created in the container do propagate, because alreadyApplied compares manifest hashes, not revs.
Cause
packages/dofs/src/sync/apply.ts:
function tombstoneIsStale(db, entry) {
const live = resolveInode(db, entry.path, { followSymlinks: false });
if (live === null) return false;
const row = db.one("SELECT rev FROM vfs_nodes WHERE inode = ?", live.inode);
return row !== undefined && row.rev > entry.rev;
}
row.revis the local node's rev (localvfs_meta.revspace).- For an upstream entry,
entry.revcomes from the peer's change log (computerd's own counter). packages/rpc/src/server.tsitself describes the push caller as "a sync peer with its own rev space".
computerd starts fresh after every sleep, so its counter is small, while the DO's grows with every write and pull. row.rev > entry.rev therefore holds for practically every path, and every container delete is dropped as "stale".
On main the predicate is also used by applyChangesSync (apply.ts:426), so the RPC server path has the same comparison. The same predicate runs on the computerd side for deletes pushed from the DO. It works today only because the DO's revs are larger, and would drop DO deletes if the container's counter were ever ahead.
Repro without a container
Drive a real Workspace over node:sqlite against a fake SyncRPC/ShellRPC peer whose counter starts at 1:
- Write
/workspace/xa few times so the local rev is well above the peer's. - Make the fake command append
{ kind: 'delete', path: '/workspace/x', rev: <peer rev> }to the peer's change log. - Run
ws.runtime.exec(..., { backend }).
Result: pulled === 0 and /workspace/x still exists.
Workaround we are running
One possible fix, which we applied as a local patch to dist/index.js: decide staleness by whether the peer has seen the local version. A node pushed to this backend (rev <= pushRev) yields to the peer's delete; a local change newer than the last completed push still wins.
function tombstoneIsStale(db, entry, backend) {
const live = resolveInode(db, entry.path, { followSymlinks: false });
if (live === null) return false;
const row = db.one("SELECT rev FROM vfs_nodes WHERE inode = ?", live.inode);
if (row === void 0) return false;
return row.rev > readWatermark(db, "pushRev", backend ?? DEFAULT_BACKEND_ID);
}
// call site in applyChanges: tombstoneIsStale(db, entry, options.backend)
After a watermark divergence (pullOnceImpl resets pushRev to 0), deletes stay conservatively dropped until the next push re-establishes the watermark. We are not sure this is the right fix for the computerd side, or for pack pulls, but the cross-space comparison looks unintended.
@gardener-cf can you triage and find a fix for this issue?
@scuffi Triaged: the report is valid. tombstoneIsStale in packages/dofs/src/sync/apply.ts compares the live node's rev (local counter) against entry.rev (peer's counter), and packages/rpc/src/server.ts applies peer pushes as source: 'upstream' — so container deletes are checked across unrelated rev spaces and dropped once local revs run ahead. Likely fix: decide staleness in local rev space, e.g. compare against the backend's pushRev watermark like your patch, minding watermark resets and pack pulls. Needs a code change; none made here.
@gardener-cf validate the issue and push a PR with a fix
@gardener-cf validate the issue and push a PR with a fix
@scuffi Validated: four new entry/pack integration regressions fail against the original cross-peer revision comparison. I propose opening https://github.com/cloudflare/computer/pull/185 with a fix: pulls use the selected backend's local push watermark; push receivers use the committed sender cursor to protect recreations from replayed deletes. Unpushed local changes remain protected. All 220 dofs sync tests and 99 RPC sync tests pass, along with typechecking and targeted formatting/lint checks. Validation used in-process SQLite peers, not a real container.
@gardener-cf validate this was fixed in #230 & #231
@scuffi Validated by inspecting both merged PRs and current main: the reported cross-peer revision comparison is fixed. #230 replaces it with backend-specific push-cursor checks on pulls and sender-cursor replay checks on push receivers, and acknowledges clean pulls. #231 adds deletion fingerprints so matching pulled files can be removed even when acknowledgment is blocked. Regression tests cover smaller peer revisions, both push directions, entries/pack transports, and unacknowledged pulled files.
I attempted the focused dofs tests, but vitest is unavailable, so this is source-level validation, not a passing runtime reproduction. Caveats remain: older peers without fingerprints conservatively retain unacknowledged files; crash replay can delete an identically recreated file. No code or issue-state change is proposed.