Skip to content

fix(sessions): release reconcile lease before terminal state (#130161) - #130185

Merged
obviyus merged 1 commit into
openclaw:mainfrom
sunlit-deng:sunlit/fix/issue-130161
Aug 27, 2026
Merged

obviyus merged 1 commit into
openclaw:mainfrom
sunlit-deng:sunlit/fix/issue-130161

Conversation

@sunlit-deng

@sunlit-deng sunlit-deng commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes a lifecycle race where the deferred transcript-reconciliation Worker could publish done or failed before 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

  • Real process proof used the production transcript persistence and reconciliation owners, a real Node Worker, and a real temporary agent SQLite database.
  • On current main at 9bd50c803cce88f2ab387ddaf6cc29b4ef004005, both done and failed reached 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.
  • On exact head 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. Both done and failed paths 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.
  • Targeted Oxfmt and type-aware Oxlint checks passed. Hosted CI owns the exact-head build and type checks.

AI-assisted: built with Codex

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot reopened this Aug 26, 2026
@clawsweeper clawsweeper Bot added 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. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 26, 2026
@clawsweeper

clawsweeper Bot commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 27, 2026, 9:22 AM ET / 13:22 UTC.

ClawSweeper review

What this changes

This 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 provenance

Possible regression — probable (reproduction; reviewed change; known regression link). No predecessor PR is attributed.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep 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
Reviewed head: 062bbded12ec99e0247c9af9c6b7b5854f6d677a

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) The repair is narrowly scoped, preserves the existing parent lifecycle policy, and is backed by a credible boundary-level proof.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body provides after-fix real-process evidence using the production reconciliation owners, a real Node Worker, a temporary SQLite agent database, and a cleanup fence for both terminal outcomes.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body provides after-fix real-process evidence using the production reconciliation owners, a real Node Worker, a temporary SQLite agent database, and a cleanup fence for both terminal outcomes.
Evidence reviewed 6 items Current-main race: Current main sends done or failed before its finally closes the agent database, while the parent coordinator terminates the worker on either terminal message.
Exact-head repair: The worker now records one terminal result, closes the cached database, then publishes the result; cleanup failure prevents a false terminal success or failure message.
Lease owner boundary: Closing a cached agent database synchronously closes the SQLite handle and deletes its durable lease row before returning.
Findings None None.
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs run src/config/sessions/session-transcript-reconcile.lifecycle.test.ts

Result: PASS (completed)

[test] starting test/vitest/vitest.runtime-config.config.ts

 RUN  v4.1.11 /tmp/clawsweeper-live-proof-130185-SjHUQo/target

 ✓  runtime-config  src/config/sessions/session-transcript-reconcile.lifecycle.test.ts (2 tests) 5344ms
     ✓ releases its database before reporting 'done'  3131ms
     ✓ releases its database before reporting 'failed'  2211ms

 Test Files  1 passed (1)
      Tests  2 passed (2)
   Start at  13:23:14
   Duration  12.30s (transform 5.40s, setup 54ms, import 6.60s, tests 5.34s, environment 0ms)

[test] passed 1 Vitest shard in 19.19s

Assertions:

  • PASS expect_output: releases its database before reporting
  • PASS expect_output: 2 passed

How this fits together

Deferred 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]
Loading

Before merge

  • Resolve merge risk (P1) - Required exact-head CI remains incomplete; merging should wait for those checks even though the source review found no correctness defect.
  • Resolve merge risk (P1) - The bug fix has a net production increase of 10 lines, which is justified by carrying one terminal result across the required cleanup boundary.
  • Complete next step (P2) - The open PR already owns the concrete repair; it needs normal exact-head CI completion rather than a separate repair job.
Agent review details

Security

None.

PR surface

Source +10, Tests +206. Total +216 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 14 4 +10
Tests 1 206 0 +206
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 220 4 +216

Review metrics

Metric Value Why it matters
Production versus test delta production +10, tests +206 The production increase is limited to preserving one terminal result across mandatory cleanup; the new test covers both terminal paths at the worker/database boundary.

Stored data model

Persistent data-model change detected: serialized state: src/config/sessions/session-transcript-reconcile.worker.ts. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #130161
Summary: This PR is a concrete candidate repair for the linked terminal-message and durable-lease ordering defect.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge-risk options

Maintainer options:

  1. Keep cleanup before terminal handoff (recommended)
    Merge after exact-head checks complete while retaining the tested ordering that releases the durable lease before the parent can terminate the worker.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Require the exact-head lifecycle regression and required checks to pass before merge.

Technical review

Best 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.

Labels

Label changes:

  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This is a bounded transcript and durable-lease lifecycle race with no reported data loss or core-runtime outage.
  • merge-risk: 🚨 session-state: The patch changes ordering around a durable agent-database lease and worker shutdown.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides after-fix real-process evidence using the production reconciliation owners, a real Node Worker, a temporary SQLite agent database, and a cleanup fence for both terminal outcomes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides after-fix real-process evidence using the production reconciliation owners, a real Node Worker, a temporary SQLite agent database, and a cleanup fence for both terminal outcomes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Commit 233ac85 introduced the deferred transcript-reconciliation worker path whose parent termination ordering is the relevant lifecycle boundary. (role: introduced deferred reconciliation behavior; confidence: high; commits: 233ac850f03c, 7d71d7cf6b3c; files: src/config/sessions/session-transcript-reconcile.ts, src/config/sessions/session-transcript-reconcile.worker.ts)

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 (2 earlier review cycles)
  • reviewed 2026-08-26T15:40:00.344Z sha e880c208e48b4c46d3d3e84cd39c6bc8f51e3c48 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-26T16:56:41.896Z sha e880c208e48b4c46d3d3e84cd39c6bc8f51e3c48 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added the merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. label Aug 26, 2026
…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]>
@obviyus
obviyus force-pushed the sunlit/fix/issue-130161 branch from e880c20 to 062bbde Compare August 27, 2026 13:15
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 27, 2026
@obviyus
obviyus merged commit 1404c4b into openclaw:main Aug 27, 2026
462 of 464 checks passed
@obviyus

obviyus commented Aug 27, 2026 •

Copy link
Copy Markdown
Collaborator

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 062bbded12ec, both terminal results waited for cleanup. An independent process found zero leases before and after reopening the database. The lifecycle test, exact-head CI, and final ClawSweeper review passed.

  • Bug: Deferred transcript reconciliation could report completion before its Worker released the durable agent-database lease. The parent then terminated the Worker and left active-looking lease state behind.
  • Fix: The Worker now closes its database and releases the lease before publishing either terminal result. Success and failure use the same cleanup path.

Example

Before After
A completed reconcile could leave one lease that still looked live. The terminal result arrives only after the lease count returns to zero.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
…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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: M 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.

[Bug]: Reconcile worker can be terminated before releasing its database lease

2 participants