Skip to content

fix(sqlite): preserve final worker diagnostics during close - #150511

Merged
steipete merged 1 commit into
mainfrom
codex/sqlite-worker-output-drain-20260916
Sep 17, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/sqlite-worker-output-drain-20260916

Conversation

@steipete

@steipete steipete commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

SQLite workers can lose their final diagnostic lines when the last backend closes and the broker immediately terminates the worker.

User Impact

Graceful final-backend close gives pending console output a bounded chance to reach stdout/stderr before acknowledging completion, including when another open is queued. The existing five-second fallback makes this best effort. Database cleanup, queued-write settlement, and error/forced retirement retain their existing behavior.

Why This Change Was Made

SQLite replies and Node worker stdio use separate message channels, so a successful close reply does not prove buffered diagnostics were delivered. Drain output after backend and delegation cleanup but before the successful final-actor close reply.

The existing output-drain helper moves to src/process; CLI exit, native-hook relay, and sealed-worker error callers move with it. Its callback behavior and timeout stay unchanged, and the old path is removed without an alias. The existing real-worker logging fixture gains a bounded teardown burst while preserving its exact JSON and terminal-diagnostic assertions.

Evidence

  • The original Linux / Node 24.19 CI failure, observed while validating fix(pr): unify worktree source checks and suppress automatic repacks #150399, had valid JSON output and open/execute diagnostics but no terminal close diagnostic. The affected logging owners were unchanged by that PR.
  • On macOS / Node 24.19, a pure-Node close-burst probe lost the final line in 31/32 ACK-then-terminate trials, with up to 3,879 stderr bytes still queued at the ACK. Waiting for the write callback lost 0/32. The simple three-line probe and original unmodified test passed locally; those results are retained separately.
  • The strengthened existing SQLite-worker test failed before the production fix with only the first teardown diagnostic delivered, then passed after it. 156 focused tests passed across logging, SQLite lifecycle/store behavior, runtime guards, sealed-worker entry, and one-shot CLI output, including callback/fallback and real piped JSON/TTY checks. The logging regression passed again on final syntax.
  • Deslop, final independent P2 review, targeted typed lint, core types, and the remaining selected schema, database, media, sidecar, import-cycle, webhook, and auth guards passed. Full tracked-source search found no old helper-path or symbol references.

The initial check:changed run passed its preceding guards, production/test typechecks, and export scans, then rejected an implicit-return Promise executor. That expression now uses the equivalent block body. Final targeted typed lint, the logging test, incremental core types, and the exact remaining guards passed; the original aggregate failure is retained rather than relabeled green. The full test suite was not run locally. The first PR CI run passed the real SQLite logging regression on Linux, including the terminal close diagnostic, with 563 passing and two skipped tests in its storage/runtime shard. That run remained red on unrelated Control UI, Qwen, preparation-fixture, and compiler-tooling checks.

The refreshed head includes the landed Control UI, Qwen, and preparation-fixture fixes. Its SQLite patch is byte-identical to the reviewed patch, and all ten accepted source-file hashes are unchanged. Required CI completed successfully for this exact head. Its first attempt cancelled two jobs before runner acquisition; the approved failed-only rerun completed both Node test shards on GitHub-hosted Ubuntu. The canonical watcher reports green and the exact run receipt confirms attempt 2 succeeded. Prior failures remain retained, and no test timeout or assertion was relaxed.

@clawsweeper

clawsweeper Bot commented Sep 17, 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 docs Improvements or additions to documentation cli CLI command changes size: S maintainer Maintainer-authored PR labels Sep 17, 2026
@steipete
steipete marked this pull request as ready for review September 17, 2026 02:24
@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 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 17, 2026, 1:09 AM ET / 05:09 UTC (Revision 3).

ClawSweeper review

What this changes

Preserves final SQLite worker diagnostics by draining console output before acknowledging close and moves the existing drain helper into a shared process module.

Merge readiness

✅ Ready for maintainer review

The fix remains useful: current main still acknowledges final worker close without draining diagnostics. No blocking correctness or security defect was found, and GitHub confirms successful CI for the reviewed head.

Priority: P2
Reviewed head: fd7c5b3373bd05d6071ffb00028ee4e5cf447352

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level fix with complete caller migration, meaningful regression coverage, and successful CI for the reviewed head.
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. Its recorded Node close-burst observations and actual broker/worker regression target diagnostic delivery before retirement; focused tests and verified CI provide supplemental validation.
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. Its recorded Node close-burst observations and actual broker/worker regression target diagnostic delivery before retirement; focused tests and verified CI provide supplemental validation.
Evidence reviewed 8 items Introduced shutdown ordering: The successful final-backend close drains output after delegation cleanup and before posting its reply. Failed closes and nonfinal closes retain their existing behavior.
Broker serialization and retirement: The broker retains the current request until its reply, prevents dispatch of another queued request meanwhile, and awaits close acknowledgement before normal retirement. The added wait therefore preserves request ordering.
Existing helper reused without competing implementation: The prior helper already drained both streams with a five-second fallback. Its behavior is preserved at the new location, all three existing production callers migrate, and the tracked-source search found no retired helper references.
Findings None None.
Security None None.

How this fits together

