Skip to content

fix: crashed SQLite store worker leaves no reason in logs or metrics - #163377

Open
sxh313 wants to merge 5 commits into
openclaw:mainfrom
sxh313:fix/sqlite-worker-exit-cause-163150
Open

sxh313 wants to merge 5 commits into
openclaw:mainfrom
sxh313:fix/sqlite-worker-exit-cause-163150

Conversation

@sxh313

@sxh313 sxh313 commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Closes #163150

What Problem This Solves

Fixes: when a SQLite store worker thread disappears, the worker lifecycle counters call it an
unattributed exit and the Gateway log says nothing, so an operator cannot tell a crash from a
retirement the broker asked for.

User Impact

User impact: a retirement the broker requested now shows its own reason (closed, or failure
when the slot had already failed) in the stability bundle's workerLifecycle, and a worker that
leaves without any request writes exactly one warning line naming its cause to the log file, so a
lost storage worker is diagnosable from the bundle and the log instead of only from a repro.

Why This Change Was Made

The lifecycle registry takes the retirement reason from whatever the worker's owner recorded
before native exit; without that record it falls back to exit, which
docs/gateway/prometheus.md already defines as "an owner did not specify a reason". The task-pool
owners do record it, the SQLite store worker owner never did, so every one of its retirements
landed in the fallback. Reasons are now recorded where this owner asks the worker to leave, and on
the error/messageerror events that precede native exit. A departure that no one requested has
no other witness, so it is logged once at warn; requested retirements stay silent because their
caller already reports the outcome. Nothing in the broker's failure path changed, and the log line
carries only the redacted error text.

Evidence

Failing test first, then the fix, on src/infra/sqlite-worker-broker-lifecycle.test.ts:

 FAIL  src/infra/sqlite-worker-broker-lifecycle.test.ts > SQLite worker slots > attributes a broker-requested retirement instead of an unattributed exit
AssertionError: expected +0 to be 1
    207|       await lifecycle.retire(slot);
  >  209|       expect(retirementCount("closed")).toBe(closedBefore + 1);

 FAIL  src/infra/sqlite-worker-broker-lifecycle.test.ts > SQLite worker slots > reports a worker that leaves on its own once, naming its cause
AssertionError: expected +0 to be 1
  >  253|     expect(retirementCount("failure")).toBe(failureBefore + 1);

After the change the same two tests pass, and they check both halves of the symptom against the
real registry and the real log-file transport: a retirement the owner asked for adds a closed
count and leaves exit unchanged, and a worker that throws on its own adds a failure count while
the log file holds one left without a retirement request line containing the cause text.

 TEST  src/infra/sqlite-worker-broker-lifecycle.test.ts
 ... > attributes a broker-requested retirement instead of an unattributed exit 87ms
 ... > reports a worker that leaves on its own once, naming its cause 178ms

Adjacent lanes, run locally with the same config:

 src/infra/sqlite-worker-broker.test.ts   Tests 10 passed, Duration 42.94s
 src/infra/worker-cpu.test.ts             Tests 7 passed with sqlite-worker-logging.test.ts,
                                          Duration 20.95s

Local gates: oxfmt --check clean on both files (28ms), run-oxlint.mjs on the core tsconfig
reported "Found 0 warnings and 0 errors" (68.1s), git diff --check clean, and
check-line-cap-ratchet.mts reported "Line-cap ratchet OK: 2 changed source files; no new
violations or over-cap growth". check-changed.mjs --dry-run listed the CI gates this diff
selects. Pre-commit hooks ran normally; no hook was skipped.

Cost of the new tests, per the repo validation rules: they add 87ms and 178ms inside a file whose
targeted run takes 26s with a warm transform cache and 212s cold on this machine. Neither test
sleeps, polls, or uses a wall-clock timer; they await the worker online event, the slot's own
exit promise, and flushLogger().

Gaps worth naming: the run was Windows, where the six pre-existing cases in this test file already
fail at fileURLToPath("file:///openclaw/...") with ERR_INVALID_FILE_URL_PATH before this
change and in code this diff does not touch, so those cases are covered here by CI's Linux infra
lane; the two new tests derive their carrier URL from import.meta.url so they run on both
platforms. pnpm tsgo:core refuses a worktree that shares its install with the main checkout
("Declaration input escapes checkout"), so the typecheck gate was not run locally and is left to
CI. No live Gateway was started on this machine; the log-line half is proven by reading the file
the file transport actually wrote.

