Skip to content

fix(test): avoid slow and incorrect test discovery in large checkouts - #131382

Merged
steipete merged 1 commit into
mainfrom
codex/qa-planner-batched-discovery-20260827
Aug 28, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/qa-planner-batched-discovery-20260827

Conversation

@steipete

Copy link
Copy Markdown
Contributor
Additional instructions

Keep Allow edits from maintainers enabled for this PR.

What Problem This Solves

Fixes an issue where developers running targeted tests could spend minutes discovering helper dependents, causing the planner's own startup hook to exceed its 180-second limit and skip all 84 tests. In large checkouts, test discovery could also silently include the wrong files: untracked tests in changed-source impact plans, and ignored tests in explicit glob selections.

Why This Change Was Made

The targeted import scanner searched the repository separately for each term of each reverse-import node and repeatedly parsed overlapping candidates. It now searches once per uncached frontier and shares parsed import edges with the existing full-graph fallback. Each term retains its own candidate membership, so the existing broad-term cap, central-helper first-success rule, direct-only tooling scan, stop-at-test boundary, and literal-reference checks remain intact. Patterns travel on stdin to avoid the operating system's argument-size limit.

Both affected Git inventories could exceed Node's default 1 MiB output buffer and silently fall back to a directory walk, changing their membership rules. Import discovery now reuses the existing scoped, bounded 16 MiB planner inventory implementation. Explicit glob discovery retains its distinct tracked-plus-untracked, exclude-ignored contract and uses the same finite bound.

Provenance: the per-node scan and import-inventory query without an explicit output bound are traceable to dd4613a26870e6b0b1183becd7ebb17432a60ca5 (May 16, 2026; code author and committer @vincentkoc; no PR traced). The structure was carried forward by #117407 (tooling discovery, August 1) and #122572 (ripgrep optimization, August 12), both authored and merged by @steipete. This establishes code ancestry, not when repository growth first made the failures observable.

This removes the duplicate import-graph inventory query, per-node importer cache, and repeated parsing paths. A blanket full-graph replacement was evaluated but rejected because it slowed a narrow cold target and changed selected coverage. No timeout increase, new configuration, dependency change, or forced test environment is involved.

Tooling LOC: +177 / −167 (net +10); tests: +92 / −0. The remaining tooling growth owns batched per-term selection and bounded stdin transport while consolidating inventory and parsing ownership. Product runtime code is unchanged.

User Impact

Developers get faster targeted-test planning with the same selected coverage. Changed-source impact remains tracked-only; explicit globs still include newly authored untracked tests while respecting ignored files. There are no product configuration, protocol, storage, or user-facing runtime changes.

Evidence

Two authentic regressions use a real Git index larger than 1 MiB, with index-only padding instead of thousands of physical fixture files:

  • Before the import-inventory repair, changing a tracked source selected an untracked importing test. The fixed result selects only the tracked consumer.
  • Before the explicit-inventory repair, glob expansion included an ignored test. The fixed result contains exactly the tracked and untracked consumers, excluding the ignored file. The assertion compares exact sorted membership and still rejects duplicates and omissions.

Preservation tests cover converging/cyclic import frontiers, same-basename isolation, stopping at test boundaries, live-test exclusion, direct-only tooling imports, and exact literal tooling references.

On the same source base and Node 24.20.0, all seven saved complete before/after plan objects and SHA-256 digests match. The four original startup calls changed as follows:

Target Cold before Cold after Repository searches
Gateway connection test mocks 5.887 s 3.108 s 3 → 1
Memory runtime test mocks 10.359 s 3.701 s 9 → 2
Temporary-directory helper 121.604 s 13.041 s 58 → 4
Non-interactive onboarding helpers 16.931 s 6.237 s 6 → 2

Total: 154.782 → 26.088 seconds, with 76 → 9 searches. The broad helper retains all 766 entries across 42 plans. An explicit owner, workflow literal references, and a separate narrow helper process also retain identical plans. Warm calls issue no subprocesses; fixed Git inventory queries exit successfully without ENOBUFS. These are observed standalone timings, not timing assertions or portable performance guarantees.

Validation on the unchanged production patch:

  • node scripts/run-vitest.mjs src/scripts/test-projects.test.ts: 84 passed, 32.56 seconds, fresh worker with no preceding test file and the original four-call hook order unchanged. The original Node 24 hook exceeded 180 seconds.
  • node scripts/run-vitest.mjs test/scripts/test-projects.test.ts: 305 passed, original case order, 189.85 seconds.
  • test/scripts/test-extension.test.ts: 158 passed in the same-production grouped run. That grouped run exposed an incorrect ordering assumption in the new inventory fixture; exact membership was corrected and the complete 305-case planner file rerun successfully. No production ordering was changed.
  • node scripts/check-changed.mjs --base HEAD^ --head HEAD -- scripts/test-projects.test-support.mts scripts/lib/extension-test-plan.mts test/scripts/test-projects.test.ts: passed on commit 63c62a28990f0dab590f8ab1948acd98daeb5ba0, including script/root-test typechecks, formatting, targeted lint, and selected guards.
  • One isolated Codex review at the default P0 scope: no accepted/actionable findings.

The real planner and real Git/ripgrep commands were exercised locally. This change does not involve a provider/channel API, product Gateway, or graphical interface; no live-provider or GUI proof is claimed.

AI-assisted implementation and review with Codex.

@clawsweeper

clawsweeper Bot commented Aug 28, 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 scripts Repository scripts size: M maintainer Maintainer-authored PR labels Aug 28, 2026
@steipete
steipete marked this pull request as ready for review August 28, 2026 01:45
@steipete

Copy link
Copy Markdown
Contributor Author

Ready to land the reviewed head 63c62a28990f0dab590f8ab1948acd98daeb5ba0.

Exact-head CI run 33133828532 and Workflow Sanity run 33133801491 passed. Native review validation and OPENCLAW_TESTBOX=1 scripts/pr prepare-run 131382 passed using exact-head hosted evidence, without a rebase or source change.

Local Node 24.20.0 proof: node scripts/run-vitest.mjs src/scripts/test-projects.test.ts (84 passed, fresh worker and original hook order), node scripts/run-vitest.mjs test/scripts/test-projects.test.ts (305 passed), and node scripts/check-changed.mjs --base HEAD^ --head HEAD -- scripts/test-projects.test-support.mts scripts/lib/extension-test-plan.mts test/scripts/test-projects.test.ts (passed). The PR body records both authentic inventory REDs, the qualified 158-case sibling proof, and all seven identical complete before/after plans. Original four cold calls improved from 154.782s to 26.088s; no portable timing guarantee is claimed.

One isolated Codex review at default P0 scope found no accepted/actionable findings. ClawSweeper's latest comment is still a review-started placeholder, with no findings or rank-up moves to address. Full repository tests were not rerun locally for this bounded tooling repair; no provider/channel/GUI proof is claimed because product runtime is unchanged.

@steipete
steipete merged commit f1e9960 into main Aug 28, 2026
266 checks passed
@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

maintainer Maintainer-authored PR scripts Repository scripts size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant