Skip to content

fix(session-worker): isolate receipts between sequential commits - #165904

Merged
steipete merged 6 commits into
mainfrom
dbasync/w5locked-receipts
Oct 6, 2026
Merged

steipete merged 6 commits into
mainfrom
dbasync/w5locked-receipts

Conversation

@steipete

@steipete steipete commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A retained session worker operation can report two successful commits while storing only the first event. The second transfer is refused because its receiver is still occupied; settlement then accepts the first operation’s old acknowledgment and returns success again.

Solution

Reset candidate, admission, transfer identity, receiver, and transfer-completion state before each sequential commit. Keep candidate and admission in an explicit per-commit state object so asynchronous worker callbacks own the actual receipt state.

The regression sends two real event-append commands through the existing worker owner and checks both acknowledgments and durable row order. No new worker, schema, transport, authority bypass, or replay path is introduced. Existing single-commit native settlement and entry-publication callers retain their current behavior; the multiple-commit consumer is the following locked transcript adapter, whose candidates do not carry entry-replacement publication state.

Impact

Prevents a refused later operation from borrowing an earlier successful receipt. This is a prerequisite for independent transcript commits within one retained writer reservation. Production diff: +24/−16, net +8; 40 changed lines. Static T1: 846 → 846; this repair moves no SQL sites. New OPENCLAW_* names: 0. No schema, retention, durability, permission, migration, or SDK signature changes.

Evidence

Original head (2da280d69e9b)

  • Before the fix, the new real-owner regression failed in 68.40 s wall: two acknowledgments and result 2, but durable rows contained only the first new event.
  • After the fix, 52 tests in 7 focused files passed with --maxWorkers=1, 491.19 s wall. The new regression’s body took 1.664 s. The suite includes lost replies, callback failures, unknown native settlement, prepared-source cleanup, live authority, binding compensation, and lifecycle projection.
  • Shared runtime-process build graph and get-reply/history/reconcile import checks: 14 tests in 4 files passed, 38.82 s wall.
  • Database-worker ratchet passed against the pinned parent, 37.18 s; T1 reduction 0.
  • Madge: zero cycles, 133.81 s.
  • Fresh independent P2 Codex review: scoped clean, 167.23 s.
  • Full node scripts/check-changed.mjs --base 89072df2366088a3b3239e494a889baafcda47ed passed in 1,740.37 s wall, including types, budgets, dead exports, lint, and architecture guards. The exact-head SDK comparison passed in 372.66 s, with no Plugin SDK API changes (digest ff7b090f). The canonical package/tarball check passed in 892.06 s. The published 2026.9.8 → candidate update cell passed in 684.87 s, preserving durable and incognito sessions, returning readyz=200, and verifying the running version. Exact-head proof ran on Hetzner through the repository wrapper (cbx_ee42738387cf, run run_c6fc0b7afbcab764a346b01c67a4cc14). CI test seconds are not yet available; the parent stack's CI dependency audit is blocked by inherited source-map-js advisory GHSA-68fv-2mgg-jv7q. This repair changes no dependency manifests or lockfile.

The native locked-append settlement foundation #165894 has merged. Related work: #165793, #165764, and #162433. This keeps the receipt owner repair separate so the locked worker cutover remains within its production-line cap.

Integration (9d06ca108e11)

Merged main at 86e2107b5269 with a merge commit. Kept main's consolidated host authority and worker routing unchanged and removed an automatically duplicated compatibility record. The final delta against that baseline is only the receipt owner and its regression: production +24/−16 and tests +64. The inherited source-map-js advisory fix is included.

Fresh independent P2 Codex autoreview is scoped clean. Production and all core-test typechecks pass; Madge reports zero cycles. The changed-lane planner selects only core and core tests. Formatting and git diff --check pass.

Focused proof: 62 passed, 2 failed across 8 files, 1,117.83 s wall with --maxWorkers=1. The sequential receipt regression passes (5.319 s test body), as do native locked FIFO shutdown, entry publication/lost replies, live authority, native-binding settlement, Goal persistence, and ordered reads. Exact-head CI run 37449041132 succeeded with zero failed jobs and 8,233 aggregate job-seconds. The PR-context check initially rejected a renamed Evidence heading; restoring that required heading passed without a code change or CI rerun.

