Repository navigation
improve: speed up Doctor checks on large session histories - #133100
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 30, 2026, 1:44 AM ET / 05:44 UTC. ClawSweeper reviewWhat this changesThe 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 readinessKeep 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 Priority: P3 Review scores
Verification
How this fits togetherDoctor 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
Before merge
Agent review detailsSecurityNone. PR surfaceSource +6, Tests +18. Total +24 across 2 files. View PR surface stats
Review metrics
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
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
untrustednorUntrusted: 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
ui/vite.config.tsexpectspako3.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.3a4858ce31315cf837840cb62d36a5eff46ca41a.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-survivorlane withOPENCLAW_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, andOPENCLAW_UPGRADE_SURVIVOR_VOLUME_CRON_JOBS=10000vianode 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.