The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 00:45 UTC
fix(opencode): long command turns no longer fail when the command request times out (#27677)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Nov 9, 2026 at 23:56 UTC
eff45664fae739f0efadaee13acc145ddf0d0b66
2 files changed
+82
packages/provider-opencode/src/server/adapter.test.ts
+80
@@ -1509,6 +1509,86 @@ describe("OpenCodeAdapterV2", () => {
1509
),
1510
);
1511
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
+
1592
it.effect("compacts with the native summarize API and emits a completed compaction", () =>
1593
Effect.gen(function* () {
1594
const nativeEvents = asyncEventStream();
packages/provider-opencode/src/server/adapter.ts
+2
@@ -3026,7 +3026,9 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
3026
}),
3027
).pipe(
3028
Effect.asVoid,
3029
+ // OpenCode answers only when generation ends; once admitted, the event stream owns the outcome.
3030
Effect.tapError((cause) =>
3031
+ Deferred.isDoneUnsafe(receipt) ||
3032
abortController.signal.aborted ||
3033
turn.finalized ||
3034
turn.admissionGeneration !== generation