The two local failures are in unchanged session-accessor.reply-init-concurrency.test.ts: commits after same-session activity from another process hit the fixture's 10 s scenario watchdog, and rejects a transcript rewrite after another process commits an append hit the 15 s test deadline. The first path invokes the changed owner only once per operation; the second uses native transcript writes after setup. Neither exercises the repeated-commit reset. The watchdog spans multiple phases and does not join the timed-out child request, so the second failure may follow unfinished work. The full file then passed five candidate runs (36/27/31/30/35 s) and five baseline runs (31/40/39/43/33 s), each singly with --maxWorkers=1 and original file order on Testbox run 37450913977. The verified capsule changed only the receipt owner to its exact merge-base bytes for baseline runs; all other tested production sources are identical. No timeout, assertion, or retry policy changed. The precise stalled macOS phase and contribution of host load remain unknown; these are recorded unreproduced local failures, not an inherited-CI bypass claim. Testbox command exit was 0 and the lease was stopped/completed; backing workflow cancellation during one-shot cleanup is expected.

Released SDK check: inspected v2026.10.1-beta.1 and v2026.9.8. The repaired owner is internal, has no SDK/runtime export or documented subpath, and this repair changes no signature. The existing released async facades and compatibility record remain unchanged. The post-integration SDK API report passed locally with no API changes against the integrated main baseline (digest ff7b090f). No worker import, launcher module, host-SQL site, or OPENCLAW_* name is added; existing runtime-config fork routing covers the regression.

ClawSweeper completed the exact-head review at 2026-10-06T10:23:55.280Z with no correctness or security findings and no before-merge items.

Keep prepared initialization rollback and opaque SDK deletion mutations on native planning and transaction paths. Ordinary host-minted binding participants retain worker execution and receipt settlement. Remove worker-only initialization finalizers and protect the same-store authority boundary with a real rollback regression.
Join accepted native lock operations in FIFO order before releasing the
reservation, including callback failure and Gateway close. Preserve prepared
receipt authority and its original cleanup receiver through harness adapters.

Add awaited locked-message preparation with physical identity and fresh-insert
version checks. Keep the released synchronous option deprecated and compatible,
and migrate bundled catalog and Codex callers. No schema or durability change.
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 6, 2026
@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 6, 2026, 6:43 AM ET / 10:43 UTC (Revision 5).

ClawSweeper review

What this changes

The PR clears each session worker commit’s receipt and transfer state so later transcript writes cannot reuse an earlier acknowledgment.

Merge readiness

✅ Ready for maintainer review

This PR remains useful: current main still carries receipt state across sequential commits. The focused repair has relevant production-boundary proof, and no introduced correctness or security defect was found.

Priority: P2
Reviewed head: 9d06ca108e11df6a771445aee513941ab4b3af7a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with strong relevant proof and no actionable introduced defect.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The recorded before/after run exercises the changed settlement owner through the actual worker event-append domain and verifies two acknowledged commits against ordered durable SQLite rows; the integrated-head regression also passes. This production-boundary proof covers the internal repair. No stored-data contract changes require migration proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The recorded before/after run exercises the changed settlement owner through the actual worker event-append domain and verifies two acknowledged commits against ordered durable SQLite rows; the integrated-head regression also passes. This production-boundary proof covers the internal repair. No stored-data contract changes require migration proof.
Evidence reviewed 9 items Pinned introduction: The verified base-to-head delta resets candidate, admission, transfer identity, receiver, and transfer completion before each commit; the only other introduced change is the durable-row regression.
Still necessary on current main: Fetched main retains operation-wide candidate and admission state and does not reset the transfer receiver before the next commit. The owner is unchanged between the pinned base and fetched main; the merged native-lock foundation does not supply this repair.
Real worker regression: The new test sends two event-append commands through the actual retained execution and worker domain, checks two acknowledgments, and independently reads SQLite rows to require both events in order. It supplies neither mocked receipts nor mocked transport results.
Findings None None.
Security None None.

How this fits together

Session workers persist session entries and transcript events in SQLite. Their settlement owner matches transferred candidates to commit receipts before publishing results to callers.

flowchart TD
  A[Session operation] --> B[Retained writer reservation]
  B --> C[Fresh commit state]
  C --> D[Worker transaction]
  D --> E[Candidate transfer and receipt]
  E --> F[Confirm native settlement]
  F --> G[Publish acknowledged result]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +8, Tests +64. Total +72 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 24 16 +8
Tests 1 64 0 +64
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 88 16 +72

Review metrics

None.

Technical review

Best possible solution:

Keep one receipt-settlement owner with fresh transfer and admission state for every sequential commit while preserving the existing writer reservation and live authorization checks.

Do we have a high-confidence way to reproduce the issue?

Yes: two awaited event commits within one retained worker operation expose the stale receiver and acknowledgment path, with durable-row assertions distinguishing false success. The PR records a failing before-control; this review verified the mechanism from source without executing it.

Is this the best way to solve the issue?

