Skip to content

fix: prevent transcript writes racing reclamation shutdown - #147178

Merged
steipete merged 1 commit into
mainfrom
codex/fix-reclamation-close-admission-20260913
Sep 13, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/fix-reclamation-close-admission-20260913

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Related: #130741

What Problem This Solves

Fixes foreground transcript writes racing a retained cleanup worker's shutdown when the worker retires or switches databases.

User Impact

Session writes wait for cleanup shutdown to finish before accessing the same database, preserving their existing FIFO order.

Why This Change Was Made

Native SQLite close can perform writes. Route the retained worker's close through the existing per-agent write queue, keep the worker alive while queued, and hold its reservation until actual worker exit. Exact lease cleanup still happens after exit.

Evidence

The real database-switch regression failed on the original code: close dispatched before the preceding foreground write released admission, and the following write ran before native exit. The fixed order is foreground release, close dispatch, worker exit, then the following write.

Six native retirement cases passed on the rebased commit covering database switching, path/root retirement, idle shutdown, crashes, and exact lease receipts. Before the patch-identical rebase, the complete 30-command changed-file check plan had passing evidence across its initial prefix, the corrected Node Worker transfer-list lint call, and the eight remaining guards. Independent review found no actionable P0–P2 findings. The rebase onto current main preserves the exact two-file patch and excludes the separate live-fixture changes.

One earlier broader local run passed 26 cases and failed one during shared-state database opening with SQLITE_BUSY while selecting rollback journal mode. The blocking peer and journal-policy input were not captured; that failure remains unresolved and is not claimed repaired here. End-to-end Swarm performance verification continues separately.

Exact-head CI passed after one targeted failed-job rerun. The initial attempt timed out while terminating a Logbook test fork after all assertions passed. A bounded Linux diagnostic then passed the full 27-file, 360-test shard and observed every test fork exit; it did not reproduce or explain the original timeout.

@steipete
steipete marked this pull request as ready for review September 13, 2026 16:31
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Sep 13, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 12:38 PM ET / 16:38 UTC.

ClawSweeper review

What this changes

Serializes cleanup-worker shutdown with transcript writes and extends the database-switch regression to verify ordering through native worker exit.

Merge readiness

✅ Ready for maintainer review

The fix remains necessary on current main. The patch preserves the existing ownership model, and no blocking correctness or security findings were identified.

Priority: P2
Reviewed head: 5087a5e99e29ca16b850b30b2f7b4b6b16a6c275

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful native regression coverage and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply. Supplemental evidence exercises production reclamation with real Node workers and SQLite, checking foreground release, close dispatch, native exit, and the surviving transcript write.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply. Supplemental evidence exercises production reclamation with real Node workers and SQLite, checking foreground release, close dispatch, native exit, and the surviving transcript write.
Evidence reviewed 9 items Introduced scope: The verified merge-base-to-head patch changes only reclamation shutdown and its existing database-switch regression. The host-verified test merge preserves unrelated base-branch changes.
Current main still needs the fix: Current main dispatches close and awaits exit without reserving the per-agent writer queue. The proposed shutdown reservation is absent.
Existing queue owns serialization: The worker reservation uses the existing FIFO and prevents inherited foreground callbacks from reentering while native work holds it. Shutdown waits for active request settlement, reserves that queue through native exit, and retains exact lease cleanup afterward.
Findings None None.
Security None None.

How this fits together

Session reclamation removes obsolete session data using a retained SQLite worker. Its shutdown shares the agent database with foreground transcript writes, so both must coordinate through the same write queue.

flowchart TD
  A[Foreground transcript writes] --> C[Per-agent write queue]
  B[Cleanup worker retirement] --> C
  C --> D[Dispatch worker close]
  D --> E[SQLite cleanup and native exit]
  E --> F[Resume queued writes]
  E --> G[Release exact worker lease]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +13, Tests +104. Total +117 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 16 3 +13
Tests 1 106 2 +104
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 122 5 +117

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +13 net lines; tests +104 net lines Production growth adds shutdown settlement to the existing queue; the larger test extension checks native ordering and persisted transcript survival.

Technical review

Best possible solution:

