Repository navigation
fix(logbook): drain accepted work before closing SQLite - #138754
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Native Logbook proof passed on commit
The source-bound external probes execute the real owners: node --import ./scripts/tsx.mjs "$PROOF/native.mjs" "$CHECKOUT"
node --import ./scripts/tsx.mjs "$PROOF/registry.mjs" "$CHECKOUT" candidate
node --import ./scripts/tsx.mjs "$PROOF/reentrant.mjs" "$CHECKOUT"The built CLI queries the normal isolated Gateway, then repeats after shutdown/restart: openclaw gateway call logbook.status --json
openclaw gateway call logbook.days --json
openclaw gateway call logbook.timeline --params '{"day":"2026-09-04"}' --jsonFull Gateway payload SHA-256 before and after restart: All synthetic state is removed, the local port is closed, and no owned processes remain. Source and proof-script hashes are retained in the completion receipt. The expected injected analysis failure and retired-service refusal are recorded, not suppressed. This is orderly drain, not immediate cancellation or interruption of accepted node/model work. Provider and node boundaries use deterministic synthetic responses; no personal screen capture, external model call or channel delivery occurs. The live Gateway uses capture-disabled reads. No PostgreSQL, other-platform, Workboard or subsequent Logbook query-change coverage is claimed. |
|
Codex review: needs maintainer review before merge. Reviewed September 4, 2026, 9:55 PM ET / September 5, 2026, 01:55 UTC. ClawSweeper reviewWhat this changesLogbook now stops accepting database work, drains accepted captures, analysis, and standups, and shares that shutdown with plugin retirement before closing SQLite. Merge readiness✅ Ready for maintainer review Keep open as a necessary, focused lifecycle repair: current main still closes SQLite before asynchronous work settles. No blocking correctness findings were identified. Priority: P1 Review scores
Verification
How this fits togetherLogbook turns screen captures and model responses into a local activity journal. Its background service and Gateway methods share a SQLite store whose connection must remain open until accepted work finishes saving. flowchart TD
A[Capture and analysis timers] --> C[Logbook service]
B[Gateway journal requests] --> C
C --> D[Accepted asynchronous work]
E[Shutdown or plugin retirement] --> F[Reject new work and drain]
D --> G[Save results or original errors]
G --> H[Close SQLite once]
F --> H
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +49, Tests +276. Total +325 across 7 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the lifetime owner in LogbookService: a store-only close guard cannot protect asynchronous gaps between queries, so the focused operation tracking and shared retirement drain are justified. Do we have a high-confidence way to reproduce the issue? Yes: hold a capture or model response, stop the service, then release it; current main closes SQLite before the continuation writes. This is source-proven and supported by supplied before/after probes, not independently executed during this review. Is this the best way to solve the issue? Yes, for orderly database shutdown: the patch uses the existing asynchronous service and lifecycle contracts and covers each database-using operation without changing storage formats. Provider interruption remains separate work rather than a prerequisite for this repair. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against e2b49d25399d. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
* refs/remotes/origin/main: (602 commits) fix(plugins): trace trust refusals and repair legacy provenance (openclaw#138746) perf(sqlite): reuse compiled plugin state point reads (openclaw#138758) refactor: type chat prefetch dependencies and clean loading tests (openclaw#138793) ci: reduce Doctor test startup and core lint jobs (openclaw#138796) feat(update): retain run history and share outcome reports (openclaw#138690) chore(deps): update @openclaw/fs-safe to 0.8.1 (openclaw#138500) fix: preserve global board ownership from pinning to notifications (openclaw#138675) fix(gateway): deliver session catalog updates from slow hosts (openclaw#138674) perf(sessions): index pending conversation replies (openclaw#127182) perf(auth): reuse ordered provider alias entries (openclaw#138805) docs(diagnostics): clarify whole-process CPU metrics (openclaw#138804) perf(memory): narrow source reads and stream embedding cache rows (openclaw#138766) fix: allow older source on newer Testbox checkouts (openclaw#138782) fix(agents): preserve recovered task progress and lifecycle ownership (openclaw#138785) perf(codex): reduce rollout tail scan CPU (openclaw#138784) perf(gateway): stop projecting history deltas at the byte budget (openclaw#138655) fix(build): bound native declaration inputs to checkout (openclaw#138742) fix(cli): preserve foreground Gateway argument handling (openclaw#138765) fix(ui): align task toolbar with side-panel tabs (openclaw#138769) fix(logbook): drain accepted work before closing SQLite (openclaw#138754) ... # Conflicts: # src/agents/embedded-agent-runner/compact.queued.ts
Related: #127526, #127608.
What Problem This Solves
Fixes an issue where stopping or replacing Logbook could lose an accepted capture, analysis result, or generated standup because SQLite closed while the operation awaited a runtime response. Recording an analysis failure could also replace the original error with a closed-database error. Registry retirement could leave the service's database and timers alive when ordinary service shutdown was skipped.
Why This Change Was Made
The service now owns admitted database-using operations through their final writes and error recording. Stop prevents new work and clears timers immediately, then waits for accepted work before closing the connection once. Capture, analysis, and standup retain their admitted store; analysis finishes its current batch without starting another after shutdown begins. Day questions remain independent because they finish all database reads before awaiting the answer.
Ordinary service stop and whole-plugin restart/disable cleanup share that drain. Retirement revokes the published service and prevents a retired registration from opening a database later. Session/run cleanup does not dispose the global store. Existing host shutdown deadlines, model/capture deadlines, write queries, schemas, retention, and configuration are unchanged.
User Impact
Accepted activity and standup results can finish saving during shutdown, and actual model failures retain their original error. Shutdown may wait for already accepted work under the existing host deadline; no new timeout or cancellation policy is introduced.
Evidence
db1f25125721passed all five phases on the first attempt: the held-operation matrix, actual registry retirement, reentrant shutdown, nine fresh-process table-hash/integrity checks, and real Gateway status/days/timeline payloads before and after restart. The exact-head runtime build passed. All synthetic state and processes were removed; the complete synthetic trace is posted below.Production delta is +49 lines, including a net-neutral move of the existing status type. The added code supplies the previously missing service-operation lifetime owner and retirement binding; placing a drain only in the database store would miss the asynchronous work between queries. Tests add 276 lines net. The old immediate-close path and duplicate stop ownership are removed.
The related reports also propose forwarding cancellation through structured media extraction. This PR repairs database lifetime by draining accepted work and preserves current cancellation contracts; it does not claim that separate interruption work is implemented or automatically close those broader reports.