Repository navigation
fix(gateway): skip abort partial persistence when the final reply is already committed - #132123
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs real behavior proof before merge. Reviewed August 29, 2026, 12:39 AM ET / 04:39 UTC. ClawSweeper reviewWhat this changesThe branch skips a late abort-partial transcript append when the newest terminal assistant row has matching text and run identity. Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readiness⛔ Blocked until stronger real behavior proof is added - 6 items remain Keep open: the queued predicate can still race the synchronous terminal-row writer, so the duplicate transcript entry remains possible. The prior run-identity fix is sound, but the supplied gateway proof exercises the different-run preservation case rather than the headline same-run deduplication. Priority: P1 Review scores
Verification
How this fits togetherGateway abort handling persists buffered assistant output into a session transcript. The change consults the durable transcript before recording an abort partial, affecting session history seen by later clients. flowchart LR
A[Buffered assistant reply] --> B[Chat abort]
B --> C[Queued append predicate]
D[Embedded terminal writer] --> E[SQLite transcript]
C --> E
E --> F{Same run and text?}
F -->|Yes| G[Skip abort partial]
F -->|No| H[Append abort partial]
Before merge
Findings
Agent review detailsSecurityNone. PR surfaceSource +108, Tests +524. Total +632 across 7 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Make the final committed-row check part of the synchronous SQLite transaction that decides the abort append, or place both writer paths under one canonical serialization owner, then prove the direct-terminal-write interleaving cannot append a duplicate. Do we have a high-confidence way to reproduce the issue? Yes, from source: pause the new predicate after it reads an older row, synchronously append the matching terminal row through the embedded session writer, then allow the abort transaction to proceed; it will append the duplicate. Is this the best way to solve the issue? No. The run-scoped comparison fixes the prior text-only loss, but placing it before the transaction does not protect it from the actual synchronous terminal writer. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against dc2b26c73fa1. LabelsLabel changes:
Label justifications:
EvidenceAcceptance criteria:
What 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 (4 earlier review cycles)
|
…already committed A run that settles and commits its final assistant row keeps the same text in its live buffer until the lifecycle end event clears it. When settle stalls, the buffer survives and a late chat.abort re-persists the buffered text as an injected abort partial, duplicating the committed reply in the transcript. Abort persistence now reads the last committed assistant row and skips the append when it already carries the same text, covering the rpc, stop-command, and placement-abandon origins at the single persistence boundary. Co-Authored-By: Claude <[email protected]>
…ter queue Reading the last committed assistant row outside the append left the skip decision racing a final commit that could land between the read and the append, and a declined decision surfaced as a failed placement abandonment instead of a skipped write. The transcript turn persistence already owns a writer-queue predicate that runs before the SQLite transaction; thread the committed-row comparison through it so the durable read and the append decision are atomic against every other transcript writer, and report the decline as a skipped append rather than an error. Co-Authored-By: Claude <[email protected]>
Adds a real-gateway proof: a first turn commits the reply, a second run buffers identical text while the provider stream stays open, then a chat.abort lands. The observed after-fix gateway outcome is a single committed assistant row, captured through the real client, gateway process, and SQLite transcript store. Co-Authored-By: Claude <[email protected]>
Co-Authored-By: Claude <[email protected]>
The abort decision reads the live run buffer, so the proof now waits for the gateway broadcast carrying the reply text rather than a fixed delay. Co-Authored-By: Claude <[email protected]>
Promise.withResolvers needs an ES2024 lib; the test-root tsconfig targets ES2023. test/helpers/promise.js already re-exports the canonical deferred. Co-Authored-By: Claude <[email protected]>
The committed-row skip predicate compared text alone, so a distinct earlier run that produced byte-identical reply text suppressed the new run's genuine abort-marked partial. Read the terminal row's stored __openclaw.runId alongside its text and skip only when both match the aborted run; rows without an attached identity fail open so the abort record survives. Co-Authored-By: Claude <[email protected]>
c4bc264 to
d96e279
Compare
|
Thanks @ruel225! Proof: On exact current-main baseline
Example
|
…2123) Prevent accepted late aborts from duplicating same-run final replies when synchronous transcript writers bypass the process queue. Co-authored-by: ruel225 <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Refs #131711.
A run can commit its final assistant reply while its live Gateway buffer still holds the same text. If a late abort is accepted before lifecycle cleanup clears that buffer, abort persistence writes the completed reply again as a
gateway-injectedabort partial.Why This Change Was Made
Abort persistence now checks the newest committed assistant row after the SQLite write transaction begins. It skips the append only when both the stored run identity and normalized reply text match the aborted run.
The commit-edge check matters because embedded and worker terminal writers can write synchronously without the process-local writer queue. A queue-level check could read stale state, then append after a terminal row committed.
Text equality alone is not enough. A different run can produce the same text, and a legacy row can have no stored run identity. Both cases still preserve the real abort partial.
This is complementary to #131949. That PR closes one late-abort admission window at the reply-operation owner. This PR keeps the shared persistence boundary idempotent for accepted aborts from RPC,
/stop, and placement abandonment.User Impact
Operators keep one durable copy of a completed reply when a late abort arrives during delayed settlement. Genuine partial replies from another run still remain in history.
Evidence
Real isolated Gateway red/green proof
The same source-lane scenario used a loopback Responses provider, an isolated Gateway, a real SQLite transcript, and a context-engine gate that held post-turn settlement after the final reply committed. The test observed the reply on the Gateway chat stream, confirmed the committed row carried the same run ID, called
chat.abort, closed SQLite handles, and reopened the transcript.5d3bd15130a28e293b9bbeee61c84dd0f6c162bf: failed with two matching assistant rows after abort.d96e279fec13ea0e954eca1641ee91ea1a90f969: one matching durable row before abort, one after abort, zero abort-marked duplicates, and one row after reopening SQLite.{"runId":"pr132123-proof-run","replyVisible":true,"waitBeforeAbort":"timeout","durableRowsBeforeAbort":1,"abort":{"ok":true,"aborted":true,"runIds":["pr132123-proof-run"]},"durableRowsAfterAbort":1,"abortMarkedRowsAfterAbort":0,"reopenedRows":1,"reopenedAbortMarkedRows":0}Focused regression coverage
Judged line count: production
+69/-2; tests+618/-0. The production growth adds one synchronous commit predicate and the durable run-identity reader. The repair commit removes the contributor branch's earlier queue-level reader and predicate plumbing, so the final path has one transaction-owned decision.