Skip to content

chore(test): reduce large-index GC startup overhead - #155928

Merged
steipete merged 1 commit into
mainfrom
codex/test-worktree-gc-prepared-child
Sep 22, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/test-worktree-gc-prepared-child

Conversation

@steipete

@steipete steipete commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The large-index worktree GC regression spends part of its bounded child-process run loading TypeScript and source workers.

User Impact

No product behavior changes. The large-index case is faster in both measured pairs, with the same real Git input and recovery assertions. Whole-command benefit is inconclusive, and the cause of the historical CI timeout remains unexplained.

Why This Change Was Made

The test now uses the existing prepared-subprocess owner, as the Code Mode retention fixtures do. A thin fixture runs GC in a real Node main-thread process and resolves its nested Git worker from the same prepared generation. Source execution retains the existing resolver fallback.

The 180,000-entry index, 60-second managed deadline, strict process-tree exit, local-edit/deletion restoration, and all 37 cases remain. Production GC and inventory code are unchanged. The real main-thread boundary matters: #138066 originally caught a stack overflow that Vitest worker threads could miss.

Evidence

Proof used configured Blacksmith Testbox, pinned to f9c524daa03e5febd2bc3fb01c6f3cb7387798bd plus the exact five-file candidate tree fa7b62db5bfee47df970b8c44774ae722bd8d235.

  • 20 complete standalone files, 37 passes each, using pnpm test src/agents/worktrees/service.gc.test.ts --maxWorkers=1.
  • Three original-order native CI replays, each with 3,777 passes and four original skips. Actual resources matched the failed job: eight CPUs, 33,231,855,616 bytes RAM, two admitted plans, two workers per plan. Original groups, case identities, assertions and deadlines remained; automatic retries were disabled.
  • 109 existing sibling cases passed across worktree recovery, Code Mode retention, and compiled-worker ownership/transforms.
  • The complete selected changed gate passed in 1,569.144 s, including all 25 core-test type partitions and script types. pnpm build passed in 314.001 s. Independent P2 review found no actionable issues.
  • Separate executed-route traces verified the actual Node entrypoint and nested Git worker. A translated version of the historical unsafe bulk spread produced a real RangeError through both routes. This is a translated primitive control, not a replay of the entire historical checkout.

Comparison lease · Standalone, siblings, gate and build lease · Original-order qualification lease. These identify the Testbox leases; the manual command receipts and downloaded archives were verified separately. All owned leases are stopped. Published-head CI is recorded below.

Current-main integration

The unchanged five-file optimization was refreshed onto 85a481530c44cebb0736f9bf00a9da18cd786fcf, including the canonical wrapper-inventory repair 3a4bbc6882a. Its stable patch ID remains 1772e9ca8a3d818a9c46980dc62576008539a2de; current manual proof covers candidate tree 81cc43e79550069ad674df7379d851a5440d586d.

The first published head fcfc835bfe733b5b2642ab86d990e0a368f42ab7 ran as merge 914cd06d6a1c830ac92659c99f52a4ba46c9f7e8 onto f0d26603a5c1210dab73e4362b017eccdd585931. Its GC shard passed all 37 cases: 37.651 s summed reported case durations, including 8.837 s for the large-index whole case. CI did not emit a complete file wall time. The overall run failed in five tooling jobs: a prior main refactor, 43d85e5f9ac3, had omitted the extracted reader-context and spawn-diagnostics files from the wrapper inventory. The canonical two-row repair restores those dependencies; it is inherited from main, outside this optimization's five-file delta.

Current integration used configured Blacksmith Testbox. Its proof passed:

  • One complete GC file: 37 passed, 65.693 s command wall, 44.840 s test phase, 9.494 s large-index case, 11.636 s worker preparation, and 2.66 GiB peak command RSS.
  • Compiler ownership/transform siblings: 38 passed in 76.112 s.
  • All five previously failed tooling groups, retaining their original 196-file payloads and file order: 6,809 passed, 138 skips, zero failures. Every one of the 33 originally failed case names is now explicitly passing. Native admission was retained, retries were disabled, and this standard Testbox's four CPUs/16.56 GB differ from the original constrained tooling runners. No identical-interleaving or cross-base case-inventory claim is made.
  • The complete canonical changed gate passed in 1734.900 s. Fresh independent P2 review found no actionable issues. No extra manual full build was selected; the earlier build remains bound to f9, and the green published-head CI below supplies the integration build.

Published head 7099bd69ee5bdd3037c15ad8e166542aaf0f0fae now has green CI, including the integration build. It tested merge 3a9cb24efbee3feaabc32c1682c46fe2165867be onto bc635fc9400da428818ceb9e736de26336ee8f96. The GC shard passed all 37 cases: 41.133 s summed reported case durations, including 11.002 s for the large-index whole case. CI did not emit a complete-file wall time. These are absolute costs on the published merge, not a new before/after comparison.

These are current-source absolute costs, not another before/after benchmark. The earlier ABBA, 20 standalone runs and three original-order replays below retain their original source bindings and qualifications.

Measured cost

The untraced comparison ran all 37 cases on four CPUs/16.56 GB, using the normal runner and cache policy:

Arm Complete command Large-index case Worker preparation Peak command RSS
Baseline A1 58.973 s 17.378 s 10.269 s 2.78 GiB
Prepared B1 50.114 s 9.069 s 8.626 s 2.71 GiB
Prepared B2 100.752 s 14.510 s 25.924 s 2.67 GiB
Baseline A2 93.600 s 26.427 s 14.377 s 2.79 GiB

The target case improved 47.81% before the interruption and 45.09% afterward. The comparison was interrupted between B1 and B2 for 22m14.861s, measured from B1's test-file end to B2's command start; the original B1 command-end timestamp was not recorded. Preparation and unrelated case costs drifted substantially. These measurements do not establish a whole-file, full-suite, or memory saving; overlapping phases are not additive.

The three qualification replays took 449.363/421.280/437.896 s, with large-index whole-case times of 15.067/16.978/16.692 s. These are absolute costs, not new before/after comparisons. The file needs real processes and Git recovery to exercise the main-thread stack and filesystem contracts; reducing the index or substituting mocked recovery would lose that proof.

Source binding and interrupted-proof qualifications

The first comparison stopped after B1 because its proof driver incorrectly required identical emitted bytes across separate generations. Full compiler input maps were identical; the fixture differed only in its generated service-chunk import. The compiler embeds the output directory in external URLs, so those names are directory-bound. The corrected check verifies each generation against its own manifest; only the unrun B2/A2 cells resumed. The original assertion failure, executed-route traces, negative controls and timing gap remain preserved. Transitive service-chunk bytes were no longer available after normal generation disposal. No per-arm or per-replay loaded-byte attestation is claimed.

One later standalone command, B03, completed while local disk exhaustion interrupted its control-process capture. Read-only recovery verified all 37 passing cases, command exit 0, all 618 source hashes, all 10,585 compiler-input hashes, emitted-output manifest checks and native disposal verification. It was counted once, with a separately recorded post-interruption source snapshot; the original controller result/source-after files are missing. B04–B20 then completed with normal per-phase receipts. Pre-test transport, idle-expiry and ownership-transfer refusals are retained separately and receive no test credit.

The final 281-file standalone/gate/build archive and separate 25-file original-order archive were hash-verified. Historical f9 measurements and manual checks retain their pinned source. Newer main registrations for benchmark/process fixtures and the Git worker's workspace-input native-section handling were not silently included in that historical proof; current 85a integration is recorded separately above. The canonical main unused-export repair is 1619aff4781603cb998646f5ac8068603dbd3e20; it is unrelated to this five-file delta.

The current-main proof also stopped after three successful commands because its completion-label guard checked shard_name; the native runner emits timing_key when present. The successful command exit, test results, native completion marker, all 849 source hashes and original archive were reconciled. Only that proof guard was corrected; the completed commands were retained and only four unrun tooling groups plus the changed gate continued. The current source has six additional cases across the same 196 selected files: three ownership-table cases from newer main's Gateway registrations, and three newly added CI workflow-guard cases. This was a proof-harness interruption, not a test failure or retry.

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

clawsweeper Bot commented Sep 22, 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 scripts Repository scripts agents Agent runtime and tooling size: XS maintainer Maintainer-authored PR labels Sep 22, 2026
@steipete
steipete marked this pull request as ready for review September 22, 2026 20:02
@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 Sep 22, 2026
@clawsweeper

clawsweeper Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 22, 2026, 6:38 PM ET / 22:38 UTC (Revision 3).

ClawSweeper review

What this changes

The PR precompiles the large-index worktree cleanup test’s Node subprocess and nested workers to reduce startup overhead without changing product behavior.

Merge readiness

✅ Ready for maintainer review

The optimization remains useful on current main, preserves the regression’s meaningful checks, and has no actionable correctness findings. The supplied performance evidence appropriately limits its claim to the large-index case.

Priority: P3
Reviewed head: 7099bd69ee5bdd3037c15ad8e166542aaf0f0fae

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable optimization with substantial, carefully qualified execution evidence and no actionable findings.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The supplied Testbox evidence exercises the changed Node child through real worktree cleanup and Git recovery, reports faster target-case execution, and records passing current-base restoration checks. Historical and current measurements remain separately qualified; no stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied Testbox evidence exercises the changed Node child through real worktree cleanup and Git recovery, reports faster target-case execution, and records passing current-base restoration checks. Historical and current measurements remain separately qualified; no stored-data contract changes.
Evidence reviewed 8 items Pinned introduced change: The merge-base-to-head patch changes only test fixtures and their build registrations. Production cleanup, inventory logic, dependencies, and authorization contracts are unchanged.
Regression contract preserved: The case retains 180,000 synthetic tracked entries, the 60-second child deadline, strict process-tree exit, removal checks, original commit restoration, local-edit restoration, and tracked-deletion checks. The new child explicitly asserts main-thread execution.
Existing preparation owner reused: The declaration registration redirects the fixture through the existing compiled-subprocess plugin. Build entries include the fixture and existing runtime workers; the shared URL resolver selects the prepared dist directory or source fallback. This is OpenClaw test infrastructure and establishes no dependency on the Codex harness.
Findings None None.
Security None None.

How this fits together

OpenClaw’s worktree cleanup tests exercise removal and recovery against real Git repositories. The test runner prepares subprocess code before a bounded Node child runs cleanup, then checks that saved edits and deletions restore correctly.

flowchart TD
  A[Large Git index fixture] --> B[Test runner]
  B --> C[Prepared subprocess build]
  C --> D[Node main-thread cleanup]
  D --> E[Git worker and repository]
  E --> F[Removal and snapshot results]
  F --> G[Restore and verify edits]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +19, Other +4. Total +23 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 3 26 7 +19
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 2 4 0 +4
Total 5 30 7 +23

Review metrics

Metric Value Why it matters
Reported target-case improvement 47.81% and 45.09% faster in the two measured pairs The improvement is scoped to the large-index case; interrupted timing and preparation drift prevent a whole-command savings claim.
Reported current integration cost 65.693 s command wall; 9.494 s large-index case The PR records the changed test’s actual cost and explains why real processes and Git recovery remain necessary.

Technical review

Best possible solution:

Keep the real Git recovery regression while preparing its child runtime through the existing test-runner owner.

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

Not applicable as a product bug: this is test-performance work supported by source-bound before/after measurements. The historical CI timeout remains unexplained, and this review did not execute tests.

Is this the best way to solve the issue?

Yes. Reusing the existing preparation owner removes source-loading work from the child’s deadline while preserving the real Node/Git boundary and recovery assertions.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The supplied Testbox evidence exercises the changed Node child through real worktree cleanup and Git recovery, reports faster target-case execution, and records passing current-base restoration checks. Historical and current measurements remain separately qualified; no stored-data contract changes.

Label justifications:

  • P3: This is a bounded test-performance improvement with no product behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied Testbox evidence exercises the changed Node child through real worktree cleanup and Git recovery, reports faster target-case execution, and records passing current-base restoration checks. Historical and current measurements remain separately qualified; no stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied Testbox evidence exercises the changed Node child through real worktree cleanup and Git recovery, reports faster target-case execution, and records passing current-base restoration checks. Historical and current measurements remain separately qualified; no stored-data contract changes.

Evidence

