Skip to content

perf(doctor): build canonical repair groups in place - #170177

Merged
steipete merged 1 commit into
mainfrom
dbasync/redmain-doctor-grouping-publication
Oct 12, 2026
Merged

steipete merged 1 commit into
mainfrom
dbasync/redmain-doctor-grouping-publication

Conversation

@steipete

@steipete steipete commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

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) and fc4d5d744fad (#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:

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 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 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: 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.

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.
@clawsweeper

clawsweeper Bot commented Oct 12, 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 commands Command implementations size: XS labels Oct 12, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 12, 2026
@clawsweeper

clawsweeper Bot commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: The two grouping loops copy 144,012,000 accumulated references.
  • After: Each loop appends each candidate once, preserving group membership and order.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) A correct, worthwhile optimization with focused production-owner evidence; controlled performance causality and targeted shipped-entry-point proof are not established.
Proof confidence 🦐 gold shrimp (3/6) The repository state identifies this as maintainer-authored, so the ordinary contributor proof gate does not apply; reported composed-head scale and owner runs exercise both changed production loops, while the successful update job is broader smoke evidence and its detailed logs were network-blocked.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Performance · Worth it: Yes · Fix scope: Complete
User problem: Doctor spends avoidable allocation and copying work constructing large alias repair groups.
Reason: The maintainer-authored direction has clear value for an existing scale workload and introduces no setting, API, schema, or competing owner.

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
Reviewed head: 55c9c214b2b9080ff778460de0cd1f2c8df8da94

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: The targeted repair evidence uses the production-owner harness rather than the shipped Doctor CLI, and no comparable before/after benchmark establishes timeout causality.
Agent review details

How this fits together

Doctor 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]
Loading

Technical review

Best 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

  • Doctor candidate hydration grouping keeps the original intent (61221c4: Bound session repair memory by retaining compact facts and hydrating selected candidates at the storage owner.)
  • Transcript generation preparation grouping keeps the original intent (fc4d5d7: Normalize imported transcript generations before canonical copy or archival so recovery remains safe.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Verified introduced change: The pinned introduction diff replaces only two accumulated-array spread operations with appends to function-owned groups; keys, consumers, SQL, transactions, and repair decisions remain unchanged. (src/commands/doctor-session-canonical-keys.ts:136, 55c9c214b2b9)
  • Current-main need: Fetched main retains both quadratic spread expressions; comparing the concrete modules against the reviewed head shows the same focused optimization remains necessary. (src/config/sessions/session-accessor.sqlite-canonical-repair.ts:167, 08f9f52fb180)
  • Repair-boundary coverage: The existing scale fixture supplies 12,001 aliases and 200,000 transcript events, invokes the production repair owner in a Node child under Doctor maintenance ownership, and checks retained events, the winning canonical node, and foreign keys. (src/commands/doctor-session-canonical-keys.scale.test.ts:30, 55c9c214b2b9)
  • Composed-head evidence: The full PR body reports passing scale and owner-repair runs on composed heads. GitHub source reads confirm the reported heads contain the same grouping changes. These are production-owner harness results, not a controlled before/after timeout benchmark. (55c9c214b2b9)
  • Published-driver update receipt: The linked published-driver update job succeeded at f1979f3, including its update step. The composed CI run as a whole failed other lanes. Downloading job logs was blocked by the managed proxy's Azure-host allowlist, so detailed readiness and preservation assertions were not independently inspected. (f1979f3b6f5a)
  • Current failed check: The current PR context and evidence check rejects missing authored section headings; its annotations establish a body-format failure rather than a production-code failure. Other required checks were still running at inspection. (55c9c214b2b9)

Likely related people:

  • Josh Avant: Raw commit fc4d5d7 adds src/config/sessions/session-accessor.sqlite-canonical-repair.ts:154 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: fc4d5d744fad; files: src/config/sessions/session-accessor.sqlite-canonical-repair.ts)

PR surface

Source +12. Total +12 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 16 4 +12
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 16 4 +12

Review metrics

Metric Value Why it matters
Production versus test LOC Production +16/-4; tests +0/-0 The small increase replaces repeated array reconstruction with explicit append branches and reuses existing repair coverage.

Labels

Label changes:

  • add P2: This is a focused improvement for large Doctor repair groups; the source proves unnecessary quadratic work, but the reported timeout is not causally attributed to it.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: This is a focused improvement for large Doctor repair groups; the source proves unnecessary quadratic work, but the reported timeout is not causally attributed to it.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 12, 2026, 3:43 PM ET / 19:43 UTC.

@steipete
steipete merged commit 1a598b2 into main Oct 12, 2026
128 of 132 checks passed
@steipete
steipete deleted the dbasync/redmain-doctor-grouping-publication branch October 12, 2026 19:46
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 13, 2026
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.
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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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