Skip to content

Commit 964fa99

Browse files
authored
feat(test): compile subprocesses once per invocation (#132716)
* feat(test): compile subprocesses once per invocation Own fresh compiled subprocess generations through compiler and borrower shutdown. Preserve source watch mode, native report publication, provider hooks, and recorded terminal failures. Simplify fallback and fixture ownership while retaining boundary regressions. * fix(test): resolve environment helper after suite relocation * fix(test): preserve errors while finalizing worker reports * fix(agents): keep provider discovery out of task presentation Render user-facing error copy through generic classification without activating provider hooks. Reuse the classification and parsed payload within the renderer instead of classifying the same text twice. Preserve prepared and discovered provider policy for runtime callers. Remove shared-worker registry assertions from the structured HTTP test. * fix(browser): keep cleanup imports out of agent tools * style(ui): remove unused microphone picker variables
1 parent 072aabb commit 964fa99

131 files changed

Lines changed: 7900 additions & 2825 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1865,7 +1865,7 @@ src/agents/embedded-agent-utils.ts 3
18651865
src/agents/exec-auto-reviewer.ts 1
18661866
src/agents/exec-defaults.ts 2
18671867
src/agents/execution-auth-binding.ts 1
1868-
src/agents/failover-error.ts 22
1868+
src/agents/failover-error.ts 15
18691869
src/agents/failover/retry-evidence.ts 1
18701870
src/agents/failover/signal-details.ts 1
18711871
src/agents/fallback-skip-cache.ts 1
@@ -3293,7 +3293,6 @@ src/logging/json-console-line.ts 2
32933293
src/logging/levels.ts 2
32943294
src/logging/log-file-shared.ts 1
32953295
src/logging/logger.ts 14
3296-
src/logging/node-require.ts 2
32973296
src/logging/parse-log-line.ts 1
32983297
src/logging/redact-internal-state.ts 1
32993298
src/logging/redact.ts 3

‎config/max-lines-baseline.txt‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,6 @@ src/agents/embedded-agent-runner/transcript-file-state.test.ts
356356
src/agents/embedded-agent-subscribe.handlers.lifecycle.test.ts
357357
src/agents/embedded-agent-subscribe.handlers.tools.test.ts
358358
src/agents/embedded-agent-subscribe.subscribe-embedded-agent-session.subscribeembeddedagentsession.test.ts
359-
src/agents/failover-error.ts
360359
src/agents/harness/native-hook-relay.test.ts
361360
src/agents/harness/selection.test.ts
362361
src/agents/harness/selection.ts

‎docs/gateway/security/secure-file-operations.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ OpenClaw sets fs-safe's optional native helper to **off** by default:
1616
- the guarded JavaScript paths support OpenClaw's normal filesystem operations;
1717
- disabling native loading keeps runtime behavior deterministic across desktop, Docker, CI, and bundled-app environments.
1818

19-
The OpenClaw package includes fs-safe's prebuilt native helpers for Linux x64/arm64 (glibc and musl), macOS x64/arm64, and Windows x64. No separate platform package, download, or compiler is needed. Loading these helpers remains optional.
19+
The OpenClaw package includes fs-safe's prebuilt native helpers for Linux x64/arm64 (glibc and musl), macOS x64/arm64, and Windows x64. Runtime entries and the packaged sealed worker share one native asset tree. No separate platform package, download, or compiler is needed. Loading these helpers remains optional.
2020

2121
OpenClaw only changes the _default_. An explicit setting always wins:
2222

‎docs/reference/test.md‎

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,62 @@ existing temporary directories, Node or Vitest caches, or other global caches. S
172172
validators; it does not require `TSX_DISABLE_CACHE` in the invoking shell. Raw
173173
external `tsx` and `node --import tsx` invocations outside these launchers are unchanged.
174174

175+
### Source tests and subprocess builds
176+
177+
Non-watch runs through `pnpm test` or `scripts/run-vitest.mjs` keep Vitest tests
178+
and runtime parents on TypeScript. Importing a declared subprocess entrypoint
179+
compiles the fixed test entry set and its workspace dependencies into one fresh
180+
invocation directory under `.artifacts/vitest-workers/`.
181+
182+
The seven application subprocess entries run as plain Node JavaScript without a
183+
TypeScript loader: SQLite read-only snapshots, database verification, Tailscale
184+
route ownership, the service relay, its POSIX and Windows anchors, and the memory
185+
plugin's KNN child. The same generation also compiles the fake-backend TUI
186+
fixture's four runtime roots together: the real TUI, embedded reply producer,
187+
reply metadata reader, and outbound normalizer. Shared chunks preserve their
188+
module and WeakMap identity. Generated TUI fixtures remain `.mts` files: Node
189+
launches them with `--import tsx` for their own syntax, while Bun handles that
190+
syntax natively without the Node loader. Only their runtime imports change.
191+
Application/package build entries and Vitest source parents stay unchanged. This
192+
does not convert Worker-thread entries or arbitrary source CLI fixtures.
193+
194+
Preparation is lazy across both projects and shards. Config imports, listing
195+
tests, and tiny tests that do not import these declarations do not load the
196+
subprocess compiler or compile workers. A shard that needs a declaration requests the
197+
outer runner's single build through its existing Node IPC channel during module
198+
collection, before fixture hooks and readiness deadlines. Every finite invocation
199+
that needs a declaration pays for this fixed entry set; preparation timing is
200+
reported separately from child execution. The runner starts one short-lived native
201+
Node or Bun compiler child and joins it before returning the verified manifest to
202+
borrowers. The compiler module graph lives in that child, not the long-lived runner
203+
or Vitest worker. No shard can select a different build graph or adopt another invocation's output. The outer
204+
runner retains the generation until child close and process-group cleanup
205+
finish, then verifies it before reporting success. Standalone Vitest and watch runs retain
206+
source execution: its public close hooks run concurrently with pool shutdown,
207+
so compilation and artifact deletion require the repository runner's ownership.
208+
A lost owner or failed build fails the run.
209+
Disposal cancels pending compilation and joins it and every borrower before
210+
removing the directory. An uncertain compiler or borrower join retains the
211+
generation and fails the run. Abnormal termination can also leave an unused
212+
directory; later runs never adopt it.
213+
214+
Every preparation compiles current source; checkout `dist/` is neither an input
215+
nor a fallback. Build errors, missing artifacts, and changes to recorded build
216+
inputs fail the run. Compilation includes the native subprocess fixtures before
217+
they impose resource limits. Third-party dependencies remain external except for
218+
the always-bundled OpenClaw packages. Each generation carries all seven fs-safe
219+
native helpers in its own private tree, using the package runtime's loader-relative
220+
layout. The package itself shares one native tree between runtime entries and its
221+
sealed worker; it does not copy a second tree beside that worker. The helpers'
222+
original source hashes are pinned before copying and verified alongside compiler
223+
output; missing or altered assets fail verification. The default stays off, and
224+
the existing `off`/`auto`/`require` opt-ins retain their behavior.
225+
226+
Watch mode deliberately keeps the existing live-source path, including tsx for
227+
Node subprocesses and native TypeScript handling for Bun. It creates no prepared generation, so a new child launch
228+
reads current source rather than reusing a compiled snapshot. Existing Vitest
229+
watch dependency tracking still determines when tests rerun.
230+
175231
Test wrapper runs end with a short `[test] passed|failed|skipped ... in ...` summary; Vitest's own duration line stays the per-shard detail.
176232

177233
| Command | What it does |

‎extensions/browser/src/browser/client-fetch.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import {
1212
} from "openclaw/plugin-sdk/error-runtime";
1313
import { resolveTimerTimeoutMs } from "openclaw/plugin-sdk/number-runtime";
1414
import { readResponseWithLimit } from "openclaw/plugin-sdk/response-limit-runtime";
15+
import { formatCliCommand } from "openclaw/plugin-sdk/setup-tools";
1516
import { fetchWithSsrFGuard } from "openclaw/plugin-sdk/ssrf-runtime";
1617
import {
1718
normalizeOptionalString,
1819
normalizeLowercaseStringOrEmpty,
1920
} from "openclaw/plugin-sdk/string-coerce-runtime";
20-
import { formatCliCommand } from "../cli/command-format.js";
2121
import { getRuntimeConfig } from "../config/config.js";
2222
import { isLoopbackHost } from "../gateway/net.js";
2323
import { getBridgeAuthForPort } from "./bridge-auth-registry.js";

‎extensions/browser/src/cli/command-format.ts‎

Lines changed: 0 additions & 4 deletions
This file was deleted.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// The plugin owns its native subprocess's source and packaged locations.
2+
export const vectorKnnProcessEntrypoint = {
3+
currentModuleUrl: import.meta.url,
4+
sourceWorkerName: "manager-search-knn.child",
5+
distWorkerPath: "extensions/memory-core/memory-search-knn.child.js",
6+
} as const;

‎extensions/memory-core/src/memory/manager-search-knn-subprocess.ts‎

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
resolveRuntimeWorkerArgv,
55
resolveRuntimeWorkerUrl,
66
} from "openclaw/plugin-sdk/process-runtime";
7+
import { vectorKnnProcessEntrypoint } from "./manager-search-knn-entrypoint.js";
78
import type { VectorKnnChildInput, VectorKnnChildResult } from "./manager-search-knn.child.js";
89
import {
910
isVectorKnnRow,
@@ -27,14 +28,6 @@ class VectorKnnSubprocessError extends Error {
2728
}
2829
}
2930

30-
function resolveVectorKnnChildUrl(): URL {
31-
return resolveRuntimeWorkerUrl({
32-
currentModuleUrl: import.meta.url,
33-
sourceWorkerName: "manager-search-knn.child",
34-
distWorkerPath: "extensions/memory-core/memory-search-knn.child.js",
35-
});
36-
}
37-
3831
function buildChildEnv(env: NodeJS.ProcessEnv = process.env): NodeJS.ProcessEnv {
3932
const childEnv: NodeJS.ProcessEnv = {};
4033
for (const name of ["PATH", "SystemRoot", "SYSTEMROOT", "WINDIR", "TEMP", "TMP", "TMPDIR"]) {
@@ -184,7 +177,7 @@ export async function runVectorKnnInSubprocess(
184177
}
185178
let child;
186179
try {
187-
const childUrl = resolveVectorKnnChildUrl();
180+
const childUrl = resolveRuntimeWorkerUrl(vectorKnnProcessEntrypoint);
188181
child = spawn(process.execPath, resolveRuntimeWorkerArgv(childUrl), {
189182
env: buildChildEnv(),
190183
shell: false,

‎extensions/qa-lab/src/qa-gateway-config.test.ts‎

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -81,21 +81,25 @@ describe("buildQaGatewayConfig", () => {
8181
);
8282
});
8383

84-
it("stamps fresh QA configs with the current OpenClaw version", () => {
85-
const cfg = buildQaGatewayConfig({
86-
bind: "loopback",
87-
gatewayPort: 18789,
88-
gatewayToken: "token",
89-
workspaceDir: "/tmp/qa-workspace",
90-
...createQaChannelTransportParams(),
91-
});
84+
it.each(["/tmp/qa-first/workspace", "/tmp/qa-second/workspace"])(
85+
"stamps fresh QA configs and confines rolling logs (%s)",
86+
(workspaceDir) => {
87+
const cfg = buildQaGatewayConfig({
88+
bind: "loopback",
89+
gatewayPort: 18789,
90+
gatewayToken: "token",
91+
workspaceDir,
92+
...createQaChannelTransportParams(),
93+
});
9294

93-
expect(cfg.meta).toEqual({ lastTouchedVersion: OPENCLAW_VERSION });
94-
expect(cfg.plugins?.allow).toEqual(["memory-core", "qa-lab", "qa-channel"]);
95-
expect(getPrimaryModel(cfg.agents?.defaults?.model)).toBe("mock-openai/gpt-5.6-luna");
96-
expect(cfg.agents?.entries?.qa).not.toHaveProperty("default");
97-
expect(cfg.channels?.["qa-channel"]?.baseUrl).toBe("http://127.0.0.1:43124");
98-
});
95+
expect(cfg.meta).toEqual({ lastTouchedVersion: OPENCLAW_VERSION });
96+
expect(cfg.logging?.file).toBe(`${workspaceDir}/logs/openclaw-YYYY-MM-DD.log`);
97+
expect(cfg.plugins?.allow).toEqual(["memory-core", "qa-lab", "qa-channel"]);
98+
expect(getPrimaryModel(cfg.agents?.defaults?.model)).toBe("mock-openai/gpt-5.6-luna");
99+
expect(cfg.agents?.entries?.qa).not.toHaveProperty("default");
100+
expect(cfg.channels?.["qa-channel"]?.baseUrl).toBe("http://127.0.0.1:43124");
101+
},
102+
);
99103

100104
it("keeps mock-openai as the default provider lane", () => {
101105
const cfg = buildQaGatewayConfig({

‎extensions/qa-lab/src/qa-gateway-config.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ export function buildQaGatewayConfig(params: {
215215
meta: {
216216
lastTouchedVersion: OPENCLAW_VERSION,
217217
},
218+
// Keep daily rollover and pruning inside the owned QA workspace.
219+
logging: {
220+
file: `${params.workspaceDir}/logs/openclaw-YYYY-MM-DD.log`,
221+
},
218222
memory: {
219223
search: {
220224
...mockMemorySearch,

0 commit comments

Comments
 (0)