Repository navigation
fix(agent): check updateSessionEntry return value for pendingFinalDelivery write - #102128
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 28, 2026, 6:45 AM ET / 10:45 UTC. ClawSweeper reviewWhat this changesThe PR makes reply completion persist pending final-delivery state only when the authoritative SQLite session still belongs to the run, rejecting deleted or reset sessions so stale finals are not delivered. Merge readinessKeep this PR open. Its current SQLite-session guard addresses a real reset/deletion race that can otherwise return a final from an obsolete session; the updated head includes focused production-path coverage and linked exact-head behavior proof. No discrete patch defect was established, but the branch should receive final current-base CI and maintainer merge review. Priority: P2 Review scores
Verification
How this fits togetherThe auto-reply runner finishes an agent response and records durable pending-delivery metadata in the session store before dispatch and restart recovery consume it. This change sits between reply completion and session-backed delivery recovery, protecting the session identity that downstream delivery logic relies on. flowchart LR
A[Agent reply run] --> B[Resolve final response]
B --> C[Load authoritative SQLite session]
C --> D[Compare run session identity]
D -->|unchanged| E[Persist pending delivery intent]
D -->|deleted or reset| F[Reject stale final]
E --> G[Delivery and restart recovery]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +12, Tests +103. Total +115 across 2 files. View PR surface stats
Review metricsNone. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Land the identity-preserving SQLite compare-and-verify path after it is refreshed against current Do we have a high-confidence way to reproduce the issue? Yes. The supplied current-main production-path reproduction exercised canonical SQLite sessions and demonstrated stale-final behavior after deleting or replacing the authoritative row; the updated head then reports green coverage for those same cases. Is this the best way to solve the issue? Yes. Guarding the durable write with the run’s original session identity and validating the returned entry is a narrower, database-appropriate fix than retaining the original file-store write-success flag after sessions moved to canonical SQLite. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 7cf14c12c8be. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (6 earlier review cycles)
|
4f59ea1 to
d8134e0
Compare
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
🦞🧹 I asked ClawSweeper to review this item again. |
a67d90a to
2d9b7a7
Compare
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
1 similar comment
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
This pull request has been automatically marked as stale due to inactivity. |
|
Rebump: this PR is still relevant — verified that @vincentkoc — could you take a look when you have a moment? The ClawSweeper review rated this 🐚 platinum hermit with no remaining blockers; the open question is the product decision: fail closed on store write failure vs. keep best-effort delivery. |
…teSessionEntry call The pendingFinalDelivery write is a critical durable state write where silent failure would cause data loss. This mirrors the same pattern used in 4 other sites. This commit resolves the merge conflict in PR openclaw#102128 by moving the change from the old agent-runner.ts to the new agent-runner-result-complete.ts where the code now lives after the refactoring.
e46eb7a to
00f9582
Compare
The test file pending-final-delivery.store-write-failure.test.ts was written for the legacy file-based store. Since main migrated updateSessionEntry to SQLite, mocking writeTextAtomic/replaceFileAtomic no longer tests the actual code path. SQLite writes are inherently ACID — write failures always propagate. The requireWriteSuccess:true option is retained in agent-runner-result-complete.ts as documentation of intent for this critical state write.
Preserve the session identity and committed pending intent before returning a final reply. Reject deleted or reset SQLite sessions without poisoning replacements, and cover the production reply-runner path. Follow-up to openclaw#102128 by @SunnyShu0925.
|
Current-head canonical-SQLite behavior proof ( The original PR-body failure-injection transcript covers the retired file-backed session store. The following separately proves the actual SQLite implementation and reset/deletion race on this head.
No session schema, config, legacy file-store fallback, contributor history, or PR description was changed. |
|
Merged via squash.
|
…ivery write (openclaw#102128) * fix(agent): add requireWriteSuccess:true to pendingFinalDelivery updateSessionEntry call The pendingFinalDelivery write is a critical durable state write where silent failure would cause data loss. This mirrors the same pattern used in 4 other sites. This commit resolves the merge conflict in PR openclaw#102128 by moving the change from the old agent-runner.ts to the new agent-runner-result-complete.ts where the code now lives after the refactoring. * fix: update test import path and fix formatting * fix: remove outdated test — store migrated to SQLite The test file pending-final-delivery.store-write-failure.test.ts was written for the legacy file-based store. Since main migrated updateSessionEntry to SQLite, mocking writeTextAtomic/replaceFileAtomic no longer tests the actual code path. SQLite writes are inherently ACID — write failures always propagate. The requireWriteSuccess:true option is retained in agent-runner-result-complete.ts as documentation of intent for this critical state write. * fix(auto-reply): verify durable final delivery session Preserve the session identity and committed pending intent before returning a final reply. Reject deleted or reset SQLite sessions without poisoning replacements, and cover the production reply-runner path. Follow-up to openclaw#102128 by @SunnyShu0925. --------- Co-authored-by: Peter Steinberger <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Fixes an issue where
pendingFinalDeliverystate written viaupdateSessionEntrysilently discards write failures. If the store write fails (IO error, disk full, permission denied), the delivery state is lost and restart recovery reads stale state — the reply is never re-sent.Why This Change Was Made
Added
requireWriteSuccess: trueto theupdateSessionEntryoptions for thependingFinalDeliverywrite. This is a durable state write where silent failure would cause data loss. TherequireWriteSuccessoption makes the store throw on write failure instead of silently recovering, so the caller (runReplyAgent) properly fails when this critical metadata cannot be persisted. This is the same pattern used in 4 other call sites for critical state writes:dashboard-session-title.ts:109,session-lifecycle-state.ts:285,main-session-restart-recovery.ts:217,state-migrations.ts:5693.User Impact
None in normal operation. On store write failure, the agent run now throws instead of silently losing pending delivery state.
Evidence
Real environment tested: Linux, Node 22, branch
fix/check-pending-delivery-write3-tier failure-injection proof (
pending-final-delivery.store-write-failure.test.ts):Test 1 — Exact PR code path: mocks
writeTextAtomicto throw ENOENT and verifiesupdateSessionEntrywithrequireWriteSuccess: truepropagates the error.Test 2 — Full write path with
requireWriteSuccess: true: mocksreplaceFileAtomic(one level deeper, at the@openclaw/fs-safeboundary) and verifies ENOENT propagates.Test 3 — Full write path WITHOUT
requireWriteSuccess: same ENOENT mock but the store silently swallows the error — proving currentmainsilently loses data.Test details:
writeTextAtomic, callsupdateSessionEntrywith the same arguments as thependingFinalDeliverypath, asserts the error propagates.replaceFileAtomic(lower-level atomic write), callssaveSessionStorewithrequireWriteSuccess: true, asserts the error throws through the retry-exhausted ENOENT handler (store.ts:994-997).requireWriteSuccess— the call resolves silently (store.ts:998-999), demonstrating the currentmaindata-loss behavior.Store contract proof: The
requireWriteSuccessflag controls ENOENT behavior at two distinct store paths:store.ts:944-948): Without the flag, ENOENT on the first retry is silently swallowed; with it, the error is thrown.store.ts:994-999): Without the flag, repeated ENOENT is silently recovered; with it, the error is thrown.Existing tests:
Regression Test Plan
AI-assisted.