Repository navigation
fix(gateway): stop run-end transcript reads once the Gateway drains or closes - #204544
Conversation
…r closes Since #204281 every run end reads its transcript through the row backfill without a close fence, so runs that end during shutdown reopened the sealed agent database after its clean-close receipt. Fence every backfill read in the function that opens the store. Co-authored-by: obviyus <[email protected]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR makes every optional session transcript backfill consume the Gateway’s existing drain and shutdown signals. Example: An active run finishes after the Gateway has begun shutdown.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Regression provenanceRegression provenance — verified: source commit Merge readiness✅ Ready for maintainer review Keep open: this collaborator-authored PR addresses a current-main shutdown regression with a focused shared-owner fix; source review found no introduced code defect. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherRun-end finalizers and session-row enrichment request bounded transcript facts through a shared reader, which reserves the database writer and dispatches a worker operation. flowchart TD
A[Run end finalizers] --> C[Shared transcript reader]
B[Session row enrichment] --> C
D[Gateway lifecycle signals] --> C
C --> E[Database writer admission]
E --> F[Transcript worker]
F --> G[Preview and activity facts]
Technical reviewBest possible solution: Keep the shutdown check in the shared backfill reader, retain queue scheduling checks, and let the existing database owner settle accepted work. Do we have a high-confidence way to reproduce the issue? Current main’s run-end helper reaches the backfill without cancellation, while the earlier shutdown check depends on a caller-supplied signal; the reported restart assertion matches this path, but this read-only review executed no target code. Is this the best way to solve the issue? The patch is the smallest complete source repair: it applies existing lifecycle policy at the shared operation and removes the superseded caller argument without adding another owner or changing worker settlement. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against ca33faf055fd. Provenance checked
TestingProof path: none. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +5. Total +5 across 2 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 24, 2026, 4:42 AM ET / 09:42 UTC. |
…r closes (#204544) ## Problem During a Gateway restart or stop, a run that ends after the agent database's clean-close receipt can reopen the sealed store. `test/gateway-restart-resume.e2e.test.ts` ("restart markers survive graceful shutdown (blocked store: false)") catches it: a `session.rowTranscript.backfill` reservation starts after the clean-close (`expected true to be false` at the `[close-backfill-proof]` check). No scheduled CI lane runs this file. Cause: #204281 added `readVisibleSessionActivityAt`. Every run end calls it, and it uses `backfillSessionRowTranscriptFields` with no signal. #188976 fenced only the session-row projection queue. Shutdown aborts the active runs, those runs end, and each run end then opens the store again. ## Solution The drain and shutdown fence moves into `backfillSessionRowTranscriptFields`, the function that opens the store. Every caller gets it, including the run-end read. The `signal` parameter is removed, because its only caller (the projection queue) passed the same two signals. ## Impact - A run that ends while the Gateway drains or closes does not advance unread. The run-end read already treats a failure as "unread unchanged". Accepted edge case: a visible reply that lands during shutdown does not light the unread dot. - No change outside shutdown. - Production: +16 / −11 lines in 2 files. ## Evidence - Base (`main`), the same filtered case: the `[close-backfill-proof]` check fails in cycle 1. - Head: cycle 1 passes the check (a run free of a local port probe that sends `GET /` to new listeners and breaks the fixture's JSON parse). Unit tests `session-row-transcript-backfill.test.ts` (16) and `session-accessor.sqlite-maintenance-read.test.ts` (8) pass. `pnpm tsgo:core` passes. - The e2e case is still red on head, at a later step: in cycle 2, a queued input is cancelled at restart (`HANDLED_QUEUED_BEFORE_RESTART_2_1`). That failure also occurs on `57dd84bd`, before #204281, so it has a separate cause. It is tracked separately. Co-authored-by: Ayaan Zaidi <[email protected]> (cherry picked from commit 76e2021) Co-authored-by: RomneyDa <[email protected]>
…r closes (openclaw#204544) ## Problem During a Gateway restart or stop, a run that ends after the agent database's clean-close receipt can reopen the sealed store. `test/gateway-restart-resume.e2e.test.ts` ("restart markers survive graceful shutdown (blocked store: false)") catches it: a `session.rowTranscript.backfill` reservation starts after the clean-close (`expected true to be false` at the `[close-backfill-proof]` check). No scheduled CI lane runs this file. Cause: openclaw#204281 added `readVisibleSessionActivityAt`. Every run end calls it, and it uses `backfillSessionRowTranscriptFields` with no signal. openclaw#188976 fenced only the session-row projection queue. Shutdown aborts the active runs, those runs end, and each run end then opens the store again. ## Solution The drain and shutdown fence moves into `backfillSessionRowTranscriptFields`, the function that opens the store. Every caller gets it, including the run-end read. The `signal` parameter is removed, because its only caller (the projection queue) passed the same two signals. ## Impact - A run that ends while the Gateway drains or closes does not advance unread. The run-end read already treats a failure as "unread unchanged". Accepted edge case: a visible reply that lands during shutdown does not light the unread dot. - No change outside shutdown. - Production: +16 / −11 lines in 2 files. ## Evidence - Base (`main`), the same filtered case: the `[close-backfill-proof]` check fails in cycle 1. - Head: cycle 1 passes the check (a run free of a local port probe that sends `GET /` to new listeners and breaks the fixture's JSON parse). Unit tests `session-row-transcript-backfill.test.ts` (16) and `session-accessor.sqlite-maintenance-read.test.ts` (8) pass. `pnpm tsgo:core` passes. - The e2e case is still red on head, at a later step: in cycle 2, a queued input is cancelled at restart (`HANDLED_QUEUED_BEFORE_RESTART_2_1`). That failure also occurs on `c28cebe5`, before openclaw#204281, so it has a separate cause. It is tracked separately. Co-authored-by: Ayaan Zaidi <[email protected]>
Problem
During a Gateway restart or stop, a run that ends after the agent database's clean-close receipt can reopen the sealed store.
test/gateway-restart-resume.e2e.test.ts("restart markers survive graceful shutdown (blocked store: false)") catches it: asession.rowTranscript.backfillreservation starts after the clean-close (expected true to be falseat the[close-backfill-proof]check). No scheduled CI lane runs this file.Cause: #204281 added
readVisibleSessionActivityAt. Every run end calls it, and it usesbackfillSessionRowTranscriptFieldswith no signal. #188976 fenced only the session-row projection queue. Shutdown aborts the active runs, those runs end, and each run end then opens the store again.Solution
The drain and shutdown fence moves into
backfillSessionRowTranscriptFields, the function that opens the store. Every caller gets it, including the run-end read. Thesignalparameter is removed, because its only caller (the projection queue) passed the same two signals.Impact
Evidence
main), the same filtered case: the[close-backfill-proof]check fails in cycle 1.GET /to new listeners and breaks the fixture's JSON parse). Unit testssession-row-transcript-backfill.test.ts(16) andsession-accessor.sqlite-maintenance-read.test.ts(8) pass.pnpm tsgo:corepasses.HANDLED_QUEUED_BEFORE_RESTART_2_1). That failure also occurs on57dd84bd, before fix(sessions): unread advances only when a run ends with a new visible reply #204281, so it has a separate cause. It is tracked separately.