Skip to content

improve: speed up Doctor checks for absent plugin state - #146926

Merged
steipete merged 1 commit into
mainfrom
codex/perf-crabbox-doctor-context
Sep 13, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/perf-crabbox-doctor-context

Conversation

@steipete

@steipete steipete commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Cold Doctor state checks load a broad runtime dependency graph even when they already have the required store context or the plugin's state directory is absent.

User Impact

Doctor avoids unnecessary imports while preserving the existing migration owners, state formats, validation and recovery behavior. Existing Voice Call databases still receive schema checks even without a legacy call log. No configuration, schema, retention, resource-custody or public SDK contract changes are introduced.

The measured improvement is local test-case time. Full command and Linux CI speedups are not yet established.

Why This Change Was Made

Crabbox Doctor now reads both required namespaces through its supplied context and shares unchanged limits, selectors and row projection with the runtime through a lightweight private module. Memory Host defers its state-store dependency until an actual read or write; every original key, timestamp and query argument is prepared before that await. Voice Call returns the existing empty result before loading repair machinery only when its entire store root is absent.

These changes belong together: the first two partial versions merely moved the same cold load to the next detector. The complete change removes that unnecessary load from the observed sweep. Runtime storage operations remain with their existing owners.

Evidence

An uninstrumented original/candidate/original comparison ran the same first two corpus cases in the same order, preserving both Doctor/startup passes and all assertions. First-case times were 39.02 / 31.08 / 36.83 seconds. The two-case total was 40.90 seconds for the candidate versus 48.00 seconds averaged across the controls, a 14.8% local reduction. The diagnostic sweep separately retained all 46 declared migration owners and 512 callback invocations, while first detection fell from 18.38 to 10.05 seconds.

The candidate's dirty checkout triggered an extra canonical pretest build, so its overall local command was slower. No wrapper or CI speedup is claimed; committed CI must establish the job-level result. This was a same-host macOS source-mode sample using Node 24.21 and pnpm 12.3.4, not the full corpus or a Linux benchmark.

All 235 focused tests, the full build and required changed-file checks passed. Four absent-state regression cases fail at the original repair imports and pass with the fix; retained cases cover database-only repair, malformed logs, partial writes/retry, capacity, concurrent sequencing, rollback and reopen. Two fresh plain-Node processes also exercised the compiled public SDK: append/read followed by a separate lock-owned export and persisted read, with exact event bytes and cleanup verified.

Exact-head CI34751724130 passed, including both startup corpus files (58 tests) and all 91 affected plugin Doctor cases. The actual tested merge preserves the eight candidate files. The full corpus group took242.96s; that is an observation, not a controlled before/after improvement.

The repository-required published-updater compatibility cell passed: published [email protected] updater to exact candidate607628d8, using existing base-scenario state and trusted harnessf3bdcc10. The actual file-tag update is followed by automatic-migration assertions before the subsequent standalone Doctor phase, preserved-state checks and Gateway health/readiness/status. The lane passed in393s, one attempt, zero retries; artifact hashes and phase order were verified. The explicit file spec bypasses the published driver's same-version no-op. Inner updater/repair JSON and a direct installed-tree hash are not uploaded, so zero repair and byte-for-byte installed-tree attestation are not claimed. This resolves the review's required compatibility items without changing migration or stored-data contracts.

Independent P2 review found no actionable defect across two evidence batches; maintainer review covered the full owners and the split-context limitations. Source checks confirm unchanged selectors, limits, persisted types, normalizer and journal/query arguments. The final eight source files are identical to their tested and reviewed bytes after the mechanical refresh onto current main.

Production adds 45 net lines for the shared lightweight record owner, prepared arguments and absent-directory checks; tests add 37. No new loader, cache, SDK seam, worker, shard, wait or deadline. Changelog remains release-owned.

@steipete steipete self-assigned this Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 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 channel: voice-call Channel integration: voice-call extensions: crabbox size: S maintainer Maintainer-authored PR labels Sep 13, 2026
@steipete
steipete marked this pull request as ready for review September 13, 2026 10:23
@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 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 13, 2026, 6:57 AM ET / 10:57 UTC (Revision 2).

ClawSweeper review

What this changes

Doctor avoids loading unnecessary storage code for plugin checks, while Memory Host loads its storage implementation only when reading or writing events.

Merge readiness

⛔ Blocked before merge - 3 items remain

The optimization remains useful on current main, and no introduced correctness defect was found. The maintainer-owned PR is not a cleanup-close candidate.

