fix(storage): refresh chunk mtime when a put reuses it (R-5.2)
writeImmutableChunk returned early when a chunk with the same digest already existed, so the chunk kept its old lastModified. Orphan GC decides "not referenced" from the page journal and deletes in the worker; another tab's GC holding a stale answer could delete a day-old chunk right after this put reused it and left staging, and the committed object then failed INTEGRITY_FAILED on open. A dedup hit now rewrites the identical bytes through the atomic writable path, which refreshes lastModified so DELETE_ORPHAN_CHUNK's grace check skips it. Readers of the committed chunk see either copy, never a partial file. The mutation lock scope is unchanged. Verified: new test "R-5.2 a dedup-reused chunk is protected by the grace period again" ages a committed chunk, reuses it from a second put and finalizes. Before the fix LIST_ORPHAN_CANDIDATES still returned the reused digest; now it is neither listed nor deleted and the second object verifies. Gates: check:architecture, check:types:app/test/web-worker, lint, test:component pass; test:unit passes except removal-fixture.test.ts, which needs gitignored release artifacts absent from a fresh worktree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d758934e9c
commit
e28e9f75fb
@@ -1219,6 +1219,21 @@ export function createOpfsWorkerRuntime(
|
||||
);
|
||||
await directory.removeEntry(fileName);
|
||||
} else {
|
||||
// R-5.2. A dedup hit must restart the chunk's grace period. Orphan GC
|
||||
// reads "not referenced" from the page journal and deletes in the
|
||||
// worker, so another tab's GC can hold a stale answer for a chunk that
|
||||
// this put is about to reference once staging is gone. An atomic
|
||||
// rewrite of the identical bytes refreshes lastModified, and readers of
|
||||
// the committed chunk see either copy, never a partial file.
|
||||
const { directory, fileName } = await resolveFileParent(
|
||||
dependencies.root,
|
||||
path,
|
||||
false,
|
||||
);
|
||||
await writeWithAtomicWritable(
|
||||
await directory.getFileHandle(fileName),
|
||||
bytes,
|
||||
);
|
||||
return;
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user