Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

ci(ubicloud): re-root the uploaded typecheck state when node_modules is a symlink, so verify's typecheck runs warm from a worktree

garrytan8b71f8a4da92
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f98be86348..0e57ecfd72 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,20 @@ credits are retained; no result has been reassigned to another provider. Origina
identifiers and attribution are available in the pre-removal Git revision
`6040075c6cb95be5881cc2e1b76ef7d71f4e5d29` (retained on 2026-09-23).
+## [Unreleased]
+
+**The Ubicloud gate's `verify` typecheck runs warm from a worktree whose `node_modules` is a symlink.** Verify's typecheck on #6673's gate timed out at 121 s against its 120 s cap; the rerun passed at 113 s. That gate ran from a `git worktree` whose `node_modules` is a symlink to the main checkout's, a common way to skip a `bun install` per worktree. tsc records each source file relative to the buildinfo's directory, but it records the files it reaches through node_modules by their real path: the TypeScript lib files and bun-types' globals, 990 entries in all. In that layout, those entries point out of the checkout (`../../../../../../../../workspace/gbrain/node_modules/typescript/lib/lib.es5.d.ts`). On the VM they resolve to nothing, the global declarations count as changed, and tsc rechecks every file. All four of that worktree's gates logged `verify's typecheck runs warm`, but the typecheck took 84, 85, 113 and 121 s, the same as a cold one. The 120 s cap is unchanged.
+
+### Itemized changes
+
+- **`scripts/ubicloud/typecheck-state.ts` `portableBuildInfo`** writes the uploaded copy (`<run>/typecheck.tsbuildinfo`). It moves every entry under the real path of the checkout's `node_modules` back under the checkout's own `node_modules` path, which the VM's frozen install lays out the same way. A checkout with a real `node_modules` is copied unchanged. Only the `fileNames` table carries paths; everything else in tsc 5.9's buildinfo refers to files by index. tsc still checks every file's content hash, so a wrong mapping costs time, never correctness.
+- **`scripts/ci-ubicloud.ts`** uploads that copy. When it re-roots entries, the log line says how many. If an entry still resolves outside the checkout, the state is not uploaded, and the log says verify's typecheck runs cold and why, instead of claiming it runs warm.
+- **Proof.** Forced probe on a 16-vCPU gate VM, typecheck alone:
+ - The buildinfo written from a symlinked worktree took 84 s and 91 s.
+ - The same file re-rooted took 16 s and 15 s.
+ - The gate's own verify step, run from that worktree. Before: the log said `runs warm` and verify's typecheck took 90 s. After: the log said `990 entries re-rooted from the symlinked node_modules; verify's typecheck runs warm`, and the typecheck took 16 s.
+- **`test/scripts/ubicloud-typecheck-state.test.ts`** builds a worktree with a symlinked `node_modules` and the entries tsc 5.9 wrote there. It checks that lib and bun-types entries are re-rooted, sources are kept, a path outside both is counted, a plain checkout is unchanged, and a file without `fileNames` is refused.
+
## [0.60.219.0] - 2026-10-14
**A new brain made by `gbrain setup` is finished when setup ends, and a plain-English question to `gbrain recall` now finds facts on a brain without embeddings.** Before, `gbrain setup claude-code` (or `codex`) created a brain and then printed a line telling you to run `gbrain apply-migrations --yes --no-autopilot-install` yourself, so a fresh install still had setup migrations pending and `gbrain doctor` said so. Setup now runs those migrations itself, on the brain it just created, and says which ones it ran. Separately, on a brain with no embeddings, `gbrain recall "how does the user take their coffee"` printed "No matching facts." even when a fact about coffee existed, because recall looked for an entity with that whole sentence as its name. Now it ranks the facts against the sentence as a question and tells you it did.
diff --git a/scripts/ci-ubicloud.ts b/scripts/ci-ubicloud.ts
index 572115b953..af39cc3e37 100755
--- a/scripts/ci-ubicloud.ts
+++ b/scripts/ci-ubicloud.ts
@@ -44,7 +44,7 @@
*/
import { spawnSync, type ChildProcess } from "node:child_process";
-import { appendFileSync, existsSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
+import { appendFileSync, mkdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { dirname, join, resolve } from "node:path";
import {
@@ -62,7 +62,7 @@ import {
type WeightTable,
} from "./ubicloud/schedule.ts";
import { runScript, type RunScriptOpts } from "./ubicloud/run-script.ts";
-import { buildTypecheckState, typecheckBuildInfo } from "./ubicloud/typecheck-state.ts";
+import { buildTypecheckState, portableBuildInfo, typecheckBuildInfo } from "./ubicloud/typecheck-state.ts";
const ROOT = resolve(import.meta.dir, "..");
const RUNNER = join(ROOT, "scripts/ubicloud/ubi-runner.sh");
@@ -403,12 +403,19 @@ async function main() {
for (const step of control) {
if (step.lane === "verify" && typecheckState) {
const { code, ms } = await typecheckState;
- const sent = existsSync(join(ROOT, buildInfo!))
- ? await runner(["ssh", vm.name, `mkdir -p ${quote(dirname(`${REMOTE_DIR}/${buildInfo}`))} && cat > ${quote(`${REMOTE_DIR}/${buildInfo}`)}`], { input: join(ROOT, buildInfo!) })
+ const local = `local incremental typecheck (exit ${code}, ${Math.round(ms / 1000)}s)`;
+ const state = join(runDir, "typecheck.tsbuildinfo");
+ let portable: ReturnType<typeof portableBuildInfo> = null;
+ try { portable = portableBuildInfo(ROOT, buildInfo!, state); } catch { /* absent or unreadable: reported below */ }
+ const sent = portable && portable.outside === 0
+ ? await runner(["ssh", vm.name, `mkdir -p ${quote(dirname(`${REMOTE_DIR}/${buildInfo}`))} && cat > ${quote(`${REMOTE_DIR}/${buildInfo}`)}`], { input: state })
: null;
+ const rerooted = portable?.moved ? `, ${portable.moved} entries re-rooted from the symlinked node_modules` : "";
log(sent?.code === 0
- ? `typecheck state: local incremental typecheck (exit ${code}, ${Math.round(ms / 1000)}s) uploaded to ${vm.name}; verify's typecheck runs warm`
- : `typecheck state: ${sent ? `upload to ${vm.name} failed (exit ${sent.code})` : `no ${buildInfo} after the local typecheck (exit ${code})`}; verify's typecheck runs cold`);
+ ? `typecheck state: ${local} uploaded to ${vm.name}${rerooted}; verify's typecheck runs warm`
+ : `typecheck state: ${!portable ? `no readable ${buildInfo} after the ${local}`
+ : portable.outside ? `${portable.outside} entries of the ${local} resolve outside the checkout, not uploaded`
+ : `upload to ${vm.name} failed (exit ${sent!.code})`}; verify's typecheck runs cold`);
}
log(`control on ${vm.name}: ${step.lane}${step.files.length ? ` (${step.files.length} exclusive files, sequential)` : ""}`);
const { parsed, logPath } = await runBatch(vm, 1, step.lane, step.files);
diff --git a/scripts/structural-suites.tsv b/scripts/structural-suites.tsv
index aaefab35e4..92f3a7ad76 100644
--- a/scripts/structural-suites.tsv
+++ b/scripts/structural-suites.tsv
@@ -322,7 +322,7 @@ test/scripts/stress-plan.test.ts execution profiles 3 readFileSync
test/scripts/test-env-opt-ins-guard.test.ts check-test-env-opt-ins 5 readFileSync
test/scripts/test-shard.slow.test.ts test-shard.sh — LPT balance contract 5 readFileSync
test/scripts/test-shard.slow.test.ts test-shard.sh — exclusion contract 7 readFileSync
-test/scripts/ubicloud-typecheck-state.test.ts (file-level) 2 readFileSync
+test/scripts/ubicloud-typecheck-state.test.ts (file-level) 3 readFileSync
test/search/graph-signals-wire-integration.test.ts v0.40.4 — source-grep regression guard 1 source-surface-helper
test/serve-behavior-notice-6543.test.ts (file-level) 3 readFileSync
test/serve-http-admin-route-guard.test.ts (file-level) 6 readFileSync
diff --git a/scripts/ubicloud/README.md b/scripts/ubicloud/README.md
index 99c8e35eeb..4d1d755375 100644
--- a/scripts/ubicloud/README.md
+++ b/scripts/ubicloud/README.md
@@ -93,8 +93,13 @@ tarball never carries). The orchestrator builds that state with
(`scripts/ubicloud/typecheck-state.ts`). Cold, verify's typecheck took 81-84 s
on a 16-vCPU VM and crossed the 120 s per-check cap on a loaded host; warm, it
takes 16-19 s. tsc revalidates every file by content hash, so the state never
-changes the result. The run log says whether verify's typecheck ran warm or
-cold, and the local build's output is in `logs/local-typecheck.log`. Items run through the `ci:local` wrappers
+changes the result. When the local checkout's `node_modules` is a symlink (a
+worktree sharing another checkout's install), tsc records node_modules files by
+their real path outside the checkout; the uploaded copy
+(`<run>/typecheck.tsbuildinfo`) re-roots them under the checkout's own
+`node_modules`, or the state would not apply on the VM and its typecheck would run
+cold. The run log says whether verify's typecheck ran warm or cold, and the local
+build's output is in `logs/local-typecheck.log`. Items run through the `ci:local` wrappers
(`scripts/ubicloud/ci-item.sh`): `run-unit-shard.sh`, `run-serial-tests.sh` and
`run-slow-tests.sh` accept explicit file arguments for this purpose, and
`run-e2e.sh` runs each E2E file against its slot's own server and pooler. The
diff --git a/scripts/ubicloud/typecheck-state.ts b/scripts/ubicloud/typecheck-state.ts
index d1cd84f22c..07ac45eb02 100644
--- a/scripts/ubicloud/typecheck-state.ts
+++ b/scripts/ubicloud/typecheck-state.ts
@@ -11,11 +11,21 @@
* verify. tsc rereads every file and compares content hashes, so a stale or
* foreign buildinfo costs time, never correctness; type errors are recorded
* in it and reported again on the VM.
+ *
+ * tsc records each file relative to the buildinfo's directory, but reaches
+ * node_modules files (the lib files, bun-types' globals) through their real
+ * path. In a worktree whose node_modules is a symlink to another checkout's,
+ * those entries climb out of the checkout ("../../../../../../../../workspace/
+ * gbrain/node_modules/typescript/lib/lib.es5.d.ts"), resolve to nothing on the
+ * VM, and the changed globals make tsc recheck every file: the upload ran cold
+ * (84-121 s) while the log said warm (#6673). `portableBuildInfo` re-roots
+ * those entries under the checkout's own node_modules path, which the VM's
+ * frozen install has in the same layout.
*/
import { spawn, type ChildProcess } from "node:child_process";
-import { closeSync, openSync, readFileSync } from "node:fs";
-import { join } from "node:path";
+import { closeSync, openSync, readFileSync, realpathSync, writeFileSync } from "node:fs";
+import { dirname, join, relative, resolve, sep } from "node:path";
/** The buildinfo path `bun run typecheck` writes, relative to the checkout, or null when it writes none. */
export function typecheckBuildInfo(root: string): string | null {
@@ -39,3 +49,29 @@ export function buildTypecheckState(root: string, logPath: string, onSpawn: (chi
child.once("close", (code) => done({ code: code ?? 1, ms: Date.now() - started }));
});
}
+
+/**
+ * Write `root`'s buildinfo to `out` with every entry reached through a
+ * symlinked node_modules re-rooted under `root/node_modules`. Returns how many
+ * entries moved and how many still resolve outside `root` (those would be
+ * rechecked from scratch on the VM), or null when the file is not a buildinfo.
+ */
+export function portableBuildInfo(root: string, buildInfo: string, out: string): { moved: number; outside: number } | null {
+ const path = join(root, buildInfo);
+ const info = JSON.parse(readFileSync(path, "utf8")) as { fileNames?: unknown };
+ if (!Array.isArray(info.fileNames)) return null;
+ const base = dirname(path), modules = join(root, "node_modules");
+ const real = realpathSync(modules);
+ let moved = 0, outside = 0;
+ info.fileNames = info.fileNames.map((name: string) => {
+ let file = resolve(base, name);
+ if (real !== modules && file.startsWith(real + sep)) {
+ file = modules + file.slice(real.length);
+ moved++;
+ }
+ if (!file.startsWith(root + sep)) outside++;
+ return relative(base, file).split(sep).join("/");
+ });
+ writeFileSync(out, JSON.stringify(info));
+ return { moved, outside };
+}
diff --git a/test/scripts/ubicloud-typecheck-state.test.ts b/test/scripts/ubicloud-typecheck-state.test.ts
index 96e444df1e..1b70ee5a70 100644
--- a/test/scripts/ubicloud-typecheck-state.test.ts
+++ b/test/scripts/ubicloud-typecheck-state.test.ts
@@ -4,10 +4,10 @@
* verify's typecheck on the VM runs incrementally instead of cold.
*/
import { afterEach, expect, test } from 'bun:test';
-import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
import { join, resolve } from 'node:path';
-import { buildTypecheckState, typecheckBuildInfo } from '../../scripts/ubicloud/typecheck-state.ts';
+import { buildTypecheckState, portableBuildInfo, typecheckBuildInfo } from '../../scripts/ubicloud/typecheck-state.ts';
const ROOT = resolve(import.meta.dir, '..', '..');
const dirs: string[] = [];
@@ -37,3 +37,31 @@ test('building the state runs the typecheck script and reports its exit code, ev
expect(readFileSync(join(dir, 'out.txt'), 'utf8')).toBe('checked\n');
expect(existsSync(join(dir, 'log.txt'))).toBe(true);
});
+
+test('entries reached through a symlinked node_modules are re-rooted under the checkout, so they resolve on the VM', () => {
+ const top = mkdtempSync(join(tmpdir(), 'gbrain-typecheck-portable-'));
+ dirs.push(top);
+ const shared = join(top, 'main', 'node_modules'), root = join(top, 'work', 'gate');
+ mkdirSync(join(shared, '.cache'), { recursive: true });
+ mkdirSync(root, { recursive: true });
+ symlinkSync(shared, join(root, 'node_modules'));
+ const climb = '../'.repeat(join(root, 'node_modules', '.cache').split('/').length - 1);
+ // What tsc 5.9 wrote from such a worktree (#6673): sources relative to the buildinfo, node_modules files through their real path.
+ writeFileSync(join(shared, '.cache', 'tc.tsbuildinfo'), JSON.stringify({
+ fileNames: [`${climb}${shared.slice(1)}/typescript/lib/lib.es5.d.ts`, `${climb}${shared.slice(1)}/@types/bun/node_modules/bun-types/globals.d.ts`, '../../src/core/engine.ts', `${climb}${top.slice(1)}/elsewhere/x.ts`],
+ fileInfos: [], version: '5.9.3',
+ }));
+ const out = join(top, 'portable.tsbuildinfo');
+ expect(portableBuildInfo(root, 'node_modules/.cache/tc.tsbuildinfo', out)).toEqual({ moved: 2, outside: 1 });
+ const written = JSON.parse(readFileSync(out, 'utf8')) as { fileNames: string[]; version: string };
+ expect(written.fileNames.slice(0, 3)).toEqual(['../typescript/lib/lib.es5.d.ts', '../@types/bun/node_modules/bun-types/globals.d.ts', '../../src/core/engine.ts']);
+ expect(written.version).toBe('5.9.3');
+
+ const plain = join(top, 'plain');
+ mkdirSync(join(plain, 'node_modules', '.cache'), { recursive: true });
+ writeFileSync(join(plain, 'node_modules', '.cache', 'tc.tsbuildinfo'), JSON.stringify({ fileNames: ['../typescript/lib/lib.es5.d.ts', '../../src/a.ts'] }));
+ expect(portableBuildInfo(plain, 'node_modules/.cache/tc.tsbuildinfo', out)).toEqual({ moved: 0, outside: 0 });
+ expect((JSON.parse(readFileSync(out, 'utf8')) as { fileNames: string[] }).fileNames).toEqual(['../typescript/lib/lib.es5.d.ts', '../../src/a.ts']);
+ writeFileSync(join(plain, 'node_modules', '.cache', 'tc.tsbuildinfo'), '{}');
+ expect(portableBuildInfo(plain, 'node_modules/.cache/tc.tsbuildinfo', out)).toBeNull();
+});