Skip to content

fix(workboard): stop SQLite descriptor leaks on plugin reload - #122146

Merged
obviyus merged 4 commits into
openclaw:mainfrom
NianJiuZst:codex/issue-121592
Sep 5, 2026
Merged

obviyus merged 4 commits into
openclaw:mainfrom
NianJiuZst:codex/issue-121592

Conversation

@NianJiuZst

@NianJiuZst NianJiuZst commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #121592

What Problem This Solves

Fixes an issue where operators reloading Workboard would accumulate SQLite file descriptors in the running Gateway. The SQLite factory returned a close callback, but the Workboard store discarded it and registered no resource cleanup.

Why This Change Was Made

Workboard now retains that callback and connects each store to the existing registry-retirement lifecycle. Its store runtime joins admitted Gateway calls, tools, terminal hooks and background work before closing the old connection. New operations on a closed store fail explicitly. Session reset/delete does not close the process-wide store.

The existing mutation queue and change tracker now share that lifetime owner. Unowned Gateway/tool fallback stores are removed. Existing command draining, registry cache eviction, native compare-and-swap methods and request/lifecycle authority remain unchanged. Current-main keyed collection reads are preserved.

No schema, stored representation, retention or operator configuration changes.

User Impact

Normal Workboard reloads no longer grow descriptors linearly. Fresh stores still support create, read, update, comment, move and delete. An admitted start request can record its outcome after replacement without closing the live successor.

Evidence

Current candidate: 0b22be085f1dad5966a33349f0e582469ce1f622.
Packaged product-tested head: 87a99e6e0fc161f202caf872aaf3cee13c55e047.
Main baseline: 325426c75fc7303cae45880b835dcd28807af4a1.
Integrated main: f19b43e46f91c1788597264cb4cbc35e0a17f2ff.

Real product proof used a normally enabled bundled Workboard in an installed package, in an isolated secretless Linux container on Node 24.20.0. The driver used the shipped CLI/Gateway methods, config.get revision hashes, supported config.patch updates and actual hot-reload completion. Only that Gateway PID's own Workboard database/WAL/shared-memory descriptors were measured.

Scenario Main Repaired head
Three normal disable/re-enable cycles Active totals grew 5 → 7 → 9 → 11 Active totals stayed 5 → 5 → 5 → 5
Retired connection Its WAL descriptor remained Its WAL descriptor disappeared after cleanup
Two repeated overlaps with a live successor Not claimed for baseline Each peaked at 7, settled at 6, then disabled at 5; no growth on repetition
Card operations and retained data Passed Passed before/after reload, session reset/delete and both overlaps
In-flight start across replacement Recorded failure Both cases recorded a blocked card, failure notice and cleared claim; fresh successor operations passed while the old request was paused

The in-flight input was a supported repository worktree setup script that waited for release, then exited 23. No model or channel credentials were needed. The same Gateway PID and process instance remained alive throughout every measurement.

Descriptor interpretation and retained failed attempt

An initial zero-total-descriptor assertion was incorrect for this topology. Prepared-model discovery holds a separate non-activated registry/store. SQLite deliberately retains and reuses database descriptors from closed connections while another connection holds POSIX locks; closing those descriptors directly would disturb that other connection.

This was verified with a separate native dependency experiment and the exact Node 24.20.0 close implementation and SQLite 3.53.4 Unix close contract. The native experiment is dependency evidence, not the Workboard product proof.

The final, uninstrumented product proof requires each retired WAL descriptor to disappear, the identified successor and unretired registry WAL descriptors to remain, and repeated fixed-concurrency sequences to stay bounded. It does not claim zero total descriptors or rely on garbage collection/process exit.

Test-only CI recovery