Priority: P2
Reviewed head: 607628d87163406aaaa34f686f0fa647d22ef4c9

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable optimization with meaningful regression coverage and successful exact-head CI; updater compatibility verification remains a landing gate.
Proof confidence 🌊 off-meta tidepool Not applicable: The ordinary external-contributor proof gate does not apply to this maintainer-owned PR. The body records Doctor timing comparisons and compiled Memory Host persistence checks; the separately required published-updater acceptance result remains pending.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The ordinary external-contributor proof gate does not apply to this maintainer-owned PR. The body records Doctor timing comparisons and compiled Memory Host persistence checks; the separately required published-updater acceptance result remains pending.
Evidence reviewed 9 items Introduced scope and clean checkout: The pinned merge-base-to-head change matches the eight supplied introduced files. The checkout matches the earlier reviewed head, git diff --check passed, and git status remained clean.
Crabbox preserves storage ownership: Both namespaces now use the supplied context. Its production factory binds the plugin identity and default environment to the existing keyed-store owner; the extracted limits, selectors, and lease projection preserve their original values and encoding.
Absent-state guard preserves existing repairs: Voice Call skips repair imports only when the entire resolved store root is absent. Existing tests retain database-only schema repair, malformed-log preservation, partial-write recovery, and capacity coverage; four added cases cover default/custom absent stores in detection and migration.
Findings None None.
Security None None.

How this fits together

Doctor inspects plugin state and delegates repairs to plugin-owned migrations. These changes reduce dependencies loaded during inspection while retaining the existing SQLite storage and recovery owners.

flowchart TD
  A[Doctor state checks] --> B[Crabbox migration context]
  A --> C{Voice Call store exists?}
  B --> D[Existing plugin storage]
  C -->|No| E[Empty result]
  C -->|Yes| F[Existing detection and repair]
  F --> D
  G[Memory event reads and writes] --> H[Load storage on demand]
  H --> D
Loading

Before merge

Agent review details

Security

None.

PR surface

Source +45, Tests +37. Total +82 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 6 87 42 +45
Tests 2 39 2 +37
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 126 44 +82

Review metrics

Metric Value Why it matters
Production versus test growth production +45 net lines; tests +37 net lines Production growth is justified by shared lightweight record policy, prepared storage arguments, and absent-directory checks without a new storage or SDK owner.

Stored data model

Persistent data-model change detected: migration/backfill/repair: extensions/crabbox/doctor-contract-api.ts, migration/backfill/repair: extensions/voice-call/doctor-contract-api.ts, unknown-data-model-change: extensions/crabbox/doctor-contract-api.ts, unknown-data-model-change: extensions/voice-call/doctor-contract-api.ts, unknown-data-model-change: src/memory-host-sdk/event-store.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Retain the lightweight shared record policy and existing migration/storage owners, with published-updater compatibility established before landing.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Retain the lightweight shared record policy and existing migration/storage owners, with published-updater compatibility established before landing.

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

Yes for the unnecessary-loading mechanism: current-main source reaches the identified imports during otherwise empty checks. The local timing comparison is contributor-reported; this review did not execute it.

Is this the best way to solve the issue?

Yes. Reusing the supplied store context and deferring imports removes the observed overhead without duplicating migration logic or changing persisted formats.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This is a bounded Doctor performance improvement with measured local benefit and no established urgent user-facing regression.
  • 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 ordinary external-contributor proof gate does not apply to this maintainer-owned PR. The body records Doctor timing comparisons and compiled Memory Host persistence checks; the separately required published-updater acceptance result remains pending.

Evidence

What I checked:

  • Introduced scope and clean checkout: The pinned merge-base-to-head change matches the eight supplied introduced files. The checkout matches the earlier reviewed head, git diff --check passed, and git status remained clean. (607628d87163)
  • Crabbox preserves storage ownership: Both namespaces now use the supplied context. Its production factory binds the plugin identity and default environment to the existing keyed-store owner; the extracted limits, selectors, and lease projection preserve their original values and encoding. (src/infra/state-migrations.plugin-doctor-context.ts:285, 607628d87163)
  • Absent-state guard preserves existing repairs: Voice Call skips repair imports only when the entire resolved store root is absent. Existing tests retain database-only schema repair, malformed-log preservation, partial-write recovery, and capacity coverage; four added cases cover default/custom absent stores in detection and migration. (extensions/voice-call/doctor-contract-api.ts:274, 607628d87163)
  • Memory event contract retained: Normalization, workspace keys, timestamps, retention limits, journal arguments, and query arguments remain prepared before the new lazy import. Existing callers already await these operations, and sequence allocation remains with the existing storage owner. (src/memory-host-sdk/event-store.ts:303, 607628d87163)
  • Current main still has the unnecessary imports: Inspected fetched-main source retains Crabbox's runtime-store import, Voice Call's repair import before the absent-store check, and Memory Host's eager storage import. No merged replacement was established; the bounded GitHub related-PR search was unavailable. (src/memory-host-sdk/event-store.ts:4, 4d48e9c1e026)
  • Latest release comparison: The v2026.9.4 source also eagerly imports Memory Host storage. This confirms that the lazy-loading change is not present in that release. (src/memory-host-sdk/event-store.ts:4, 3a9d69db306c)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rank-up moves

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

  • Record the completed published-updater-to-candidate acceptance result and verify that it covers candidate 607628d.

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 (1 earlier review cycle)
  • reviewed 2026-09-13T10:30:00.765Z sha 607628d :: blocked before merge. :: none

@steipete
steipete merged commit 3ec33f5 into main Sep 13, 2026
267 checks passed
@steipete
steipete deleted the codex/perf-crabbox-doctor-context branch September 13, 2026 11:24
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to zachisfine/openclaw that referenced this pull request Sep 13, 2026
* temp/pr-146799: (70 commits)
  test: reuse explicit fallback config fixtures (openclaw#146948)
  fix(computer): return fresh window observations after actions (openclaw#146822)
  refactor(feishu): remove unreachable requester topic selection (openclaw#146904)
  improve(gateway): reduce CPU spent listing agent-owned sessions (openclaw#137745)
  fix(ui): avoid recapturing chat drafts during UI updates (openclaw#146884)
  fix(ui): show system uptime in the debug overlay (openclaw#146960)
  fix(retry): honor waits beyond the native timer limit (openclaw#145718)
  fix(ui): keep chat history idle when run status changes (openclaw#146802)
  fix(ui): reuse persisted text during chat streaming (openclaw#146831)
  refactor(qa): share harness drift result construction (openclaw#146903)
  test(agents): coordinate settings lock contention (openclaw#146949)
  fix(worker): avoid repeatedly serializing screenshot history (openclaw#146907)
  fix(secrets): stop buffered upload writes after cancellation (openclaw#146840)
  perf(doctor): avoid unnecessary state runtime imports (openclaw#146926)
  improve: reduce compaction request estimation work (openclaw#146961)
  fix(ci): wait for forwarded avatar imports before assertions (openclaw#146729)
  perf(workers): skip configured Git author lookups (openclaw#146833)
  fix: admit borrowed memory writes through the agent database owner (openclaw#146760)
  fix(discord): prevent voice playback gaps and stale turn controls (openclaw#146798)
  improve: reduce worktree filesystem stalls and archive syncs (openclaw#146906)
  ...
vincentkoc added a commit that referenced this pull request Sep 13, 2026
* commit 'ccfd2377cd07d1ad3a583ba64d08e29a065f7061': (1587 commits)
  fix(ui): avoid recapturing chat drafts during UI updates (#146884)
  fix(ui): show system uptime in the debug overlay (#146960)
  fix(retry): honor waits beyond the native timer limit (#145718)
  fix(ui): keep chat history idle when run status changes (#146802)
  fix(ui): reuse persisted text during chat streaming (#146831)
  refactor(qa): share harness drift result construction (#146903)
  test(agents): coordinate settings lock contention (#146949)
  fix(worker): avoid repeatedly serializing screenshot history (#146907)
  fix(secrets): stop buffered upload writes after cancellation (#146840)
  perf(doctor): avoid unnecessary state runtime imports (#146926)
  improve: reduce compaction request estimation work (#146961)
  fix(ci): wait for forwarded avatar imports before assertions (#146729)
  perf(workers): skip configured Git author lookups (#146833)
  fix: admit borrowed memory writes through the agent database owner (#146760)
  fix(discord): prevent voice playback gaps and stale turn controls (#146798)
  improve: reduce worktree filesystem stalls and archive syncs (#146906)
  fix(ui): avoid extra chat rail work while replies stream (#146883)
  improve(ui): speed up populated Usage timelines (#146947)
  test(gateway): retain auth recovery failure diagnostics (#146925)
  fix(tests): create private temporary home directories (#146931)
  ...

# Conflicts:
#	test/tsconfig/tsconfig.core.test.agents-other.json
#	test/tsconfig/tsconfig.core.test.agents-root.json
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: voice-call Channel integration: voice-call extensions: crabbox 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