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 21, 09:45 UTC
fix(opencode): unanswered stop now offers Force stop (#31021)
Julius Marminge committed
Nov 16, 2026 at 17:34 UTC
6fa874e98ebc39715775b1223fa9a77166bdef4b
2 files changed
+83
-10
packages/provider-opencode/src/server/adapter.test.ts
+56
@@ -4509,6 +4509,62 @@ describe("OpenCodeAdapterV2", () => {
4509
}).pipe(Effect.provide(Layer.merge(IdAllocator.layer, McpProviderSessions.layer))),
4510
);
4511
4512
+ it.effect("reports an unanswered session abort as an interrupt timeout", () =>
4513
+ Effect.gen(function* () {
4514
+ const events = asyncEventStream();
4515
+ const abortCalled = promiseGate<void>();
4516
+ let abortCalls = 0;
4517
+ const harness = yield* makeOpenCodeRuntimeHarness("abort-timeout", "root", {
4518
+ event: {
4519
+ subscribe: async (_input: unknown, options: { signal?: AbortSignal }) => {
4520
+ options.signal?.addEventListener("abort", () => events.close(), { once: true });
4521
+ return { stream: events.stream };
4522
+ },
4523
+ },
4524
+ session: {
4525
+ create: async () => ({ data: { id: "root", time: { created: 1, updated: 1 } } }),
4526
+ get: async () => ({ data: { id: "root", time: { created: 1, updated: 1 } } }),
4527
+ promptAsync: async () => ({ data: true }),
4528
+ status: async () => ({ data: { root: { type: "busy" } } }),
4529
+ messages: async () => ({ data: [] }),
4530
+ children: async () => ({ data: [] }),
4531
+ abort: async (_input: unknown, options?: { readonly signal?: AbortSignal }) => {
4532
+ // Only the Stop request hangs; session teardown still gets an answer.
4533
+ if (++abortCalls > 1) return { data: true };
4534
+ abortCalled.resolve();
4535
+ await new Promise<void>((_resolve, reject) =>
4536
+ options?.signal?.addEventListener("abort", () => reject(options.signal!.reason), {
4537
+ once: true,
4538
+ }),
4539
+ );
4540
+ return { data: true };
4541
+ },
4542
+ },
4543
+ mcp: { add: async () => ({ data: true }) },
4544
+ });
4545
+ yield* harness.startTurn();
4546
+ const snapshot = yield* harness.runtime.readThreadSnapshot({
4547
+ providerThread: harness.providerThread,
4548
+ });
4549
+ const turn = snapshot.providerTurns.at(-1)!;
4550
+ const interrupt = yield* harness.runtime
4551
+ .interruptTurn({ providerThread: harness.providerThread, providerTurnId: turn.id })
4552
+ .pipe(Effect.flip, Effect.forkScoped);
4553
+ yield* Effect.promise(() => abortCalled.promise);
4554
+ yield* TestClock.adjust("10 seconds");
4555
+
4556
+ const error = yield* Fiber.join(interrupt);
4557
+ assert.strictEqual(error._tag, "ProviderAdapterInterruptTimeoutError");
4558
+ assert.deepInclude(error, {
4559
+ providerThreadId: harness.providerThread.id,
4560
+ providerTurnId: turn.id,
4561
+ });
4562
+ }).pipe(
4563
+ Effect.provide(Layer.merge(IdAllocator.layer, McpProviderSessions.layer)),
4564
+ Effect.scoped,
4565
+ ),
4566
+ );
4567
+
4568
it.effect("fails an active turn when the OpenCode event stream ends cleanly", () =>
4569
Effect.gen(function* () {
4570
const nativeEvents = asyncEventStream();
packages/provider-opencode/src/server/adapter.ts
+27
-10
@@ -88,6 +88,7 @@ export const OPENCODE_PROVIDER = ProviderDriverKind.make("opencode");
88
export const OPENCODE_DEFAULT_INSTANCE_ID = defaultInstanceIdForDriver(OPENCODE_PROVIDER);
89
export const OPENCODE_SDK_PROTOCOL = "opencode-sdk.sse" as const;
90
const DEFAULT_OPENCODE_SETTINGS = Schema.decodeSync(OpenCodeSettings)({});
91
+const OPENCODE_STOP_CONFIRM_TIMEOUT_MS = 10_000;
92
93
const makeOpenCodeMessageId = Effect.fnUntraced(function* (
94
clock: Ref.Ref<{ readonly epochMillis: number; readonly counter: number }>,
@@ -2790,7 +2791,11 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
2791
// Native aborts target the whole session, so replacement admission waits for all cleanup.
2792
const cleanupSessionWork = Effect.fn("OpencodeAdapter.cleanupSessionWork")(function* (
2793
state: OpenCodeThreadState,
2793
- rootAbort: Effect.Effect<unknown, Effect.Error<ReturnType<typeof abortRootSession>>>,
2794
+ rootAbort: Effect.Effect<
2795
+ unknown,
2796
+ | Effect.Error<ReturnType<typeof abortRootSession>>
2797
+ | ProviderAdapter.ProviderAdapterInterruptTimeoutError
2798
+ >,
2799
) {
2800
const root = yield* rootAbort.pipe(Effect.result);
2801
const descendants = yield* abortDescendants(state.nativeSessionId).pipe(Effect.result);
@@ -4160,7 +4165,18 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
4165
sdkCall("session.abort", { sessionID: sessionId }, (signal) =>
4166
client.session.abort({ sessionID: sessionId }, { signal }),
4167
).pipe(
4163
- Effect.timeout("10 seconds"),
4168
+ Effect.timeoutOrElse({
4169
+ duration: OPENCODE_STOP_CONFIRM_TIMEOUT_MS,
4170
+ orElse: () =>
4171
+ Effect.fail(
4172
+ new ProviderAdapter.ProviderAdapterInterruptTimeoutError({
4173
+ driver: OPENCODE_PROVIDER,
4174
+ providerThreadId: interruptInput.providerThread.id,
4175
+ providerTurnId: interruptInput.providerTurnId,
4176
+ timeoutMs: OPENCODE_STOP_CONFIRM_TIMEOUT_MS,
4177
+ }),
4178
+ ),
4179
+ }),
4180
Effect.catch((cause) =>
4181
turn.finalized
4182
? Effect.void
@@ -4176,14 +4192,15 @@ export const makeOpenCodeAdapterV2 = Effect.fn("makeOpenCodeAdapterV2")(function
4192
},
4193
(effect, interruptInput) =>
4194
effect.pipe(
4179
- Effect.mapError(
4180
- (cause) =>
4181
- new ProviderAdapter.ProviderAdapterInterruptError({
4182
- driver: OPENCODE_PROVIDER,
4183
- providerThreadId: interruptInput.providerThread.id,
4184
- providerTurnId: interruptInput.providerTurnId,
4185
- cause,
4186
- }),
4195
+ Effect.mapError((cause) =>
4196
+ cause._tag === "ProviderAdapterInterruptTimeoutError"
4197
+ ? cause
4198
+ : new ProviderAdapter.ProviderAdapterInterruptError({
4199
+ driver: OPENCODE_PROVIDER,
4200
+ providerThreadId: interruptInput.providerThread.id,
4201
+ providerTurnId: interruptInput.providerTurnId,
4202
+ cause,
4203
+ }),
4204
),
4205
),
4206
),