@devries-cameron20 / t3code-1 / commits / 9f6f5540cf
Fork 0

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

fix(server): worktree handoff no longer leaves Antigravity threads Waiting (#39422)

Julius Marminge committed Nov 19, 2026 at 15:41 UTC 9f6f5540cfe975b6c2748f8e11de62c243dd4414
4 files changed +99 -6
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+41 -1
@@ -623,6 +623,7 @@ const makePromptInactivityHarness = Effect.fnUntraced(function* (input: {
623 ) => AcpSessionRuntime.AcpSessionRuntime["Service"]["prompt"];
624 readonly cancelled?: Deferred.Deferred<void>;
625 readonly followAgentWorkState?: boolean;
626 + readonly sessionScope?: Scope.Scope;
627 }) {
628 const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
629 const natives: Array<AcpSessionRuntime.AcpSessionRuntime["Service"]> = [];
@@ -663,12 +664,15 @@ const makePromptInactivityHarness = Effect.fnUntraced(function* (input: {
664 cwd: process.cwd(),
665 });
666 const modelSelection = { instanceId, model: "default" } as const;
666 - const runtime = yield* adapter.openSession({
667 + const opened = adapter.openSession({
668 threadId,
669 providerSessionId: ProviderSessionId.make("provider-session-acp-prompt-inactivity"),
670 modelSelection,
671 runtimePolicy,
672 });
673 + const runtime = yield* input.sessionScope === undefined
674 + ? opened
675 + : opened.pipe(Effect.provideService(Scope.Scope, input.sessionScope));
676 const providerThread = yield* runtime.ensureThread({ threadId, modelSelection, runtimePolicy });
677 const startTurn = (ordinal: number) =>
678 DateTime.now.pipe(
@@ -5840,6 +5844,42 @@ describe("AcpAdapterV2", () => {
5844 }).pipe(Effect.provide(layerTest)),
5845 );
5846
5847 + it.effect("ends a running T3 MCP tool call when its session closes mid-prompt", () =>
5848 + Effect.gen(function* () {
5849 + const sessionScope = yield* Scope.make();
5850 + const harness = yield* makePromptInactivityHarness({
5851 + sessionScope,
5852 + environment: () => ({ T3_ACP_EMIT_TRACKED_TOOL_CALL_KIND_THEN_HANG: "other" }),
5853 + });
5854 + const trackedToolStatus = (event: ProviderAdapter.ProviderAdapterV2Event) =>
5855 + event.type === "turn_item.updated" &&
5856 + event.turnItem.nativeItemRef?.nativeId === "tracked-tool-call"
5857 + ? event.turnItem.status
5858 + : undefined;
5859 + yield* harness.startTurn(1);
5860 + yield* harness.runtime.events.pipe(
5861 + Stream.filter((event) => trackedToolStatus(event) !== undefined),
5862 + Stream.runHead,
5863 + );
5864 + // t3_worktree_handoff releases the live session while its own tool call is open.
5865 + yield* Scope.close(sessionScope, Exit.void);
5866 + // The event queue outlives the session; only events emitted by the close remain.
5867 + const after = yield* harness.runtime.events.pipe(
5868 + Stream.filter((event) => trackedToolStatus(event) !== undefined),
5869 + Stream.map(trackedToolStatus),
5870 + Stream.takeUntil((status) => status !== "pending" && status !== "running"),
5871 + Stream.runCollect,
5872 + Effect.map((collected) => Array.from(collected)),
5873 + Effect.timeoutOption("1 second"),
5874 + Effect.forkChild,
5875 + );
5876 + yield* TestClock.adjust("1 second");
5877 + const statuses = Option.getOrElse(yield* Fiber.join(after), () => []);
5878 + // regression: #39410 the handoff's tool call stayed running after the session closed.
5879 + assert.include(["completed", "failed", "interrupted", "cancelled"], statuses.at(-1));
5880 + }).pipe(Effect.provide(layerTest)),
5881 + );
5882 +
5883 it.live("does not poll the process ledger while a cgroup lease owns teardown", () =>
5884 Effect.gen(function* () {
5885 if ((yield* HostProcess.Platform) !== "linux") return;
apps/server/src/orchestration-v2/RunExecutionService.ts
+5 -1
@@ -2055,7 +2055,11 @@ export const layer: Layer.Layer<
2055 ).pipe(Effect.as(false)),
2056 ),
2057 );
2058 - if (handedOff) return;
2058 + if (handedOff) {
2059 + // Its tool calls, the handoff's own among them, died with that process.
2060 + yield* endWorkLostAfterRootRun(completedAt);
2061 + return;
2062 + }
2063 }
2064 yield* Effect.logWarning("orchestration V2 provider event ingestion failed", {
2065 runId: input.run.id,
apps/server/src/orchestration-v2/SelectionRestart.integration.test.ts
+47 -4
@@ -16,6 +16,7 @@ import {
16 ProviderTurnId,
17 type RunId,
18 ThreadId,
19 + TurnItemId,
20 } from "@t3tools/contracts";
21 import * as DateTime from "effect/DateTime";
22 import * as Effect from "effect/Effect";
@@ -462,19 +463,54 @@ it.live.each(["pooled", "exclusive"] as const)(
463 state,
464 mode === "pooled" ? pooledCapabilities : exclusiveCapabilities,
465 );
466 + const handoffToolId = TurnItemId.make(`turn-item:workspace-handoff:${mode}:tool`);
467 // A session that closes on detach is never asked to interrupt: Claude's cannot answer.
468 + // Its turn is inside the handoff's own tool call, which the closed session never ends.
469 const adapter: ProviderAdapter.ProviderAdapterV2["Service"] =
470 mode === "pooled"
471 ? base
472 : {
473 ...base,
474 openSession: (input) =>
472 - base.openSession(input).pipe(
473 - Effect.map((session) => ({
475 + Effect.gen(function* () {
476 + const session = yield* base.openSession(input);
477 + const toolEvents =
478 + yield* Queue.unbounded<ProviderAdapter.ProviderAdapterV2Event>();
479 + return {
480 ...session,
481 + events: Stream.merge(session.events, Stream.fromQueue(toolEvents)),
482 + startTurn: (turn) =>
483 + Effect.gen(function* () {
484 + yield* session.startTurn(turn);
485 + const now = yield* DateTime.now;
486 + yield* Queue.offer(toolEvents, {
487 + type: "turn_item.updated",
488 + driver,
489 + turnItem: {
490 + id: handoffToolId,
491 + type: "dynamic_tool",
492 + threadId: turn.threadId,
493 + runId: turn.runId,
494 + nodeId: turn.rootNodeId,
495 + providerThreadId: turn.providerThread.id,
496 + providerTurnId: ProviderTurnId.make(`provider-turn:${turn.attemptId}`),
497 + nativeItemRef: null,
498 + parentItemId: null,
499 + ordinal: 1,
500 + status: "running",
501 + title: "t3_worktree_handoff",
502 + toolName: "t3-code.t3_worktree_handoff",
503 + input: {},
504 + output: null,
505 + startedAt: now,
506 + completedAt: null,
507 + updatedAt: now,
508 + },
509 + });
510 + }),
511 interruptTurn: () => Effect.die("an exclusive handoff must not interrupt"),
476 - })),
477 - ),
512 + };
513 + }),
514 };
515 const layerRegistry = ProviderAdapterRegistry.layerSingle(adapter);
516
@@ -585,6 +621,13 @@ it.live.each(["pooled", "exclusive"] as const)(
621 ),
622 "an intentional workspace handoff must not project an interrupt result or a failure",
623 );
624 + if (mode === "exclusive") {
625 + // regression: #39410 the handoff's tool call stayed running after its session closed.
626 + assert.equal(
627 + projection.turnItems.find((item) => item.id === handoffToolId)?.status,
628 + "interrupted",
629 + );
630 + }
631 assert.deepEqual(
632 (yield* Ref.get(state)).started.map((turn) => turn.cwd),
633 [cwd, handoffCwd],
packages/provider-acp/src/server/adapter.ts
+6
@@ -9646,6 +9646,12 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
9646 yield* Ref.update(continuationGeneration, (value) => value + 1);
9647 }),
9648 );
9649 + // A session released mid-prompt (worktree handoff) never sees its prompt settle.
9650 + const openTurn = yield* Ref.get(activeTurn);
9651 + if (openTurn !== null && !openTurn.finalized) {
9652 + openTurn.interrupted = true;
9653 + yield* finalizeTurn(openTurn, "interrupted");
9654 + }
9655 const requests = [...(yield* Ref.get(pendingRuntimeRequests)).values()];
9656 yield* Effect.forEach(
9657 requests,