Skip to content

fix(sqlite): unblock Windows cleanup after state shutdown - #146160

Merged
steipete merged 2 commits into
mainfrom
codex/sqlite-coordinator-retirement
Sep 12, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/sqlite-coordinator-retirement

Conversation

@steipete

@steipete steipete commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Related: #145634

What Problem This Solves

Resolves a problem where Windows cleanup can fail after explicit state shutdown because a pooled coordinator handle remains open. In the Gateway archive-race fixture, removing its temporary home stalls on the coordinator lock file and times out after 120 seconds.

Why This Change Was Made

Explicit state retirement now consumes and closes its idle coordinator through the existing acquisition and release owner. Active same-process owners retain their lock until the final normal release, and pooling eligibility is recalculated after an authority callback can select a caller-owned path.

The package-exit regression now exercises an actual child process exit and required lease reacquisition, replacing a test-order-dependent choice of process exit listener. Its fixture closes state before deleting the directory.

User Impact

Explicit retirement releases idle coordinator resources; caller-owned runtime locations and temporary or relocated homes can be removed once all active owners release. Ordinary writes retain their existing idle coordinator reuse, and active same-path or unrelated owners keep their locks.

Evidence

  • Both idle/held retirement regressions fail on the original source because the native coordinator remains open, then pass with the fix. Active same-path and unrelated peers stay excluded until their owning releases.
  • All three warm-destination callback cases fail before the callback repair and pass afterward: runtimeDirectory, coordinatorPath, and keepAlive. They now extend the existing idle-eligibility test; its final suite passed 15 tests with three existing platform skips.
  • Shared-state retirement (13 tests), package adoption (8 tests), and the related coordinator suites passed. Existing platform skips were preserved; overlapping reruns are not added to these counts.
  • The original, unchanged Gateway test, retries Gateway visitation when a peer archives after async restoration, passed on Windows with Node 26.8.2 in 11.129 seconds under its existing 120-second budget, including all body assertions and fixture cleanup.
  • The child-exit lease test passed in 2.617 seconds. Temporarily omitting exit registration makes it fail on required reacquisition after the child reaches its expected exit code 23; the mutation was restored before validation.
  • Core production, state/session test, and infra test type graphs; scoped type-aware lint; formatting; and transaction/schema guards passed. Earlier full-source conflict-marker and ratchet guards passed before the callback/test follow-up.
  • Initial independent P0–P2 review and fresh independent review of the callback/test delta both passed. The delta was reviewed in a task-owned Linux checkout with a byte-identical patch after Windows source-snapshot memory failures. Only a retirement-comment wording correction followed review; the reviewed production and test bytes remain unchanged.

Exact-head hosted CI remains the landing gate. No schema, config, data migration, or transaction-boundary change is involved.

@clawsweeper

clawsweeper Bot commented Sep 12, 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.

@steipete
steipete marked this pull request as ready for review September 12, 2026 16:02
@openclaw-barnacle openclaw-barnacle Bot added size: S maintainer Maintainer-authored PR labels Sep 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 12, 2026
@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 12, 2026, 1:31 PM ET / 17:31 UTC (Revision 3).

ClawSweeper review

What this changes

The PR closes pooled SQLite coordinator handles after explicit state shutdown while preserving active locks, and strengthens callback and process-exit regression tests.

Merge readiness

✅ Ready for maintainer review

This repair remains necessary on current main. The prior callback-ordering finding is resolved, and this review found no remaining actionable correctness defects.

