Skip to content

fix(doctor): report which config-flow owners have work - #207146

Merged
fuller-stack-dev merged 2 commits into
openclaw:mainfrom
fuller-stack-dev:fix/doctor-config-flow-answer
Nov 28, 2026
Merged

fuller-stack-dev merged 2 commits into
openclaw:mainfrom
fuller-stack-dev:fix/doctor-config-flow-answer

Conversation

@fuller-stack-dev

@fuller-stack-dev fuller-stack-dev commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Related: #204775

What Problem This Solves

openclaw doctor --fix stops the Gateway and runs its config flow on every run, even on a healthy install. To make that stop conditional later, each step must first report truthfully whether it has work. The config flow reported work whenever anything other than its state schema input was involved, because only that one input had a read-only check. That answer said nothing about which owners actually had work.

User Impact

None visible today: Doctor still stops the Gateway and runs every step exactly as before. The trace now shows, per owner, whether the config flow had work, and the step answers none only when every owner answers none. Three owners still have no read-only predicate, so on a healthy install the step still answers work, now with the reason in the trace.

Why This Change Was Made

Each input calls the predicate its owner's writer acts on, decided from one config snapshot read without observation. Every SQLite read goes through decideDoctorPendingFromLiveStores, so a store nobody holds answers undecidable, and agent stores are listed inside the state database guard. Where a writer decided inline, the decision moved to a shared function the writer now also uses (retired state files, A2UI widget inspection, relative session stores, the legacy config file rename, cron preflight work, plugin obligations). Writer behavior is unchanged.

Inputs, in the order the flow reaches them:

Input Decides from Notes
state-write-admission orphaned sidecars, state DB permission drift the r+ probe writes nothing and stays
legacy-state-dir pending legacy state root
legacy-config legacy file name, invalid or legacy shapes, automatic repair plan, suspicious-config recovery
state-schema the existing plan from #206694
retired-state retired runtime, delivery queue and plugin index files
session-entry-state the repair's own inspection (apply: false)
plugin-convergence planStartupPluginConvergence().required any install record means work
plugin-obligations the obligation ledger (pending and deferred rows) and the configured plugin set no registry, no lifecycle lease
cron partition selection, retired cron files, legacy quarantine, Codex policy targets
legacy-state-detection the migration graph's own detection, including plugin detectLegacyState previews and legacy exec approvals
agent-databases planAgentDatabaseMigration(...).pending from #206707, with the preflight's discovery
a2ui-widgets the retirement's own inspection
relative-session-stores the repair's own discovery
legacy-state-steps no check yet always-run graph steps: delivery queue entries, workspace aliases, Skill Workshop proposals, ACP session metadata, orphan session keys, transcript directives, config machine state, shared auth store
update-history no check yet interrupted update reconciliation reads through a copy
config-repairs no check yet the config repair sequence, channel Doctor sequences, system agent workspace files

Plugin obligations: any recorded obligation, pending or deferred, is work (the flow reopens and settles it again), and a configured plugin that is unavailable is work (it becomes one). A plugin refused by policy is not recorded by the flow and is not counted. The reopen behavior and the registry queries are unchanged.

Evidence

Tested commits: base 870f9a62706 (main) and head 9fd46d12b73. The PR head c0d6346772f differs from the tested head by a dropped unused export, test-only edits and a merge of main that touches none of these owners. Cells: Linux Docker, systemd user Gateway, npm install of a local pack under the unpublished version 2026.11.13, Telegram and X channels, three agents, no network. The healthy store was seeded with the base build, settled with two doctor --fix runs, and restored byte-identical (sha256 over all files) before every run.

Method: strace -f plus a preload that records every write-intent fs call and every node:sqlite open, write statement and BEGIN IMMEDIATE/EXCLUSIVE with its JS caller, limited to the doctor.config-flow span (and, on the head, to each doctor.pending.config-flow.* span).

Red (base, healthy install): doctor.pending.config-flow pending=work check=owner, with config-flow.state-schema the only input. What the flow still opens, writes or creates on that install (after #206694, #206707, #206513):

Item Caller Needs an input?
r+ open of state/openclaw.sqlite preflight state write admission no: writes nothing, the only writability proof
writable open of state/openclaw.sqlite with connection setup (journal_mode=WAL, wal_autocheckpoint, synchronous), no transaction, no row Skill Workshop proposal retirement (readDatabaseProposals), a legacy graph step yes: in legacy-state-steps, no predicate yet
private snapshot copy of the state database under ~/.cache/openclaw with its staging token store transcript directives step (hasActiveAgentDatabaseLease, artifact-preserving read) no: private scratch, removed after the read
connection-local PRAGMAs (writable_schema catalog reads, busy_timeout, cache_size) on read-only connections schema readers no: change no file

No file bytes, rows, leases or BEGIN IMMEDIATE in the span. With a configured plugin that cannot be installed (an earlier fixture had slack configured), the same span also wrote migration_runs twice, took the plugin lifecycle lease (four state_leases writes) and called npm; that case is the plugin-convergence and plugin-obligations guard below.

Green (head, same restored store): every input with a check answers none; the three without one keep the step at work.

doctor.pending.config-flow.state-write-admission 0.6ms pending=none check=owner
doctor.pending.config-flow.legacy-state-dir 0.1ms pending=none check=owner
doctor.pending.config-flow.legacy-config 90.9ms pending=none check=owner
doctor.pending.config-flow.state-schema 85.9ms pending=none check=owner
doctor.pending.config-flow.retired-state 3.3ms pending=none check=owner
doctor.pending.config-flow.session-entry-state 31.3ms pending=none check=owner
doctor.pending.config-flow.plugin-convergence 2.2ms pending=none check=owner
doctor.pending.config-flow.plugin-obligations 94.0ms pending=none check=owner
doctor.pending.config-flow.cron 432.6ms pending=none check=owner
doctor.pending.config-flow.legacy-state-detection 629.1ms pending=none check=owner
doctor.pending.config-flow.agent-databases 524.4ms pending=none check=owner
doctor.pending.config-flow.legacy-state-steps 0.1ms pending=work check=default
doctor.pending.config-flow.a2ui-widgets 24.9ms pending=none check=owner
doctor.pending.config-flow.relative-session-stores 2.0ms pending=none check=owner
doctor.pending.config-flow.update-history 0.0ms pending=work check=default
doctor.pending.config-flow.config-repairs 0.0ms pending=work check=default
doctor.pending.config-flow 0.0ms pending=work check=owner

Cost of the check on this store: about 1.9 s in all (cron 433 ms, legacy-state detection 629 ms, agent databases 524 ms, the rest under 100 ms each). Inside each config-flow.* span the preload saw no write-intent fs call, no writable open of a real store, no BEGIN, and no copy: only read-only opens with connection-local PRAGMAs. The longest single SQLite statement the check issues is the agent database plan's read-only integrity check (the plan's integrity condition, run in its worker); it was not timed per statement here and grows with database size. The flow itself still runs everything after the check, so on large agent databases the integrity check now runs twice per doctor --fix until the stop becomes conditional.

Guards (base, then head on the same restored store, then head again without restoring). Schema and config seeds were applied while the Gateway was serving, because a Gateway boot heals them first.

Seed Base Head, first run Head, next run Result content
state schema: drop capture_events_flow_idx repaired config-flow.state-schema=work none schema identical to base
agent database: drop an index in the work agent database repaired config-flow.agent-databases=work none schema identical to base
legacy config: retired routing key migrated config-flow.legacy-config=work (config-dependent inputs undecidable on the invalid config) none openclaw.json identical to base
configured plugin that is not installed (absent-owner) obligation recorded pending plugin-convergence=work, plugin-obligations=work plugin-obligations=work (pending row); the flow then settles it ledger rows identical to base
recorded obligation, plugin unconfigured settled completed plugin-obligations=none once settled none identical
Memory Core detectLegacyState preview (an invalid events file) source kept, Doctor exits 1 legacy-state-detection=work work again: the plugin keeps the invalid source, as on base identical
state database mode 0644 healed before the config flow by an earlier step all inputs none none identical

Not run through the CLI: the legacy state directory. With ~/.openclaw moved to ~/.clawdbot, base and head both refuse before maintenance ("State directory selection changed before moving ...") because the service unit names the state directory; the input is covered by the unit test.

Tests. src/commands/doctor-config-flow-pending.test.ts (rewritten, 12 cases on real stores; fails on main, where the inputs do not exist): every input traced in order and the step work while an input has no check, with no file changed beside a held store; per-input work/none for permission drift and orphaned sidecars, a legacy state directory, a legacy config shape, a retired state file, a retired cron store (held store, no file change), a recorded obligation with and without a config file, an unavailable configured plugin; undecidable without sidecars for every SQLite-reading input when no connection holds the store; the agent database plan undecidable without the preflight's discovery. The one previous case (state-schema input only) is replaced by the first case, which covers it. Generic guards: doctor-maintenance.stopped-systemd.test.ts and doctor-health-contributions.pending-read-only.test.ts pass (75). Writer suites for every refactored owner pass.

Checks. pnpm tsgo:core pass. node scripts/check-changed.mjs: every lane passes except the dead-export scan, which reports AgentHarnessSideQuestionRequest and isRemoteAgentDispatchInvocation in files this PR does not touch (inherited from main). Session identity ratchet: no entries in touched files. CI on c0d6346772f: green.

Review. autoreview, Codex route (gpt-6.1-sol), --max-priority P2 --thinking high, with the owners and callers as committed source context (15 to 16 files) and the contract in the prompt. Pass 1: four P2. Fixed: agent stores the session scanners open were not guarded (now listed inside the state guard), the ledger was skipped without a config file, permission drift was missing from admission. Rejected: a policy-refused plugin is not recorded by the flow, so it is not ledger work. Pass 2: one P2, rejected with evidence (a nested artifact-preserving scope does not copy the state database under live reads; requiresArtifactPreservingSnapshot and the direct-read branch take the live read), and a held-store cron test added. Pass 3: scoped-clean.

Whole doctor --fix on the healthy install, head: 95 of 110 decisions trace none check=owner. Not none: client-credentials (no check), database-migrations (undecidable), config-flow (via legacy-state-steps, update-history, config-repairs), contributions auth-profile-migration, session-transcripts, state-integrity, codex-session-routes, legacy-cron, skills, memory-search, final-config-validation, and service-definition.

Not proven: macOS, Windows, pnpm, Bun and Git installs, PostgreSQL, large stores, a check beside a serving Gateway (the checks ran inside the stop, beside Doctor's own connections). No timing comparison is claimed.

Red: measured list in the config-flow span (base, healthy)
span doctor.config-flow: 5618 ms, origin pid 4975, 840 events in window
   1  fs openSync ~/.openclaw/state/openclaw.sqlite
   3  sqlite-open-rw  :memory:
   1  sqlite-open-rw  file://~/.cache/openclaw/<scratch>/owner.sqlite?mode=rw
   1  sqlite-open-rw  file://~/.openclaw/state/openclaw.sqlite?mode=rw
   1  sqlite-write exec file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA busy_timeout = 4989
   1  sqlite-write exec file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA busy_timeout = 5000
   1  sqlite-write exec file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA foreign_keys = ON;
   1  sqlite-write exec file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA journal_size_limit = 67108864;
   1  sqlite-write exec file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA synchronous = NORMAL;
   1  sqlite-write exec file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA wal_autocheckpoint = 0;
   1  sqlite-write exec file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA wal_autocheckpoint = 16384;
   1  sqlite-write exec ~/.cache/openclaw/<scratch>/<copy>/database.sqlite :: PRAGMA busy_timeout = 0
   1  sqlite-write exec ~/.cache/openclaw/<scratch>/<copy>/database.sqlite :: PRAGMA busy_timeout = 250
   1  sqlite-write exec ~/.cache/openclaw/<scratch>/<copy>/database.sqlite :: PRAGMA busy_timeout = 5000
   3  sqlite-write exec ~/.cache/openclaw/<scratch>/<copy>/database.sqlite :: PRAGMA busy_timeout = 5000; PRAGMA query_only = ON; PRAGMA trusted_schema = OFF;
   2  sqlite-write exec ~/.cache/openclaw/<scratch>/<copy>/database.sqlite :: PRAGMA writable_schema = ON;
   2  sqlite-write exec ~/.cache/openclaw/<scratch>/<copy>/database.sqlite :: PRAGMA writable_schema = RESET;
   1  sqlite-write exec ~/.openclaw/agents/main/agent/openclaw-agent.sqlite :: PRAGMA cache_size = -65536;
   1  sqlite-write exec ~/.openclaw/agents/ops/agent/openclaw-agent.sqlite :: PRAGMA cache_size = -65536;
   1  sqlite-write exec ~/.openclaw/agents/work/agent/openclaw-agent.sqlite :: PRAGMA cache_size = -65536;
  23  sqlite-write exec ~/.openclaw/state/openclaw.sqlite :: PRAGMA busy_timeout = 0
   4  sqlite-write exec ~/.openclaw/state/openclaw.sqlite :: PRAGMA cache_size = -16384; PRAGMA mmap_size = 268435456;
 361  sqlite-write exec ~/.openclaw/state/openclaw.sqlite :: PRAGMA writable_schema = ON;
 361  sqlite-write exec ~/.openclaw/state/openclaw.sqlite :: PRAGMA writable_schema = RESET;
   1  sqlite-write get file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA journal_mode = WAL;
(read-only sqlite opens in window: 64)
Green: config-flow span (head, same store)
span doctor.config-flow: 2662 ms, origin pid 9136, 726 events in window
   1  fs openSync ~/.openclaw/state/openclaw.sqlite
   3  sqlite-open-rw  :memory:
   1  sqlite-open-rw  file://~/.cache/openclaw/<scratch>/owner.sqlite?mode=rw
   1  sqlite-open-rw  file://~/.openclaw/state/openclaw.sqlite?mode=rw
   1  sqlite-write exec file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA busy_timeout = 4994
   1  sqlite-write exec file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA busy_timeout = 5000
   1  sqlite-write exec file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA foreign_keys = ON;
   1  sqlite-write exec file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA journal_size_limit = 67108864;
   1  sqlite-write exec file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA synchronous = NORMAL;
   1  sqlite-write exec file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA wal_autocheckpoint = 0;
   1  sqlite-write exec file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA wal_autocheckpoint = 16384;
   1  sqlite-write exec ~/.cache/openclaw/<scratch>/<copy>/database.sqlite :: PRAGMA busy_timeout = 0
   1  sqlite-write exec ~/.cache/openclaw/<scratch>/<copy>/database.sqlite :: PRAGMA busy_timeout = 250
   1  sqlite-write exec ~/.cache/openclaw/<scratch>/<copy>/database.sqlite :: PRAGMA busy_timeout = 5000
   3  sqlite-write exec ~/.cache/openclaw/<scratch>/<copy>/database.sqlite :: PRAGMA busy_timeout = 5000; PRAGMA query_only = ON; PRAGMA trusted_schema = OFF;
   2  sqlite-write exec ~/.cache/openclaw/<scratch>/<copy>/database.sqlite :: PRAGMA writable_schema = ON;
   2  sqlite-write exec ~/.cache/openclaw/<scratch>/<copy>/database.sqlite :: PRAGMA writable_schema = RESET;
   1  sqlite-write exec ~/.openclaw/agents/main/agent/openclaw-agent.sqlite :: PRAGMA cache_size = -65536;
   1  sqlite-write exec ~/.openclaw/agents/ops/agent/openclaw-agent.sqlite :: PRAGMA cache_size = -65536;
   1  sqlite-write exec ~/.openclaw/agents/work/agent/openclaw-agent.sqlite :: PRAGMA cache_size = -65536;
  23  sqlite-write exec ~/.openclaw/state/openclaw.sqlite :: PRAGMA busy_timeout = 0
   4  sqlite-write exec ~/.openclaw/state/openclaw.sqlite :: PRAGMA cache_size = -16384; PRAGMA mmap_size = 268435456;
 305  sqlite-write exec ~/.openclaw/state/openclaw.sqlite :: PRAGMA writable_schema = ON;
 305  sqlite-write exec ~/.openclaw/state/openclaw.sqlite :: PRAGMA writable_schema = RESET;
   1  sqlite-write get file://~/.openclaw/state/openclaw.sqlite?mode=rw :: PRAGMA journal_mode = WAL;
(read-only sqlite opens in window: 62)

@clawsweeper

clawsweeper Bot commented Nov 28, 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 commands Command implementations size: L labels Nov 28, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. 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. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Nov 28, 2026
@clawsweeper

clawsweeper Bot commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: passed.

What this changes

This PR adds read-only pending-work checks and individual trace entries for Doctor’s config-flow owners.

Example: Doctor inspects an install without retired state files such as ~/.openclaw/acp/event-ledger.json.

  • Before: The config flow reports work without a separate retired-state decision.
  • After: The retired-state input reports pending=none, while unchecked owners still keep the overall config flow at work.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The implementation appears coherent and worthwhile, but required Doctor upgrade validation is absent.
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: Refactor · Worth it: Yes · Fix scope: Complete
User problem: Doctor’s trace does not identify which config-flow owners require maintenance, leaving a prerequisite for avoiding unnecessary Gateway stops incomplete.
Reason: The maintainer-authored direction matches the recorded staged design, reuses existing repair owners and adds no user option or changed maintenance default.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR adds useful owner-level diagnostics for the ongoing Doctor work, and inspection found no definite introduced correctness defect.

Reviewed head: c0d6346772f670214a3101e38be4af6f88a190ce

Before merge

None.

Findings

None.

Agent review details

How this fits together

Doctor calls these checks before running its existing config repair flow; they consume configuration and store inspections and produce maintenance trace decisions without controlling whether repairs execute.

flowchart TD
  A[Doctor command] --> B[Database preflight]
  B --> C[Config-flow pending checks]
  C --> D[Existing owner predicates]
  D --> E[Per-owner maintenance trace]
  E --> F[Existing config repair flow]
Loading

Technical review

Best possible solution:

Retain the existing repair owners and conservative pending answers, then complete the required validation before landing.

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

Current main’s source establishes the diagnostic limitation: unchecked config-flow inputs force work without individual owner trace entries; no runtime reproduction was performed.

Is this the best way to solve the issue?

Reusing existing owner predicates and preserving unconditional repair execution is a coherent preparatory change; it does not yet solve unnecessary Gateway stops.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Jason (Json): Raw commit e2e0974 adds src/flows/doctor-health-startup.ts:296 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: e2e0974c98e4; files: src/flows/doctor-health-startup.ts)
  • Peter Steinberger: Raw commit 13f9b2c adds src/infra/state-migrations.state-dir.ts:218 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 13f9b2cc3b38; files: src/infra/state-migrations.state-dir.ts)

PR surface

Source +467, Tests +235. Total +702 across 11 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 10 527 60 +467
Tests 1 246 11 +235
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 11 773 71 +702

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.

Review metrics

Metric Value Why it matters
Pending-check coverage 13 checked inputs; 3 default-work inputs The remaining unchecked owners deliberately prevent this PR from enabling a no-stop Doctor path.

Root-cause cluster

Relationship: partial_overlap
Canonical: #204775
Summary: This PR implements a diagnostic prerequisite within the broader prepared-release and Doctor maintenance program.

Members:

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

Labels

Label changes:

  • 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:

  • 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.

  • Supply the required Doctor upgrade evidence for the reviewed revision.

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.

Reviewed November 27, 2026, 9:40 PM ET / November 28, 2026, 02:40 UTC.

@fuller-stack-dev
fuller-stack-dev merged commit 218d29f into openclaw:main Nov 28, 2026
151 checks passed
@fuller-stack-dev

Copy link
Copy Markdown
Member Author

Merged via squash.

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

Labels

commands Command implementations P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: L 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