Skip to content

Commit c643018

Browse files
fix(opencode): a failed background subagent no longer pins its thread
An OpenCode background subagent whose own turn failed never reported back to its parent, so the adapter kept the call live forever: the thread kept showing "1 agent working in the background" and a Stop could not clear it, because the roster is only emptied by the adapter that owns the call. Settle a background call with the failure when the child's turn ends, so the provider thread's roster drops it and the thread stops showing an agent that is gone. Autonomously generated by opencode/minimax-m3.1-flash-free through the OpenCode harness in T3 Code.
1 parent a71a6c3 commit c643018

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,28 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
10921092
event("session.execution.started", { sessionID: CHILD }),
10931093
];
10941094

1095+
it.effect("settles a background subagent that fails, so no work is left pending", () =>
1096+
Effect.gen(function* () {
1097+
const { runtime, thread } = yield* resumed([
1098+
...launchedAndRunning,
1099+
// The parent turn ends, and the background child fails: it reports
1100+
// nothing back, so its call has to end with the failure.
1101+
event("session.execution.succeeded", { sessionID: SESSION }),
1102+
event("session.execution.failed", {
1103+
sessionID: CHILD,
1104+
error: { type: "provider.quota", message: "Rate limit exceeded." },
1105+
}),
1106+
]);
1107+
const watch = yield* watchCalls(runtime, thread);
1108+
yield* runtime.startTurn(withLineage(thread));
1109+
yield* watch.until(
1110+
() => watch.calls.get("Sleep")?.status === "failed" && watch.state.roster?.length === 0,
1111+
);
1112+
assert.deepEqual(watch.state.roster, []);
1113+
assert.isFalse(yield* runtime.hasPendingBackgroundWorkForThread!(thread));
1114+
}).pipe(Effect.scoped),
1115+
);
1116+
10951117
it.effect("settles every call that joined a running subagent with its one report", () =>
10961118
Effect.gen(function* () {
10971119
const { runtime, thread } = yield* resumed([

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,11 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
15561556
const call = state.subagent.call;
15571557
if (!call.background && terminal.status !== "completed") {
15581558
yield* settleCall(call, terminal.status);
1559+
} else if (call.background && terminal.status === "failed") {
1560+
// A background call is settled by the report its parent reads, and a
1561+
// child that failed has no report to read: the call would stay live
1562+
// forever and the thread would keep showing an agent that is gone.
1563+
yield* settleCall(call, terminal.status, terminal.failure.message);
15591564
}
15601565
return;
15611566
}

0 commit comments

Comments
 (0)