Skip to content

improve: speed up Doctor checks on large session histories - #133100

Merged
steipete merged 1 commit into
mainfrom
codex/profile-migration-performance
Aug 30, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/profile-migration-performance

Conversation

@steipete

@steipete steipete commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Doctor repeatedly scans every stored message during session upgrade checks, even after a history is already current. Node CPU profiles of 20,000 synthetic sessions / 500,000 events showed legacy-label normalization consuming about 27% of the label check's sampled execution.

Why This Change Was Made

Skip the frozen legacy rewrite rules when decoded message text contains neither untrusted nor Untrusted: every existing rule requires one of those spellings. Keep the check after JSON decoding so Unicode-escaped historical labels still migrate. The existing repair owner, timestamp handling, exact-snapshot validation, and runtime stripping contracts are unchanged.

This adds six production lines and extends the existing escaped/unescaped repair cases (+26/-8 test lines). The small filter removes redundant regex work without duplicating the migration rules or adding a cache. No SQLite schema, transaction, durability, recovery, configuration, or API changes.

User Impact

Faster Doctor label checks for large histories containing ordinary or already-migrated messages. Legacy labels retain the same detection and repair behavior.

Evidence

  • Node v26.8.1 CPU profiles identified the hot path and confirmed the regex work disappears for ordinary messages.
  • Full label-health owner on 20,000 synthetic sessions / 500,000 events: median 1,821.72 ms → 988.75 ms (45.72% lower). Three fresh processes per version, three rounds each, interleaved B/A, A/B, B/A. The database SHA-256 was identical before/after. This measures the label-check phase, not the whole upgrade.
  • 80 focused tests passed: label migration, header repair, runtime stripping, Unicode escapes, exact-snapshot guards, malformed siblings, metadata preservation, and unchanged bytes under a 256 MiB heap.
  • Formatting, targeted lint, core typechecking, and diff checks passed. The aggregate local test typecheck stops at the pre-existing shared-install mismatch (ui/vite.config.ts expects pako 3.0.1; the shared install resolves 1.0.11 without declarations); all fresh CI production/test typecheck jobs pass with the pinned dependency setup. Independent Codex review with full owner/reader/test/stripper evidence found no actionable findings.
  • Exact-head CI passed for 3a4858ce31315cf837840cb62d36a5eff46ca41a.
  • Blacksmith Testbox Docker proof: latest stable 2026.7.1-2 → package built from that exact commit; the existing published upgrade survivor lane passed. Verified 20,000 sessions, 497,750 transcript events, and 10,000 cron jobs five times, including automatic migration before standalone Doctor/capability consent and after restart. Eight Gateway history samples across two agents retained all 144 checked messages and identical hashes across restart. Repeated Doctor completed in 21s under its unchanged 60s budget; startup readiness was 8s. Wrapper exit 0; lease stopped after evidence capture. The holder workflow may show cancelled after external cleanup.

Docker command: existing published-upgrade-survivor lane with OPENCLAW_UPGRADE_SURVIVOR_BASELINE_SPECS=2026.7.1-2, OPENCLAW_UPGRADE_SURVIVOR_SCENARIOS=sqlite-volume, OPENCLAW_UPGRADE_SURVIVOR_VOLUME_SESSIONS=20000, OPENCLAW_UPGRADE_SURVIVOR_VOLUME_EVENTS_PER_SESSION=25, and OPENCLAW_UPGRADE_SURVIVOR_VOLUME_CRON_JOBS=10000 via node scripts/test-docker-all.mjs. The real update command selects the candidate tarball explicitly; this does not claim background stable-to-main channel switching. Fixture plugin capability consent remains explicit.

The importer profile also exposed time in synchronous SQLite commits and disposable-spool cleanup. Those settings are intentionally unchanged: storage durability/recovery tuning needs a separate accepted design and failure proof.

@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: XS maintainer Maintainer-authored PR labels Aug 30, 2026
@steipete
steipete marked this pull request as ready for review August 30, 2026 05:31
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 1:44 AM ET / 05:44 UTC.

ClawSweeper review

What this changes

The PR speeds up Doctor’s session transcript-label migration by skipping legacy rewrite regexes for decoded message text that cannot match a legacy label.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

Keep this PR open for normal maintainer handling. The introduced fast path is limited to Doctor’s legacy-label migration, and direct source review shows every rewrite rule requires either untrusted or Untrusted; the added decoded-text guard and escaped-label regression coverage preserve that invariant.

Priority: P3
Reviewed head: 3a4858ce31315cf837840cb62d36a5eff46ca41a

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, owner-local optimization with regression coverage for the important decoded Unicode-escape case; no actionable correctness or security issue was found.
Proof confidence 🌊 off-meta tidepool Not applicable: This repository-member PR is exempt from the external-contributor real-behavior-proof gate; its body reports benchmark results, while source review confirms the changed migration path and focused regression coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This repository-member PR is exempt from the external-contributor real-behavior-proof gate; its body reports benchmark results, while source review confirms the changed migration path and focused regression coverage.
Evidence reviewed 7 items Introduced change: The verified PR delta adds only an early return before the existing legacy rewrite rules; no storage, configuration, or transaction behavior is changed.
Matcher invariant: All eight legacy rewrite patterns require the lower-case or capitalized legacy spelling, so text rejected by the guard could not have been rewritten by the prior implementation.
Decoded-content boundary: The migration applies the helper only after JSON event decoding, for string content and text parts; this makes escaped JSON label text visible to the new guard.
Findings None None.
Security None None.

How this fits together

Doctor scans persisted SQLite session transcript events and rewrites old inbound-metadata headers into the current marker-based format. The filter runs after event JSON decoding, before the canonical legacy rewrite rules and existing guarded persistence path.

flowchart LR
  A[Stored session transcript] --> B[Doctor label health check]
  B --> C[Decode event message text]
  C --> D{Legacy spelling present?}
  D -->|Yes| E[Apply canonical legacy rewrites]
  D -->|No| F[Keep text unchanged]
  E --> G[Guarded transcript update]
  F --> G
Loading

Before merge

  • Complete next step (P2) - This member-authored, maintainer-labeled PR has no mechanical repair identified and should proceed through normal exact-head CI and maintainer review.
Agent review details

Security

None.

PR surface

Source +6, Tests +18. Total +24 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 6 0 +6
Tests 1 26 8 +18
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 32 8 +24

Review metrics

Metric Value Why it matters
Production versus test LOC production +6; tests +26/-8 The small production increase is the necessary early return that avoids all legacy regex work for ordinary decoded messages; tests add escaped and capitalized legacy-label coverage.

Technical review

Best possible solution:

Retain this owner-local decoded-text fast path and its escaped legacy-label coverage, then merge once the exact-head required checks complete.

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

Not applicable: this is a performance optimization, not a report of broken behavior. The source identifies the exact repeated rewrite path and the test exercises the relevant decoded escaped-input cases.

Is this the best way to solve the issue?

Yes. The early return sits in the canonical migration owner after JSON decoding, preserves every existing matching condition, and avoids adding caches, alternate migration paths, or storage changes.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against d5672464f2e8.

Labels

Label changes:

  • add P3: This is a bounded performance improvement to Doctor’s maintenance path, with no changed user-facing contract.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This repository-member PR is exempt from the external-contributor real-behavior-proof gate; its body reports benchmark results, while source review confirms the changed migration path and focused regression coverage.

Label justifications:

  • P3: This is a bounded performance improvement to Doctor’s maintenance path, with no changed user-facing contract.
  • 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: This repository-member PR is exempt from the external-contributor real-behavior-proof gate; its body reports benchmark results, while source review confirms the changed migration path and focused regression coverage.

Evidence

What I checked:

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

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.

@steipete
steipete merged commit 7fa0bd1 into main Aug 30, 2026
314 of 315 checks passed
@steipete
steipete deleted the codex/profile-migration-performance branch August 30, 2026 05:46
@steipete

Copy link
Copy Markdown
Contributor 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 maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS 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