Skip to content

perf(tests): reuse model manifest selection imports - #131194

Merged
steipete merged 1 commit into
mainfrom
perf/model-manifest-workspace-tests
Aug 27, 2026
Merged

steipete merged 1 commit into
mainfrom
perf/model-manifest-workspace-tests

Conversation

@steipete

Copy link
Copy Markdown
Contributor

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:

Median metric Before After
Scoped wall 6.490s 6.065s
Vitest duration 2.530s 2.090s
Test body 1.705s 0.162s
Collection import 0.021s 1.075s
Max RSS 817,842 KiB 665,958 KiB
User / system CPU 7.225s / 0.580s 6.490s / 0.540s
Passing tests 21 21
Cached module artifacts 423 423
Sampled process tree size, including time/runner helpers 6 6

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-model replaces workspace-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, and embedded-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:changed passed, 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.

@clawsweeper

clawsweeper Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@steipete
steipete marked this pull request as ready for review August 27, 2026 21:24
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Aug 27, 2026
@steipete

Copy link
Copy Markdown
Contributor Author

Benchmark and fault proof for 090bf5376e62fc39d5775dc1f58c55e390523e4c:

The baseline is 6e827231257cf7c9c26ecd54fdc73d8c30afa5d8. One dedicated Linux Blacksmith Testbox ran an excluded warmup per variant, then eight alternating AB/BA pairs. Each invocation used a distinct filesystem module cache, one Vitest worker, import diagnostics and GNU time. The benchmark's final whitespace cleanup does not change the measured code; the fault and sibling runs used the final committed test source.

/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"
Pair Order Baseline wall Optimized wall
1 AB 6.47s 6.02s
2 BA 6.11s 6.13s
3 AB 6.56s 5.75s
4 BA 6.36s 6.11s
5 AB 6.02s 5.88s
6 BA 6.66s 6.51s
7 AB 6.51s 6.01s
8 BA 7.22s 6.34s

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

- const workspaceDir = params.workspaceDir ?? getActivePluginRegistryWorkspaceDirFromState();
+ const workspaceDir = getActivePluginRegistryWorkspaceDirFromState();

Both original and optimized tests fail the same existing uses manifest policies when the workspace context is explicit case: actual fast-model, expected workspace-custom/fast-model (20 pass / 1 fail). Restore the owner and all 21 pass. The mutation was isolated and fully restored; no production edit is in the PR.

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=verbose

The two core files also passed 155 cases with --sequence.shuffle --sequence.seed=20260827. Complete local env -u OPENCLAW_TESTBOX pnpm check:changed passed, including all 17 core-test typecheck shards and all three dead-export scans. Formatting, git diff --check, deslop and fresh isolated Codex autoreview are clean (autoreview P0 scope, with the full ownership/test-value review performed separately).

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.

@steipete

Copy link
Copy Markdown
Contributor Author

Exact-head CI is green for 090bf5376e62fc39d5775dc1f58c55e390523e4c: 41 successful jobs, 19 intentional scope skips, no failures or retries. The required openclaw/ci-gate is SUCCESS. The exact-head watcher completed GREEN.

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.

@steipete
steipete merged commit ef858c0 into main Aug 27, 2026
180 checks passed
@steipete
steipete deleted the perf/model-manifest-workspace-tests branch August 27, 2026 21:34
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 28, 2026
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 size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant