Skip to content

Commit ce0fafe

Browse files
authored
fix(tooling): avoid build and test startup stalls on shared tsx caches (#130924)
* fix(tooling): avoid shared tsx cache startup stalls Use the shared preloader before tsx initializes so maintained build, check, and test commands retain memory transforms without scanning other checkouts' disk caches. Preserve changed-cwd forks and copied tooling closures. * test: align command contracts with tooling bootstrap
1 parent fdefa67 commit ce0fafe

21 files changed

Lines changed: 704 additions & 360 deletions

‎.github/workflows/plugin-npm-release.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ on:
2222
- "scripts/lib/plugin-npm-package-manifest.mts"
2323
- "scripts/lib/tsx-cli-shim.mjs"
2424
- "scripts/lib/local-check-runtime.mts"
25+
- "scripts/tsx.mjs"
2526
- "scripts/lib/plugin-npm-release.ts"
2627
- "scripts/lib/plugin-publication-candidates.ts"
2728
- "scripts/lib/plugin-publication-collector.ts"

‎docs/reference/test.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ reconcile dependencies before the remote wrapper starts.
7979

8080
## Core commands
8181

82+
Maintained JavaScript tooling wrappers and root package commands use tsx's
83+
in-process transform cache. They skip its shared disk cache before the loader
84+
starts, and child tooling inherits that policy. This does not relocate or clean
85+
temporary directories, Node or Vitest caches, or other global caches. Raw external
86+
`tsx` and `node --import tsx` invocations outside these launchers are unchanged.
87+
8288
Test wrapper runs end with a short `[test] passed|failed|skipped ... in ...` summary; Vitest's own duration line stays the per-shard detail.
8389

8490
| Command | What it does |

‎package.json‎

Lines changed: 283 additions & 283 deletions
Large diffs are not rendered by default.

‎scripts/ci-changed-scope.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ const WINDOWS_SQLITE_SCOPE_RE = /^src\/(?:state\/|.*sqlite.*\.ts$)/;
6262
const WINDOWS_FILE_URL_SCOPE_RE =
6363
/^(?:src\/agents\/tools\/(?:media-tool-file-url\.windows\.test|media-tool-shared(?:\.test)?|pdf-tool(?:\.test)?)|src\/auto-reply\/(?:reply\/stage-sandbox-media|reply\.triggers\.trigger-handling\.stages-inbound-media-into-sandbox-workspace\.test)|src\/media\/(?:local-media-path(?:\.windows\.test)?|local-roots(?:\.test)?|web-media(?:\.file-url\.windows\.test)?)|src\/channels\/inbound-event\/media(?:\.test)?|src\/gateway\/managed-image-attachments(?:\.test)?|extensions\/msteams\/src\/(?:media-helpers|messenger)(?:\.test)?)\.ts$/;
6464
const WINDOWS_SCOPE_RE =
65-
/^(extensions\/mxc\/|src\/agents\/(?:bash-tools\.exec-script-(?:preflight|target)|bash-tools\.exec\.script-preflight\.test)\.ts$|src\/config\/sessions\/(?:session-accessor\.sqlite-archive(?:\.worker(?:\.test)?)?|store\.session-lifecycle-mutation\.test)\.ts$|src\/process\/|src\/infra\/(?:(?:advertised-lan-host|exec-allowlist-pattern|fs-safe-remove)(?:\.windows)?(?:\.test)?|ports(?:-inspect|\.test)|ssh-client(?:\.windows\.test)?|update-managed-service-handoff(?:-(?:command|lifecycle)\.test)?|windows-install-roots)\.ts$|src\/shared\/(?:import-specifier|runtime-import)(?:\.test)?\.ts$|src\/test-utils\/openclaw-test-state(?:\.test)?\.ts$|scripts\/(?:android-(?:app-i18n|pin-version)\.ts|ci-run-timings\.mjs|e2e\/lib\/package-compat\.mjs|generate-bundled-channel-config-metadata\.ts|install\.ps1|openclaw-cross-os-release-checks\.ts|plan-release-workflow-matrix\.mjs|run-additional-boundary-checks\.mts|verify-docker-attestations\.mjs|github\/run-openclaw-cross-os-release-checks\.sh|(?:npm-runner|pnpm-runner|ui|vitest-process-group)\.(?:mjs|mts|js)|lib\/(?:direct-run\.(?:mjs|mts)|format-generated-module\.mts|tsx-cli-shim\.mjs|cross-os-release-checks\/[^/]+\.ts))$|test\/scripts\/(?:direct-run-entrypoints|format-generated-module|install-ps1|npm-runner|openclaw-cross-os-release-workflow|pnpm-runner|ui|vitest-process-group)\.test\.ts$|package\.json$|pnpm-lock\.yaml$|pnpm-workspace\.yaml$|\.github\/workflows\/(?:ci|openclaw-cross-os-release-checks-reusable)\.yml$|\.github\/actions\/setup-node-env\/action\.yml$|\.github\/actions\/setup-pnpm-store-cache\/action\.yml$)/;
65+
/^(extensions\/mxc\/|src\/agents\/(?:bash-tools\.exec-script-(?:preflight|target)|bash-tools\.exec\.script-preflight\.test)\.ts$|src\/config\/sessions\/(?:session-accessor\.sqlite-archive(?:\.worker(?:\.test)?)?|store\.session-lifecycle-mutation\.test)\.ts$|src\/process\/|src\/infra\/(?:(?:advertised-lan-host|exec-allowlist-pattern|fs-safe-remove)(?:\.windows)?(?:\.test)?|ports(?:-inspect|\.test)|ssh-client(?:\.windows\.test)?|update-managed-service-handoff(?:-(?:command|lifecycle)\.test)?|windows-install-roots)\.ts$|src\/shared\/(?:import-specifier|runtime-import)(?:\.test)?\.ts$|src\/test-utils\/openclaw-test-state(?:\.test)?\.ts$|scripts\/(?:android-(?:app-i18n|pin-version)\.ts|ci-run-timings\.mjs|e2e\/lib\/package-compat\.mjs|generate-bundled-channel-config-metadata\.ts|install\.ps1|openclaw-cross-os-release-checks\.ts|plan-release-workflow-matrix\.mjs|run-additional-boundary-checks\.mts|verify-docker-attestations\.mjs|github\/run-openclaw-cross-os-release-checks\.sh|tsx\.mjs|(?:npm-runner|pnpm-runner|ui|vitest-process-group)\.(?:mjs|mts|js)|lib\/(?:direct-run\.(?:mjs|mts)|format-generated-module\.mts|tsx-cli-shim\.mjs|cross-os-release-checks\/[^/]+\.ts))$|test\/scripts\/(?:direct-run-entrypoints|format-generated-module|install-ps1|npm-runner|openclaw-cross-os-release-workflow|pnpm-runner|ui|vitest-process-group)\.test\.ts$|package\.json$|pnpm-lock\.yaml$|pnpm-workspace\.yaml$|\.github\/workflows\/(?:ci|openclaw-cross-os-release-checks-reusable)\.yml$|\.github\/actions\/setup-node-env\/action\.yml$|\.github\/actions\/setup-pnpm-store-cache\/action\.yml$)/;
6666
const WINDOWS_TEST_SCOPE_RE =
6767
/^(extensions\/mxc\/test\/(?:mxc-backend|sandbox-policy-loader)\.test\.ts$|src\/agents\/bash-tools\.exec\.script-preflight\.test\.ts$|src\/config\/sessions\/(?:session-accessor\.sqlite-archive\.worker|store\.session-lifecycle-mutation)\.test\.ts$|src\/process\/(?:exec\.windows|supervisor\/supervisor\.anchored-shell\.real|terminal-pty|windows-command)\.test\.ts$|src\/infra\/(?:advertised-lan-host(?:\.windows)?|exec-allowlist-pattern|fs-safe-remove|ports|ssh-client\.windows|update-managed-service-handoff-(?:command|lifecycle)|windows-install-roots)\.test\.ts$|src\/shared\/runtime-import\.test\.ts$|src\/state\/openclaw-database-paths\.windows\.test\.ts$|src\/test-utils\/openclaw-test-state\.test\.ts$|test\/scripts\/(?:direct-run-entrypoints|format-generated-module|npm-runner|openclaw-cross-os-release-workflow|pnpm-runner|ui|vitest-process-group)\.test\.ts$)/;
6868
const WINDOWS_SECRETREF_SCOPE_RE =

‎scripts/docs-sync-publish.mjs‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ const SYNC_SUPPORT_FILES = [
3737
source: path.join(ROOT, "scripts", "lib", "local-check-runtime.mts"),
3838
target: path.join(".openclaw-sync", "lib", "local-check-runtime.mts"),
3939
},
40+
{
41+
source: path.join(ROOT, "scripts", "tsx.mjs"),
42+
target: path.join(".openclaw-sync", "tsx.mjs"),
43+
},
4044
{
4145
source: path.join(ROOT, "scripts", "lib", "mintlify-accordion.mjs"),
4246
target: path.join(".openclaw-sync", "lib", "mintlify-accordion.mjs"),

‎scripts/lib/plugin-publication-candidates.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const PLUGIN_NPM_RELEASE_AUTHORITY_PATHS = [
3131
"scripts/lib/plugin-npm-package-manifest.mts",
3232
"scripts/lib/plugin-npm-release.ts",
3333
"scripts/lib/tsx-cli-shim.mjs",
34+
"scripts/tsx.mjs",
3435
"scripts/plugin-npm-publish.sh",
3536
"scripts/plugin-npm-release-check.ts",
3637
"scripts/plugin-npm-release-plan.ts",

‎scripts/lib/tsx-cli-shim.mjs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,14 @@ function resolveTsxImport(checkoutRoot) {
5555
throw resolutionError;
5656
}
5757

58+
export async function registerToolingTsx() {
59+
// tsx indexes the entire shared disk cache before expiration, coupling startup
60+
// to other checkouts' cache size. This flag retains its in-process Map and
61+
// reaches descendant tooling before their loaders initialize.
62+
process.env.TSX_DISABLE_CACHE = "1";
63+
await import(resolveTsxImport(SHIM_CHECKOUT_ROOT));
64+
}
65+
5866
function signalExitCode(signal) {
5967
const signalNumber = osConstants.signals[signal];
6068
return typeof signalNumber === "number" ? 128 + signalNumber : 1;
@@ -118,7 +126,7 @@ async function runTsxCliShimInner(moduleUrl, options) {
118126
try {
119127
const implementationUrl = new URL(options.implementation, moduleUrl);
120128
const implementationPath = fileURLToPath(implementationUrl);
121-
const tsxImport = resolveTsxImport(SHIM_CHECKOUT_ROOT);
129+
const tsxImport = new URL("../tsx.mjs", import.meta.url).href;
122130
const nodeExecutable = process.versions.bun ? "node" : process.execPath;
123131
child = spawn(
124132
nodeExecutable,

‎scripts/pr‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ pr_wrapper_components=(
5252
scripts/lib/direct-run.mjs
5353
scripts/lib/tsx-cli-shim.mjs
5454
scripts/lib/local-check-runtime.mts
55+
scripts/tsx.mjs
5556
scripts/verify-pr-hosted-gates.mjs
5657
scripts/verify-pr-hosted-gates.mts
5758
scripts/watch-pr-ci.mjs

‎scripts/test-projects.test-support.mts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2362,7 +2362,7 @@ const SEMANTIC_TOOLING_TARGET_PATTERNS: Array<[RegExp, string[]]> = [
23622362
[/^scripts\/ci-changed-scope\.mjs$/u, [...changedScopeTests, "control-ui-i18n"]],
23632363
[/^scripts\/check-changed\.(?:mjs|mts)$/u, ["changed-lanes"]],
23642364
[/^scripts\/changed-lanes\.(?:mjs|mts)$/u, ["changed-lanes"]],
2365-
[/^scripts\/lib\/tsx-cli-shim\.mjs$/u, ["direct-run-entrypoints"]],
2365+
[/^scripts\/(?:lib\/tsx-cli-shim|tsx)\.mjs$/u, ["direct-run-entrypoints"]],
23662366
[
23672367
new RegExp(
23682368
[

‎scripts/tsx.mjs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { registerToolingTsx } from "./lib/tsx-cli-shim.mjs";
2+
3+
// fork() inherits execArgv but can change cwd. Keep our root-script preload
4+
// resolvable there without rewriting unrelated flags or other preloads.
5+
const preload = "./scripts/tsx.mjs";
6+
for (const [index, arg] of process.execArgv.entries()) {
7+
if (arg === preload && process.execArgv[index - 1] === "--import") {
8+
process.execArgv[index] = import.meta.url;
9+
} else if (arg === `--import=${preload}`) {
10+
process.execArgv[index] = `--import=${import.meta.url}`;
11+
}
12+
}
13+
14+
await registerToolingTsx();

0 commit comments

Comments
 (0)