CI on head e129273e8 (server-recorded base dbb580aed, which is 171 commits behind current main): 129 check runs = 67 success / 59 skipped / 1 neutral (CodeQL) / 2 failure. The two failures are checks-windows-node-test-5 (completed 2026-10-02T08:19:37Z) and the 2 s aggregate openclaw/ci-gate that follows it in the same run. The failing case is test/scripts/write-unified-entry-dts.test.ts > write-unified-entry-dts > reuses unaffected canonical groups while rebuilding runtime after input edits, and it throws ERR_PACKAGE_PATH_NOT_EXPORTED: Package subpath './record-coerce' is not defined by "exports" from a package.json inside that test's own temporary fixture project (%TEMP%\oc-vt-8AAiWh\openclaw-sdk-declarations-5DFbNf\Project\node_modules\@openclaw\normalization-core), imported from src/process/exec-result.ts in the same temp tree. This diff is two files, both src/infra/sqlite-worker-broker-lifecycle.*: it touches none of test/scripts/, packages/normalization-core/, or src/process/, and packages/normalization-core/package.json on this head does export ./record-coerce.

What is deliberately not claimed here: inheritance is not proven. That node-id was re-run in a clean detached worktree checked out at this PR's base commit dbb580aed, and it fails there too - but with a different, Windows-only error while the fixture links its compiler (EPERM: operation not permitted, symlink '..\typescript\bin\tsc' -> '...\Project\node_modules\.bin\tsgo'), so this machine's harness cannot exercise that fixture path and no local verdict about the CI error is available. For reference, the same checks-windows-node-test-5 check completed with success at 2026-10-02T15:23:03Z on unrelated head 5ce2d2d6 (#163594). No rerun, re-push, or rebase was dispatched to chase a green signal, per the repository's validation rules; naming this failure is offered so a maintainer can weigh it against the two lanes this change actually touches.

Record the retirement reason before terminating a store worker and log an
unrequested departure once with its cause, so worker lifecycle counters and
gateway logs say why a SQLite worker left instead of blaming a plain exit.

Closes openclaw#163150
@clawsweeper

clawsweeper Bot commented Oct 2, 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.

@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 Oct 2, 2026
@clawsweeper

clawsweeper Bot commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR attributes requested SQLite worker retirements and logs unexpected departures once with a redacted cause.

Example: A SQLite storage worker throws Error("sqlite carrier lost").

  • Before: Its retirement is counted as exit, with no dedicated departure warning.
  • After: Its retirement is counted as failure, and one warning includes sqlite carrier lost.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch appears correct and has useful regression coverage, but supplied evidence does not meet this review's shipped-behavior proof gate.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Operators cannot distinguish requested SQLite worker retirement from an unexpected departure using lifecycle counters and Gateway logs.
Reason: The original report establishes a concrete diagnostics contract, and the patch supplies it without changing storage or recovery policy.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR: current main retains the reported diagnostics gap, and the focused patch introduces no concrete correctness defect; GitHub reports a merge conflict.

Priority: P2
Reviewed head: fef42420d6b325d962604fe79f8d6284ca9179e0

Before merge

  • Add real behavior proof - The body and Patrick-Erichsen's qualification establish tests and native-worker harness coverage, including real file logging, but provide no shipped Gateway or CLI execution of the changed diagnostics; the existing proof label does not waive this gate, so the contributor should attach redacted logs or terminal output covering requested retirement and unexpected departure, omitting IPs, keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Complete next step - Resolve GitHub's reported merge conflict, preserving current-main lifecycle behavior and this PR's diagnostics.

Findings

None.

Tests

  • Missing end-to-end proof: Supply a shipped Gateway or CLI run showing requested retirement attribution and one redacted warning for an unexpected SQLite worker departure.
Agent review details

How this fits together

The SQLite broker lifecycle owns storage-worker creation and retirement, forwarding native events to failure settlement and publishing diagnostics through the existing worker registry and logger.

flowchart LR
  A[SQLite broker] --> B[Worker lifecycle]
  B --> C[Native storage worker]
  C --> D[Error and exit events]
  D --> B
  B --> E[Lifecycle counters]
  B --> F[Redacted warning log]
  B --> G[Failure settlement]
Loading

Technical review

Best possible solution:

Retain the focused diagnostic change in the existing lifecycle owner while preserving current-main admission, custody, and failure-settlement behavior.

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

Current-main lifecycle, registry, and failure-settlement source show why requested exits remain unattributed and unexpected departures lack a dedicated warning; no target code was executed.

Is this the best way to solve the issue?

The patch uses the existing retirement registry and redacting logger at the lifecycle owner, with meaningful native-worker regression coverage and no competing policy owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • SQLite lifecycle and failure preservation keeps the original intent (dd7d596: Retain the running updater's worker generation and preserve failures through cleanup and replacement.)
  • Runtime-specific worker construction and close policy keeps the original intent (improve: keep SQLite workers alive on Bun builds that release native handles #161764: Reuse workers only when the selected runtime demonstrably releases native SQLite resources; existing runtime-loader coverage comes from the earlier Windows Bun repair.)
  • Mock-export baseline keeps the original intent (unknown: The current baseline entry covers the replaced closed mock factory; spreading importOriginal removes that exception, making its deletion shrink-only maintenance. Earlier baseline history was unavailable.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit f8f1ad8 adds src/infra/sqlite-worker-broker-lifecycle.ts:118 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f8f1ad838157; files: src/infra/sqlite-worker-broker-lifecycle.ts)

PR surface

Source +25, Tests +116, Other -1. Total +140 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 29 4 +25
Tests 1 119 3 +116
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 0 1 -1
Total 3 148 8 +140

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #163150
Summary: This PR addresses the canonical diagnostics report; worker-loss recovery is a separate concern.

Members:

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

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The change restores useful storage-worker diagnostics without fixing or introducing a demonstrated runtime outage.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (7 earlier review cycles)
  • reviewed 2026-10-02T08:09:01.329Z sha e129273 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-02T15:44:56.516Z sha e129273 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T06:10:06.649Z sha cd511bc :: needs maintainer review before merge. :: none
  • reviewed 2026-10-05T08:16:21.639Z sha 627eb37 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-06T03:07:20.275Z sha 627eb37 :: needs changes before merge. :: none
  • reviewed 2026-10-06T21:13:30.794Z sha 2f80ae4 :: needs maintainer review before merge. :: none
  • reviewed 2026-10-06T21:59:19.662Z sha fef4242 :: needs maintainer review before merge. :: none

Reviewed November 5, 2026, 4:59 PM ET / 21:59 UTC (Revision 8).

sxh and others added 2 commits October 5, 2026 14:02
The broker-lifecycle suite mocks ./worker-cpu.js through importOriginal, so its
closed-factory baseline entry is orphaned and the ratchet only shrinks.
@Patrick-Erichsen Patrick-Erichsen self-assigned this Oct 6, 2026
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Independent exact-head qualification for 627eb37da0743bbed8f347236b77548a8084bb58 completed.

Module-only pre-fix control: six intended diagnostic assertion failures. Candidate: 42 passing tests across six suites, including four real Linux Node24 Worker cases (normal retirement, caller-requested failure, unexpected exit0 and uncaught error). Every case released its native thread and slot, with registry occupancy back to baseline. Unrequested departures produced one redacted warning; a synthetic bearer canary was absent from the retained logs. Thirty surrounding owner/policy file hashes stayed unchanged. Supported secretless Crabbox run_f92370a0a043/cbx_796e5cc6f057 exited0 and its container was independently verified removed; root verified38 exported file hashes.

Independent AutoReview completed scoped-clean for all three selected files at P0–P2. The +25 production lines implement the missing diagnostic owner witness with the existing registry/logger; termination, custody, admission, failure settlement, slots, storage and redaction policies stay unchanged. Unexpected exit0 retains the existing exit attribution. This proves Linux native lifecycle events; it does not claim SQL semantics, Windows or Codex/provider execution.

Fresh GitHub now reports a test-file merge conflict at the same head. This is not a ready-to-merge claim: native preparation and resulting exact-head gates still need to complete. No merge or deployment performed.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

sxh313 added 2 commits October 7, 2026 05:05
Main added an opener-authority table to this test file and a request
diagnostics field to the broker job type, so the base sync keeps both sides:

- imports are the union of the upstream admission helpers and the retirement
  registry symbols this PR reads
- the ./worker-cpu.js factory stays the spread-preserving one, which is why
  the baseline entry for it is removed and ./bun-sqlite-library.js remains
- sqlite-worker-broker-lifecycle.ts is unchanged on main, so this PRs
  departure reporting applies as authored
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed 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. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 5, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 5, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SQLite store worker exits are all counted as "exit" with no code or cause, and the broker never logs why a worker slot failed

2 participants