Skip to content

Commit 697f17f

Browse files
fix(server): flow claim check reads the selector agent-device uses
agent-device keeps the last of a repeated flag, but the launcher read the first, so `batch --serial x --serial <held>` passed the claim check and ran on the held device. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 3c221f5 commit 697f17f

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎apps/server/src/device/AgentDeviceShim.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,8 @@ if (!existsSync(entry)) {
239239
console.error(${JSON.stringify(STALE_RUNTIME)});
240240
process.exit(1);
241241
}
242-
const valueOf = flag => { const inline = options.find(arg => arg.startsWith(flag + "=")); if (inline) return inline.slice(flag.length + 1); const index = options.indexOf(flag); return index >= 0 ? options[index + 1] : undefined; };
242+
// agent-device keeps the last of a repeated flag.
243+
const valueOf = flag => { let value; for (let index = 0; index < options.length; index++) { if (options[index].startsWith(flag + "=")) value = options[index].slice(flag.length + 1); else if (options[index] === flag) value = options[++index]; } return value; };
243244
const endpoint = () => { try { const url = new URL(valueOf("--daemon-base-url") ?? JSON.parse(readFileSync(valueOf("--config"), "utf8")).daemonBaseUrl); return ["127.0.0.1", "localhost", "[::1]"].includes(url.hostname) && url.port ? url : undefined; } catch { return undefined; } };
244245
const local = informational || refused.has(name) ? undefined : endpoint();
245246
if (local) {

‎apps/server/src/device/AgentDeviceTarget.test.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,13 @@ exec '${process.execPath.replaceAll("'", "'\"'\"'")}' "$@"
372372
yield* Effect.promise(() => launch(flow, { T3_TEST_SESSIONS: held("t3-b") })),
373373
).toEqual([...flow, ...selected]);
374374
}
375+
// agent-device runs on the last of a repeated selector, so that is the one checked.
376+
const repeated = ["batch", "--serial", "unused", "--serial", "emulator-5554"];
377+
yield* Effect.promise(() =>
378+
expect(launch(repeated, { T3_TEST_SESSIONS: held("t3-a") })).rejects.toThrow(
379+
"Error (DEVICE_IN_USE)",
380+
),
381+
);
375382
// A flow sent to another daemon is checked against that daemon's sessions.
376383
const elsewhere = ["batch", "--steps-file", "/s.json", "--daemon-base-url", "http://b:1"];
377384
expect(

0 commit comments

Comments
 (0)