Repository navigation
fix(sessions): release reconcile lease before terminal state (#130161) - #130185
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 9:22 AM ET / 13:22 UTC. ClawSweeper reviewWhat this changesThis PR makes the deferred transcript-reconciliation worker close its cached agent database and release its durable lease before telling its parent that reconciliation succeeded or failed. Regression provenancePossible regression — probable (reproduction; reviewed change; known regression link). No predecessor PR is attributed. Merge readinessKeep open: current main still exposes the terminal message before worker cleanup, while this exact head moves durable lease release ahead of that boundary and adds a real-Worker regression test for both outcomes. No patch defect found; required exact-head CI is still running. Likely related people: Peter Steinberger (high confidence). Priority: P2 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherDeferred transcript reconciliation prepares database-backed index updates in a Node worker, then sends a terminal result to its parent coordinator. The parent terminates the worker after that result, so the worker-owned lease must be released before the terminal handoff. flowchart LR
A[Dirty transcript index] --> B[Reconciliation worker]
B --> C[Agent database and lease]
C --> D[Close database and release lease]
D --> E[Terminal result]
E --> F[Parent coordinator]
F --> G[Worker termination]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +10, Tests +206. Total +216 across 2 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Copy recommended automerge instructionTechnical reviewBest possible solution: Retain the single cleanup-before-terminal handoff in the worker and the real-Worker regression covering both successful and failed reconciliation. Do we have a high-confidence way to reproduce the issue? Yes. The PR body supplies a deterministic current-main real-Worker reproduction using a cleanup fence, and the inspected source shows the terminal message precedes the close on current main. Is this the best way to solve the issue? Yes. Moving the cleanup to the worker immediately before its terminal publication repairs the owner boundary without weakening the parent's required termination behavior. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9bd50c803cce. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (2 earlier review cycles)
|
…w#130161) The parent terminates transcript reconcile workers when it receives a terminal result. Release the worker-owned database lease before crossing that terminal boundary. Co-authored-by: Grynn <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
e880c20 to
062bbde
Compare
|
Thanks @sunlit-deng! Credit to @Grynn for the original report and patch. Proof: On exact current main, real Worker success and failure runs both left one lease visible to an independent process after the parent settled. On exact PR head
Example
|
…w#130185) A terminal transcript-reconciliation result must mean the Worker has already released its durable agent-database lease. This keeps later database lifecycle operations from seeing stale live-looking ownership. Co-authored-by: sunlit-deng <[email protected]> Co-authored-by: Grynn <[email protected]> Co-authored-by: Ayaan Zaidi <[email protected]>
What Problem This Solves
Fixes a lifecycle race where the deferred transcript-reconciliation Worker could publish
doneorfailedbefore releasing its durable agent-database lease. The parent immediately terminates the Worker after either terminal message, so the lease row could remain until the Gateway process exited.Fixes #130161
Why This Change Was Made
The Worker now computes one terminal result, closes its cached agent database, releases the durable lease, and then publishes that result. Success and failure use the same cleanup-before-terminal path. A cleanup failure cannot publish a false cleanup-complete result.
User Impact
Deferred transcript reconciliation no longer leaves active-looking lease metadata that can block later agent-database lifecycle work.
Evidence
mainat9bd50c803cce88f2ab387ddaf6cc29b4ef004005, bothdoneandfailedreached the parent while lease cleanup was fenced. The parent settled immediately. An independent process still found one lease, and a real retry/open succeeded but left that lease present.062bbded12ec99e0247c9af9c6b7b5854f6d677a, neither terminal result reached the parent while cleanup was fenced. After cleanup, an independent process found zero leases, passed the no-open-lease check, reopened and closed the agent database, and still found zero leases. Bothdoneandfailedpaths passed.node scripts/run-vitest.mjs run src/config/sessions/session-transcript-reconcile.lifecycle.test.ts— 2 passed.node scripts/run-vitest.mjs run src/config/sessions/session-accessor.sqlite-active-events.test.ts src/config/sessions/session-accessor.sqlite-message-cut.test.ts— 38 passed.node scripts/run-vitest.mjs run src/state/openclaw-agent-db.test.ts -t 'closes only the cached database|retains its durable lease'— 2 passed.AI-assisted: built with Codex