Skip to content

fix(doctor): prevent inspection timeouts from repeated continuation scans - #168069

Merged
steipete merged 1 commit into
mainfrom
upd/upd-l1529
Oct 10, 2026
Merged

steipete merged 1 commit into
mainfrom
upd/upd-l1529

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes repeated service-inspection timeouts during Doctor maintenance and update repair when continuation guards repeatedly validate a large state database. Closes #168031. Thanks @Tosko4 for the event-loop probe and SQLite profile.

User Impact

An already recorded repair continuation no longer causes a full database scan at every native service guard. Doctor can inspect and maintain the managed Gateway within the existing inspection budget. Fresh update ownership checks and full validation for actual ledger writes remain in place.

Why This Change Was Made

resolveDoctorUpdateAdmission previously reopened the one-shot ledger writer even when the requested receipt was already present. The writer validated integrity before discovering there was nothing to change. Doctor now uses its current admission read to recognize the existing continuation or takeover receipt. A missing receipt still goes through the transactional writer, including its integrity checks and authority revalidation. No new integrity cache, schema, configuration, or timeout is introduced.

Secondary report: the current restoration readiness budget remains 60 seconds. Current Doctor already warns and completes repair when the Gateway is still starting or its service is running at expiry; a stopped/failed service still fails restoration. That behavior is unchanged and its existing readiness tests passed.

Evidence

  • Regression uses real isolated SQLite, real continuation writing, and the real systemd command-query deadline with a synthetic fast manager. Each real synchronous integrity check is charged six seconds through a deterministic clock. Baseline fails with systemd-inspection-deadline-exceeded; the fix admits the query and still refuses a subsequently created competing update.
  • node scripts/run-vitest.mjs src/commands/doctor-maintenance.admission-warm.test.ts --maxWorkers=1: 10/10 tests passed in all three runs. Wrapper wall times: 54.49 s, 30.19 s, 37.39 s; test time approximately 19 s, 19 s, 22 s. The new regression took 4.61–4.77 s, with no real six-second sleep.
  • Ten importer/sibling files passed once using the repository test wrapper (command below). The native Windows lifecycle case retains its platform skip on macOS; both portable fixture tests passed. Existing takeover, schema/file replacement, quarantine, custody, service inspection, and readiness controls passed.
  • node scripts/check-changed.mjs --base d810d753e31b: FAILED at the inherited dead-export gate. Production scan reports isTelegramReadOnlyControlLaneText, buildDirectChatContext, and the resolveContextTokens re-export; full-tree scan reports the Telegram export. These files are unchanged from the lane base through observed origin/main. Core and all 27 test typecheck partitions passed. This inherited main failure is recorded separately from the change; the later lint/architecture gates were therefore run directly and passed (below).
  • Direct remaining gates all passed: core oxlint on both touched TypeScript files, native state-schema version, database-first legacy stores, media download helper roundtrip, runtime sidecar loaders, runtime import cycles (0), webhook auth/body ordering, pairing-store group auth, and pairing account scope. Oxlint initially caught one shadowed callback parameter in the new code; renaming it resolved the finding without changing behavior.
  • node scripts/check-madge-import-cycles.ts: 0 cycles. git diff --check: passed.
  • Independent P1 Codex review was attempted but the engine exited 1 without a verdict. Maintainer review of the PR head is still required.

The importer command took 774.60 s including its full runtime prerequisite build (429.9 s). The pre-existing doctor-maintenance.admission-activation.test.ts cases took 40.629 s, 38.430 s, and 46.919 s (125.978 s total); that fixture retains real synchronous snapshot/helper subprocesses around native guards. No timeout, retry, skip, or assertion was changed. Hosted CI timing is pending. This is local boundary proof, not a live Linux/systemd or 150 MB database reproduction.

node scripts/run-vitest.mjs \
  src/daemon/schtasks.integration.e2e.test.ts \
  src/daemon/schtasks.stop.test.ts \
  src/cli/update-cli/update-command-service-maintenance.test.ts \
  src/commands/doctor-maintenance.interruption.process.test.ts \
  src/commands/doctor-maintenance.admission-activation.test.ts \
  src/commands/doctor-maintenance.service-inspection.test.ts \
  src/commands/doctor-maintenance.finish-revalidation.test.ts \
  src/commands/doctor-maintenance.readiness.test.ts \
  src/state/openclaw-state-db-existing-write.test.ts \
  src/daemon/systemd-user-transport.test.ts --maxWorkers=1

Diff: production +14/−1, tests +54/−1, docs +6/−0. Auto-merge is off.

Reuse already recorded continuation and takeover receipts after fresh update admission. Actual ledger writes retain full integrity validation, while no-op guards no longer spend the native inspection deadline reopening the writer.

Closes #168031. Thanks @Tosko4 for the event-loop and SQLite profile.
@clawsweeper

clawsweeper Bot commented Oct 10, 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 commands Command implementations size: S labels Oct 10, 2026
@steipete
steipete marked this pull request as ready for review October 10, 2026 01:25
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 10, 2026
@clawsweeper

clawsweeper Bot commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Doctor skips redundant ledger writes when fresh admission already contains the required continuation or takeover receipt.

Example: The supplied regression inspects openclaw.service with a 5,000 ms deadline and charges each integrity check 6,000 ms.

  • Before: An already recorded continuation triggers another integrity scan and systemd-inspection-deadline-exceeded.
  • After: The query returns openclaw.service without reopening the writer, while a subsequently created competing update is refused.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch appears correct and has meaningful regression coverage, but required shipped-behavior proof is absent and the linked issue is only partially addressed.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: Doctor and update repair repeatedly miss service-inspection deadlines while redundant ledger validation blocks the CLI.
