@@ -19,6 +19,7 @@ import * as Exit from "effect/Exit";
1919import * as FileSystem from "effect/FileSystem" ;
2020import * as Layer from "effect/Layer" ;
2121import * as Path from "effect/Path" ;
22+ import * as Queue from "effect/Queue" ;
2223import * as Stream from "effect/Stream" ;
2324import { ChildProcessSpawner } from "effect/process" ;
2425import type * as EffectAcpSchema from "effect-acp/compat" ;
@@ -31,6 +32,7 @@ import { makeAntigravityAcpRuntime } from "../../provider/acp/AntigravityAcpSupp
3132import { normalizeAntigravitySessionUpdate } from "../../provider/acp/AntigravityProtocol.ts" ;
3233import * as IdAllocator from "@t3tools/provider-core/server/IdAllocator" ;
3334import * as ProviderAdapter from "@t3tools/provider-core/server/ProviderAdapter" ;
35+ import { makeTurnInput } from "./AcpAdapterV2.testkit.ts" ;
3436import {
3537 makeAntigravityAcpAdapterFlavor ,
3638 makeAntigravityAdapterV2 ,
@@ -122,6 +124,100 @@ const layerSession = Layer.mergeAll(
122124 TestProviderHost . layer ( ) . pipe ( Layer . provide ( NodeServices . layer ) ) ,
123125) ;
124126
127+ describe ( "AntigravityAdapterV2 harness recovery" , ( ) => {
128+ it . effect ( "fails a broken harness and resumes the same thread in a fresh process" , ( ) =>
129+ Effect . gen ( function * ( ) {
130+ const childProcessSpawner = yield * ChildProcessSpawner . ChildProcessSpawner ;
131+ const fileSystem = yield * FileSystem . FileSystem ;
132+ const path = yield * Path . Path ;
133+ const crypto = yield * Crypto . Crypto ;
134+ const mockAgentPath = yield * path . fromFileUrl (
135+ new URL ( "../../../scripts/acp-mock-agent.ts" , import . meta. url ) ,
136+ ) ;
137+ const workspace = yield * fileSystem . makeTempDirectoryScoped ( ) ;
138+ const requestLogPath = path . join ( workspace , "requests.jsonl" ) ;
139+ let processCount = 0 ;
140+ const instanceId = ProviderInstanceId . make ( "antigravity-recovery-test" ) ;
141+ const adapter = yield * makeAntigravityAdapterV2 ( {
142+ instanceId,
143+ selfInvocation : yield * resolveSelfInvocation ( ) ,
144+ makeRuntime : ( input ) =>
145+ Effect . suspend ( ( ) => {
146+ processCount += 1 ;
147+ return makeAntigravityAcpRuntime ( {
148+ ...input ,
149+ childProcessSpawner,
150+ spawn : {
151+ command : process . execPath ,
152+ args : [ mockAgentPath ] ,
153+ cwd : input . cwd ,
154+ env : {
155+ T3_ACP_ANTIGRAVITY : "1" ,
156+ T3_ACP_REQUEST_LOG_PATH : requestLogPath ,
157+ ...( processCount === 1 ? { T3_ACP_ANTIGRAVITY_HARNESS_FAILURE : "1" } : { } ) ,
158+ } ,
159+ } ,
160+ } ) . pipe ( Effect . provideService ( Crypto . Crypto , crypto ) ) ;
161+ } ) ,
162+ withProcess : ( _stop , task ) => task ,
163+ defaultModel : Effect . succeed ( undefined ) ,
164+ } ) ;
165+ const threadId = ThreadId . make ( "thread-antigravity-recovery" ) ;
166+ const modelSelection = { instanceId, model : "gemini-test-low" } as const ;
167+ const runtimePolicy = ProviderAdapter . ProviderAdapterV2RuntimePolicy . make ( {
168+ runtimeMode : "full-access" ,
169+ interactionMode : "default" ,
170+ cwd : workspace ,
171+ } ) ;
172+ const session = yield * adapter . openSession ( {
173+ threadId,
174+ providerSessionId : ProviderSessionId . make ( "provider-session-antigravity-recovery" ) ,
175+ modelSelection,
176+ runtimePolicy,
177+ } ) ;
178+ const events = yield * Queue . unbounded < ProviderAdapter . ProviderAdapterV2Event > ( ) ;
179+ yield * session . events . pipe (
180+ Stream . runForEach ( ( event ) => Queue . offer ( events , event ) ) ,
181+ Effect . forkScoped ,
182+ ) ;
183+ const providerThread = yield * session . ensureThread ( {
184+ threadId,
185+ modelSelection,
186+ runtimePolicy,
187+ } ) ;
188+ const now = yield * DateTime . now ;
189+ const terminal = Stream . fromQueue ( events ) . pipe (
190+ Stream . filter ( ( event ) => event . type === "turn.terminal" ) ,
191+ Stream . runHead ,
192+ ) ;
193+ yield * session . startTurn (
194+ makeTurnInput ( { threadId, providerThread, instanceId, runtimePolicy, modelSelection, now } ) ,
195+ ) ;
196+ const failed = yield * terminal ;
197+ assert . equal ( failed . _tag , "Some" ) ;
198+ if ( failed . _tag === "Some" ) assert . equal ( failed . value . status , "failed" ) ;
199+ yield * session . startTurn (
200+ makeTurnInput ( {
201+ threadId,
202+ providerThread,
203+ instanceId,
204+ runtimePolicy,
205+ modelSelection,
206+ now,
207+ ordinal : 2 ,
208+ } ) ,
209+ ) ;
210+ const completed = yield * terminal ;
211+ assert . equal ( completed . _tag , "Some" ) ;
212+ if ( completed . _tag === "Some" ) assert . equal ( completed . value . status , "completed" ) ;
213+ assert . equal ( processCount , 2 ) ;
214+ const requests = yield * fileSystem . readFileString ( requestLogPath ) ;
215+ assert . include ( requests , "session/resume" ) ;
216+ assert . include ( requests , "mock-session-1" ) ;
217+ } ) . pipe ( Effect . provide ( layerSession ) , Effect . scoped ) ,
218+ ) ;
219+ } ) ;
220+
125221describe ( "AntigravityAdapterV2 client file system" , ( ) => {
126222 it . effect ( "confines agent file requests to the workspace under full access" , ( ) =>
127223 Effect . gen ( function * ( ) {
0 commit comments