GeezerVison is showing github.com — fix(evals): apply earlier launcher commands before routing an open · pingdotgg/t3code@a7f42df
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: evals/mcp-tool-use/devices.test.ts +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -854,6 +854,13 @@ it.effect( | 854 | 854 | ); | 855 | 855 | // An open in the other thread's own session is not refused, and gets no route. | 856 | 856 | assert.notInclude(told(commandLine(held, "open com.acme.app", owner)), "In the new call"); | | 857 | + // An open after the same call closes the other thread's session finds the device free. | | 858 | + const reopen = told(`${commandLine(held, "close", owner)}; ${piped}`); | | 859 | + assert.include( | | 860 | + reopen, | | 861 | + `\`${piped}\` drives Acme iPhone, ${IPHONE}, on build-mac, which no other session holds: it prints no DEVICE_IN_USE`, | | 862 | + ); | | 863 | + assert.notInclude(reopen, `which session ${owner} holds`); | 857 | 864 | // Neither do commands other than open. | 858 | 865 | assert.notInclude( | 859 | 866 | told(`${commandLine(spare, "screenshot /tmp/a.png")} && echo ok`), | |
Collapse file Copy file name to clipboardExpand all lines: evals/mcp-tool-use/devices.ts +16-12Lines changed: 16 additions & 12 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -366,25 +366,34 @@ export const agentDeviceSessions = ( | 366 | 366 |
| 367 | 367 | /** | 368 | 368 | * Each launcher `open` a new call makes, read as the tracker reads calls, with the other thread's | 369 | | - * session that holds its device. agent-device refuses an open that has one with DEVICE_IN_USE. | | 369 | + * session that holds its device and whether another session holds it at all. agent-device refuses | | 370 | + * an open that has a holder with DEVICE_IN_USE. Each launcher command runs in order, so an earlier | | 371 | + * `close --session <owner>` in the same call frees the device for a later open. | 370 | 372 | */ | 371 | 373 | const opensIn = ( | 372 | 374 | targets: ReadonlyArray<LauncherTarget>, | 373 | 375 | { sessions, variables }: ReturnType<typeof followSessions>, | 374 | 376 | command: string, | 375 | 377 | owners: ReadonlyArray<AgentDeviceOwner>, | 376 | | -) => | 377 | | - shellInvocations( | | 378 | +) => { | | 379 | + const current = new Map(sessions); | | 380 | + return shellInvocations( | 378 | 381 | withAliases(command, launcherAliases(command, targets)), | 379 | 382 | new Map(variables), | 380 | 383 | false, | 381 | 384 | true, | 382 | 385 | ).flatMap((action) => { | 383 | 386 | const call = action.remote ? undefined : launcherCall(targets, action.words); | 384 | | - return call?.command === "open" && call.tracked !== undefined | 385 | | - ? [{ call, words: action.words, owner: holder(call, call.tracked, sessions, owners) }] | 386 | | - : []; | | 387 | + if (call?.tracked === undefined) return []; | | 388 | + const owner = holder(call, call.tracked, current, owners); | | 389 | + const held = owners.some( | | 390 | + (candidate) => | | 391 | + candidate.deviceId === call.deviceId && current.get(candidate.session) !== undefined, | | 392 | + ); | | 393 | + if (owner === undefined) current.set(call.tracked, afterCall(call, current.get(call.tracked))); | | 394 | + return call.command === "open" ? [{ call, words: action.words, owner, held }] : []; | 387 | 395 | }); | | 396 | +}; | 388 | 397 |
| 389 | 398 | /** | 390 | 399 | * What the shell simulator is told of the sessions the launchers name, and other threads', with | @@ -891,18 +900,13 @@ export const makeDeviceTools = Effect.fn("evaluateMcpToolUse.makeDeviceTools")(f | 891 | 900 | const opens = | 892 | 901 | command === undefined || owners.length === 0 | 893 | 902 | ? [] | 894 | | - : opensIn(targets, followed, command, owners).flatMap(({ call, words, owner }) => { | | 903 | + : opensIn(targets, followed, command, owners).flatMap(({ call, words, owner, held }) => { | 895 | 904 | const opened = `\`${words.join(" ")}\` drives ${deviceName(call.deviceId)}`; | 896 | 905 | const error = owner && inUseError(call, owner); | 897 | 906 | if (owner !== undefined && error !== undefined) | 898 | 907 | return [ | 899 | 908 | `${opened}, which session ${owner.session} holds: it fails with exit code 1, printing "Error (${error.code}): ${error.message}" and "Hint: ${error.hint}"`, | 900 | 909 | ]; | 901 | | - const held = owners.some( | 902 | | - (candidate) => | 903 | | - candidate.deviceId === call.deviceId && | 904 | | - followed.sessions.get(candidate.session) !== undefined, | 905 | | - ); | 906 | 910 | return held | 907 | 911 | ? [] | 908 | 912 | : [`${opened}, which no other session holds: it prints no DEVICE_IN_USE`]; | |
|