OpenClaw Test Performance
Use evidence first. The goal is real pnpm test, plugin-suite, and
plugin-inspector speed/RSS improvement with coverage intact, not runner tuning by
guesswork.
Workflow
- Read the relevant local
AGENTS.md files before editing:
src/agents/AGENTS.md for agent/import hotspots.
src/channels/AGENTS.md and src/plugins/AGENTS.md for plugin/channel
laziness.
src/gateway/AGENTS.md for server lifecycle tests.
test/helpers/AGENTS.md and test/helpers/channels/AGENTS.md for shared
contract helpers.
src/infra/outbound/AGENTS.md for outbound/media/action tests.
- Establish a baseline before changing code:
- Prefer
pnpm test:perf:groups --full-suite --allow-failures --output <file>
for full-suite ranking.
- For bundled plugin breadth, run the smallest relevant
pnpm test:extensions:batch <plugin[,plugin...]> or plugin-inspector command
before jumping to the full extension sweep.
- For a scoped hotspot use:
/usr/bin/time -l pnpm test <file-or-files> --maxWorkers=1 --reporter=verbose
- For import-heavy suspicion add:
OPENCLAW_VITEST_IMPORT_DURATIONS=1 OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN=1.
- Separate wall/runner noise from real file cost:
- Compare Vitest duration, test body timing, import breakdown, wall time, and
max RSS.
- Re-run single files when grouped/full-suite numbers look stale or noisy.
- If a full-suite grouped run reports a lane failure but JSON says tests
passed, capture that as harness/noise and verify the suspect file directly.
- Pick the next attack by return and risk:
- High return: one file/test dominates seconds or RSS and has a clear root.
- High leverage: one plugin or SDK barrel causes every plugin-inspector or
extension-batch run to load broad runtime.
- Lower risk: static descriptors, target parsing, routing, auth bypass,
setup hints, registry fixtures, or test server lifecycle.
- Higher risk: real memory/runtime behavior, live providers, protocol
contracts, or broad production refactors.
- Fix the root cause, not the symptom:
- Move static metadata/parsing into narrow helpers or lightweight artifacts
reused by full runtime and fast paths.
- Prefer dependency injection, loaded-plugin-only lookup, explicit fixtures,
and pure helpers over broad mocks.
- Reuse suite-level servers/clients when a fresh handshake is irrelevant.
- Keep schedulers/background loops off unless the test proves scheduling.
- In plugin paths, move static metadata into manifest/lightweight artifacts
and keep runtime plugin loads behind explicit execution boundaries.
- Preserve coverage shape:
- Do not delete a slow integration proof unless the exact production
composition is extracted into a named helper and tested.
- Keep one cheap integration smoke when cross-component wiring matters.
- State explicitly what incidental coverage was removed, if any.
- Re-benchmark the same command after the change and compute seconds plus
percent gain.
- Update the running report when requested or when this thread is tracking one.
Include before/after commands, artifacts, coverage notes, verification, and
next attack order.
- Commit with
scripts/committer "<message>" <paths...> and push when the
user asked for commits/pushes. Stage only files touched for this attack.
Plugin-Suite Workflow
Use this section when perf work involves bundled plugins, plugin-inspector, SDK
barrels, package-boundary tests, or extension suites.
- Map the suite shape first:
- source tests:
pnpm test extensions/<id> or pnpm test:extensions:batch <id>
- package boundaries:
pnpm run test:extensions:package-boundary:canary and
pnpm run test:extensions:package-boundary:compile
- all bundled source tests:
pnpm test:extensions
- plugin import memory:
pnpm test:extensions:memory -- --json .artifacts/test-perf/extensions-memory.json
- plugin-inspector/report work: keep report primitives in
plugin-inspector;
keep wrappers thin and collect peak RSS when the command supports it.
- Start narrow, then widen:
- one plugin changed: run that plugin's tests and plugin-inspector slice.
- SDK/public barrel changed: add representative provider, channel, memory,
and feature plugins.
- loader/runtime mirror changed: add package-boundary checks and build/package
proof as needed.
- unknown shared plugin behavior: run
test:extensions:batch groups before
pnpm test:extensions.
- Treat plugin-inspector failures as product signals:
- JSON must parse.
- warnings/errors must be classified, not hidden.
- runtime capture should be quiet and config-tolerant.
- command output should include wall time, exit code, and peak RSS when
available.
- For broad or package-heavy plugin proof, use Crabbox-backed Blacksmith
Testbox by default on maintainer machines:
pnpm crabbox:run -- --provider blacksmith-testbox --timing-json -- OPENCLAW_TESTBOX=1 pnpm test:extensions:batch <ids>
- add
--keep/--id <id-or-slug> only when several commands must share one
warmed box; stop it with pnpm crabbox:stop -- <id-or-slug>.
- If plugin performance is package-artifact sensitive, switch to
openclaw-pre-release-plugin-testing and Package Acceptance rather than
trusting source-only timing.
Metric Collection
Collect at least one stable metric before and after. Prefer the same machine and
same command. For Testbox comparisons, use the same tbx_... id when possible.
| Metric |
Use for |
Preferred source |
| wall time |
user-visible suite cost |
/usr/bin/time -l, test wrapper duration, Testbox run time |
| Vitest duration |
test body/import cost |
Vitest output per file/shard |
| import duration |
broad barrel/runtime loads |
OPENCLAW_VITEST_IMPORT_DURATIONS=1 |
| max RSS |
memory pressure and OOM risk |
/usr/bin/time -l, pnpm test:extensions:memory, wrapper memory summaries |
| CPU/user/sys |
CPU-bound vs wait-bound split |
/usr/bin/time -l locally, Testbox job timing when local CPU is noisy |
| heap snapshots |
real leak vs retained module graph |
openclaw-test-heap-leaks workflow |
Local scoped command with CPU/RSS:
timeout 240 /usr/bin/time -l pnpm test <file> --maxWorkers=1 --reporter=verbose
Plugin import memory profile:
pnpm build
pnpm test:extensions:memory -- --top 20 --json .artifacts/test-perf/extensions-memory.json
Targeted plugin import memory:
pnpm test:extensions:memory -- --extension discord --extension telegram --skip-combined
Heap/RSS escalation:
OPENCLAW_TEST_MEMORY_TRACE=1 \
OPENCLAW_TEST_HEAPSNAPSHOT_INTERVAL_MS=60000 \
OPENCLAW_TEST_HEAPSNAPSHOT_DIR=.tmp/heapsnap \
OPENCLAW_TEST_WORKERS=2 \
OPENCLAW_TEST_MAX_OLD_SPACE_SIZE_MB=6144 \
pnpm test
Use openclaw-test-heap-leaks when RSS keeps growing across intervals, workers
OOM, or the suspect command has app-object retention. Do not call RSS growth a
leak until snapshots or retainers support it.
Common Root Causes
- Full bundled channel/plugin runtime loaded for static data.
getChannelPlugin() fallback used when an already-loaded fixture or pure
parser would suffice.
- Broad
api.ts, runtime-api.ts, test-api.ts, or plugin-sdk barrels pulled
into hot tests.
- SDK root aliases or package barrels pulling focused subpaths back into a broad
plugin graph.
- Plugin-inspector loading runtime code just to render metadata, reports, or CI
policy scores.
- Bundled plugin capture reusing real config/home state instead of synthetic,
redacted, isolated state.
- Partial-real mocks using
importActual() around broad modules.
vi.resetModules() plus fresh imports in per-test loops.
- Test plugin registry seeded in
beforeAll while runtime state resets in
afterEach.
- Per-test gateway/server/client startup when state reset would suffice.
- Runtime/default model/auth selection paid by idle snapshots or fixtures.
- Plugin-owned media/action discovery triggered before checking whether args
contain plugin-owned fields.
- Timings missing from
test/fixtures/test-timings.unit.json, causing hotspot
files to stay in shared workers.
- Parallel Vitest runs sharing
node_modules/.experimental-vitest-cache without
distinct OPENCLAW_VITEST_FS_MODULE_CACHE_PATH values.
Benchmark Commands
Scoped file:
timeout 240 /usr/bin/time -l pnpm test <file> --maxWorkers=1 --reporter=verbose
Scoped file with import breakdown:
timeout 240 /usr/bin/time -l env \
OPENCLAW_VITEST_IMPORT_DURATIONS=1 \
OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN=1 \
pnpm test <file> --maxWorkers=1 --reporter=verbose
Grouped suite:
pnpm test:perf:groups --full-suite --allow-failures \
--output .artifacts/test-perf/<name>.json
Extension batch:
pnpm test:extensions:batch <plugin[,plugin...]> -- --reporter=verbose
All extension tests:
pnpm test:extensions
Package-boundary plugin checks:
pnpm run test:extensions:package-boundary:canary
pnpm run test:extensions:package-boundary:compile
Reuse an existing Vitest JSON report:
pnpm test:perf:groups --report <vitest-json> \
--output .artifacts/test-perf/<name>.json
Verification
- Always run the targeted test surface that proves the change.
- For source changes, run
pnpm check:changed before push; in maintainer
Testbox mode run it in the warmed Testbox.
- For test-only changes, run
pnpm test:changed or the exact edited tests.
- Run
pnpm build when touching lazy-loading, bundled artifacts, package
boundaries, dynamic imports, build output, or public surfaces.
- For plugin SDK/barrel/runtime changes, add
pnpm plugin-sdk:api:check or
pnpm plugin-sdk:api:gen when the API surface may drift.
- For plugin-suite perf fixes, verify at least one representative plugin batch
plus the changed gate; use Package Acceptance if the bug only exists in a
packed artifact.
- If deps are missing/stale, run
pnpm install and retry the exact failed
command once.
- Use the report format:
| Metric | Before | After | Gain |
| -------------- | -----: | -----: | ------------: |
| File wall time | `Xs` | `Ys` | `-Zs` (`P%`) |
| Max RSS | `XMB` | `YMB` | `-ZMB` (`P%`) |
| CPU user/sys | `X/Ys` | `A/Bs` | explain |
Handoff
Keep the final concise:
- Root cause.
- Suite/plugin scope.
- Files changed.
- Before/after wall, Vitest/import, CPU, and RSS numbers where available.
- Leak classification if memory was involved: real leak, retained module graph,
or inconclusive.
- Coverage retained.
- Verification commands.
- Testbox ID or workflow URL for remote proof.
- Commit hash and push status.
1---2name: openclaw-test-performance3description: Benchmark, diagnose, and optimize OpenClaw test and plugin-suite runtime, import hotspots, CPU/RSS, heap growth, and slow coverage paths.4metadata:5 source: https://skillmd.com/skills/aniruddhaadak80/openclaw-test-performance6---78# OpenClaw Test Performance910Use evidence first. The goal is real `pnpm test`, plugin-suite, and11plugin-inspector speed/RSS improvement with coverage intact, not runner tuning by12guesswork.1314## Workflow15161. Read the relevant local `AGENTS.md` files before editing:17 - `src/agents/AGENTS.md` for agent/import hotspots.18 - `src/channels/AGENTS.md` and `src/plugins/AGENTS.md` for plugin/channel19 laziness.20 - `src/gateway/AGENTS.md` for server lifecycle tests.21 - `test/helpers/AGENTS.md` and `test/helpers/channels/AGENTS.md` for shared22 contract helpers.23 - `src/infra/outbound/AGENTS.md` for outbound/media/action tests.242. Establish a baseline before changing code:25 - Prefer `pnpm test:perf:groups --full-suite --allow-failures --output <file>`26 for full-suite ranking.27 - For bundled plugin breadth, run the smallest relevant `pnpm28test:extensions:batch <plugin[,plugin...]>` or plugin-inspector command29 before jumping to the full extension sweep.30 - For a scoped hotspot use:31 `/usr/bin/time -l pnpm test <file-or-files> --maxWorkers=1 --reporter=verbose`32 - For import-heavy suspicion add:33 `OPENCLAW_VITEST_IMPORT_DURATIONS=1 OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN=1`.343. Separate wall/runner noise from real file cost:35 - Compare Vitest duration, test body timing, import breakdown, wall time, and36 max RSS.37 - Re-run single files when grouped/full-suite numbers look stale or noisy.38 - If a full-suite grouped run reports a lane failure but JSON says tests39 passed, capture that as harness/noise and verify the suspect file directly.404. Pick the next attack by return and risk:41 - High return: one file/test dominates seconds or RSS and has a clear root.42 - High leverage: one plugin or SDK barrel causes every plugin-inspector or43 extension-batch run to load broad runtime.44 - Lower risk: static descriptors, target parsing, routing, auth bypass,45 setup hints, registry fixtures, or test server lifecycle.46 - Higher risk: real memory/runtime behavior, live providers, protocol47 contracts, or broad production refactors.485. Fix the root cause, not the symptom:49 - Move static metadata/parsing into narrow helpers or lightweight artifacts50 reused by full runtime and fast paths.51 - Prefer dependency injection, loaded-plugin-only lookup, explicit fixtures,52 and pure helpers over broad mocks.53 - Reuse suite-level servers/clients when a fresh handshake is irrelevant.54 - Keep schedulers/background loops off unless the test proves scheduling.55 - In plugin paths, move static metadata into manifest/lightweight artifacts56 and keep runtime plugin loads behind explicit execution boundaries.576. Preserve coverage shape:58 - Do not delete a slow integration proof unless the exact production59 composition is extracted into a named helper and tested.60 - Keep one cheap integration smoke when cross-component wiring matters.61 - State explicitly what incidental coverage was removed, if any.627. Re-benchmark the same command after the change and compute seconds plus63 percent gain.648. Update the running report when requested or when this thread is tracking one.65 Include before/after commands, artifacts, coverage notes, verification, and66 next attack order.679. Commit with `scripts/committer "<message>" <paths...>` and push when the68 user asked for commits/pushes. Stage only files touched for this attack.6970## Plugin-Suite Workflow7172Use this section when perf work involves bundled plugins, plugin-inspector, SDK73barrels, package-boundary tests, or extension suites.74751. Map the suite shape first:76 - source tests: `pnpm test extensions/<id>` or `pnpm test:extensions:batch <id>`77 - package boundaries: `pnpm run test:extensions:package-boundary:canary` and78 `pnpm run test:extensions:package-boundary:compile`79 - all bundled source tests: `pnpm test:extensions`80 - plugin import memory: `pnpm test:extensions:memory -- --json .artifacts/test-perf/extensions-memory.json`81 - plugin-inspector/report work: keep report primitives in `plugin-inspector`;82 keep wrappers thin and collect peak RSS when the command supports it.832. Start narrow, then widen:84 - one plugin changed: run that plugin's tests and plugin-inspector slice.85 - SDK/public barrel changed: add representative provider, channel, memory,86 and feature plugins.87 - loader/runtime mirror changed: add package-boundary checks and build/package88 proof as needed.89 - unknown shared plugin behavior: run `test:extensions:batch` groups before90 `pnpm test:extensions`.913. Treat plugin-inspector failures as product signals:92 - JSON must parse.93 - warnings/errors must be classified, not hidden.94 - runtime capture should be quiet and config-tolerant.95 - command output should include wall time, exit code, and peak RSS when96 available.974. For broad or package-heavy plugin proof, use Crabbox-backed Blacksmith98 Testbox by default on maintainer machines:99 - `pnpm crabbox:run -- --provider blacksmith-testbox --timing-json -- OPENCLAW_TESTBOX=1 pnpm test:extensions:batch <ids>`100 - add `--keep`/`--id <id-or-slug>` only when several commands must share one101 warmed box; stop it with `pnpm crabbox:stop -- <id-or-slug>`.1025. If plugin performance is package-artifact sensitive, switch to103 `openclaw-pre-release-plugin-testing` and Package Acceptance rather than104 trusting source-only timing.105106## Metric Collection107108Collect at least one stable metric before and after. Prefer the same machine and109same command. For Testbox comparisons, use the same `tbx_...` id when possible.110111| Metric | Use for | Preferred source |112| --------------- | ---------------------------------- | --------------------------------------------------------------------------- |113| wall time | user-visible suite cost | `/usr/bin/time -l`, test wrapper duration, Testbox run time |114| Vitest duration | test body/import cost | Vitest output per file/shard |115| import duration | broad barrel/runtime loads | `OPENCLAW_VITEST_IMPORT_DURATIONS=1` |116| max RSS | memory pressure and OOM risk | `/usr/bin/time -l`, `pnpm test:extensions:memory`, wrapper memory summaries |117| CPU/user/sys | CPU-bound vs wait-bound split | `/usr/bin/time -l` locally, Testbox job timing when local CPU is noisy |118| heap snapshots | real leak vs retained module graph | `openclaw-test-heap-leaks` workflow |119120Local scoped command with CPU/RSS:121122```bash123timeout 240 /usr/bin/time -l pnpm test <file> --maxWorkers=1 --reporter=verbose124```125126Plugin import memory profile:127128```bash129pnpm build130pnpm test:extensions:memory -- --top 20 --json .artifacts/test-perf/extensions-memory.json131```132133Targeted plugin import memory:134135```bash136pnpm test:extensions:memory -- --extension discord --extension telegram --skip-combined137```138139Heap/RSS escalation:140141```bash142OPENCLAW_TEST_MEMORY_TRACE=1 \143OPENCLAW_TEST_HEAPSNAPSHOT_INTERVAL_MS=60000 \144OPENCLAW_TEST_HEAPSNAPSHOT_DIR=.tmp/heapsnap \145OPENCLAW_TEST_WORKERS=2 \146OPENCLAW_TEST_MAX_OLD_SPACE_SIZE_MB=6144 \147pnpm test148```149150Use `openclaw-test-heap-leaks` when RSS keeps growing across intervals, workers151OOM, or the suspect command has app-object retention. Do not call RSS growth a152leak until snapshots or retainers support it.153154## Common Root Causes155156- Full bundled channel/plugin runtime loaded for static data.157- `getChannelPlugin()` fallback used when an already-loaded fixture or pure158 parser would suffice.159- Broad `api.ts`, `runtime-api.ts`, `test-api.ts`, or plugin-sdk barrels pulled160 into hot tests.161- SDK root aliases or package barrels pulling focused subpaths back into a broad162 plugin graph.163- Plugin-inspector loading runtime code just to render metadata, reports, or CI164 policy scores.165- Bundled plugin capture reusing real config/home state instead of synthetic,166 redacted, isolated state.167- Partial-real mocks using `importActual()` around broad modules.168- `vi.resetModules()` plus fresh imports in per-test loops.169- Test plugin registry seeded in `beforeAll` while runtime state resets in170 `afterEach`.171- Per-test gateway/server/client startup when state reset would suffice.172- Runtime/default model/auth selection paid by idle snapshots or fixtures.173- Plugin-owned media/action discovery triggered before checking whether args174 contain plugin-owned fields.175- Timings missing from `test/fixtures/test-timings.unit.json`, causing hotspot176 files to stay in shared workers.177- Parallel Vitest runs sharing `node_modules/.experimental-vitest-cache` without178 distinct `OPENCLAW_VITEST_FS_MODULE_CACHE_PATH` values.179180## Benchmark Commands181182Scoped file:183184```bash185timeout 240 /usr/bin/time -l pnpm test <file> --maxWorkers=1 --reporter=verbose186```187188Scoped file with import breakdown:189190```bash191timeout 240 /usr/bin/time -l env \192 OPENCLAW_VITEST_IMPORT_DURATIONS=1 \193 OPENCLAW_VITEST_PRINT_IMPORT_BREAKDOWN=1 \194 pnpm test <file> --maxWorkers=1 --reporter=verbose195```196197Grouped suite:198199```bash200pnpm test:perf:groups --full-suite --allow-failures \201 --output .artifacts/test-perf/<name>.json202```203204Extension batch:205206```bash207pnpm test:extensions:batch <plugin[,plugin...]> -- --reporter=verbose208```209210All extension tests:211212```bash213pnpm test:extensions214```215216Package-boundary plugin checks:217218```bash219pnpm run test:extensions:package-boundary:canary220pnpm run test:extensions:package-boundary:compile221```222223Reuse an existing Vitest JSON report:224225```bash226pnpm test:perf:groups --report <vitest-json> \227 --output .artifacts/test-perf/<name>.json228```229230## Verification231232- Always run the targeted test surface that proves the change.233- For source changes, run `pnpm check:changed` before push; in maintainer234 Testbox mode run it in the warmed Testbox.235- For test-only changes, run `pnpm test:changed` or the exact edited tests.236- Run `pnpm build` when touching lazy-loading, bundled artifacts, package237 boundaries, dynamic imports, build output, or public surfaces.238- For plugin SDK/barrel/runtime changes, add `pnpm plugin-sdk:api:check` or239 `pnpm plugin-sdk:api:gen` when the API surface may drift.240- For plugin-suite perf fixes, verify at least one representative plugin batch241 plus the changed gate; use Package Acceptance if the bug only exists in a242 packed artifact.243- If deps are missing/stale, run `pnpm install` and retry the exact failed244 command once.245- Use the report format:246247```markdown248| Metric | Before | After | Gain |249| -------------- | -----: | -----: | ------------: |250| File wall time | `Xs` | `Ys` | `-Zs` (`P%`) |251| Max RSS | `XMB` | `YMB` | `-ZMB` (`P%`) |252| CPU user/sys | `X/Ys` | `A/Bs` | explain |253```254255## Handoff256257Keep the final concise:258259- Root cause.260- Suite/plugin scope.261- Files changed.262- Before/after wall, Vitest/import, CPU, and RSS numbers where available.263- Leak classification if memory was involved: real leak, retained module graph,264 or inconclusive.265- Coverage retained.266- Verification commands.267- Testbox ID or workflow URL for remote proof.268- Commit hash and push status.