Skip to content

fix(doctor): reduce duplicate work in database diagnostics - #180184

Open
steipete wants to merge 1 commit into
mainfrom
fix/e2e-daily-l2c-doctor-db-inspection
Open

steipete wants to merge 1 commit into
mainfrom
fix/e2e-daily-l2c-doctor-db-inspection

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes redundant cold plugin migration loading during Doctor's per-store database report, which adds work to Doctor repairs and Gateway test setup.

User Impact

Doctor reuses migration contracts it has already loaded instead of importing them again in its physical-inspection worker. Disabled owners, retained imports, missing or unreadable stores, schema checks, PostgreSQL observations, and read-only custody remain covered. There are no configuration, schema, migration, or operator-action changes.

Why This Change Was Made

The per-store diagnostics introduced in #174912 run legacy migration inspection in a fresh worker namespace. Doctor's existing process can inspect those same contracts under the same artifact-preserving read scope and send the resulting facts to the worker. Physical discovery and store inspection stay in the worker; diagnostic results are not cached.

Found via the daily scheduled Gateway E2E shards (run ids above): 39200506864, 39370388323, and 39544982957.

Evidence

Acceptance rule: remove duplicate contract initialization for already-loaded owners, preserve disabled-owner retained-data detection and fresh inspection results, and keep all store checks and existing test deadlines unchanged. This is a work-count comparison, not a wall-time benchmark: the local host is unqualified for timing claims.

The production-boundary fixture uses three real generated plugin contracts and one retained legacy source. On unchanged base 855b0aa7242e, the retained-data assertions pass but the work-count assertion fails: five contract initializations instead of three. The candidate passes with three total initializations. The fixture preloads two enabled owners, then requires diagnostics to inspect a third, disabled and repair-deferred owner. It also removes the retained source and requires the next inspection to report no pending import without initializing contracts again.

The source inventory contains 20 bundled migration owners and four SQLite-only migration detectors across three owners. Discovery already loads its migration entry list once per inspection, not once per store. The waste is the cold reload across the Doctor/inspection-worker boundary. The separate physical worker, per-store snapshots, SQLite image opens, owner/schema validation, and PostgreSQL probes are intentionally retained. The unresolved-engine path remains in the worker so it cannot inherit an unrelated host engine context.

The fixture accounting is host initializations 2 → 3, worker initializations 3 → 0, total 5 → 3. This moves the first disabled-owner load to the host while deleting the two duplicate enabled-owner loads; it does not claim all host work decreased. There is no new cache. The simplification pass retained one inspection owner and the existing physical worker (production delta +37/-13, regression +90 lines).

Owning tests: 17 passed / 1 timed out across doctor-database-engine-inspection, doctor-database-engine, doctor-database-diagnostics, and doctor-database-network-storage. The existing diagnostics case at doctor-database-diagnostics.test.ts:21 hit its unchanged 120s deadline, without an assertion mismatch. Its legacy-remedy snapshot, unreadable-root, and missing-agent siblings pass. That timeout is not baseline-attributed and remains an explicit proof gap. No snapshot was updated. The new regression's local test time was 7.367s; CI seconds are pending. It needs real loaded modules and a real worker to detect duplicated initialization.

Targeted Doctor typecheck, direct oxlint, oxfmt check, git diff --check, and the full pnpm build pass. Independent Codex review through P2 is scoped-clean.

All four requested E2E files ran serially before and after, with fresh isolated HOME/state/config/XDG paths per file:

File Base Candidate
test/e2e/line-doctor-group-allowlist.built-cli.e2e.test.ts 6 failed 6 failed: original 30s command deadlines; first failure is in backup preparation before database diagnostics
test/scripts/doctor-config-preflight-plugin-index.built-cli.e2e.test.ts 2 passed 1 passed / 1 failed: original 30s repair-command deadline; stale-index refresh/readiness passes
src/commands/doctor.runs-legacy-state-migrations-yes-mode-without.e2e.test.ts 5 passed 4 passed / 1 failed: yes-mode case hits original 30s test deadline; Nix refusal, restart behavior, and OAuth migration pass
src/commands/doctor.auth-profile-consumers.e2e.test.ts 3 failed 3 failed: child status 141, child status null, interactive Doctor does not exit

The two candidate-only local E2E deadline failures remain unattributed; both traces complete Database engines and proceed into later Doctor sections. The auth helper has an unchanged 60s child deadline but omits the spawn error, so exit 141 alone is not conclusive timeout evidence. No auth-reference or LINE assertion drift was established. These runs used the repository-default pinned Bun runtime via a Node v26.5.0 launcher; scheduled CI used Node v24.21.0. The overloaded host cannot establish a timing regression or improvement. Qualified Linux/Node deadline recovery remains open.

Focused proof commands (tests used fresh temporary HOME, state/config, XDG, and Vitest-cache paths):