Reason: The optimization has clear value, but obviyus's linked reproduction establishes a remaining standalone Doctor cold-read failure; use Related instead of Closes for #168031.

Merge readiness

✅ Ready for maintainer review

Keep this PR open: it contains a useful, focused optimization absent from current main, with no concrete introduced code defect found.

Priority: P1
Reviewed head: 4fd814e7e761e31a632bc80408d42fbaf5fc3dd4

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide an after-fix published-updater-to-candidate update-repair run with a running systemd Gateway and a representative large database, showing maintenance admission and restoration.
Agent review details

How this fits together

Doctor's maintenance admission reads the shared SQLite update ledger, evaluates current driver ownership, and supplies guards to native service inspection and maintenance.

flowchart TD
A[Doctor maintenance] --> B[Fresh ledger read]
B --> C[Driver ownership admission]
C --> D[Existing receipt]
D --> E[Native service guard]
C --> F[Missing receipt]
F --> G[Validated ledger writer]
G --> E
Loading

Technical review

Best possible solution:

Retain this focused optimization and address cold admission-reader costs separately through the existing Doctor and state-reader owners.

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

Source confirms that repeated continuation guards enter full writer integrity validation inside a five-second inspection deadline; the linked report includes official-release traces and a separate current-main CLI reproduction, but this review ran no target code.

Is this the best way to solve the issue?

Skipping an already satisfied write at the existing admission owner is a narrow root-cause improvement that retains fresh ownership evaluation and validated mutations.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Doctor continuation admission changes intended behavior with a stated reason (8b16e53: The merged coordination refactor separated read-only storage guards from receipt-writing service admission while preserving current authority and transaction ownership.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 54abbae adds src/commands/doctor-maintenance-admission.ts:14 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 54abbae585bc; files: src/commands/doctor-maintenance-admission.ts)
  • Jason (Json): Raw commit 942a27d adds src/commands/doctor-maintenance-admission.ts:9 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 942a27def95d; files: src/commands/doctor-maintenance-admission.ts)

PR surface

Source +13, Tests +53, Docs +6. Total +72 across 3 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 14 1 +13
Tests 1 54 1 +53
Docs 1 6 0 +6
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 74 2 +72

Review metrics

Metric Value Why it matters
Production versus regression code production +14/-1; tests +54/-1 The small production shortcut is supported by a distinct deadline regression using real SQLite rather than assertions that mirror the helper.

Labels

Label changes:

  • add P1: The optimization addresses repeated failures of Doctor and update-repair maintenance reported on an official release.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: The optimization addresses repeated failures of Doctor and update-repair maintenance reported on an official release.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Provide redacted after-fix CLI recovery evidence for the affected systemd installation.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

Reviewed October 9, 2026, 9:31 PM ET / October 10, 2026, 01:31 UTC.

@steipete
steipete merged commit d12658c into main Oct 10, 2026
192 of 194 checks passed
@steipete
steipete deleted the upd/upd-l1529 branch October 10, 2026 01:34
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 10, 2026
…tion deadlines (openclaw#168069)

With a systemd user Gateway running and a ~150 MB state database, openclaw update repair and doctor --fix never entered maintenance: each continuation guard re-recorded the repair continuation, which ran writer admission and a full synchronous integrity scan on the CLI main thread, so the 5 s service-manager inspection deadline expired, the verdict became unavailable, Doctor did not stop the Gateway and maintenance stayed deferred. Doctor admission now treats an existing continuation or takeover receipt as already recorded (the fresh admission read still checks authority), so no writer admission or full scan runs inside the deadline; actual writes keep full validation. Closes openclaw#168031. Reported by @Tosko4.
RomneyDa pushed a commit that referenced this pull request Oct 10, 2026
…tion deadlines (#168069)

With a systemd user Gateway running and a ~150 MB state database, openclaw update repair and doctor --fix never entered maintenance: each continuation guard re-recorded the repair continuation, which ran writer admission and a full synchronous integrity scan on the CLI main thread, so the 5 s service-manager inspection deadline expired, the verdict became unavailable, Doctor did not stop the Gateway and maintenance stayed deferred. Doctor admission now treats an existing continuation or takeover receipt as already recorded (the fresh admission read still checks authority), so no writer admission or full scan runs inside the deadline; actual writes keep full validation. Closes #168031. Reported by @Tosko4.

(cherry picked from commit d12658c)
wheakerd pushed a commit to wheakerd/clawdbot that referenced this pull request Oct 22, 2026
…tion deadlines (openclaw#168069)

With a systemd user Gateway running and a ~150 MB state database, openclaw update repair and doctor --fix never entered maintenance: each continuation guard re-recorded the repair continuation, which ran writer admission and a full synchronous integrity scan on the CLI main thread, so the 5 s service-manager inspection deadline expired, the verdict became unavailable, Doctor did not stop the Gateway and maintenance stayed deferred. Doctor admission now treats an existing continuation or takeover receipt as already recorded (the fresh admission read still checks authority), so no writer admission or full scan runs inside the deadline; actual writes keep full validation. Closes openclaw#168031. Reported by @Tosko4.

(cherry picked from commit d12658c)
(cherry picked from commit 56cd4b1)
Co-authored-by: RomneyDa <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations docs Improvements or additions to documentation P1 High-priority user-facing bug, regression, or broken workflow. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

1 participant