Skip to content

Commit eff4566

Browse files
fix(opencode): long command turns no longer fail when the command request times out (pingdotgg#27677)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 577c524 commit eff4566

2 files changed

Lines changed: 82 additions & 0 deletions

File tree

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

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,6 +1509,86 @@ describe("OpenCodeAdapterV2", () => {
15091509
),
15101510
);
15111511

1512+
it.effect("keeps an admitted native command running when its HTTP request times out", () =>
1513+
Effect.gen(function* () {
1514+
const nativeEvents = asyncEventStream();
1515+
const commandCalled = promiseGate<string>();
1516+
let rejectCommand!: (cause: unknown) => void;
1517+
const commandResponse = new Promise<never>((_, reject) => {
1518+
rejectCommand = reject;
1519+
});
1520+
const sessionId = "native-command-timeout";
1521+
const harness = yield* makeOpenCodeRuntimeHarness("native-command-timeout", sessionId, {
1522+
event: {
1523+
subscribe: async (_input: unknown, options: { signal?: AbortSignal }) => {
1524+
options.signal?.addEventListener("abort", () => nativeEvents.close(), { once: true });
1525+
return { stream: nativeEvents.stream };
1526+
},
1527+
},
1528+
command: { list: async () => ({ data: [{ name: "review" }] }) },
1529+
session: {
1530+
create: async () => ({ data: { id: sessionId, time: { created: 1, updated: 1 } } }),
1531+
command: (input: { messageID: string }) => {
1532+
commandCalled.resolve(input.messageID);
1533+
return commandResponse;
1534+
},
1535+
},
1536+
});
1537+
const start = yield* harness.startTurn("/review staged changes").pipe(Effect.forkScoped);
1538+
const messageID = yield* Effect.promise(() => commandCalled.promise);
1539+
yield* Effect.promise(() =>
1540+
nativeEvents.push({
1541+
type: "message.updated",
1542+
properties: {
1543+
sessionID: sessionId,
1544+
info: {
1545+
id: messageID,
1546+
sessionID: sessionId,
1547+
role: "user",
1548+
time: { created: DateTime.toEpochMillis(harness.now) },
1549+
},
1550+
},
1551+
}),
1552+
);
1553+
yield* Fiber.join(start);
1554+
const terminal = yield* harness.runtime.events.pipe(
1555+
Stream.filter((event) => event.type === "turn.terminal"),
1556+
Stream.take(1),
1557+
Stream.runCollect,
1558+
Effect.forkScoped,
1559+
);
1560+
1561+
// Node's fetch gives up on a command still running in OpenCode after 300 s.
1562+
rejectCommand(
1563+
new TypeError("fetch failed", {
1564+
cause: Object.assign(new Error("Headers Timeout Error"), {
1565+
name: "HeadersTimeoutError",
1566+
code: "UND_ERR_HEADERS_TIMEOUT",
1567+
}),
1568+
}),
1569+
);
1570+
yield* Effect.promise(() =>
1571+
nativeEvents.push({
1572+
type: "session.status",
1573+
properties: { sessionID: sessionId, status: { type: "busy" } },
1574+
}),
1575+
);
1576+
yield* Effect.promise(() =>
1577+
nativeEvents.push({ type: "session.idle", properties: { sessionID: sessionId } }),
1578+
);
1579+
1580+
const [event] = yield* Fiber.join(terminal);
1581+
assert.equal(
1582+
event?.type === "turn.terminal" ? event.status : undefined,
1583+
"completed",
1584+
"a command admitted by its user receipt must not fail when its HTTP request times out",
1585+
);
1586+
}).pipe(
1587+
Effect.provide(Layer.merge(IdAllocator.layer, McpProviderSessions.layer)),
1588+
Effect.scoped,
1589+
),
1590+
);
1591+
15121592
it.effect("compacts with the native summarize API and emits a completed compaction", () =>
15131593
Effect.gen(function* () {
15141594
const nativeEvents = asyncEventStream();

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3026,7 +3026,9 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
30263026
}),
30273027
).pipe(
30283028
Effect.asVoid,
3029+
// OpenCode answers only when generation ends; once admitted, the event stream owns the outcome.
30293030
Effect.tapError((cause) =>
3031+
Deferred.isDoneUnsafe(receipt) ||
30303032
abortController.signal.aborted ||
30313033
turn.finalized ||
30323034
turn.admissionGeneration !== generation

0 commit comments

Comments
 (0)