Repository navigation
perf(tests): reuse model manifest selection imports - #131194
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Benchmark and fault proof for The baseline is /usr/bin/time -v -o "$sample_dir/time.txt" env \
OPENCLAW_VITEST_MAX_WORKERS=1 \
OPENCLAW_VITEST_FS_MODULE_CACHE_PATH="$sample_dir/module-cache" \
OPENCLAW_VITEST_IMPORT_DURATIONS=1 \
OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN=1 \
pnpm test src/agents/model-selection-manifest-workspace.test.ts \
--maxWorkers=1 --reporter=verbose --reporter=json \
--outputFile="$sample_dir/vitest.json"
Median wall 6.490 → 6.065s, 0.425s / 6.55% faster, seven of eight paired wins. Median Vitest 2.530 → 2.090s; body 1.705 → 0.1615s; collection import 0.021 → 1.075s; max RSS 817842 → 665958 KiB; user/system CPU 7.225/0.580 → 6.490/0.540s. Static imports change timing buckets, so acceptance uses total scoped wall, not body-only timing. Both variants pass 21 cases, write 423 cached module artifacts, and have six sampled process-tree members including time/runner helpers. This is reduced repeated module evaluation/retention, not a demonstrated heap leak. The reversible fault ignored explicit workspace in - const workspaceDir = params.workspaceDir ?? getActivePluginRegistryWorkspaceDirFromState();
+ const workspaceDir = getActivePluginRegistryWorkspaceDirFromState();Both original and optimized tests fail the same existing Test audit: these tests protect workspace-scoped model policies, prepared-policy reuse, alias normalization, and avoidance of unnecessary discovery. The fault above is a concrete regression they catch. Every existing case/assertion is retained rather than duplicated, and sharing the owner instance also exposes cross-call leakage. No production seam, export, cache, hook, broader mock or weaker expectation was introduced. The four mutable mocks still reset per case; the partial-real metadata mock from #129791 and the runner's per-file cleanup remain intact. Focused proof passed on macOS and Linux: 177 tests / four files / three native routed shards: pnpm test \
src/agents/model-selection-manifest-workspace.test.ts \
src/agents/model-selection.test.ts \
src/agents/model-selection.plugin-runtime.test.ts \
src/agents/embedded-agent-runner/model-resolution-consistency.test.ts \
--maxWorkers=1 --reporter=verboseThe two core files also passed 155 cases with Production LOC +0/-0; tests +25/-39, net -14. No runtime, lifecycle, process, storage, migration, provider, plugin SDK, security or authorization boundary changed. No live Gateway mutation was needed for this test-only change. Benchmark Testbox provisioning run: the SSH command exit results above are the proof; Actions tracks provisioning/cleanup. The task-owned Testbox is stopped after artifact collection. Exact-head CI is still running and must be green before native prepare/merge. At this posting, the latest ClawSweeper comment is the acknowledgement; no Rank-up moves have been published yet. I will recheck before landing. |
|
Exact-head CI is green for Native review artifacts validated with zero findings. The final test's remaining tokens are identical to the baseline after excluding only the intended import/reset/async edits, confirming no assertion or fixture drift. Benchmark, fault and sibling proof are in the preceding evidence comment. The latest ClawSweeper comment currently says review started; no actual findings or Rank-up moves have been published. There are no published moves to apply or skip. Proceeding through the repository-native prepare/merge gates without waiting on the asynchronous review publisher. |
|
Merged via squash.
|
What Problem This Solves
Maintainers running the configured-model workspace tests pay for reloading the same module graph before each of 21 cases, although those cases vary config and mock results rather than module-owned state.
Why This Change Was Made
Import the existing model-selection owner once and continue resetting the four mutable mocks before every case. Keep every case, assertion, partial-real mock factory, and the runner's per-file cleanup unchanged. Manifest resolution state already belongs to each model-selection invocation, so no production cache or new test seam is needed.
User Impact
No user-facing behavior changes. The scoped suite is 6.55% faster in an eight-pair benchmark and uses 18.6% less peak memory, while retaining workspace isolation, prepared policy reuse, mixed-provider alias normalization, and no-unnecessary-discovery checks.
Evidence
One task-owned Blacksmith Testbox, Linux/Node 24, one Vitest worker, excluded warmup for each variant, eight order-balanced AB/BA pairs, distinct filesystem-module-cache paths, import diagnostics, and
/usr/bin/time -v:Wall improvement is 0.425s / 6.55%, with seven of eight paired wins (median paired improvement 0.350s). Static imports move work from test bodies to collection; neither the body-only reduction nor the overlapping top-ten import breakdown is used as the acceptance metric. No process, browser, storage, provider, or lifecycle boundary was removed.
The baseline and optimized suites both reject a reversible production mutation that ignores the explicit workspace: the same case fails because
fast-modelreplacesworkspace-custom/fast-model. Restoring the owner returns all 21 cases to green. The mutation is not part of this PR.Focused owner/sibling proof passed locally and on the same Testbox: 177 tests across
model-selection-manifest-workspace,model-selection,model-selection.plugin-runtime, andembedded-agent-runner/model-resolution-consistency, using their three native routed shards.Benchmark and Linux fault/sibling environment: https://github.com/openclaw/openclaw/actions/runs/33116267630. Commands executed through the task's Testbox lease; the Actions run tracks provisioning and cleanup, not the SSH command verdicts. The lease is stopped after evidence collection.
Production LOC: +0/-0. Tests: +25/-39 (net -14). Deslop complete; fresh Codex autoreview reports no actionable findings. Complete
env -u OPENCLAW_TESTBOX pnpm check:changedpassed, including all 17 core-test typecheck shards and all three dead-export scans. A shuffled 155-test owner/workspace run also passed (seed 20260827). Exact-head hosted CI evidence will be posted before landing.