Yes: resetting the existing owner’s per-commit state directly repairs the leak without adding another writer, replay path, or public contract.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 8dc04b001e10.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This bounded internal persistence repair prevents sequential commits from reporting success using a stale acknowledgment.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The recorded before/after run exercises the changed settlement owner through the actual worker event-append domain and verifies two acknowledged commits against ordered durable SQLite rows; the integrated-head regression also passes. This production-boundary proof covers the internal repair. No stored-data contract changes require migration proof.
  • proof: sufficient: Contributor real behavior proof is sufficient. The recorded before/after run exercises the changed settlement owner through the actual worker event-append domain and verifies two acknowledged commits against ordered durable SQLite rows; the integrated-head regression also passes. This production-boundary proof covers the internal repair. No stored-data contract changes require migration proof.

Evidence

What I checked:

  • Pinned introduction: The verified base-to-head delta resets candidate, admission, transfer identity, receiver, and transfer completion before each commit; the only other introduced change is the durable-row regression. (src/config/sessions/session-entry-patch.ts:222, 9d06ca108e11)
  • Still necessary on current main: Fetched main retains operation-wide candidate and admission state and does not reset the transfer receiver before the next commit. The owner is unchanged between the pinned base and fetched main; the merged native-lock foundation does not supply this repair. (src/config/sessions/session-entry-patch.ts:183, 8dc04b001e10)
  • Real worker regression: The new test sends two event-append commands through the actual retained execution and worker domain, checks two acknowledgments, and independently reads SQLite rows to require both events in order. It supplies neither mocked receipts nor mocked transport results. (src/config/sessions/session-entry-patch.settlement.test.ts:34, 9d06ca108e11)
  • Recorded before and after proof: The captured PR body reports the regression failing before the repair with two acknowledgments but only one new durable event, passing afterward, and passing again at the integrated head in 5.319 seconds. The integrated focused run records 62 passes and two unchanged concurrency-test timeouts, without claiming those failures were fixed. These are contributor-recorded observations; this read-only review did not execute tests. (9d06ca108e11)
  • Authority and settlement boundary: The unchanged admission owner authorizes the binding and checks live execution, caller authority, and physical identity before granting transaction or commit admission. Private native receipts describe completion rather than granting write authority. Resetting those receipt projections adds no principal, permission, or authority bypass. (src/config/sessions/session-accessor.sqlite-replacement-worker.ts:147, 9d06ca108e11)
  • Implementation boundary and compatibility: The event domain borrows the canonical worker connection and transfers a candidate before commit admission. The introduced patch changes only in-memory settlement state, with no schema, serialized format, SDK signature, dependency, or Codex protocol change. No affirmative dependency signal requires sibling Codex inspection. (src/config/sessions/session-message-rewrite.worker.ts:172, 9d06ca108e11)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (4 earlier review cycles)
  • reviewed 2026-10-06T02:00:59.584Z sha 2da280d :: needs maintainer review before merge. :: none
  • reviewed 2026-10-06T02:07:49.799Z sha 2da280d :: needs maintainer review before merge. :: none
  • reviewed 2026-10-06T09:56:19.595Z sha 2da280d :: blocked before merge. :: none
  • reviewed 2026-10-06T10:23:55.280Z sha 9d06ca1 :: needs maintainer review before merge. :: none

@github-actions

github-actions Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Security-sensitive guard cleared

Current revision: 9d06ca108e11df6a771445aee513941ab4b3af7a

This PR no longer changes files in the maintainer security-review tier.

Separate CODEOWNERS requirements still apply to security policy and enforcement files.

Preserve the landed host source authority and worker test routing. Keep one SDK compatibility record after the foundation merge. The remaining PR delta is the receipt owner reset and its real-worker regression.
@steipete

steipete commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@openclaw-barnacle openclaw-barnacle Bot added size: S and removed docs Improvements or additions to documentation agents Agent runtime and tooling extensions: codex size: XL labels Oct 6, 2026
@steipete
steipete merged commit 5d13f20 into main Oct 6, 2026
151 of 156 checks passed
@steipete
steipete deleted the dbasync/w5locked-receipts branch October 6, 2026 10:57
@steipete

steipete commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 7, 2026
…nclaw#165904)

* fix(sessions): preserve native rollback authority

Keep prepared initialization rollback and opaque SDK deletion mutations on native planning and transaction paths. Ordinary host-minted binding participants retain worker execution and receipt settlement. Remove worker-only initialization finalizers and protect the same-store authority boundary with a real rollback regression.

* test(sessions): retain rollback observer receiver

* fix(sessions): settle accepted locked transcript appends

Join accepted native lock operations in FIFO order before releasing the
reservation, including callback failure and Gateway close. Preserve prepared
receipt authority and its original cleanup receiver through harness adapters.

Add awaited locked-message preparation with physical identity and fresh-insert
version checks. Keep the released synchronous option deprecated and compatible,
and migrate bundled catalog and Codex callers. No schema or durability change.

* style(sessions): avoid shadowing transcript lock parameters

* fix(sessions): prevent stale worker commit acknowledgments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant