@devries-cameron20 / t3code-1 / commits / 3f905cac2e
Fork 0

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

fix(acp): time out silent Antigravity prompts (#30377)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

shivam committed Nov 5, 2026 at 07:02 UTC 3f905cac2e4dd968684298673546aacca3323b1d
4 files changed +430 -5
apps/server/scripts/acp-mock-agent.ts
+5
@@ -1848,6 +1848,11 @@ const program = Effect.gen(function* () {
1848 if (method === "_test/finish-cancel") {
1849 return Deferred.succeed(nativeCancelRelease, undefined).pipe(Effect.as({}));
1850 }
1851 + if (method === "_test/emit-update") {
1852 + return agent.client
1853 + .sessionUpdate(params as AcpSchema.SessionNotification)
1854 + .pipe(Effect.as({}));
1855 + }
1856 if (method === "_test/startup-metadata") {
1857 return Effect.gen(function* () {
1858 for (const [metadataSessionId, commandName, modeId] of [
apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
+236 -1
@@ -36,7 +36,7 @@ import { deriveBlockedOnThreadWait } from "@t3tools/shared/orchestrationV2Pendin
36 import { resolveSelfInvocation } from "@t3tools/shared/nodeRuntime";
37 import * as DateTime from "effect/DateTime";
38 import * as Deferred from "effect/Deferred";
39 -import type * as Duration from "effect/Duration";
39 +import * as Duration from "effect/Duration";
40 import * as Cause from "effect/Cause";
41 import * as Clock from "effect/Clock";
42 import * as Effect from "effect/Effect";
@@ -515,6 +515,90 @@ function makeMockRuntime(input: {
515 });
516 }
517
518 +const isProviderAdapterProtocolError = Schema.is(ProviderAdapter.ProviderAdapterProtocolError);
519 +
520 +const makePromptInactivityHarness = Effect.fnUntraced(function* (input: {
521 + readonly environment: (runtimeOrdinal: number) => Readonly<Record<string, string>>;
522 + readonly runtimeMode?: "full-access" | "approval-required";
523 +}) {
524 + const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
525 + const path = yield* Path.Path;
526 + const natives: Array<AcpSessionRuntime.AcpSessionRuntime["Service"]> = [];
527 + const instanceId = ProviderInstanceId.make("acp-prompt-inactivity");
528 + const adapter = yield* makeAcpAdapterV2({
529 + instanceId,
530 + flavor: {
531 + driver: ACP_TEST_DRIVER,
532 + capabilities: AcpProviderCapabilitiesV2,
533 + promptInactivityTimeout: "15 minutes",
534 + makeRuntime: makeMockRuntime({
535 + childProcessSpawner,
536 + mockAgentPath: yield* path.fromFileUrl(
537 + new URL("../../../scripts/acp-mock-agent.ts", import.meta.url),
538 + ),
539 + environment: input.environment,
540 + wrapRuntime: (runtime) => {
541 + natives.push(runtime);
542 + return runtime;
543 + },
544 + }),
545 + },
546 + selfInvocation: yield* resolveSelfInvocation(),
547 + });
548 + const threadId = ThreadId.make("thread-acp-prompt-inactivity");
549 + const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
550 + runtimeMode: input.runtimeMode ?? "full-access",
551 + interactionMode: "default",
552 + cwd: process.cwd(),
553 + });
554 + const modelSelection = { instanceId, model: "default" } as const;
555 + const runtime = yield* adapter.openSession({
556 + threadId,
557 + providerSessionId: ProviderSessionId.make("provider-session-acp-prompt-inactivity"),
558 + modelSelection,
559 + runtimePolicy,
560 + });
561 + const providerThread = yield* runtime.ensureThread({ threadId, modelSelection, runtimePolicy });
562 + const startTurn = (ordinal: number) =>
563 + DateTime.now.pipe(
564 + Effect.flatMap((now) =>
565 + runtime.startTurn(
566 + makeTurnInput({ threadId, providerThread, instanceId, runtimePolicy, now, ordinal }),
567 + ),
568 + ),
569 + );
570 + return {
571 + runtime,
572 + natives,
573 + startTurn,
574 + /** A turn still running makes the next start fail, without waiting on time. */
575 + nextTurnRejected: (ordinal: number) =>
576 + startTurn(ordinal).pipe(
577 + Effect.flip,
578 + Effect.map(
579 + (error) =>
580 + isProviderAdapterProtocolError(error.cause) &&
581 + error.cause.reason === "previous_turn_active",
582 + ),
583 + Effect.catchCause(() => Effect.succeed(false)),
584 + ),
585 + emitUpdate: (notification: EffectAcpSchema.SessionNotification) =>
586 + natives.at(-1)!.request("_test/emit-update", notification),
587 + terminals: (count: number) =>
588 + runtime.events.pipe(
589 + Stream.filter((event) => event.type === "turn.terminal"),
590 + Stream.take(count),
591 + Stream.runCollect,
592 + Effect.map((events) =>
593 + Array.from(events, (event) => {
594 + if (event.type !== "turn.terminal") throw new Error("Expected a turn terminal");
595 + return event;
596 + }),
597 + ),
598 + ),
599 + };
600 +});
601 +
602 function rawProtocolMethod(event: EffectAcpProtocol.AcpProtocolLogEvent): string | undefined {
603 if (event.stage !== "raw" || typeof event.payload !== "string") return undefined;
604 for (const line of event.payload.split("\n")) {
@@ -3924,6 +4008,157 @@ describe("AcpAdapterV2", () => {
4008 }).pipe(Effect.provide(layerTest), Effect.scoped),
4009 );
4010
4011 + it.effect("fails a prompt its agent leaves silent past the inactivity timeout", () =>
4012 + Effect.gen(function* () {
4013 + const harness = yield* makePromptInactivityHarness({
4014 + environment: (runtimeOrdinal) =>
4015 + runtimeOrdinal === 1 ? { T3_ACP_HANG_PROMPT_FOREVER: "1" } : {},
4016 + });
4017 + const thought = (sessionId: string) => ({
4018 + sessionId,
4019 + update: {
4020 + sessionUpdate: "agent_thought_chunk" as const,
4021 + content: { type: "text" as const, text: "Still working." },
4022 + },
4023 + });
4024 + yield* harness.startTurn(1);
4025 + yield* TestClock.adjust("10 minutes");
4026 + yield* harness.emitUpdate(thought("mock-session-1"));
4027 + yield* TestClock.adjust("5 minutes");
4028 + // Neither another session's progress nor this session's metadata extends this turn.
4029 + yield* harness.emitUpdate(thought("foreign-session"));
4030 + yield* harness.emitUpdate({
4031 + sessionId: "mock-session-1",
4032 + update: { sessionUpdate: "available_commands_update", availableCommands: [] },
4033 + });
4034 + yield* TestClock.adjust(Duration.millis(10 * 60_000 - 1));
4035 + assert.isTrue(yield* harness.nextTurnRejected(2));
4036 +
4037 + yield* TestClock.adjust("1 millis");
4038 + yield* harness.startTurn(2);
4039 + const [silent, next] = yield* harness.terminals(2);
4040 + assert.equal(silent?.status, "failed");
4041 + assert.include(silent?.failure?.message, "15 minutes");
4042 + assert.equal(next?.status, "completed");
4043 + assert.lengthOf(harness.natives, 2);
4044 + }).pipe(Effect.provide(layerTest), Effect.scoped),
4045 + );
4046 +
4047 + it.effect(
4048 + "holds the inactivity timeout while a tool runs and restarts it when the tool ends",
4049 + () =>
4050 + Effect.gen(function* () {
4051 + const harness = yield* makePromptInactivityHarness({
4052 + environment: (runtimeOrdinal) =>
4053 + runtimeOrdinal === 1 ? { T3_ACP_EMIT_TRACKED_TOOL_CALL_KIND_THEN_HANG: "execute" } : {},
4054 + });
4055 + yield* harness.startTurn(1);
4056 + yield* harness.runtime.events.pipe(
4057 + Stream.filter(
4058 + (event) =>
4059 + event.type === "turn_item.updated" &&
4060 + event.turnItem.nativeItemRef?.nativeId === "tracked-tool-call",
4061 + ),
4062 + Stream.runHead,
4063 + );
4064 + yield* TestClock.adjust("1 hour");
4065 + assert.isTrue(yield* harness.nextTurnRejected(2));
4066 +
4067 + yield* harness.emitUpdate({
4068 + sessionId: "mock-session-1",
4069 + update: {
4070 + sessionUpdate: "tool_call_update",
4071 + toolCallId: "tracked-tool-call",
4072 + status: "completed",
4073 + },
4074 + });
4075 + yield* TestClock.adjust(Duration.millis(15 * 60_000 - 1));
4076 + assert.isTrue(yield* harness.nextTurnRejected(2));
4077 + yield* TestClock.adjust("1 millis");
4078 + yield* harness.startTurn(2);
4079 + const [silent, next] = yield* harness.terminals(2);
4080 + assert.equal(silent?.status, "failed");
4081 + assert.equal(next?.status, "completed");
4082 + }).pipe(Effect.provide(layerTest), Effect.scoped),
4083 + );
4084 +
4085 + it.effect("holds the inactivity timeout while the agent waits on an approval", () =>
4086 + Effect.gen(function* () {
4087 + const harness = yield* makePromptInactivityHarness({
4088 + environment: () => ({ T3_ACP_EMIT_TOOL_CALLS: "1" }),
4089 + runtimeMode: "approval-required",
4090 + });
4091 + yield* harness.startTurn(1);
4092 + const pending = Option.getOrThrow(
4093 + yield* harness.runtime.events.pipe(
4094 + Stream.filter(
4095 + (event) =>
4096 + event.type === "runtime_request.updated" && event.runtimeRequest.status === "pending",
4097 + ),
4098 + Stream.runHead,
4099 + ),
4100 + );
4101 + if (pending.type !== "runtime_request.updated") {
4102 + return yield* Effect.die("Expected a pending approval");
4103 + }
4104 + // Only the request is left open, so it alone holds the deadline.
4105 + yield* harness.emitUpdate({
4106 + sessionId: "mock-session-1",
4107 + update: {
4108 + sessionUpdate: "tool_call_update",
4109 + toolCallId: "tool-call-1",
4110 + status: "completed",
4111 + },
4112 + });
4113 + yield* TestClock.adjust("1 hour");
4114 + assert.isTrue(yield* harness.nextTurnRejected(2));
4115 +
4116 + yield* harness.runtime.respondToRuntimeRequest({
4117 + requestId: pending.runtimeRequest.id,
4118 + decision: "accept",
4119 + });
4120 + const [approved] = yield* harness.terminals(1);
4121 + assert.equal(approved?.status, "completed");
4122 + assert.lengthOf(harness.natives, 1);
4123 + }).pipe(Effect.provide(layerTest), Effect.scoped),
4124 + );
4125 +
4126 + it.effect("fails a running prompt once when its agent process exits", () =>
4127 + Effect.gen(function* () {
4128 + const harness = yield* makePromptInactivityHarness({
4129 + environment: (runtimeOrdinal) =>
4130 + runtimeOrdinal === 1
4131 + ? { T3_ACP_EMIT_TOOL_CALLS: "1" }
4132 + : runtimeOrdinal === 2
4133 + ? { T3_ACP_HANG_PROMPT_FOREVER: "1" }
4134 + : {},
4135 + runtimeMode: "approval-required",
4136 + });
4137 + yield* harness.startTurn(1);
4138 + // The dying agent leaves an approval unanswered.
4139 + yield* harness.runtime.events.pipe(
4140 + Stream.filter(
4141 + (event) =>
4142 + event.type === "runtime_request.updated" && event.runtimeRequest.status === "pending",
4143 + ),
4144 + Stream.runHead,
4145 + );
4146 + yield* harness.natives[0]!.notify("_test/exit", {});
4147 + const [exited] = yield* harness.terminals(1);
4148 + assert.equal(exited?.status, "failed");
4149 +
4150 + // The replacement's silent prompt still times out.
4151 + yield* harness.startTurn(2);
4152 + yield* TestClock.adjust("15 minutes");
4153 + yield* harness.startTurn(3);
4154 + const [silent, next] = yield* harness.terminals(2);
4155 + assert.equal(silent?.status, "failed");
4156 + assert.notEqual(silent?.providerTurnId, exited?.providerTurnId);
4157 + assert.equal(next?.status, "completed");
4158 + assert.lengthOf(harness.natives, 3);
4159 + }).pipe(Effect.provide(layerTest), Effect.scoped),
4160 + );
4161 +
4162 it.live("does not poll the process ledger while a cgroup lease owns teardown", () =>
4163 Effect.gen(function* () {
4164 if ((yield* HostProcess.Platform) !== "linux") return;
apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.ts
+2
@@ -273,6 +273,8 @@ export function makeAntigravityAcpAdapterFlavor(
273 // ACP 1.3.0 treats /compact as ordinary model input.
274 supportsCompaction: false,
275 requiresSignIn: isAntigravitySignInRequiredError,
276 + // Antigravity can leave a prompt open without updates; long tools and approvals pause this.
277 + promptInactivityTimeout: "15 minutes",
278 // 1.4.5 returns the root trajectory's Gemini usageMetadata delta; 1.4.1 returns none.
279 reportsPerTurnPromptUsage: true,
280 geminiPromptUsage: true,
packages/provider-acp/src/server/adapter.ts
+187 -4
@@ -149,6 +149,24 @@ const ACP_DEFERRED_FINALIZE_DEBOUNCE: Duration.Input = "3000 millis";
149 */
150 const ACP_TEXT_FLUSH_INTERVAL: Duration.Input = "50 millis";
151
152 +// Output of the running prompt. Session metadata and unknown updates do not reset its timeout.
153 +const ACP_PROMPT_ACTIVITY_UPDATES: ReadonlySet<string> = new Set([
154 + "agent_message",
155 + "agent_message_chunk",
156 + "agent_thought",
157 + "agent_thought_chunk",
158 + "tool_call",
159 + "tool_call_update",
160 + "tool_call_content_chunk",
161 + "terminal_output_chunk",
162 + "terminal_update",
163 + "plan",
164 + "plan_update",
165 + "plan_removed",
166 + "compaction_update",
167 + "compaction_summary_chunk",
168 +]);
169 +
170 export interface AcpAdapterV2RuntimeInput {
171 readonly cwd: string;
172 readonly runtimePolicy: ProviderAdapter.ProviderAdapterV2RuntimePolicy;
@@ -167,6 +185,7 @@ export interface AcpAdapterV2RuntimeInput {
185 readonly onTermination: NonNullable<AcpSessionRuntime.AcpSessionRuntimeOptions["onTermination"]>;
186 readonly onOutgoingResponseFailure?: AcpSessionRuntime.AcpSessionRuntimeOptions["onOutgoingResponseFailure"];
187 readonly onOutgoingResponse?: AcpSessionRuntime.AcpSessionRuntimeOptions["onOutgoingResponse"];
188 + readonly onIncomingRequest?: AcpSessionRuntime.AcpSessionRuntimeOptions["onIncomingRequest"];
189 }
190
191 export type AcpAdapterV2NativeLogging = Pick<
@@ -512,6 +531,11 @@ export interface AcpAdapterV2Flavor {
531 readonly reportsPerTurnPromptUsage?: boolean;
532 /** Gemini-style usage: inputTokens leaves out cachedReadTokens, outputTokens leaves out thoughtTokens. */
533 readonly geminiPromptUsage?: boolean;
534 + /**
535 + * Fails a dispatched prompt after this long with no update for its session while no
536 + * agent request, tool or subagent is open, and replaces the agent before the next turn.
537 + */
538 + readonly promptInactivityTimeout?: Duration.Input;
539 /** Grok can retain task_already_running until process exit. */
540 readonly restartRuntimeAfterInterrupt?: boolean;
541 /** Prompt failures after which the agent process keeps failing until replaced. */
@@ -1395,6 +1419,9 @@ interface ActiveAcpTurn {
1419 backgroundFinalizeGeneration: number;
1420 /** The agent's own id for this turn's prompt, from `forkFromTurn.nativeTurnId`. */
1421 nativePromptId: string | undefined;
1422 + /** Clock millis of the prompt's last progress, for `promptInactivityTimeout`. */
1423 + lastProgressAt: number;
1424 + inactivityWatchdog: Fiber.Fiber<void> | undefined;
1425 }
1426
1427 type AcpRuntimeTeardownState =
@@ -2259,6 +2286,40 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
2286 Effect.void;
2287
2288 const nativeLogging = options.nativeLogging?.(input.threadId);
2289 + const promptInactivityTimeoutMillis =
2290 + flavor.promptInactivityTimeout === undefined
2291 + ? undefined
2292 + : Duration.toMillis(flavor.promptInactivityTimeout);
2293 + // Each runtime owns its unanswered agent requests, so a dead process's leftovers
2294 + // and late callbacks never reach its replacement.
2295 + let openAgentRequests = new Set<string>();
2296 + const notePromptProgress =
2297 + /* Provider events include streaming deltas; avoid a span for each update. */
2298 + Effect.fnUntraced(function* (notification?: EffectAcpSchema.SessionNotification) {
2299 + if (promptInactivityTimeoutMillis === undefined) return;
2300 + if (
2301 + notification !== undefined &&
2302 + !ACP_PROMPT_ACTIVITY_UPDATES.has(notification.update.sessionUpdate)
2303 + ) {
2304 + return;
2305 + }
2306 + const context = yield* Ref.get(activeTurn);
2307 + if (
2308 + context === null ||
2309 + (notification !== undefined &&
2310 + notification.sessionId !== context.nativeThreadId &&
2311 + !context.subagentsBySessionId.has(notification.sessionId))
2312 + ) {
2313 + return;
2314 + }
2315 + context.lastProgressAt = yield* Clock.currentTimeMillis;
2316 + });
2317 + const closeAgentRequest = (agentRequests: Set<string>, requestId: string) =>
2318 + Effect.suspend(() =>
2319 + agentRequests.delete(requestId) && agentRequests === openAgentRequests
2320 + ? notePromptProgress()
2321 + : Effect.void,
2322 + );
2323 const handleRuntimeTerminationAtGeneration = (runtimeGeneration: number) =>
2324 runRuntimeCallbackAtGeneration(
2325 runtimeGeneration,
@@ -2295,6 +2356,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
2356 ).pipe(Effect.asVoid);
2357 const makeRuntimeInput = (
2358 runtimeGeneration: number,
2359 + agentRequests: Set<string>,
2360 mcpContext: AcpMcpContext,
2361 resumeSessionId?: string,
2362 onTermination: AcpAdapterV2RuntimeInput["onTermination"] = () =>
@@ -2321,7 +2383,16 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
2383 ...(flavor.clientCapabilitiesMeta ? { _meta: flavor.clientCapabilitiesMeta } : {}),
2384 },
2385 clientInfo: { name: "t3-code", version: "0.0.0" },
2324 - onTermination,
2386 + onTermination: (error) =>
2387 + Effect.sync(() => agentRequests.clear()).pipe(Effect.andThen(onTermination(error))),
2388 + ...(promptInactivityTimeoutMillis === undefined
2389 + ? {}
2390 + : {
2391 + onIncomingRequest: (requestId: string) =>
2392 + Effect.sync(() => {
2393 + agentRequests.add(requestId);
2394 + }),
2395 + }),
2396 onOutgoingResponseFailure: (requestId, error) =>
2397 Ref.modify(nativeResponseAcknowledgements, (current) => {
2398 const entry = current.get(requestId);
@@ -2350,7 +2421,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
2421 ),
2422 updated,
2423 ] as const;
2353 - }).pipe(Effect.flatten),
2424 + }).pipe(Effect.flatten, Effect.andThen(closeAgentRequest(agentRequests, requestId))),
2425 onOutgoingResponse: (requestId) =>
2426 Ref.modify(nativeResponseAcknowledgements, (current) => {
2427 const entry = current.get(requestId);
@@ -2379,7 +2450,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
2450 ),
2451 updated,
2452 ] as const;
2382 - }).pipe(Effect.flatten),
2453 + }).pipe(Effect.flatten, Effect.andThen(closeAgentRequest(agentRequests, requestId))),
2454 ...(nativeLogging?.requestLogger === undefined
2455 ? {}
2456 : { requestLogger: nativeLogging.requestLogger }),
@@ -6170,6 +6241,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6241 Effect.fnUntraced(
6242 function* (rawNotification: EffectAcpSchema.SessionNotification) {
6243 if (flavor.ignoreSessionUpdate?.(rawNotification) === true) return;
6244 + yield* notePromptProgress(rawNotification);
6245 const nativePromptId = flavor.forkFromTurn?.nativeTurnId(rawNotification);
6246 if (nativePromptId !== undefined) {
6247 const context = yield* Ref.get(activeTurn);
@@ -6780,8 +6852,11 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6852 const mcpContext = yield* readMcpContext(threadId);
6853 runtimeMcpBridge = yield* makeRuntimeMcpBridge(mcpContext, runtimeScope);
6854 const runtimeGeneration = yield* Ref.get(runtimeCallbackGeneration);
6855 + openAgentRequests = new Set();
6856 runtime = yield* flavor
6784 - .makeRuntime(makeRuntimeInput(runtimeGeneration, mcpContext, resumeSessionId))
6857 + .makeRuntime(
6858 + makeRuntimeInput(runtimeGeneration, openAgentRequests, mcpContext, resumeSessionId),
6859 + )
6860 .pipe(
6861 Effect.provideService(Scope.Scope, runtimeScope),
6862 Effect.provideService(SecureRandom.SecureRandom, random),
@@ -6821,6 +6896,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6896 // Keep live callbacks active until replacement startup succeeds.
6897 const replacementGeneration = yield* allocateRuntimeCallbackGeneration;
6898 const replacementScope = yield* Scope.make();
6899 + const replacementAgentRequests = new Set<string>();
6900 type CandidateLifecycle =
6901 | { readonly _tag: "Starting" }
6902 | { readonly _tag: "Terminated"; readonly error: EffectAcpErrors.AcpError }
@@ -6856,6 +6932,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6932 .makeRuntime(
6933 makeRuntimeInput(
6934 replacementGeneration,
6935 + replacementAgentRequests,
6936 mcpContext,
6937 undefined,
6938 handleCandidateTermination,
@@ -6919,6 +6996,7 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
6996 runtime = replacementExit.value.replacementRuntime;
6997 runtimeScope = replacementScope;
6998 runtimeMcpBridge = replacementMcpBridge;
6999 + openAgentRequests = replacementAgentRequests;
7000 yield* Ref.set(runtimeCallbackGeneration, replacementGeneration);
7001 prepareTerminalEnvironment(
7002 yield* readMcpContext(threadId),
@@ -7499,6 +7577,11 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7577 const settledStatus = context.interrupted ? "interrupted" : status;
7578 context.finalizedStatus = settledStatus;
7579 context.finalized = true;
7580 + const watchdog = context.inactivityWatchdog;
7581 + context.inactivityWatchdog = undefined;
7582 + if (watchdog !== undefined) {
7583 + yield* Fiber.interrupt(watchdog).pipe(Effect.forkDetach, Effect.asVoid);
7584 + }
7585 const directStopQuarantine = yield* Ref.get(stoppedRunQuarantine);
7586 if (flavor.subagentsIdleOnTurnCompletion === true) {
7587 for (const subagent of context.subagents.values()) {
@@ -7694,6 +7777,97 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
7777 );
7778 });
7779
7780 + const promptInactivityPaused = Effect.fn("AcpAdapterV2.promptInactivityPaused")(function* (
7781 + context: ActiveAcpTurn,
7782 + ) {
7783 + if (openAgentRequests.size > 0) return true;
7784 + if ((yield* Ref.get(pendingRuntimeRequests)).size > 0) return true;
7785 + for (const tool of context.tools.values()) {
7786 + const status = toolStatus(tool.status);
7787 + if (status === "pending" || status === "running" || status === "waiting") return true;
7788 + }
7789 + for (const subagent of context.subagents.values()) {
7790 + if (acpSubagentStatusBlocksTurnSettlement(subagent.task.status)) return true;
7791 + }
7792 + return false;
7793 + });
7794 +
7795 + /**
7796 + * Holds the transition permit from the deadline check through process teardown,
7797 + * so Stop and the next turn see either a running prompt or a replaced runtime.
7798 + */
7799 + const retireInactivePrompt = Effect.fn("AcpAdapterV2.retireInactivePrompt")(function* (
7800 + context: ActiveAcpTurn,
7801 + generation: number,
7802 + timeoutMillis: number,
7803 + ) {
7804 + const retired = yield* runRuntimeCallbackAtGeneration(
7805 + generation,
7806 + Effect.gen(function* () {
7807 + if (context.finalized || context.interrupted) return "done" as const;
7808 + if ((yield* Ref.get(activeTurn)) !== context) return "done" as const;
7809 + if (yield* Deferred.isDone(context.promptWireSettled)) return "done" as const;
7810 + const now = yield* Clock.currentTimeMillis;
7811 + if (context.lastProgressAt + timeoutMillis > now) return "rearm" as const;
7812 + if (yield* promptInactivityPaused(context)) {
7813 + context.lastProgressAt = now;
7814 + return "rearm" as const;
7815 + }
7816 + context.inactivityWatchdog = undefined;
7817 + openAgentRequests.clear();
7818 + yield* quarantineNativeTransportAtGeneration(generation);
7819 + yield* advanceRuntimeCallbackGeneration;
7820 + yield* Ref.set(runtimeRestartRequired, true);
7821 + yield* cancelPendingRuntimeRequests();
7822 + yield* terminalizeOpenForegroundTools(context, "failed");
7823 + const minutes = Math.max(1, Math.round(timeoutMillis / 60_000));
7824 + yield* finalizeTurn(
7825 + context,
7826 + "failed",
7827 + makeProviderFailure({
7828 + class: "provider_error",
7829 + message: `${flavor.runtimeHarness ?? driver} sent nothing for ${minutes} ${minutes === 1 ? "minute" : "minutes"}, so T3 Code stopped the turn and restarted the agent. Send a message to continue.`,
7830 + }),
7831 + );
7832 + return "retired" as const;
7833 + }),
7834 + );
7835 + if (Option.isNone(retired) || retired.value !== "retired") {
7836 + return Option.getOrElse(retired, () => "done" as const);
7837 + }
7838 + yield* Effect.logWarning("orchestration-v2.acp-prompt-inactive", {
7839 + driver,
7840 + providerSessionId: input.providerSessionId,
7841 + providerTurnId: context.providerTurnId,
7842 + timeoutMillis,
7843 + });
7844 + if (runtimeScope !== undefined) {
7845 + yield* Scope.close(runtimeScope, Exit.void).pipe(Effect.ignore);
7846 + }
7847 + return "retired" as const;
7848 + });
7849 +
7850 + const watchPromptInactivity = Effect.fn("AcpAdapterV2.watchPromptInactivity")(function* (
7851 + context: ActiveAcpTurn,
7852 + generation: number,
7853 + timeoutMillis: number,
7854 + ) {
7855 + yield* Deferred.await(context.promptDispatched);
7856 + context.lastProgressAt = yield* Clock.currentTimeMillis;
7857 + while (true) {
7858 + const remaining =
7859 + context.lastProgressAt + timeoutMillis - (yield* Clock.currentTimeMillis);
7860 + if (remaining > 0) {
7861 + yield* Effect.sleep(Duration.millis(remaining));
7862 + continue;
7863 + }
7864 + const outcome = yield* runtimeTransitionPermit.withPermit(
7865 + retireInactivePrompt(context, generation, timeoutMillis),
7866 + );
7867 + if (outcome !== "rearm") return;
7868 + }
7869 + });
7870 +
7871 const resolvePromptParts = Effect.fnUntraced(function* (
7872 turnInput: ProviderAdapter.ProviderAdapterV2TurnInput,
7873 sessionId: string,
@@ -8004,6 +8178,8 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
8178 promptUsage: undefined,
8179 backgroundFinalizeGeneration: 0,
8180 nativePromptId: undefined,
8181 + lastProgressAt: 0,
8182 + inactivityWatchdog: undefined,
8183 };
8184 const carryover = yield* Ref.getAndSet(carryoverSubagents, null);
8185 let rehydratedCarryoverSubagents: ReadonlyArray<ActiveAcpSubagent> = [];
@@ -8145,6 +8321,13 @@ export const makeAcpAdapterV2 = Effect.fn("makeAcpAdapterV2")(function* (
8321 const promptGeneration = yield* Ref.get(runtimeCallbackGeneration);
8322 const promptOptions = { dispatched: context.promptDispatched };
8323 context.promptSentAt = yield* Clock.currentTimeMillis;
8324 + if (promptInactivityTimeoutMillis !== undefined) {
8325 + context.inactivityWatchdog = yield* watchPromptInactivity(
8326 + context,
8327 + promptGeneration,
8328 + promptInactivityTimeoutMillis,
8329 + ).pipe(Effect.forkIn(sessionScope));
8330 + }
8331 const compactSession = isCompactionMessage(turnInput.message)
8332 ? flavor.compactSession
8333 : undefined;