@devries-cameron20 / t3code-1 / commits / 7195b69954
Fork 0

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

fix(server): stopping a Claude turn no longer hangs without an acknowledgement (#16419)

Co-authored-by: Codex (gpt-6.1-sol) <noreply@openai.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

yaacovcorcos committed Nov 1, 2026 at 07:31 UTC 7195b699547b538e49f758e314dde5c8c5d907cf
2 files changed +121 -1
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
+120
@@ -8722,6 +8722,126 @@ describe("ClaudeAdapterV2 background wake turns", () => {
8722 ),
8723 );
8724
8725 + it.effect("lets the native SDK acknowledge Stop before closing its own query", () =>
8726 + Effect.scoped(
8727 + Effect.gen(function* () {
8728 + let closes = 0;
8729 + let acknowledge = Effect.void;
8730 + const harness = yield* makeWakeHarnessWithOptions({
8731 + interrupt: Effect.suspend(() => {
8732 + assert.equal(closes, 0);
8733 + return acknowledge;
8734 + }),
8735 + close: (messages) =>
8736 + Effect.sync(() => {
8737 + closes++;
8738 + }).pipe(Effect.andThen(Queue.shutdown(messages))),
8739 + });
8740 + yield* harness.runtime.startTurn(
8741 + makeClaudeTestTurnInput({
8742 + threadId: harness.threadId,
8743 + providerThread: harness.providerThread,
8744 + now: yield* DateTime.now,
8745 + attemptId: RunAttemptId.make("graceful-stop"),
8746 + text: "Work until stopped",
8747 + attachments: [],
8748 + }),
8749 + );
8750 + acknowledge = harness.offerAndWait(
8751 + makeResultFrame({
8752 + uuid: "00000000-0000-4000-8000-000000000620",
8753 + result: "",
8754 + subtype: "error_during_execution",
8755 + errors: ["Error: Request was aborted."],
8756 + terminalReason: "aborted_streaming",
8757 + }),
8758 + );
8759 + yield* harness.until(() =>
8760 + harness.events.some(
8761 + (event) =>
8762 + event.type === "provider_turn.updated" && event.providerTurn.status === "running",
8763 + ),
8764 + );
8765 + const active = harness.events.find(
8766 + (event) =>
8767 + event.type === "provider_turn.updated" && event.providerTurn.status === "running",
8768 + );
8769 + if (active?.type !== "provider_turn.updated")
8770 + return yield* Effect.die("Missing running native turn");
8771 + yield* harness.runtime.interruptTurn({
8772 + providerThread: harness.providerThread,
8773 + providerTurnId: active.providerTurn.id,
8774 + requestRuntimeRestart: true,
8775 + });
8776 + assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "interrupted");
8777 + assert.equal(closes, 1);
8778 + assert.lengthOf(harness.terminalEvents(), 1);
8779 + }).pipe(
8780 + Effect.provide(
8781 + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
8782 + ),
8783 + ),
8784 + ),
8785 + );
8786 +
8787 + it.effect("bounds an unacknowledged native Stop and settles its turn once", () =>
8788 + Effect.scoped(
8789 + Effect.gen(function* () {
8790 + let closes = 0;
8791 + const interruptStarted = yield* Deferred.make<void>();
8792 + const harness = yield* makeWakeHarnessWithOptions({
8793 + interrupt: Deferred.succeed(interruptStarted, undefined).pipe(
8794 + Effect.andThen(Effect.never),
8795 + ),
8796 + close: (messages) =>
8797 + Effect.sync(() => {
8798 + closes++;
8799 + }).pipe(Effect.andThen(Queue.shutdown(messages))),
8800 + });
8801 + yield* harness.runtime.startTurn(
8802 + makeClaudeTestTurnInput({
8803 + threadId: harness.threadId,
8804 + providerThread: harness.providerThread,
8805 + now: yield* DateTime.now,
8806 + attemptId: RunAttemptId.make("unacknowledged-stop"),
8807 + text: "Work until stopped",
8808 + attachments: [],
8809 + }),
8810 + );
8811 + yield* harness.until(() =>
8812 + harness.events.some(
8813 + (event) =>
8814 + event.type === "provider_turn.updated" && event.providerTurn.status === "running",
8815 + ),
8816 + );
8817 + const active = harness.events.find(
8818 + (event) =>
8819 + event.type === "provider_turn.updated" && event.providerTurn.status === "running",
8820 + );
8821 + if (active?.type !== "provider_turn.updated")
8822 + return yield* Effect.die("Missing running native turn");
8823 + const stop = yield* harness.runtime
8824 + .interruptTurn({
8825 + providerThread: harness.providerThread,
8826 + providerTurnId: active.providerTurn.id,
8827 + requestRuntimeRestart: true,
8828 + })
8829 + .pipe(Effect.forkChild);
8830 + yield* Deferred.await(interruptStarted);
8831 + assert.equal(closes, 0);
8832 + yield* TestClock.adjust("11 seconds");
8833 + yield* Fiber.join(stop);
8834 + assert.equal((yield* Queue.take(harness.terminalReceipts)).status, "interrupted");
8835 + assert.equal(closes, 1);
8836 + assert.lengthOf(harness.terminalEvents(), 1);
8837 + }).pipe(
8838 + Effect.provide(
8839 + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer),
8840 + ),
8841 + ),
8842 + ),
8843 + );
8844 +
8845 it.effect("preserves settled background work until an explicit stop", () =>
8846 Effect.scoped(
8847 Effect.gen(function* () {
apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
+1 -1
@@ -10738,7 +10738,7 @@ export const makeClaudeAdapterV2 = Effect.fn("makeClaudeAdapterV2")(function* (
10738 next.add(turnInput.providerTurnId);
10739 return next;
10740 });
10741 - yield* existing.query.interrupt;
10741 + yield* existing.query.interrupt.pipe(Effect.timeoutOption("10 seconds"));
10742 yield* existing.query.close.pipe(Effect.ignore);
10743 const closed = yield* Deferred.await(existing.closed).pipe(
10744 Effect.timeoutOption(CLAUDE_STOP_CONFIRM_TIMEOUT_MS),