Repository navigation
Closed
Labels
Description
Follow-up requested by @abogartz in the approval of #181, Finding A. This is separate from the approved readLines fix; it does not require widening that PR.
BunFile.exists() and .size can cache a path's old size. If a larger file replaces that path before .text(), the read can crop the replacement. Fixing readLines does not cover callers that perform their own BunFile reads.
Verified source sites on the #181 tree:
src/memory.ts,snapshotFiles:exists()followed by snapshot-name allocation and thentext(). A cropped copy leaves an incomplete undo snapshot.src/undo.ts,restoreSnapshot: the live-targetexists()/text()read feeds partitioning and a whole-file publish.src/blocklist.ts,removeBlock: the same sequence feeds blocklist republication.src/hits.ts,rotateIfNeeded:.sizeprimes the cache beforetext()feeds the halved ledger.src/portable.ts,importMemories:exists()/text()can omit input rows. Its tally describes processed rows; it does not prove the whole source file was read.- Audit the adjacent
src/status.tsexists()/json()reader separately: it catches errors and returns null rather than publishing store contents.
Evidence:
- The maintainer reports a no-mock macOS contention probe at
e418d07: 2,568 of 6,712 snapshots lacked the final row. See the linked review for method, versions, and limitations; this rate is specific to that synthetic workload. - I independently reproduced
snapshotFilescropping on Windows / Bun 1.4.4. Write a 23-byte file, prime a real BunFile withexists(), rename a complete 10,040-byte replacement over the path, and supply that cached handle only for the source path through aspyOn(Bun, "file")seam. The real snapshot contained 23 bytes and lacked the final row, while the source remained complete. The assertion requiring full snapshot length fails. This is a deterministic file-backed regression probe, not an independently measured Windows contention rate. - The other sites above are confirmed by source inspection; their actual mutation/locking paths need dedicated regression tests before claiming measured data loss at each one.
Suggested implementation and acceptance:
- Read bytes and any size used to bound that read from the same opened file, or read the complete contents without reusing cached BunFile metadata. Preserve each caller's missing-file behavior rather than applying one blanket error policy.
- Retain containment/ownership checks, store locks, identity anchors before content reads, and anchored Windows rename retries. Snapshot copying should preserve complete contents, including newlines.
- Add deterministic failing-before/fixed-after probes for snapshot contents, restore row conservation, blocklist entry conservation, ledger rotation, and import completeness. Exercise the actual callers, including public entry points for private helpers.
- Validate Windows handle-versus-rename behavior as well as Linux/macOS replacement behavior. Run the existing snapshot, undo, blocklist, hits, import, and concurrency coverage.
- Do not claim this makes concurrent in-place writes into atomic snapshots; lock and publishing guarantees remain separate.
Prioritize snapshots, restore, and blocklist publishers. The remaining readers can be addressed in independently reviewable commits if that suits the maintainer. This is a tracking item for the requested follow-up, not a reason to hold the scoped #181 fix.
Activity
WhollyMindless commentedon Oct 29, 2026
Starting this follow-up now after checking for assignments, discussion, and overlapping open PRs. I will cover the remaining cached-size readers with caller-level regression tests, preserving locks, identity anchors, containment, and caller-specific missing-file behavior. Please redirect me if there is unposted work; the PR will remain optional for your review.
abogartz-opencode-self-improvement commentedon Oct 30, 2026
🎉 This issue has been resolved in version 0.14.23 🎉
The release is available on:
Your semantic-release bot 📦🚀