OpenClaw’s SQLite broker sends database operations to worker threads and retires workers after their backends close. Diagnostic output travels separately from operation replies, so shutdown must allow that output to drain before retirement.

flowchart TD
  A[Store close request] --> B[SQLite broker queue]
  B --> C[Worker closes backend]
  C --> D[Release delegation resources]
  D --> E{Successful final backend close?}
  E -->|Yes| F[Bounded console drain]
  E -->|No| G[Send operation reply]
  F --> G
  G --> H[Broker continues or retires worker]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +7, Tests +3, Docs +5. Total +15 across 10 files.

View PR surface stats
Area Files Added Removed Net
Source 6 36 29 +7
Tests 3 5 2 +3
Docs 1 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 10 46 31 +15

Review metrics

None.

Technical review

Best possible solution:

Keep one shared bounded output-drain owner and complete final worker shutdown only after backend cleanup and the drain attempt.

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

Yes: final-backend teardown diagnostics can race the broker’s immediate worker termination, and the existing real-worker logging fixture supplies a focused regression path. This review verified the source mechanism without executing it.

Is this the best way to solve the issue?

Yes: delaying only the successful final-close reply addresses the race at its owner while reusing existing drain behavior and preserving failure handling.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: Losing final worker diagnostics impairs troubleshooting, while the identified defect does not establish lost database writes or a broken core workflow.
  • 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. Its recorded Node close-burst observations and actual broker/worker regression target diagnostic delivery before retirement; focused tests and verified CI provide supplemental validation.

Evidence

What I checked:

  • Introduced shutdown ordering: The successful final-backend close drains output after delegation cleanup and before posting its reply. Failed closes and nonfinal closes retain their existing behavior. (src/infra/sqlite-store.worker.ts:398, fd7c5b3373bd)
  • Broker serialization and retirement: The broker retains the current request until its reply, prevents dispatch of another queued request meanwhile, and awaits close acknowledgement before normal retirement. The added wait therefore preserves request ordering. (src/infra/sqlite-worker-broker.ts:538, fd7c5b3373bd)
  • Existing helper reused without competing implementation: The prior helper already drained both streams with a five-second fallback. Its behavior is preserved at the new location, all three existing production callers migrate, and the tracked-source search found no retired helper references. (src/process/output-drain.ts:1, 88d5171c6326)
  • Current main still needs the fix: Fetched main posts the close reply immediately after delegation cleanup, without an output drain. The latest supplied release, v2026.9.4, does not contain this worker source path; no released implementation of this fix was established. (src/infra/sqlite-store.worker.ts:398, 92fdb4bfe91e)
  • Regression coverage and captured evidence: The existing test exercises the actual broker and worker thread, captures host output, and asserts exact JSON plus the terminal close diagnostic. The captured PR body reports that the strengthened teardown burst failed before the fix and passed afterward, alongside 156 focused tests. These claims were read; no target code or tests were executed during this review. (src/infra/sqlite-worker-logging.test.ts:16, fd7c5b3373bd)
  • Verified CI result: GitHub reports run 35180012533 completed successfully on attempt 2 for the exact reviewed head: https://github.com/openclaw/openclaw/actions/runs/35180012533. (fd7c5b3373bd)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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-17T02:33:43.379Z sha 4ba658ce6c34443796e1d61a3f2230ba08de4041 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-17T04:02:26.166Z sha fd7c5b3 :: needs maintainer review before merge. :: none

Drain output before acknowledging a successful final backend close, after
native and delegation cleanup. Reuse the existing five-second best-effort
output drain for CLI exits, native hook relays, and sealed worker errors.
Forced and failed retirement keep their existing behavior.

A bounded close burst makes the existing real worker logging regression
fail before this change. The repaired path passed 156 focused tests and a
final logging rerun. Selected checks and independent P2 review passed;
the initial aggregate lint error was corrected and verified separately.
@steipete
steipete force-pushed the codex/sqlite-worker-output-drain-20260916 branch from 4ba658c to fd7c5b3 Compare September 17, 2026 03:55
@steipete
steipete merged commit de4cb3d into main Sep 17, 2026
372 of 378 checks passed
@steipete
steipete deleted the codex/sqlite-worker-output-drain-20260916 branch September 17, 2026 05:12
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 17, 2026
Combine main 8dd36a0 with the
reviewed final-worker output drain from #150511 at
4ba658ce6c34443796e1d61a3f2230ba08de4041 for local integration proof.
Preserve the extracted model-source owner with the current reader
contract and keep final output drainage before owned reply transfer.

The public #149971 branch remains unchanged until its prerequisites land.
Validation: 114 focused tests passed; 2 existing Linux-only skips.
Full build, resolution formatting, and fresh independent P2 review passed.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 18, 2026
)

Drain output before acknowledging a successful final backend close, after
native and delegation cleanup. Reuse the existing five-second best-effort
output drain for CLI exits, native hook relays, and sealed worker errors.
Forced and failed retirement keep their existing behavior.

A bounded close burst makes the existing real worker logging regression
fail before this change. The repaired path passed 156 focused tests and a
final logging rerun. Selected checks and independent P2 review passed;
the initial aggregate lint error was corrected and verified separately.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation 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