Skip to content

Commit 2f19802

Browse files
salman1993claude
andcommitted
fix(runtime): always use the dev Goose profile for just desktop
`just desktop` is local-only, so it always stages the dev profile and the app accepts it in any build mode. Packaged builds still run preparation without `--dev` and stage the pinned lean profile, replacing any staged dev bundle. This removes the launcher's Tauri/Cargo argument parsing and the separate dev resource directory and config overlay. Release the preparation lock on SIGINT/SIGTERM: Node skips `finally` on Ctrl-C, which left a stale lock that blocked every later launch. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Salman Mohammed <[email protected]>
1 parent 7f23a5a commit 2f19802

9 files changed

Lines changed: 90 additions & 281 deletions

File tree

‎.gitignore‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,5 @@ coverage/
3131
dist-author/
3232

3333
# Generated immutable agent runtime resources.
34-
src-tauri/resources/agent-runtime-dev/
3534
src-tauri/resources/agent-runtime/*
3635
!src-tauri/resources/agent-runtime/README.md

‎crates/agent-controller/src/bundle.rs‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,14 +62,13 @@ impl RuntimeBundle {
6262
let source: Source =
6363
serde_json::from_str(include_str!("../../../runtime/agent-runtime.json"))
6464
.map_err(|_| "Runtime source specification is invalid")?;
65-
// Debug app builds (`just desktop`) also accept Goose's fast dev profile.
65+
// `just desktop` stages Goose's fast dev profile; packaging stages the pin's.
6666
let goose = manifest.goose == source.goose
67-
|| (cfg!(debug_assertions)
68-
&& manifest.goose
69-
== GooseSource {
70-
profile: source.goose_dev_profile,
71-
..source.goose
72-
});
67+
|| manifest.goose
68+
== GooseSource {
69+
profile: source.goose_dev_profile,
70+
..source.goose
71+
};
7372
if manifest.version != 2
7473
|| manifest.revision != source.revision
7574
|| !goose

‎crates/agent-controller/src/runtime/tests.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,15 +1552,15 @@ fn bundle_rejects_source_revisions_different_from_the_runtime_spec() {
15521552

15531553
#[test]
15541554
#[cfg(unix)]
1555-
fn bundle_accepts_the_dev_goose_profile_only_with_debug_assertions() {
1555+
fn bundle_accepts_the_dev_goose_profile() {
15561556
let tools = tempfile::tempdir().unwrap();
15571557
bundle(tools.path());
15581558
let path = tools.path().join("manifest.json");
15591559
let original: serde_json::Value = serde_json::from_slice(&fs::read(&path).unwrap()).unwrap();
15601560
let source: serde_json::Value =
15611561
serde_json::from_str(include_str!("../../../../runtime/agent-runtime.json")).unwrap();
15621562
for (profile, accepted) in [
1563-
(source["gooseDevProfile"].clone(), cfg!(debug_assertions)),
1563+
(source["gooseDevProfile"].clone(), true),
15641564
(json!("dev-other"), false),
15651565
] {
15661566
let mut manifest = original.clone();

‎docs/agent-control.md‎

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -876,23 +876,17 @@ to the same immutable source revision as the native library, plus an independent
876876
Goose revision for `goose-acp`. The build script fetches both revisions and uses
877877
pinned Cargo with locked dependencies: a release build of the Buzz tools and a
878878
lean Goose build without default features. `just desktop` builds Goose with
879-
`gooseDevProfile` instead, which only debug apps accept. `just desktop --release`
880-
keeps the pinned lean profile, as do Cargo `--release`, `-r` and explicit
881-
`--profile` arguments after the first `--`. Arguments after Cargo’s second `--`
882-
are app arguments and do not select the build mode. Sources stay checked out under `target/agent-runtime-src`, so a rebuild after a pin bump reuses
879+
`gooseDevProfile` instead, which compiles much faster. Packaged builds keep the
880+
pinned profile, and the manifest records the profile actually built. Sources stay
881+
checked out under `target/agent-runtime-src`, so a rebuild after a pin bump reuses
883882
unchanged crates. An exclusive per-checkout lock covers preparation through
884-
publication. A second preparation fails with a retry message. If interrupted,
885-
stop its remaining Git/Cargo processes before removing
886-
`target/agent-runtime-prepare.lock`; locks are never removed automatically based
887-
on age or a dead parent PID. Ordinary success/failure removes the lock.
883+
publication; a second preparation fails with a retry message. Ctrl-C releases the
884+
lock. After a force kill, stop its remaining Git/Cargo processes before removing
885+
`target/agent-runtime-prepare.lock`.
888886
Builds scrub injected Buzz/provider environment and
889887
per-shell compiler overrides (`RUSTFLAGS`, `RUSTC_*`, `CARGO_PROFILE_*`, …), and stages binaries plus
890888
revision/Goose source and build settings/target/SHA256 manifest in
891-
`src-tauri/resources/agent-runtime` for packaged builds and
892-
`src-tauri/resources/agent-runtime-dev` for ordinary desktop dev. The desktop
893-
config selects the dev directory with the same `agent-runtime/` destination;
894-
one mode cannot replace the other’s staged resources before native copying or
895-
bundling finishes. Worktrees
889+
`src-tauri/resources/agent-runtime`. Worktrees
896890
of one clone reuse a verified bundle cached under the Git common directory, keyed
897891
by the pin, tool list, build arguments and `rustc -vV`. Native build copies them to
898892
`target/debug/agent-runtime`. Generated binaries/manifest are not committed.

‎scripts/build-agent-runtime.mjs‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
rename,
1414
rm,
1515
} from "node:fs/promises";
16+
import { rmSync } from "node:fs";
1617
import { basename, dirname, join, resolve } from "node:path";
1718
import { fileURLToPath } from "node:url";
1819
import { runtimeBuildPlatform } from "./runtime-build-platform.mjs";
@@ -48,10 +49,7 @@ async function run(command, args, capture = false, cwd = root, childEnv = env) {
4849
const toolchain = await run(rustc, ["-vV"], true);
4950
const target = toolchain.match(/^host: (.+)$/m)?.[1]?.trim();
5051
if (!target) throw new Error("Could not resolve pinned Rust target");
51-
const destination = join(
52-
root,
53-
`src-tauri/resources/agent-runtime${dev ? "-dev" : ""}`,
54-
);
52+
const destination = join(root, "src-tauri/resources/agent-runtime");
5553
const filenames = spec.tools.map((name) =>
5654
process.platform === "win32" ? `${name}.exe` : name,
5755
);
@@ -278,9 +276,9 @@ async function prepare() {
278276
}
279277
}
280278

281-
// Fail closed on overlap or interruption: never remove another process's Git
282-
// checkout or staging files. A killed process can leave Cargo/Git children alive,
283-
// so stale locks require explicit cleanup after those processes have stopped.
279+
// Fail closed on overlap: never remove another process's Git checkout or staging
280+
// files. A force-killed process can leave Cargo/Git children alive, so its stale
281+
// lock requires explicit cleanup after those processes have stopped.
284282
const preparationLock = join(root, "target/agent-runtime-prepare.lock");
285283
await mkdir(dirname(preparationLock), { recursive: true });
286284
try {
@@ -291,6 +289,12 @@ try {
291289
`Runtime preparation already in progress: ${preparationLock}. Retry after it finishes. If interrupted, stop its Git/Cargo processes before removing this lock.`,
292290
);
293291
}
292+
// Ctrl-C skips `finally`; the terminal signals Git and Cargo too.
293+
for (const signal of ["SIGINT", "SIGTERM"])
294+
process.once(signal, () => {
295+
rmSync(preparationLock, { recursive: true, force: true });
296+
process.exit(1);
297+
});
294298
try {
295299
await writeFile(join(preparationLock, "owner"), `${process.pid}\n`);
296300
await prepare();

‎scripts/desktop-dev.mjs‎

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -17,59 +17,16 @@ if (
1717
}
1818
const port = values.port === undefined ? undefined : Number(values.port);
1919

20-
// Tauri's first positional argument starts implicit runner arguments too.
21-
let release = false;
22-
let runnerArgs = rest.slice(1);
23-
for (let index = 0; index < forwarded.length; index++) {
24-
const arg = forwarded[index];
25-
// Short value options may follow boolean flags, e.g. `-vr echo` or `-vf a b`.
26-
const shortValue = arg.match(/^-[vheV]*([rtcf])(.*)$/);
27-
if (arg === "--release") release = true;
28-
else if (
29-
["--runner", "--target", "--config", "--additional-watch-folders"].includes(
30-
arg,
31-
) ||
32-
(shortValue && shortValue[1] !== "f" && !shortValue[2])
33-
)
34-
index++;
35-
else if (
36-
arg === "--features" ||
37-
(shortValue?.[1] === "f" && !shortValue[2])
38-
) {
39-
while (
40-
index + 1 < forwarded.length &&
41-
!forwarded[index + 1].startsWith("-")
42-
)
43-
index++;
44-
} else if (!arg.startsWith("-")) {
45-
runnerArgs = [...forwarded.slice(index), ...rest];
46-
break;
47-
}
48-
}
49-
50-
// The first `--` starts Cargo arguments; Cargo's own `--` starts app arguments.
51-
// Explicit profiles may disable debug assertions, so use the pinned bundle for
52-
// all of them, including custom profiles whose settings this launcher cannot know.
53-
const appBoundary = runnerArgs.indexOf("--");
54-
release ||= runnerArgs
55-
.slice(0, appBoundary < 0 ? undefined : appBoundary)
56-
.some(
57-
(arg) =>
58-
arg === "--release" ||
59-
/^-[vq]*r/.test(arg) ||
60-
arg === "--profile" ||
61-
arg.startsWith("--profile="),
62-
);
63-
6420
const help = forwarded.some((arg) => arg === "--help" || arg === "-h");
6521
// Prepare resources before Tauri can compile or observe an already-running Vite.
6622
// Its dev-server readiness timeout must not include a cold runtime build.
6723
if (!help) {
6824
const prepared = spawnSync(
6925
process.execPath,
26+
// Local-only, so skip Goose's size optimizations; packaged builds keep them.
7027
[
7128
fileURLToPath(new URL("./build-agent-runtime.mjs", import.meta.url)),
72-
...(release ? [] : ["--dev"]),
29+
"--dev",
7330
],
7431
{ stdio: "inherit" },
7532
);
@@ -79,15 +36,6 @@ if (!help) {
7936
}
8037
const root = fileURLToPath(new URL("../", import.meta.url));
8138
const config = desktopOverlay(root);
82-
if (!release) {
83-
config.bundle ??= {};
84-
// Merge-patch removes the stock lean source. Both modes keep stable paths so
85-
// preparation in the other mode cannot replace resources read later by Tauri.
86-
config.bundle.resources = {
87-
"resources/agent-runtime/": null,
88-
"resources/agent-runtime-dev/": "agent-runtime/",
89-
};
90-
}
9139
// Tauri's own --port controls its static-file server, not our Vite server.
9240
// Without --port, each worktree derives its own stable port; vite.config.ts
9341
// derives the same one, so devUrl and Vite's strict port cannot disagree.

‎tests/integration/agent-runtime.test.mjs‎

Lines changed: 51 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ test("desktop dev builds Goose with the dev profile; packaged preparation keeps
123123
const spec = JSON.parse(
124124
readFileSync(path.join(directory, "runtime/agent-runtime.json"), "utf8"),
125125
);
126+
assert.notEqual(spec.gooseDevProfile, spec.goose.profile);
126127
const run = (...args) => {
127128
const result = spawnSync(
128129
process.execPath,
@@ -138,58 +139,29 @@ test("desktop dev builds Goose with the dev profile; packaged preparation keeps
138139
.trim()
139140
.split("\n")
140141
.map((line) => JSON.parse(line));
141-
const recorded = (dev = false) =>
142+
const recorded = () =>
142143
JSON.parse(
143144
readFileSync(
144-
path.join(
145-
directory,
146-
`src-tauri/resources/agent-runtime${dev ? "-dev" : ""}/manifest.json`,
147-
),
145+
path.join(directory, "src-tauri/resources/agent-runtime/manifest.json"),
148146
"utf8",
149147
),
150148
).goose;
151-
const packagedFiles = {};
152149
const sources = path.join(directory, "target/agent-runtime-src");
150+
// Packaging after desktop dev must replace the dev bundle, never accept it.
153151
for (const [args, profile] of [
154152
[[], spec.goose.profile],
155153
[["--dev"], spec.gooseDevProfile],
154+
[[], spec.goose.profile],
156155
]) {
157156
assert.match(run(...args), /Verified inputs staged/);
158-
if (args.includes("--dev"))
159-
assert.deepEqual(
160-
recorded(),
161-
spec.goose,
162-
"later packaged consumption must keep the selected lean profile",
163-
);
164-
assert.deepEqual(recorded(args.includes("--dev")), {
165-
...spec.goose,
166-
profile,
167-
});
157+
assert.deepEqual(recorded(), { ...spec.goose, profile });
168158
const gooseBuild = calls().at(-1);
169159
assert.equal(
170160
gooseBuild.args[gooseBuild.args.indexOf("--profile") + 1],
171161
profile,
172162
);
173163
assert.match(run(...args), /Agent runtime ready/);
174-
if (!args.includes("--dev")) {
175-
const packaged = path.join(
176-
directory,
177-
"src-tauri/resources/agent-runtime",
178-
);
179-
for (const name of readdirSync(packaged))
180-
packagedFiles[name] = readFileSync(path.join(packaged, name));
181-
}
182164
}
183-
// A release build consumes resources after preparation has released its lock.
184-
// Intervening dev preparation must preserve every selected packaged byte.
185-
assert.deepEqual(recorded(), spec.goose);
186-
const packaged = path.join(directory, "src-tauri/resources/agent-runtime");
187-
for (const name of readdirSync(packaged))
188-
assert.deepEqual(
189-
readFileSync(path.join(packaged, name)),
190-
packagedFiles[name],
191-
);
192-
assert.notEqual(spec.gooseDevProfile, spec.goose.profile);
193165
// Rebuilds reuse stable source checkouts, so Cargo can skip unchanged crates.
194166
assert.deepEqual(
195167
[...new Set(calls().map((call) => call.cwd))],
@@ -198,10 +170,6 @@ test("desktop dev builds Goose with the dev profile; packaged preparation keeps
198170
),
199171
);
200172
// A checkout an interrupted run left unusable is fetched again from scratch.
201-
rmSync(path.join(directory, "src-tauri/resources/agent-runtime-dev"), {
202-
recursive: true,
203-
force: true,
204-
});
205173
writeFileSync(path.join(sources, "goose/broken-checkout"), "");
206174
assert.match(run("--dev"), /Verified inputs staged/);
207175
assert.ok(!existsSync(path.join(sources, "goose/broken-checkout")));
@@ -280,7 +248,7 @@ test("overlapping preparation cannot replace another build's source checkout", a
280248
const [code] = await completed;
281249
assert.equal(code, 0, stderr);
282250
}
283-
// An abandoned lock is retained until the operator explicitly clears it.
251+
// A force-killed preparation's lock is retained until explicitly cleared.
284252
const lock = path.join(directory, "target/agent-runtime-prepare.lock");
285253
mkdirSync(lock);
286254
const abandoned = spawnSync(
@@ -323,6 +291,50 @@ test("overlapping preparation cannot replace another build's source checkout", a
323291
);
324292
});
325293

294+
test("interrupting preparation releases its lock", {
295+
skip: process.platform === "win32" && "POSIX process-group signal",
296+
}, async (t) => {
297+
const directory = mkdtempSync(path.join(tmpdir(), "buzz-agent-runtime-"));
298+
t.after(() => rmSync(directory, { recursive: true, force: true }));
299+
runtimeFixture(directory);
300+
const server = createServer();
301+
const started = once(server, "connection");
302+
server.listen(0, "127.0.0.1");
303+
await once(server, "listening");
304+
t.after(() => server.close());
305+
writeFileSync(
306+
path.join(directory, "hold-build"),
307+
String(server.address().port),
308+
);
309+
// Its own process group, like a terminal's foreground job.
310+
const child = spawn(
311+
process.execPath,
312+
["scripts/build-agent-runtime.mjs", "--dev"],
313+
{ cwd: directory, stdio: "ignore", detached: true },
314+
);
315+
const completed = once(child, "close");
316+
const [socket] = await Promise.race([
317+
started,
318+
completed.then(([code]) => {
319+
throw new Error(`Preparation exited before the compiler (${code})`);
320+
}),
321+
]);
322+
const lock = path.join(directory, "target/agent-runtime-prepare.lock");
323+
assert.ok(existsSync(lock));
324+
const compilerStopped = once(socket, "close");
325+
// Ctrl-C signals the whole foreground process group, compiler included.
326+
process.kill(-child.pid, "SIGINT");
327+
const [[code]] = await Promise.all([completed, compilerStopped]);
328+
assert.notEqual(code, 0);
329+
assert.ok(!existsSync(lock));
330+
const next = spawnSync(
331+
process.execPath,
332+
["scripts/build-agent-runtime.mjs", "--dev"],
333+
{ cwd: directory, encoding: "utf8", timeout: 10_000 },
334+
);
335+
assert.equal(next.status, 0, next.stderr);
336+
});
337+
326338
test("runtime output ignores a user-level build target and survives an interrupted build", (t) => {
327339
const directory = mkdtempSync(path.join(tmpdir(), "buzz-agent-runtime-"));
328340
t.after(() => rmSync(directory, { recursive: true, force: true }));

0 commit comments

Comments
 (0)