What I checked:

  • Pinned introduced change: The merge-base-to-head patch changes only test fixtures and their build registrations. Production cleanup, inventory logic, dependencies, and authorization contracts are unchanged. (src/agents/worktrees/service.gc.test.ts:340, 7099bd69ee5b)
  • Regression contract preserved: The case retains 180,000 synthetic tracked entries, the 60-second child deadline, strict process-tree exit, removal checks, original commit restoration, local-edit restoration, and tracked-deletion checks. The new child explicitly asserts main-thread execution. (src/agents/worktrees/service.gc.test.ts:323, 7099bd69ee5b)
  • Existing preparation owner reused: The declaration registration redirects the fixture through the existing compiled-subprocess plugin. Build entries include the fixture and existing runtime workers; the shared URL resolver selects the prepared dist directory or source fallback. This is OpenClaw test infrastructure and establishes no dependency on the Codex harness. (test/vitest/vitest.worker-artifacts.ts:125, 7099bd69ee5b)
  • Current main still needs the optimization: Fetched main still launches the large-index child with the TypeScript preload and inline evaluation; it does not contain this prepared-fixture cutover. (src/agents/worktrees/service.gc.test.ts:334, ed336efe0537)
  • Latest release comparison: The v2026.9.5 source also retains the source-loaded child. GitHub contents inspection supplied the release source after the local historical blob was unavailable. (src/agents/worktrees/service.gc.test.ts, ec9c1a13db89)
  • Source-bound performance and recovery evidence: The supplied complete PR body reports real Node/Git Testbox runs: paired large-index times of 17.378→9.069 seconds and 26.427→14.510 seconds, followed by current-base integration with all 37 cases passing. It explicitly records the interrupted comparison, preparation drift, translated overflow control, and inconclusive whole-command benefit. Historical measurements and current integration have separate source bindings; no fresh benchmark was executed during this review. (7099bd69ee5b)

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-22T20:10:28.240Z sha fcfc835 :: needs maintainer review before merge. :: none
  • reviewed 2026-09-22T22:02:10.213Z sha 7099bd6 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the codex/test-worktree-gc-prepared-child branch from fcfc835 to 7099bd6 Compare September 22, 2026 21:55
@steipete
steipete merged commit d3160de into main Sep 22, 2026
167 checks passed
@steipete
steipete deleted the codex/test-worktree-gc-prepared-child branch September 22, 2026 23:09
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

steipete added a commit that referenced this pull request Sep 22, 2026
F107: main run 35785419091, job 106941944643 exhausted the large-index
GC fixture's 60-second child deadline. A two-CPU Testbox with CPU pressure
reproduced the failure during snapshot preparation. Every traced Git
command exited; the slowest took 0.43 seconds.

Snapshot preparation awaited one lstat per changed path, including 180,000
missing tracked files. Read metadata in bounded batches of 64, joining all
reads before preserving the first path-ordered error. Keep missing-path
classification, snapshot capacity accounting, and authority guards intact.

Retain the prepared Node child fixture landed concurrently in #155928.
That change removes cold source startup; this change removes the serial
metadata bottleneck in the production snapshot owner. No deadlines,
assertions, snapshot retention, or public contracts change.
vincentkoc added a commit that referenced this pull request Sep 22, 2026
* commit '7d7f977ccfc1ac177526232e4f4960febd010015': (91 commits)
  test: avoid unused target setup in package profile fixtures (#155972)
  fix(worktrees): batch snapshot metadata reads
  test(plugin-state): distinguish borrowed and foreign lifecycle owners
  refactor(agents): share external harness session and attempt machinery (#152181)
  chore(i18n): refresh native locales (#156006)
  chore(test): retain Doctor fixture settlement diagnostics (#155944)
  perf(codex): reuse unchanged inference request bytes (#155987)
  perf(test): prepare snapshot ownership subprocess imports (#155973)
  perf(test): consolidate channel registry coverage (#155014)
  fix(runtime): preserve Node worker dependencies and cleanup diagnostics (#155292)
  perf(test): prepare worktree GC child runtime (#155928)
  fix(ui): open browser cards after delayed panel renders (#153253)
  fix(update): retain the running updater by hard link instead of copying the package (#155977)
  feat(decisions): add explicit evaluation and Labs opt-in foundation (#155134)
  fix(state): preserve lifecycle custody across worker dispatch
  improve: reuse shared tooling fixtures and defer legacy updater proof (#155731)
  improve(ui): reduce real-Gateway test preparation (#155979)
  perf(state): move session RPC SQL off the Gateway main thread (#155740)
  docs(freebsd): explain native Codex runtime limits (#155980)
  fix(qa): count Code Mode nested tool activity as transcript tool evidence (#155976)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 23, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 23, 2026
F107: main run 35785419091, job 106941944643 exhausted the large-index
GC fixture's 60-second child deadline. A two-CPU Testbox with CPU pressure
reproduced the failure during snapshot preparation. Every traced Git
command exited; the slowest took 0.43 seconds.

Snapshot preparation awaited one lstat per changed path, including 180,000
missing tracked files. Read metadata in bounded batches of 64, joining all
reads before preserving the first path-ordered error. Keep missing-path
classification, snapshot capacity accounting, and authority guards intact.

Retain the prepared Node child fixture landed concurrently in openclaw#155928.
That change removes cold source startup; this change removes the serial
metadata bottleneck in the production snapshot owner. No deadlines,
assertions, snapshot retention, or public contracts change.
@roboclaw-bot roboclaw-bot mentioned this pull request Sep 24, 2026
2 of 8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling 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. scripts Repository scripts 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