node scripts/run-vitest.mjs run \
  src/commands/doctor-database-engine-inspection.test.ts \
  src/commands/doctor-database-engine.test.ts \
  src/commands/doctor-database-diagnostics.test.ts \
  src/commands/doctor-database-network-storage.test.ts --maxWorkers=1
node scripts/run-tsgo.mjs --project test/tsconfig/tsconfig.core.test.commands-doctor.json
node_modules/.bin/oxlint -c .oxlintrc.json src/commands/doctor-database-engine-inspection{,.test}.ts
pnpm exec oxfmt --check src/commands/doctor-database-engine-inspection{,.test}.ts
git diff --check
pnpm build

The red-on-base selection was the inspection file with -t 'reuses loaded migration'. E2Es use node scripts/run-vitest.mjs run --config test/vitest/vitest.e2e.config.ts <file>, one file at a time.

A Blacksmith Testbox attempt was interrupted during local source-capsule preparation before upload/allocation; no lease was created, no remote payload ran, and no qualified timings were obtained. Local functional outcomes do not establish CI deadline recovery or a flake. No published-driver upgrade matrix was run; migration policy and stored formats are unchanged. No timeout, retry, assertion, or skip policy changes are included.

@clawsweeper

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-22T02:24:43.519298Z c789a97 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S labels Oct 22, 2026
@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. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed 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. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR prepares legacy-migration diagnostic facts in Doctor’s existing process and passes them to the physical-inspection worker.

Example: Doctor has loaded two enabled migration owners and must inspect a third, disabled owner with retained data.

  • Before: The supplied fixture records five contract initializations across the host and worker.
  • After: It records three initializations while still detecting retained data and refreshing results after its removal.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The focused implementation is coherent and has no identified introduced defect, but the submitted operational validation remains incomplete.
Proof confidence 🦪 silver shellfish (2/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: Performance · Worth it: Yes · Fix scope: Complete
User problem: Doctor diagnostics repeat migration-contract initialization already performed by the same Doctor process.
Reason: The maintainer-authored direction has a concrete work-count benefit and preserves diagnostic coverage without adding configuration, persistent state, or another decision owner.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep this PR open: it removes verified duplicate migration-contract loading, and no introduced correctness defect was found.

Priority: P2
Reviewed head: c789a97e9b7e62497e0d9d05f6ed15abc12692af

Before merge

  • Complete next step - Determine whether the audit-ledger preview failure is caused by this diff using equivalent base evidence or a head-versus-revert comparison.

Findings

None.

Tests

  • Missing end-to-end proof: Complete the latest-stable-to-candidate Doctor upgrade scenario with settings and retained data intact, and resolve or attribute the reported candidate-only deadline failures.
Agent review details

How this fits together

Doctor combines configured database engines, legacy-import facts, and physical store observations into diagnostic findings; the worker continues to discover stores and inspect their schema, connectivity, and custody.

flowchart TD
  A[Doctor command] --> B[Resolve engine selection]
  B --> C[Inspect legacy imports using loaded contracts]
  C --> D[Physical inspection worker]
  D --> E[Discover and inspect stores]
  E --> F[Database diagnostic findings]
Loading

Technical review

Best possible solution:

Reuse the existing host-loaded contracts for fresh legacy detection while retaining isolated physical inspection and unresolved-engine handling.

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

Current-main source shows legacy contracts loading in a fresh worker, and the submitted production-boundary fixture reports five initializations on the base versus three on the candidate; this review executed no target code.

Is this the best way to solve the issue?

The patch follows the smallest complete fix: retain the existing inspection owner, carry freshly prepared facts across the worker boundary, and preserve the fallback needed when engine selection fails.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 6cf7c47 adds src/commands/doctor-database-engine-inspection.ts:60 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6cf7c4775738; files: src/commands/doctor-database-engine-inspection.ts)

PR surface

Source +24, Tests +90. Total +114 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 37 13 +24
Tests 1 90 0 +90
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 127 13 +114

Review metrics

Metric Value Why it matters
Production versus regression code Production +24 net lines; tests +90 lines Growth carries prepared facts through the existing worker boundary and protects duplicate initialization, disabled-owner detection, artifact preservation, and freshness without adding a cache.

Labels

Label changes:

  • add P2: Redundant plugin initialization adds avoidable work to Doctor diagnostics, but the evidence does not establish a current user-facing outage or deadline recovery.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: Redundant plugin initialization adds avoidable work to Doctor diagnostics, but the evidence does not establish a current user-facing outage or deadline recovery.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rank-up moves

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

  • Provide the missing Doctor upgrade evidence and settle the candidate-only deadline failures.

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 October 21, 2026, 10:37 PM ET / October 22, 2026, 02:37 UTC.

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

commands Command implementations P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant