Repository navigation
perf(doctor): build canonical repair groups in place - #170177
Conversation
Append to function-owned groups instead of repeatedly copying accumulated candidates. For a single 12,001-candidate store, the two loops previously copied 144,012,000 existing references. Preserve candidate order, first database scope, SQL, and transaction behavior. The existing scale boundary remains unchanged; runtime qualification is pending in the red-main campaign.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesThis PR builds Doctor canonical-session repair groups by appending to locally owned arrays instead of repeatedly copying accumulated candidates. Example: Doctor repairs one database containing 12,001 canonical-session candidates.
Review scores
ProductKind: Performance · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it removes concrete quadratic work still present on current main while preserving repair behavior, and no actionable correctness or security defect was found. Priority: P2 Before mergeNone. FindingsNone. Tests
Agent review detailsHow this fits togetherDoctor collects canonical-session repair facts, hydrates candidates by store, and prepares transcript generations by database before the existing SQLite repair transactions. flowchart LR
A[Doctor repair] --> B[Canonical candidate facts]
B --> C[Group and hydrate by store]
C --> D[Select canonical winners]
D --> E[Group sources by database]
E --> F[Prepare transcript generations]
F --> G[Existing SQLite repair transactions]
Technical reviewBest possible solution: Land the focused in-memory optimization through the normal merge workflow while preserving the existing repair and storage contracts. Do we have a high-confidence way to reproduce the issue? Current-main source deterministically copies n(n−1)/2 references per grouping loop for one n-candidate group; the existing 12,001-candidate fixture reaches both loops, but no controlled run establishes grouping as the timeout cause. Is this the best way to solve the issue? Appending to private arrays is the simplest owner-level repair: neither group escapes during construction, and ordering, first scope, input objects, and downstream database operations remain equivalent. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 08f9f52fb180. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource +12. Total +12 across 2 files. Added test files: 0. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 12, 2026, 3:43 PM ET / 19:43 UTC. |
Doctor canonical-session repair rebuilt each accumulated candidate array for every appended row. One deep alias group bypasses the usefulness of the 64-group batch limit: the existing 12,001-candidate scale fixture causes the two grouping loops to copy 144,012,000 existing references before repair can finish. This change appends to function-owned arrays, preserving candidate order, database grouping, the first resolved database scope, SQL, transactions, and repair decisions. It changes two files (+16/-4); no new API, check, schema, or SQLite operation is introduced. The two quadratic expressions originated in `fee9ee2148a3` (openclaw#126353) and `cd4f2480c2f5` (openclaw#123495). The observed scale failure on [the earlier repair candidate](https://github.com/openclaw/openclaw/actions/runs/38283393506/job/114926176837) was a child SIGTERM at its existing 60-second limit; the last recorded phase was repair entry. This establishes the failing flow and workload, not that grouping alone caused that timeout. No causal parent control or before/after timing benchmark is claimed. Focused production-path proof: | Test | Exact composed head | Result | Vitest / wrapper wall time | | --- | --- | --- | --- | | `pnpm test src/commands/doctor-session-canonical-keys.scale.test.ts --maxWorkers=1` | `7ac691f4a04689c9711192262ad0bc3c73b6ad92` | 1/1; case 66.300 s | 126.26 / 172.89 s | | `pnpm test src/commands/doctor-session-canonical-keys.owner-repair.test.ts --maxWorkers=1` | `f1979f3b6f5ac9aa59a3f4c83dbe20b9ac49b535` | 4/4 | 234.79 / 526.36 s | The unchanged scale test executes both edited loops through a real Node child under Doctor maintenance ownership and verifies that all 200,000 transcript events survive, one expected canonical node remains, and foreign keys are valid. The owner tests preserve required creation provenance, replace a stale owner with the selected winner, recover a stolen transcript window without losing history, and verify a repeat repair is a no-op. Both receipts ended at their original clean heads with no surviving processes. These are composed-head results; the composition also contained temporary phase diagnostics excluded from this change. [Composed-head CI](https://github.com/openclaw/openclaw/actions/runs/38292637049) passed build, production and test types, all core lint stripes, source contracts, Knip, architecture/Madge, and database worker/dialect ratchets. The [published-driver update cell](https://github.com/openclaw/openclaw/actions/runs/38292637049/job/114965277486) executed and passed from published 2026.10.2 to candidate 2026.10.2 at `f1979f3b6f5a`: candidate checksum matched, update completed, readiness returned 200, and running version was verified. One Codex autoreview returned no findings. The publication preserves the newer main-key admission change. The two grouping bodies retain the reviewed and tested behavior; no standalone publication-head static run is represented as already complete. The separate low-heap dry-run memory test remains unresolved: at `f1979f3b6f5a` it exceeded its existing 90-second case limit (90.277 s; Vitest 444.68 s / wrapper 557.96 s). Its child runs `apply:false`, so neither changed grouping loop executes. This is not a passing memory result or an inferred timeout root cause. The separate fixture-only commit `c92696a32a7bd33d7ca98be7f94f09f42d2acb8f` moves its unchanged minified/split bundle preparation to `beforeAll`; its runtime rerun is pending. That fixture keeps the existing 160 MiB heap, 60-second child and 90-second case limits. This Doctor-only in-memory optimization does not remove SQLite reads, writes, or authority checks. No T1 reduction or warmed-turn SQL/request saving is claimed. Update and repair behavior remain unchanged; only group construction loses its quadratic copying cost. Direct-main publication was refused by the repository ruleset; this emergency repair uses the authorized head-pinned PR squash fallback. Main is not yet established green. Applicable newer static proof is also green at `8d087040fefe324e5ff7fa76faf497fadb542c08` in [CI run 38298120555](https://github.com/openclaw/openclaw/actions/runs/38298120555): production types, all core/general lint, source contracts, Knip/dependencies, architecture and baseline ratchets. The changed test graphs passed in core stripe 5 (`commands-doctor`, job 114974448774) and stripe 4 (`agents-sessions`, job 114974448893). The pending core-3 test stripe owns neither graph. These remain composed-head proofs with the integration limits stated above.
Doctor canonical-session repair rebuilt each accumulated candidate array for every appended row. One deep alias group bypasses the usefulness of the 64-group batch limit: the existing 12,001-candidate scale fixture causes the two grouping loops to copy 144,012,000 existing references before repair can finish. This change appends to function-owned arrays, preserving candidate order, database grouping, the first resolved database scope, SQL, transactions, and repair decisions. It changes two files (+16/-4); no new API, check, schema, or SQLite operation is introduced.
The two quadratic expressions originated in
61221c4c20ec(#126353) andfc4d5d744fad(#123495). The observed scale failure on the earlier repair candidate was a child SIGTERM at its existing 60-second limit; the last recorded phase was repair entry. This establishes the failing flow and workload, not that grouping alone caused that timeout. No causal parent control or before/after timing benchmark is claimed.Focused production-path proof:
pnpm test src/commands/doctor-session-canonical-keys.scale.test.ts --maxWorkers=17ac691f4a04689c9711192262ad0bc3c73b6ad92pnpm test src/commands/doctor-session-canonical-keys.owner-repair.test.ts --maxWorkers=1f1979f3b6f5ac9aa59a3f4c83dbe20b9ac49b535The unchanged scale test executes both edited loops through a real Node child under Doctor maintenance ownership and verifies that all 200,000 transcript events survive, one expected canonical node remains, and foreign keys are valid. The owner tests preserve required creation provenance, replace a stale owner with the selected winner, recover a stolen transcript window without losing history, and verify a repeat repair is a no-op. Both receipts ended at their original clean heads with no surviving processes. These are composed-head results; the composition also contained temporary phase diagnostics excluded from this change.
Composed-head CI passed build, production and test types, all core lint stripes, source contracts, Knip, architecture/Madge, and database worker/dialect ratchets. The published-driver update cell executed and passed from published 2026.10.2 to candidate 2026.10.2 at
f1979f3b6f5a: candidate checksum matched, update completed, readiness returned 200, and running version was verified. One Codex autoreview returned no findings. The publication preserves the newer main-key admission change. The two grouping bodies retain the reviewed and tested behavior; no standalone publication-head static run is represented as already complete.The separate low-heap dry-run memory test remains unresolved: at
f1979f3b6f5ait exceeded its existing 90-second case limit (90.277 s; Vitest 444.68 s / wrapper 557.96 s). Its child runsapply:false, so neither changed grouping loop executes. This is not a passing memory result or an inferred timeout root cause. The separate fixture-only commitc92696a32a7bd33d7ca98be7f94f09f42d2acb8fmoves its unchanged minified/split bundle preparation tobeforeAll; its runtime rerun is pending. That fixture keeps the existing 160 MiB heap, 60-second child and 90-second case limits.This Doctor-only in-memory optimization does not remove SQLite reads, writes, or authority checks. No T1 reduction or warmed-turn SQL/request saving is claimed. Update and repair behavior remain unchanged; only group construction loses its quadratic copying cost.
Direct-main publication was refused by the repository ruleset; this emergency repair uses the authorized head-pinned PR squash fallback. Main is not yet established green.
Applicable newer static proof is also green at
8d087040fefe324e5ff7fa76faf497fadb542c08in CI run 38298120555: production types, all core/general lint, source contracts, Knip/dependencies, architecture and baseline ratchets. The changed test graphs passed in core stripe 5 (commands-doctor, job 114974448774) and stripe 4 (agents-sessions, job 114974448893). The pending core-3 test stripe owns neither graph. These remain composed-head proofs with the integration limits stated above.