🔒 Fence WorkflowRun transactions and unify savepoints - #396
Conversation
PR #396: 🔒 Fence WorkflowRun transactions and unify savepoints18 files, +1340 / -207 Scope🔴 PR has 1547 lines changed. Split into focused PRs. 🟡 1547 lines changed. PRs under 400 receive more thorough review. Structural🟡 Type declarations with no consumers: SavepointManager.
Slop✅ Slop indicators look low. Static Analysis✅ Oxlint found no issues. CorrectnessFILE: packages/workflow/src/deno/workspace/private.ts FILE: packages/workflow/src/deno/connections.ts FILE: packages/workflow/src/deno/savepoints.ts |
1cbea52 to
454bad7
Compare
Why
Stack layer 4 of #365 replaces the savepoint/fencing portion of draft #387. The retained Workspace foundation needs operation-spanning savepoints and exact provider-owned transaction authority before a later layer can coordinate mutation, root capture, and journal publication safely.
This PR does not close #365.
What changes
Before:
Cloudflare DOFS initialization had synchronous savepoints, but private Workspace operations relied on a connection-wide open boolean and public Deno handles carried a discoverable raw-connection association. There was no operation savepoint whose decision waited for child teardown.
After:
Each authoritative connection has an opaque generation, each
BEGIN IMMEDIATEhas an exact active transaction identity, and provider-owned lease/handle registrations validate possession before SQLite is touched. Synchronous DOFS nesting and operation-spanning savepoints share one collision-free allocator. Operation savepoints run in a child scope, wait for teardown, and release or roll back synchronously; savepoint SQL failures poison the outer transaction so it cannot commit. After a successfulROLLBACK TOplusRELEASE, the shared rollback path invalidates both caches on the authoritative DOFS wrapper before outer transaction work resumes.How it works
The structural active-path context remains refusal-only. Adapter-private contextual Workspace operations close over the provider registry and authorize work through exact identities; public
WorkflowRunDatabasevalues expose no raw SQLite or DOFS connection.Review guide
Start with:
packages/workflow/tests/workspace-transaction.test.tsThen review:
packages/workflow/src/deno/connections.ts— generations, active transaction records, lease/token registration, and cache ownershippackages/workflow/src/deno/savepoints.ts— the shared synchronous/operation lifecycle, rollback cache cleanup, and poisoning rulespackages/workflow/src/deno/database.tsandtransaction.ts— caller-owned transaction teardown and contextual savepoint installationpackages/workflow/src/deno/workspace/private.ts— adapter-private exact-identity authorizationLook carefully at:
What must stay true
BEGIN,COMMIT, orROLLBACK; checked by WTX5 and the storage suites.How to verify it
deno test -A packages/workflow/tests/workspace-transaction.test.ts packages/workflow/tests/workspace-root.test.ts packages/workflow/tests/workspace-root-restoration.test.ts packages/workflow/tests/workflow-run-storage.test.ts packages/workflow/tests/workflow-run-journal.test.ts— 16 suites / 103 steps pass.deno task lint— 0 errors; formatting is clean.deno task check— passes.deno task test— 405 suites / 2,770 steps pass.deno task check:jsr—Success Dry run complete.deno task verify— vendor, lint, check, Deno tests, JSR, tsc, Bun tests, and docs pass on both complete runs. Node alone reproduces the already-recorded CF7 post-test asynchronous-activity flake in 💥 Stabilize Node runtime test flake in config-api CF7 #371; all CF assertions pass, PR 🔒 Fence WorkflowRun transactions and unify savepoints #396's existing Node CI is green, and this stack does not import the unrelated pending fetch fix. Both verifier runs leave the tracked tree unchanged.git diff --check origin/main...HEAD— passes.Scope
Included
BEGINtransaction identitiesIntentionally unchanged
<File>, start/resume, history/fork, Worker Shell, Git, FUSE, subprocesses, workerd, garbage collection, and schema versionsNew abstractions
ConnectionGeneration,TransactionIdentity, andWorkflowRunTransactionTokenprovide exact adapter-private authority that cannot be reconstructed from paths or structural lookalikes.RunTransactionis the authoritative active record shared by transaction, savepoint, DOFS, and private Workspace validation.Risks and limitations
Scope confirmation