Skip to content

Commit 1a7c445

Browse files
fix(opencode): a failed shell check keeps the shell, not the reconnect
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 94e070a commit 1a7c445

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

‎apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,29 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
10111011
}).pipe(Effect.scoped),
10121012
);
10131013

1014+
it.effect("keeps a background shell tracked when its check fails after a reconnect", () =>
1015+
Effect.gen(function* () {
1016+
const { runtime, thread } = yield* resumed([
1017+
...backgroundShell("sh_1"),
1018+
event("session.execution.succeeded", { sessionID: SESSION }),
1019+
{ type: "runtime_exit", status: "success" } as const,
1020+
out("event.subscribe"),
1021+
out("session.active"),
1022+
replyData("session.active", {}),
1023+
out("shell.get", { id: "sh_1", "location[directory]": WORK }),
1024+
reply("shell.get", { status: 500, body: { name: "UnknownError", data: {} } }),
1025+
drained,
1026+
]);
1027+
const watch = yield* watchCalls(runtime, thread);
1028+
yield* runtime.startTurn(turnInput(thread));
1029+
yield* watch.until(() => watch.state.variant === "drained");
1030+
assert.deepEqual(watch.state.roster, [
1031+
{ taskId: "sh_1", kind: "command", description: SHELL_COMMAND },
1032+
]);
1033+
assert.isTrue(watch.state.pending);
1034+
}).pipe(Effect.scoped),
1035+
);
1036+
10141037
it.effect("clears a background shell from the roster when the stream cannot reconnect", () =>
10151038
Effect.gen(function* () {
10161039
const { runtime, thread } = yield* resumed([

‎apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.testkit.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ const operationOf = (
8282
if (method === "DELETE" && shell !== null) {
8383
return { type: "shell.remove", input: { id: decodeURIComponent(shell[1] ?? ""), ...query } };
8484
}
85+
if (method === "GET" && shell !== null) {
86+
return { type: "shell.get", input: { id: decodeURIComponent(shell[1] ?? ""), ...query } };
87+
}
8588
if (session !== null) {
8689
const [, sessionID, rest = ""] = session;
8790
// The client sends absent optional fields as `null`; recordings omit them.

‎packages/provider-opencode/src/server/v2/adapter.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2757,6 +2757,13 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
27572757
ShellNotFoundError: () => Effect.succeed(false),
27582758
LocationNotFoundError: () => Effect.succeed(false),
27592759
}),
2760+
Effect.timeout(ACTIVE_CHECK_TIMEOUT),
2761+
// Only prunes stale shells, so a failed check keeps the shell rather than the stream.
2762+
Effect.catch((cause) =>
2763+
Effect.logWarning("Could not check an OpenCode background shell.", { cause }).pipe(
2764+
Effect.as(true),
2765+
),
2766+
),
27602767
);
27612768
if (!running) state.shells.delete(id);
27622769
}

0 commit comments

Comments
 (0)