The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 13:30 UTC
fix(dev): first dev start builds the missing resource monitor (#34975)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Jon Duea committed
Nov 14, 2026 at 12:16 UTC
f12527ecf0ee45b39a0e1a4464cb0fe8ae3ad843
3 files changed
+104
-3
docs/operations/development.md
+3
@@ -66,6 +66,9 @@ The first start in a worktree seeds its empty database from a read-only copy of
66
and dev starts with an empty database. `--no-seed` or `T3CODE_DEV_SEED=0` skips seeding.
67
To copy a larger source, run `vp run migrate-dev-db` with dev stopped. It may use
68
substantial disk space before pruning.
69
+The first start in any checkout also builds the native resource monitor with Cargo when
70
+`native/resource-monitor/target` has no binary. Without Rust, dev starts with a warning
71
+and no process telemetry; install Rust and run `vp run build:resource-monitor`.
72
Never run a development server against the live `~/.t3/userdata`.
73
See [test data](../../AGENTS.md#test-data) for copying a consistent database snapshot.
74
scripts/dev-runner.test.ts
+63
@@ -438,6 +438,69 @@ it.layer(NodeServices.layer)("dev-runner", (it) => {
438
});
439
});
440
441
+ it.effect.each([
442
+ { built: "release", cargoFails: false, expectBuild: false },
443
+ { built: "debug", cargoFails: false, expectBuild: false },
444
+ { built: undefined, cargoFails: false, expectBuild: true },
445
+ { built: undefined, cargoFails: true, expectBuild: true },
446
+ ] as const)(
447
+ "builds the resource monitor only when it is missing: built=$built cargoFails=$cargoFails",
448
+ ({ built, cargoFails, expectBuild }) =>
449
+ Effect.gen(function* () {
450
+ const fs = yield* FileSystem.FileSystem;
451
+ const spawned: Array<{ readonly command: string; readonly args: ReadonlyArray<string> }> =
452
+ [];
453
+ const warnings: Array<string> = [];
454
+ const spawnerLayer = Layer.succeed(
455
+ ChildProcessSpawner.ChildProcessSpawner,
456
+ ChildProcessSpawner.make((command) => {
457
+ const spawn = command as unknown as {
458
+ readonly command: string;
459
+ readonly args: ReadonlyArray<string>;
460
+ };
461
+ spawned.push({ command: spawn.command, args: spawn.args });
462
+ return spawn.command === "cargo" && cargoFails
463
+ ? Effect.succeed(mockProcess(101))
464
+ : Effect.succeed(mockProcess(0));
465
+ }),
466
+ );
467
+
468
+ yield* runDevRunnerWithInput(devServerInput).pipe(
469
+ Effect.provide([
470
+ emptyConfigLayer,
471
+ netServiceLayer,
472
+ spawnerLayer,
473
+ Logger.layer([
474
+ Logger.make((options) => {
475
+ if (options.logLevel === "Warn") warnings.push(String(options.message));
476
+ }),
477
+ ]),
478
+ ]),
479
+ Effect.provideService(FileSystem.FileSystem, {
480
+ ...fs,
481
+ exists: (file) =>
482
+ NodePath.basename(file) === "t3-resource-monitor"
483
+ ? Effect.succeed(
484
+ built !== undefined && NodePath.basename(NodePath.dirname(file)) === built,
485
+ )
486
+ : fs.exists(file),
487
+ }),
488
+ Effect.provideService(HostProcess.Platform, "linux"),
489
+ );
490
+
491
+ const cargo = spawned.filter((spawn) => spawn.command === "cargo");
492
+ assert.lengthOf(cargo, expectBuild ? 1 : 0);
493
+ if (expectBuild) {
494
+ assert.includeMembers([...cargo[0]!.args], ["build", "--locked", "--release"]);
495
+ assert.isTrue(cargo[0]!.args.at(-1)!.endsWith("Cargo.toml"));
496
+ }
497
+ assert.lengthOf(warnings, cargoFails ? 1 : 0);
498
+ if (cargoFails) assert.include(warnings[0]!, "vp run build:resource-monitor");
499
+ // A failed build never blocks dev.
500
+ assert.equal(spawned.at(-1)?.command, "vp");
501
+ }),
502
+ );
503
+
504
it.effect("ignores an ambient T3CODE_HOME when no home is resolved", () =>
505
Effect.gen(function* () {
506
const env = yield* createDevRunnerEnv({
scripts/dev-runner.ts
+38
-3
@@ -614,9 +614,9 @@ const runRepoScript = Effect.fn("dev-runner.runRepoScript")(function* (
614
});
615
616
/**
617
- * The first start in a worktree seeds its empty database from a small live database
618
- * and warms the web dependency cache. Each step checks for its own output, so
619
- * later starts skip it.
617
+ * The first start in a worktree seeds its empty database from a small live database,
618
+ * builds the native resource monitor, and warms the web dependency cache. Each step
619
+ * checks for its own output, so later starts skip it.
620
*/
621
const prepareFirstStart = Effect.fn("dev-runner.prepareFirstStart")(function* (input: {
622
readonly mode: DevMode;
@@ -668,6 +668,41 @@ const prepareFirstStart = Effect.fn("dev-runner.prepareFirstStart")(function* (i
668
}
669
670
const repoRoot = path.dirname(import.meta.dirname);
671
+ // Dev backends load the monitor from its Cargo output, which a fresh
672
+ // checkout or worktree does not have yet.
673
+ if (input.mode !== "dev:web") {
674
+ const crate = path.join(repoRoot, "native/resource-monitor");
675
+ const binary =
676
+ (yield* HostProcess.Platform) === "win32" ? "t3-resource-monitor.exe" : "t3-resource-monitor";
677
+ if (
678
+ !(yield* exists(path.join(crate, "target/release", binary))) &&
679
+ !(yield* exists(path.join(crate, "target/debug", binary)))
680
+ ) {
681
+ yield* Effect.logInfo("[dev-runner] building the resource monitor (first start only).");
682
+ const exitCode = yield* ChildProcess.make(
683
+ "cargo",
684
+ ["build", "--locked", "--release", "--manifest-path", path.join(crate, "Cargo.toml")],
685
+ {
686
+ cwd: repoRoot,
687
+ stdin: "ignore",
688
+ stdout: "inherit",
689
+ stderr: "inherit",
690
+ env: input.env,
691
+ extendEnv: false,
692
+ },
693
+ ).pipe(
694
+ Effect.flatMap((child) => child.exitCode),
695
+ Effect.scoped,
696
+ Effect.orElseSucceed(() => -1),
697
+ );
698
+ if (exitCode !== 0) {
699
+ yield* Effect.logWarning(
700
+ "[dev-runner] could not build the resource monitor; starting without process telemetry. Install Rust and run `vp run build:resource-monitor`.",
701
+ );
702
+ }
703
+ }
704
+ }
705
+
706
if (
707
input.mode !== "dev:server" &&
708
!(yield* exists(path.join(repoRoot, "apps/web/node_modules/.vite/deps/_metadata.json")))