mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #5653] [MERGED] fix(storage): close the transaction opening gate atomically #6866
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#6866
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/5653
Author: @kolacheee
Created: 8/29/2026
Status: ✅ Merged
Merged: 8/29/2026
Merged by: @kolacheee
Base:
staging← Head:fix/5631-tx-gate-window📝 Commits (3)
1d325e2fix(storage): close the transaction opening gate atomically0945a68fix(storage): harden the reservation and make the gate regression stage the real erasure7f07757test(storage): stage the gate race through a first-class store seam📊 Changes
2 files changed (+250 additions, -19 deletions)
View changed files
📝
packages/server/src/db/file-backed-store.ts(+62 -19)➕
scripts/regressions/tx-gate-window.regression.ts(+188 -0)📄 Description
Closes #5631
Why
The file store's transaction rollback could silently revert a concurrent plain write.
transaction()took its queue slot, then awaited the previous transaction and any in-flight flush before incrementingactiveTransactionCount— andwaitForWritableTurnhonored only the active count. A plain write passing the gate inside that window could apply after the transaction took its first-mutation table snapshot; a rollback then restored the snapshot and the write vanished from memory with no error surfaced to its caller.The nastier variant, which the regression pins explicitly: when the raced write targets a lazily-loaded chat unit, the rollback erases the freshly loaded rows too, while the unit stays marked loaded — rows that are safely on disk become invisible in memory for the rest of the session.
Found by the #5599/#5600 adversarial verification pass; it predates those fixes, but message edits now run in a transaction, so the window has more traffic near it.
The fix
A
pendingTransactionCount, incremented synchronously with queue admission, closes the gate atomically:waitForWritableTurnloops over both counters: while a transaction is active it waits on the idle waiters as before; in a pending-only window it waits on the transaction queue (the idle waiters only fire on active-count transitions, which a pending-only window never produces), re-checking after every wake.The regression, and how it earned its determinism
The write path is fully synchronous after its gate (lazy unit loads read shard files synchronously), so the real-world hazard is a one-tick scheduler placement no natural staging hits reliably — the first two drafts of this pin were provably vacuous, caught in review and by instrumented runs (the second draft paused a method on the
_fileStorefacade that the store never calls). The store now exposesafterWritableTurnin its existing test-hooks surface (thebeforeTableWriteseam family): it runs after a plain write clears the gate and before its mutation applies, never for transaction-context writes. The regression arms it for the one raced insert and asserts the pause actually engaged, so the pin cannot silently go vacuous again.A/B against "pre-fix store + seam only", two runs: with all assertions on it fails at the gate-ordering assert; with the ordering assert neutralized it fails at "the raced insert survives the rollback" — the silent erasure itself, observed. With the fix: green, including the seam-engagement assert.
Verification
activeFlushawait lets a second flush run concurrently with a transaction and persist uncommitted rows).launcher/format-guard.regression.mjs, which dies withnode: command not foundfrom a spawned POSIX shell: a PATH problem in this Windows box's environment, unrelated (the guard doesn't import the store and is untouched here). CI'scomplete-node-regressionslane runs it on ubuntu.pnpm checkgreen.Summary by CodeRabbit
Bug Fixes
Tests
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.