Keep worker shutdown inside the existing per-agent FIFO through native exit, preserving exact lease cleanup and transcript ordering.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: switching databases can dispatch native cleanup outside foreground write admission on current main. The real-worker regression encodes that ordering failure; this review did not execute it.

Is this the best way to solve the issue?

Yes. Reusing the existing worker reservation fixes the lifecycle owner without introducing another queue, changing stored data, or weakening current-authority checks.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b076a15e5103.

Labels

Label changes:

  • add P2: This fixes a concrete, bounded race between retained-worker retirement and foreground database writes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply. Supplemental evidence exercises production reclamation with real Node workers and SQLite, checking foreground release, close dispatch, native exit, and the surviving transcript write.

Label justifications:

  • P2: This fixes a concrete, bounded race between retained-worker retirement and foreground database writes.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply. Supplemental evidence exercises production reclamation with real Node workers and SQLite, checking foreground release, close dispatch, native exit, and the surviving transcript write.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 7ab5077 adds src/config/sessions/session-accessor.sqlite-reclamation-worker.ts:327 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 7ab507770f3d; files: src/config/sessions/session-accessor.sqlite-reclamation-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.

@steipete
steipete merged commit fe625db into main Sep 13, 2026
388 of 390 checks passed
@steipete
steipete deleted the codex/fix-reclamation-close-admission-20260913 branch September 13, 2026 17:53
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 13, 2026
* commit '201f11afefdb19a9c75e9d3542bf7425c80df7a7': (141 commits)
  fix: keep catalog discovery scoped and execution lazy (#147159)
  fix: serialize reclamation worker shutdown with foreground writes (#147178)
  test(sessions): cover abrupt committed transcript recovery (#143984)
  fix: stop transcript storms during context overflow recovery (#147202)
  fix: reduce CPU overhead for small history and usage reads (#147205)
  fix: resume tasks after tools finish and the model times out (#147203)
  refactor(scripts): share SQLite reliability message waits (#146900)
  feat(exec): configure approval reviewer thinking and fastMode (#147192)
  test: remove redundant Bonjour module headers (#146981)
  refactor: share streaming media tail boundary update (#146989)
  refactor(tui): classify resume candidates once (#146983)
  improve: skip unused toast dismissal work (#147196)
  fix(linux): recover saved remote connections without replacing active sessions (#146047)
  fix: doctor stays silent when Windows state dir is under OneDrive (#123720)
  feat: announce successful Daybreak retries (#147146)
  feat(code-mode): reuse results across code cells (#147154)
  refactor(test): reuse CLI plugin fixture writer (#147186)
  test: skip unused compiler setup in routing fixtures (#147194)
  test: reuse LINE webhook runtime fixture (#146710)
  fix(code-mode): check automation and process result types (#147143)
  ...
vincentkoc added a commit that referenced this pull request Sep 13, 2026
* commit '2d87daf04b78992382299d552f15ac84a86a23ed': (1815 commits)
  fix(ui): distinguish tool activity with semantic icons (#147207)
  fix(linux): recover completed Quick Chat replies without resending (#146048)
  feat(desktop): unify Tauri title bar and window controls (#147097)
  refactor(test): share plugin fixture server shims (#147225)
  perf(gateway): defer worker workspace execution imports (#143496)
  fix(gateway): post-ack webhook work fails with "Async work scope is closed" (#144801)
  refactor(scripts): centralize upgrade survivor version floors (#146975)
  fix(ci): check publication registries before FRV fanout (#147184)
  fix(qa): align system-agent delegation with channel contracts (#145905)
  improve: reduce repeated chat message identity work (#147210)
  fix(channels): remove stale pre-tool previews from Slack and Telegram (#147106)
  fix: keep catalog discovery scoped and execution lazy (#147159)
  fix: serialize reclamation worker shutdown with foreground writes (#147178)
  test(sessions): cover abrupt committed transcript recovery (#143984)
  fix: stop transcript storms during context overflow recovery (#147202)
  fix: reduce CPU overhead for small history and usage reads (#147205)
  fix: resume tasks after tools finish and the model times out (#147203)
  refactor(scripts): share SQLite reliability message waits (#146900)
  feat(exec): configure approval reviewer thinking and fastMode (#147192)
  test: remove redundant Bonjour module headers (#146981)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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.

1 participant