@devries-cameron20 / t3code-1 / commits / 28b4ceeeff
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(opencode): a Stop OpenCode 2 never answers offers Force stop (#34840)

Julius Marminge committed Nov 11, 2026 at 23:32 UTC 28b4ceeeffe9069fc7c2496b0e568778050a499a
2 files changed +66 -27
apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
+57 -24
@@ -2202,7 +2202,7 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
2202 .interruptTurn({ providerThread: thread, providerTurnId: yield* providerTurnId })
2203 .pipe(Effect.forkScoped);
2204 yield* TestClock.adjust("11 seconds");
2205 - yield* Fiber.join(interrupt);
2205 + yield* Fiber.join(interrupt).pipe(Effect.flip);
2206 });
2207 const terminals = (runtime: ProviderAdapter.ProviderAdapterV2SessionRuntime, count: number) =>
2208 runtime.events.pipe(
@@ -2217,23 +2217,57 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
2217 Effect.forkScoped,
2218 );
2219
2220 + // regression: #30193 an unanswered Stop showed the turn interrupted while its tool kept running
2221 + it.effect("reports a Stop OpenCode never answers as an interrupt timeout", () =>
2222 + Effect.gen(function* () {
2223 + const { runtime, thread } = yield* resumed(stopTimedOut);
2224 + yield* runtime.startTurn(turnInput(thread));
2225 + const interrupt = yield* runtime
2226 + .interruptTurn({ providerThread: thread, providerTurnId: yield* providerTurnId })
2227 + .pipe(Effect.exit, Effect.forkScoped);
2228 + yield* TestClock.adjust("11 seconds");
2229 + const exit = yield* Fiber.join(interrupt);
2230 + assert.propertyVal(
2231 + Exit.isFailure(exit) ? Cause.squash(exit.cause) : { _tag: "interrupt succeeded" },
2232 + "_tag",
2233 + "ProviderAdapterInterruptTimeoutError",
2234 + );
2235 + }).pipe(Effect.scoped, Effect.provide(TestClock.layer())),
2236 + );
2237 +
2238 it.effect("never lets a timed-out Stop's late end finish the next turn", () =>
2239 Effect.gen(function* () {
2222 - const { runtime, thread } = yield* resumed([
2223 - ...stopTimedOut,
2224 - out("session.active"),
2225 - reply("session.active", { data: {} }),
2226 - out("session.prompt", { sessionID: SESSION, text: "<any>" }),
2227 - promptAccepted,
2228 - event("session.execution.succeeded", { sessionID: SESSION }),
2229 - event("session.execution.started", { sessionID: SESSION }),
2230 - event("session.execution.failed", {
2231 - sessionID: SESSION,
2232 - error: { type: "provider", message: "second turn failed" },
2233 - }),
2234 - ]);
2235 - const ended = yield* terminals(runtime, 2);
2240 + const gate = makeProviderReplayGate(["late-end"]);
2241 + const { runtime, thread } = yield* resumed(
2242 + [
2243 + ...stopTimedOut,
2244 + event("session.execution.succeeded", { sessionID: SESSION }, "late-end"),
2245 + out("session.prompt", { sessionID: SESSION, text: "<any>" }),
2246 + promptAccepted,
2247 + event("session.execution.started", { sessionID: SESSION }),
2248 + event("session.execution.failed", {
2249 + sessionID: SESSION,
2250 + error: { type: "provider", message: "second turn failed" },
2251 + }),
2252 + ],
2253 + { replayGate: gate },
2254 + );
2255 + const lateEnd = yield* Deferred.make<void>();
2256 + const ended = yield* runtime.events.pipe(
2257 + Stream.filter(
2258 + (
2259 + event,
2260 + ): event is Extract<ProviderAdapter.ProviderAdapterV2Event, { type: "turn.terminal" }> =>
2261 + event.type === "turn.terminal",
2262 + ),
2263 + Stream.tap(() => Deferred.succeed(lateEnd, undefined)),
2264 + Stream.take(2),
2265 + Stream.runCollect,
2266 + Effect.forkScoped,
2267 + );
2268 yield* stopFirstTurn(runtime, thread);
2269 + gate.release("late-end");
2270 + yield* Deferred.await(lateEnd);
2271 yield* runtime.startTurn(secondTurn(thread));
2272 const [first, second] = yield* Fiber.join(ended);
2273 assert.equal(first?.status, "interrupted");
@@ -2305,8 +2339,6 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
2339 ...backgroundLaunch(CHILD),
2340 out("session.interrupt", { sessionID: SESSION }),
2341 reply("session.interrupt", "<hang>"),
2308 - out("session.active"),
2309 - replyData("session.active", { [SESSION]: { type: "running" } }),
2342 out("session.interrupt", { sessionID: SESSION }),
2343 reply("session.interrupt", { interrupted: true }),
2344 event("session.usage.updated", { sessionID: SESSION }, "drop"),
@@ -2314,6 +2346,8 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
2346 out("event.subscribe"),
2347 out("session.active"),
2348 replyData("session.active", { [CHILD]: { type: "running" } }),
2349 + out("message.list", "<any>"),
2350 + reply("message.list", { data: [], cursor: {} }),
2351 out("permission.list", { sessionID: CHILD }),
2352 replyData("permission.list", []),
2353 out("session.form.list", { sessionID: CHILD }),
@@ -2375,23 +2409,22 @@ it.layer(McpProviderSessions.layer)("OpenCode2 adapter", (it) => {
2409 );
2410 yield* runtime.startTurn(withLineage(thread));
2411 yield* Deferred.await(attached);
2378 - const interrupt = yield* runtime
2379 - .interruptTurn({ providerThread: thread, providerTurnId: yield* providerTurnId })
2380 - .pipe(Effect.forkScoped);
2412 + const stop = { providerThread: thread, providerTurnId: yield* providerTurnId };
2413 + const interrupt = yield* runtime.interruptTurn(stop).pipe(Effect.flip, Effect.forkScoped);
2414 yield* TestClock.adjust("11 seconds");
2415 yield* Fiber.join(interrupt);
2383 - yield* runtime.startTurn({ ...secondTurn(thread), appThread: withLineage(thread).appThread });
2416 + yield* runtime.interruptTurn(stop);
2417 gate.release("drop");
2418 yield* runtime.startTurn({
2419 ...continuationTurn(thread, yield* Deferred.await(offered)),
2387 - runOrdinal: 3,
2388 - providerTurnOrdinal: 3,
2420 + runOrdinal: 2,
2421 + providerTurnOrdinal: 2,
2422 });
2423 gate.release("reply");
2424 const events = [...(yield* Fiber.join(collected))];
2425 assert.deepEqual(
2426 events.flatMap((event) => (event.type === "turn.terminal" ? [event.status] : [])),
2394 - ["interrupted", "failed", "completed"],
2427 + ["interrupted", "completed"],
2428 );
2429 assert.include(
2430 events.flatMap((event) =>
packages/provider-opencode/src/server/v2/adapter.ts
+9 -3
@@ -583,7 +583,7 @@ const claudeUsageLimit = (message: string | undefined) =>
583 ? { resetAt: /\bResets at (\d{4}-\d\d-\d\dT[\d:.]+Z)\.?\s*$/.exec(message)?.[1] ?? null }
584 : undefined;
585
586 -const INTERRUPT_TIMEOUT = "10 seconds";
586 +const INTERRUPT_TIMEOUT = 10_000;
587 const INSTRUCTIONS_KEY = "t3-code";
588 const RECONNECT_ATTEMPTS = 5;
589 const RECONNECT_DELAY = "2 seconds";
@@ -4815,8 +4815,14 @@ export const make = Effect.fn("OpenCode2Adapter.make")(function* (instanceId: Pr
4815 ),
4816 );
4817 if (reply._tag === "None") {
4818 - markUnsettled(state);
4819 - return yield* lock.withPermit(finishTurn(state, { status: "interrupted" }));
4818 + if (state.active !== turn) return;
4819 + // The turn stays open: its tools may still run, and the user decides whether to Force stop.
4820 + return yield* new ProviderAdapter.ProviderAdapterInterruptTimeoutError({
4821 + driver: OPENCODE_PROVIDER,
4822 + providerThreadId: interruptInput.providerThread.id,
4823 + providerTurnId: interruptInput.providerTurnId,
4824 + timeoutMs: INTERRUPT_TIMEOUT,
4825 + });
4826 }
4827 // Stop between steer executions retracts pending steers and skips any run they already started.
4828 if (!reply.value.interrupted && state.active === turn && turn.heldEnd !== undefined) {