Priority: P2
Reviewed head: 7677a8a54b3d996730a49a4506d8a422ae01deb5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with relevant Windows validation, meaningful regressions, and no remaining actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The external-contributor gate does not apply to this maintainer-authored PR. Its reported Windows archive-race run exercises real SQLite retirement and temporary-home removal, with focused native-lock and child-exit regressions as supporting evidence; no authority boundary is changed.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor gate does not apply to this maintainer-authored PR. Its reported Windows archive-race run exercises real SQLite retirement and temporary-home removal, with focused native-lock and child-exit regressions as supporting evidence; no authority boundary is changed.
Evidence reviewed 7 items Current main still needs the retirement repair: Current main acquires the retirement coordinator without disabling pooling. Its coordinator owner retains eligible connections after release, so explicit state closure can leave the native coordinator open.
Prior callback finding resolved: After assertCurrent returns, acquisition recomputes all three pooling conditions, including keepAlive. The expanded existing test prepares the destination first and covers runtimeDirectory, coordinatorPath, and keepAlive changes.
Native custody and exclusion coverage: The idle and held retirement cases inspect real native connections, verify closure and unlink, and check that same-path and unrelated competing connections remain excluded until their owners release.
Findings None None.
Security None None.

How this fits together

OpenClaw’s shared-state lifecycle uses SQLite coordinator connections to serialize database operations across processes. Their release policy determines when locks end and when Windows can remove the surrounding files.

flowchart TD
  A[State writes or shutdown] --> B[State lifecycle coordinator]
  B --> C[Acquire existing or fresh connection]
  C --> D[Perform protected operation]
  D --> E{Last active owner released?}
  E -->|No| F[Preserve active lock]
  E -->|Yes| G{Retirement requested?}
  G -->|Yes| H[Close native connection]
  G -->|No| C
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +24, Tests +85. Total +109 across 6 files.

View PR surface stats
Area Files Added Removed Net
Source 3 35 11 +24
Tests 3 142 57 +85
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 177 68 +109

Review metrics

Metric Value Why it matters
Production versus test growth Production +24 net lines; tests +85 net lines Production growth carries retirement intent through existing owners; test growth covers native closure, callback changes, and actual process exit.

Technical review

Best possible solution:

Keep ordinary coordinator reuse while making explicit retirement release native handles through the existing lifecycle owner after its final active reference.

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

Yes, from source: warm a default coordinator, explicitly close its state database, and inspect the retained native handle before removing its Windows home. The PR reports matching Windows validation; this review did not execute it.

Is this the best way to solve the issue?

Yes. The patch repairs release policy in the existing coordinator owner, preserves reference-counted exclusion, and adds no schema, persisted setting, or parallel cleanup mechanism.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This fixes a bounded Windows cleanup failure after explicit state shutdown without evidence of a broader runtime outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit 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 external-contributor gate does not apply to this maintainer-authored PR. Its reported Windows archive-race run exercises real SQLite retirement and temporary-home removal, with focused native-lock and child-exit regressions as supporting evidence; no authority boundary is changed.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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-09-12T16:10:05.361Z sha abe57e5 :: blocked before merge. :: [P2] Recompute pooling eligibility after the authority callback
  • reviewed 2026-09-12T17:22:34.766Z sha 7677a8a :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added 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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 12, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

Addressed the callback-ordering finding in 7677a8a54b3d996730a49a4506d8a422ae01deb5. Pooling eligibility is now recomputed after the authority callback, including keepAlive !== false. The existing idle test now prepares the destination file first and covers changes to runtimeDirectory, coordinatorPath, and keepAlive; all three cases fail before the repair and pass afterward.

The exposed CI listener-order assumption is also fixed: the package lease test now uses an actual child exit (code 23), then requires immediate lease reacquisition. Omitting exit registration makes that proof fail. Fixture cleanup closes SQLite before deleting its directory.

Local affected suites, three type graphs, scoped lint, and independent delta review pass. The unchanged Windows Gateway archive-race case passes in 11.129 seconds under its original 120-second budget. Current-head CI is running.

@clawsweeper

clawsweeper Bot commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete
steipete merged commit 147e8db into main Sep 12, 2026
190 of 192 checks passed
@steipete
steipete deleted the codex/sqlite-coordinator-retirement branch September 12, 2026 17:37
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 13, 2026
…46160)

* fix(sqlite): unblock Windows cleanup after state shutdown

* fix(sqlite): preserve callback-time coordinator cleanup
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