The candidate adds only the already-landed acquisition fixture from
0d830e9e74488c1ee5a3af461b147cb683f0581f (#136146) on top of the product-tested
head. This is an exact one-file port, not an import of that commit's broader
Gateway changes. Its new helper dependencies already match.

All production, dependency and package inputs remain identical, so the complete
installed Workboard proof above is retained without rebuilding or replaying it.
The fresh acquisition run passed all 29 cases, including the previously failing
GatewayClient authentication/rejected-shutdown case. Socket closure, server
ownership and selector assertions are unchanged. The fixture isolates and joins
the deliberately retained raw-close cases.

The failure in CI run 33927539775
is preserved. Its precise close-order cause is not claimed proven by this port.
Fresh exact-head CI run 33931014430
passed, including checks-node-compact-large-1, and the fresh independent review
passed. The old merge input was not rerun.

Checks

  • Regression red: both real SQLite-backed registration/CLI retirement cases failed before the repair.
  • Integrated head: 355 Workboard backend tests, 53 host lifecycle controls and five doctor-contract tests passed.
  • Full changed gate passed: both type lanes, all ratchets/boundaries/storage guards, import-cycle checks and lint across 8,991 plugin files.
  • Canonical package build, package inventory/import-graph integrity and installed CLI checks passed.
  • git diff --check passed.
  • Test-only recovery head: all 29 acquisition cases and its full changed core-test gate passed.
  • Workboard production +286/-211 (net +75); tests +274/-0. The added behavior is the missing resource lifetime and complete-operation drain; a close-only or mutation-queue-only fix would interrupt compound requests. The acquisition port adds +215/-83 test lines already present on main, with zero production changes.

Focused commands:

node scripts/run-vitest.mjs extensions/workboard src/plugins/plugin-command-runtime.test.ts src/plugins/runtime.test.ts src/plugins/loader.runtime-registry.test.ts src/plugins/host-hook-cleanup-timeout.test.ts
node scripts/check-changed.mjs --base origin/main --head HEAD
node scripts/package-openclaw-for-docker.mjs --allow-unreleased-changelog --output-dir <package-output> --output-name openclaw-candidate.tgz
node product-proof.mjs <installed-openclaw.mjs> <fresh-proof-directory> fixed
node scripts/run-vitest.mjs src/gateway/test-helpers.acquisition.test.ts
node scripts/check-changed.mjs -- src/gateway/test-helpers.acquisition.test.ts

Review dispositions and scope

Both ClawSweeper rank-up moves are addressed: a semantic current-main port and actual packaged SQLite lifecycle proof. The submitted generic registry changes are omitted because current main already owns cache eviction and command draining. The old registration test-helper path is not an executable test; current loader/runtime/command controls were run instead.

The September 4 23:48 UTC review found no patch defect and judged product proof
sufficient, but could not fetch the native explanatory sources. The retained
Node source at lines 1030–1036 and 1431–1440 finalizes statements and invokes
sqlite3_close_v2; SQLite's Unix source at lines 1244–1255 and 2338–2371 explains
and implements deferred file-descriptor close while another connection holds
locks. Fresh upstream reads matched both retained complete sources. Both were
supplied directly to the fresh independent review, which passed all 11 passes
on 0b22be085f1dad5966a33349f0e582469ce1f622 with no findings at LandPR's required
P0 threshold. The review included 588 complete evidence artifacts.

This resolves the review's source-inspection request and its associated decision:
the native contract was checked, not waived or accepted unchecked. No replacement
contributor product proof or change to another registry's lifetime was needed.

Named follow-ups remain separate: generic registration rollback drops runtime cleanup callbacks, and non-activating prepared-runtime discovery eagerly opens its own store. Installed failing-plugin and acquisition-stack diagnostics are retained. This PR does not redefine another registry's lifetime or claim to repair generic rollback.

The original contribution by @NianJiuZst remains in ancestry and retains primary credit. AI-assisted.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@clawsweeper clawsweeper Bot added merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. 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 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 4, 2026, 7:48 PM ET / 23:48 UTC.

ClawSweeper review

What this changes

The PR gives each Workboard registration ownership of its SQLite connection, drains admitted operations before closing it, removes unowned fallback connections, and adds lifecycle regression tests.

Merge readiness

⛔ Blocked before merge - 3 items remain

This remains a useful fix: current main and v2026.9.1 still discard Workboard's SQLite cleanup callback. No introduced blocking defect was found, and the packaged behavior proof is sufficient; independent verification of the cited native descriptor-retention explanation remains a reviewer-side limitation.

Priority: P2
Reviewed head: 87a99e6e0fc161f202caf872aaf3cee13c55e047
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent ownership repair with strong packaged behavior evidence and no blocking code finding; the reviewer-side native inspection limitation does not reduce its quality rating.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The captured installed-package CLI/Gateway evidence exercises the changed retirement owner through real hot reloads, shows bounded descriptors and retired WAL disappearance, and preserves card outcomes during overlapping successor operations; it is not merely unit-test or startup evidence.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured installed-package CLI/Gateway evidence exercises the changed retirement owner through real hot reloads, shows bounded descriptors and retired WAL disappearance, and preserves card outcomes during overlapping successor operations; it is not merely unit-test or startup evidence.
Evidence reviewed 11 items The defect remains on current main: WorkboardStore.openSqlite retains the four stores and dataVersion but omits close; the plugin registration still lacks the proposed runtime cleanup. The Workboard subtree has no changes between the pinned base and fetched main.
Latest supplied release still omits cleanup: The supplied v2026.9.1 release commit contains the same factory projection that discards close; this is not an already-shipped fix.
Canonical issue remains open: The supplied discussion identifies #121592 as the same discarded-cleanup defect and explicitly pairs this PR with it. That issue should remain open until an implementation lands.
Findings None None.
Security None None.

How this fits together

Workboard is OpenClaw's local task board. Dashboard requests, agent tools, commands, and session events use its SQLite store; replacing the plugin registry must retire that store without interrupting admitted work or closing its successor.

flowchart TD
  A[Dashboard requests and agent tools] --> B[Registration-owned Workboard store]
  C[Commands and session events] --> B
  D[Plugin registry replacement] --> E[Stop new work and drain admitted operations]
  B --> E
  E --> F[Close retired SQLite connection]
  D --> G[Independent successor store]
Loading

Decision needed

Question Recommendation
May this lifetime repair proceed on the recorded packaged Gateway evidence, or must the exact-version native descriptor-retention explanation be independently checked first? Accept the recorded product evidence: Accept the bounded reload and overlapping-successor results while treating the independently unchecked native explanation as ancillary.

Why: The source repair and product observations support the fix, but this worker cannot complete the applicable upstream inspection because the cited sources are unreachable.

Before merge

  • Resolve merge risk (P1) - The exact-version Node/SQLite explanation for retained database descriptors could not be independently inspected in this worker; this is a reviewer limitation, not missing contributor proof or a demonstrated patch defect.
  • Complete next step (P2) - Resolve the native-contract inspection limitation by independently checking the linked sources or explicitly accepting the recorded packaged evidence without that check.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source +75, Tests +274. Total +349 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 8 286 211 +75
Tests 2 274 0 +274
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 560 211 +349

Review metrics

Metric Value Why it matters
Production versus test growth Production net +75 lines; tests +274 lines The old tracker and queue are consolidated into the lifetime owner; remaining growth implements complete-operation draining that a close-only callback would not provide.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #121592
Summary: This PR is the candidate implementation for the linked open Workboard connection-lifetime 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. Decide the mitigation before merge
    Keep one registration-owned lifetime that absorbs the existing mutation queue and change tracker, drains complete admitted operations, and closes only its retired SQLite connection without changing stored data or configuration.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep one registration-owned lifetime that absorbs the existing mutation queue and change tracker, drains complete admitted operations, and closes only its retired SQLite connection without changing stored data or configuration.

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

Yes, from source: current main discards the factory cleanup callback, and repeated registry replacement is the supplied reproduction path. The captured packaged baseline supports that mechanism; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes. Repairing connection ownership at registration and draining whole operations preserves compound requests while reusing existing host retirement; no competing configuration path or storage migration is needed.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 66fa0bd2be4f.

Labels

Label justifications:

  • P2: This repairs accumulating SQLite resources during optional Workboard reloads without evidence of an immediate core-runtime outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured installed-package CLI/Gateway evidence exercises the changed retirement owner through real hot reloads, shows bounded descriptors and retired WAL disappearance, and preserves card outcomes during overlapping successor operations; it is not merely unit-test or startup evidence.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured installed-package CLI/Gateway evidence exercises the changed retirement owner through real hot reloads, shows bounded descriptors and retired WAL disappearance, and preserves card outcomes during overlapping successor operations; it is not merely unit-test or startup evidence.

Evidence

What I checked:

  • The defect remains on current main: WorkboardStore.openSqlite retains the four stores and dataVersion but omits close; the plugin registration still lacks the proposed runtime cleanup. The Workboard subtree has no changes between the pinned base and fetched main. (extensions/workboard/src/store.ts:640, 66fa0bd2be4f)
  • Latest supplied release still omits cleanup: The supplied v2026.9.1 release commit contains the same factory projection that discards close; this is not an already-shipped fix. (extensions/workboard/src/store.ts, ad6fe23aecb9)
  • Canonical issue remains open: The supplied discussion identifies Workboard SQLite store leaks connections on plugin-registry replacement #121592 as the same discarded-cleanup defect and explicitly pairs this PR with it. That issue should remain open until an implementation lands.
  • Lifecycle owner and operation drain: Registration cleanup closes only unscoped disable/restart events. The new runtime rejects fresh operations after closing starts, permits admitted nested work, joins outstanding operations, and retains a single cleanup promise. Gateway handlers, tools, terminal hooks, and reconciliation enter that owner. (extensions/workboard/src/store-runtime.ts:24, 87a99e6e0fc1)
  • Existing host retirement and sibling boundaries: The host already waits for registry-bound command executions before runtime cleanup and derives restart versus disable from the successor registry. The PR preserves that flow, native compare-and-swap methods, change notifications, and stopped-sweep generation checks rather than replacing host lifecycle policy. (src/plugins/runtime.ts:103, 87a99e6e0fc1)
  • Dependency gate applies to Node and SQLite, not Codex: The SQLite factory closes its maintenance handle and database; the SDK opener constructs node:sqlite DatabaseSync. The PR's descriptor interpretation additionally cites exact Node and SQLite implementations. No changed path or proof scenario requires a Codex harness or protocol contract. (extensions/workboard/src/sqlite-store.ts:1638, 87a99e6e0fc1)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Josh Lehman: 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 (6 earlier review cycles)
  • reviewed 2026-08-11T16:53:57.457Z sha cca5224 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-15T00:59:22.306Z sha cca5224 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-18T12:19:33.122Z sha cca5224 :: needs maintainer review before merge. :: none
  • reviewed 2026-08-25T05:58:24.264Z sha cca5224 :: needs changes before merge. :: none
  • reviewed September 1, 2026, 9:05 PM ET / September 2, 2026, 01:05 UTC sha unknown :: needs changes before merge. :: none
  • reviewed 2026-09-04T23:12:14.444Z sha 87a99e6 :: blocked before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 18, 2026
@obviyus

obviyus commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

The semantic current-main port is published at 87a99e6e0fc161f202caf872aaf3cee13c55e047. The PR body now records the actual packaged Gateway red/green, repeated in-flight successor controls, full checks, and the exact native SQLite descriptor interpretation. Both previous rank-up moves are addressed; the source contribution remains in ancestry.

@clawsweeper

clawsweeper Bot commented Sep 4, 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:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. merge-risk: 🚨 availability 🚨 May cause crashes, hangs, restart loops, stalls, or process outages. labels Sep 4, 2026
Port the acquisition test from 0d830e9 (openclaw#136146). Preserve socket-close, server ownership, and selector assertions while joining disposable workers for intentionally retained raw acquisitions.
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XL and removed size: L labels Sep 4, 2026
@obviyus
obviyus merged commit 7baae61 into openclaw:main Sep 5, 2026
192 checks passed
@obviyus

obviyus commented Sep 5, 2026

Copy link
Copy Markdown
Collaborator

Thanks @NianJiuZst!

Landed as 7baae61fa1f, preserving your primary credit and the original contribution's ancestry in the reviewed branch.

Proof: The installed Gateway stayed alive through supported Workboard reloads, fresh card operations and repeated in-flight successor overlap. Each retired WAL descriptor disappeared; fresh stores and recorded request outcomes remained usable.

  • Bug: Workboard discarded its SQLite close callback, so completed reloads accumulated handles.
  • Fix: Each registration owns its store lifetime and drains complete admitted operations before closing its own connection. Session cleanup does not close the active store.
Before After
Normal reload totals grew 5 → 7 → 9 → 11 Active totals stayed 5 across repeated reloads
Retired WAL handles remained Retired WAL handles closed; successor handles remained
No owned operation drain Fresh operations and recorded in-flight outcomes survived replacement

Validation: 413 Workboard/host/doctor tests, full changed checks, canonical package integrity and installed Gateway proof. The final test-only fixture port passed all 29 acquisition cases and its changed checks. Production/package inputs were unchanged, so the complete product proof was retained.

Exact-head CI 33931014430 passed on 0b22be085f1. Fresh independent LandPR review passed all 11 passes at the required P0 threshold. The latest ClawSweeper source-access limitation was resolved by checking the exact Node/SQLite sources and supplying both complete files to that review; no proof or CI exception was used.

The landed change contains only the ten Workboard files: production +286/-211 (net +75), tests +274. The acquisition fixture was already on main and adds no extra landed delta. Issue #121592 is closed. AI-assisted.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 5, 2026
…aw#122146)

Closes openclaw#121592.

Retain the Workboard SQLite factory's close callback and invoke it through the existing registry-retirement lifecycle. Drain admitted Gateway, tool and background operations before closing that registration's store. Keep session-only cleanup and successor stores usable.

Reuse current registry eviction and command-drain ownership. Preserve native compare-and-swap methods and current-main keyed collection reads. No schema, retention or operator configuration changes.

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

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. plugin: workboard proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XL 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.

Workboard SQLite store leaks connections on plugin-registry replacement

2 participants