fix(server): recycle Antigravity ADC runtimes before 60m expiry and fail silent empty turns #48319
Openonlydole(GitHub profile, opens in a new tab)wants to merge 2 commits into
main fromrefs/pull/48319/headopened View on GitHubPushed1ad6566
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- @@ -11102,0 +11155,21 @@11155+ (canLoadSession || canResumeSession) &&11156+ !(yield* Ref.get(runtimeRestartRequired)) &&11157+ !acpIsProviderContinuationMessage(turnInput.message)11158+ ? yield* continuationPermit.withPermit(11159+ Effect.gen(function* () {11160+ const startedAtMillis = yield* Ref.get(runtimeStartedAt);11161+ if (11162+ startedAtMillis === null ||11163+ (yield* Clock.currentTimeMillis) - startedAtMillis <11164+ maxRuntimeAgeBeforeTurnMillis11165+ ) {11166+ return false;11167+ }11168+ const hasIdleOutlivingSubagents = [...idleOutlivingSubagents.values()].some(11169+ (entries) => entries.size > 0,11170+ );11171+ return (11172+ !(yield* Ref.get(continuationRequested)) &&11173+ (yield* Ref.get(wakeBuffer)).length === 0 &&11174+ (yield* Ref.get(runningBackgroundTaskIds)).size === 0 &&11175+ (yield* Ref.get(detachedBackgroundCommands)).size === 0 &&@@ -10752,6 +10768,16 @@10752107681075310769 const restartRuntimeAfterTeardownIfRequired = Effect.fnUntraced(function* (1075410770 threadId: ThreadId | null,10771+ resumeSessionId?: string,1075510772 ) {1075610773 const restartRequired = yield* Ref.get(runtimeRestartRequired);10757- if (!restartRequired) return false;10774+ if (!restartRequired) return undefined;10775+ if (resumeSessionId !== undefined && (canLoadSession || canResumeSession)) {10776+ const initialFailure = yield* Ref.modify(initialSessionActivationFailure, (failure) =>10777+ failure?.sessionId === resumeSessionId ? [failure.error, null] : [undefined, failure],10778+ );10779+ if (initialFailure !== undefined) {10780+ return yield* initialFailure;10781+ }10782+ const mcpContext = yield* readMcpContext(threadId);10783+ prepareTerminalEnvironment(mcpContext, resumeSessionId);
- @@ -11102,0 +11156,21 @@11156+ !(yield* Ref.get(runtimeRestartRequired)) &&11157+ !acpIsProviderContinuationMessage(turnInput.message)11158+ ? yield* continuationPermit.withPermit(11159+ Effect.gen(function* () {11160+ const startedAtMillis = yield* Ref.get(runtimeStartedAt);11161+ if (11162+ startedAtMillis === null ||11163+ (yield* Clock.currentTimeMillis) - startedAtMillis <11164+ maxRuntimeAgeBeforeTurnMillis11165+ ) {11166+ return false;11167+ }11168+ const hasIdleOutlivingSubagents = [...idleOutlivingSubagents.values()].some(11169+ (entries) => entries.size > 0,11170+ );11171+ return (11172+ !(yield* Ref.get(continuationRequested)) &&11173+ (yield* Ref.get(wakeBuffer)).length === 0 &&11174+ (yield* Ref.get(runningBackgroundTaskIds)).size === 0 &&11175+ (yield* Ref.get(detachedBackgroundCommands)).size === 0 &&11176+ (yield* Ref.get(detachedUnawaitedTools)).size === 0 &&
- @@ -216,10 +219,21 @@216219 | {217220 readonly failure: OrchestrationV2ProviderFailure;218221 readonly threadDisposition: "reusable" | "broken";219222 readonly resumeWith?: string;220223 }221224 | undefined {225+ const { stopReason } = result;222226 const errorText =223227 step?.type === ERROR_STEP_TYPE224228 ? new TextDecoder().decode(step.payload ?? new Uint8Array())225229 : undefined;230+ const reusable = (failure: OrchestrationV2ProviderFailure) =>231+ ({ failure, threadDisposition: "reusable" }) as const;232+ // After ~60m in Agent Platform ADC mode, agy's OAuth refresh fails with context canceled233+ // and session/prompt resolves cleanly with only USER_INPUT recorded and no model output.234+ if (235+ errorText === undefined &&236+ options?.retired !== true &&237+ options?.receivedOutput !== true &&238+ stopReason === "end_turn" &&239+ result.usage === undefined &&@@ -10757,0 +10786,21 @@10786+ const activated = yield* startAcpRuntime(threadId, resumeSessionId).pipe(10787+ Effect.onError(() => reportStartupPhase(undefined)),10788+ );10789+ yield* Ref.set(runtimeRestartRequired, false);10790+ yield* reportStartupPhase(undefined);10791+ yield* Ref.set(activeSessionId, activated.sessionId);10792+ yield* Ref.set(loadingSessionId, null);10793+ yield* setActiveSessionSetup(activated);10794+ rememberTerminalEnvironment(activated.sessionId, yield* readMcpContext(threadId));10795+ yield* resetPublishedCatalogKey;10796+ yield* Ref.set(activeSelection, null);10797+ yield* Ref.set(activeInteractionMode, null);10798+ // A failed prompt may have been dropped, so the fresh runtime sends T3's notes again.10799+ yield* Ref.set(promptInstructionStates, new Map());10800+ yield* Ref.set(promptRuntimeInstructions, new Map());10801+ yield* Ref.set(deliveredAppContext, new Map());10802+ yield* Ref.set(compactionMarkers, new Map());10803+ yield* Ref.set(completedCompactionIds, new Set());10804+ yield* Ref.set(snapshot, emptySnapshotState());10805+ return { restarted: true as const, activated };10806+ }@@ -10757,0 +10784,21 @@10784+ yield* reportStartupPhase("launch");10785+ yield* reportStartupPhase("resume");10786+ const activated = yield* startAcpRuntime(threadId, resumeSessionId).pipe(10787+ Effect.onError(() => reportStartupPhase(undefined)),10788+ );10789+ yield* Ref.set(runtimeRestartRequired, false);10790+ yield* reportStartupPhase(undefined);10791+ yield* Ref.set(activeSessionId, activated.sessionId);10792+ yield* Ref.set(loadingSessionId, null);10793+ yield* setActiveSessionSetup(activated);10794+ rememberTerminalEnvironment(activated.sessionId, yield* readMcpContext(threadId));10795+ yield* resetPublishedCatalogKey;10796+ yield* Ref.set(activeSelection, null);10797+ yield* Ref.set(activeInteractionMode, null);10798+ // A failed prompt may have been dropped, so the fresh runtime sends T3's notes again.10799+ yield* Ref.set(promptInstructionStates, new Map());10800+ yield* Ref.set(promptRuntimeInstructions, new Map());10801+ yield* Ref.set(deliveredAppContext, new Map());10802+ yield* Ref.set(compactionMarkers, new Map());10803+ yield* Ref.set(completedCompactionIds, new Set());10804+ yield* Ref.set(snapshot, emptySnapshotState());@@ -11102,0 +11156,21 @@11156+ !(yield* Ref.get(runtimeRestartRequired)) &&11157+ !acpIsProviderContinuationMessage(turnInput.message)11158+ ? yield* continuationPermit.withPermit(11159+ Effect.gen(function* () {11160+ const startedAtMillis = yield* Ref.get(runtimeStartedAt);11161+ if (11162+ startedAtMillis === null ||11163+ (yield* Clock.currentTimeMillis) - startedAtMillis <11164+ maxRuntimeAgeBeforeTurnMillis11165+ ) {11166+ return false;11167+ }11168+ const hasIdleOutlivingSubagents = [...idleOutlivingSubagents.values()].some(11169+ (entries) => entries.size > 0,11170+ );11171+ return (11172+ !(yield* Ref.get(continuationRequested)) &&11173+ (yield* Ref.get(wakeBuffer)).length === 0 &&11174+ (yield* Ref.get(runningBackgroundTaskIds)).size === 0 &&11175+ (yield* Ref.get(detachedBackgroundCommands)).size === 0 &&11176+ (yield* Ref.get(detachedUnawaitedTools)).size === 0 &&@@ -11102,0 +11164,21 @@11164+ maxRuntimeAgeBeforeTurnMillis11165+ ) {11166+ return false;11167+ }11168+ const hasIdleOutlivingSubagents = [...idleOutlivingSubagents.values()].some(11169+ (entries) => entries.size > 0,11170+ );11171+ return (11172+ !(yield* Ref.get(continuationRequested)) &&11173+ (yield* Ref.get(wakeBuffer)).length === 0 &&11174+ (yield* Ref.get(runningBackgroundTaskIds)).size === 0 &&11175+ (yield* Ref.get(detachedBackgroundCommands)).size === 0 &&11176+ (yield* Ref.get(detachedUnawaitedTools)).size === 0 &&11177+ (yield* Ref.get(carryoverSubagents)) === null &&11178+ !hasIdleOutlivingSubagents11179+ );11180+ }),11181+ )11182+ : false;11183+ if (shouldRecycleStaleRuntime) {11184+ yield* Ref.set(runtimeRestartRequired, true);
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed