Skip to content

fix(session): reserve the WAL writer before reading revisions - #1452

Merged
yyjeqhc merged 1 commit into
mainfrom
fix/session-wal-write-reservation
Nov 28, 2026
Merged

yyjeqhc merged 1 commit into
mainfrom
fix/session-wal-write-reservation

Conversation

@yyjeqhc

@yyjeqhc yyjeqhc commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Closes #1451.

Workflow Session persistence reads the stored revision before upserting a Session. With a deferred transaction, another connection can commit to the shared WAL between those statements. SQLite then rejects the Session write because its read snapshot is stale.

Start each dirty Session batch with BEGIN IMMEDIATE. The writer now acquires its reservation under the existing five-second busy timeout before checking revisions. The batch still commits atomically after the revision and identity checks.

The regression exercises the SessionStore flush path against a temporary file. A SQLite statement hook in the test attempts an insert into an unrelated audit table just as the Session upsert is prepared. This puts the competing write after the revision read without relying on sleeps.

Validation

  • With the original deferred transaction, the regression reproduced Session persistence failed: database is locked. With this fix, the test verifies that the competing insert sees a busy writer, both Session events reach disk, and the audit insert succeeds after the flush.
  • cargo test --locked -p webcodex-workflow-session --lib on macOS passed with 303 tests and 8 ignored. The passing tests include batch rollback and stale writer coverage.
  • cargo fmt --all -- --check and git diff --check passed.

@yyjeqhc
yyjeqhc merged commit 6ea6ed5 into main Nov 28, 2026
17 checks passed
@yyjeqhc
yyjeqhc deleted the fix/session-wal-write-reservation branch November 28, 2026 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug / fix proposal] Workflow Session WAL write transaction can fail with database is locked during concurrent audit writes

1 participant