@@ -43,6 +43,7 @@ import * as Queue from "effect/Queue";
4343import * as Schema from "effect/Schema" ;
4444import * as Scope from "effect/Scope" ;
4545import * as Stream from "effect/Stream" ;
46+ import * as TestClock from "effect/testing/TestClock" ;
4647import { Tool } from "effect/ai" ;
4748import { formatClaudeResumeCompactionQuestion } from "@t3tools/shared/claudeCompaction" ;
4849import { HostProcessPlatform } from "@t3tools/shared/hostProcess" ;
@@ -6627,6 +6628,68 @@ describe("ClaudeAdapterV2 background wake turns", () => {
66276628 ) ,
66286629 ) ;
66296630
6631+ it . effect ( "ends a subagent's open call when Stop's close of the CLI times out" , ( ) =>
6632+ Effect . scoped (
6633+ Effect . gen ( function * ( ) {
6634+ const TOOL_USE_ID = "toolu-idle-close-timeout" ;
6635+ const BASH = "toolu-idle-close-timeout-bash" ;
6636+ // close() leaves the stream open, so Stop gives up waiting for it.
6637+ const harness = yield * makeWakeHarnessWithOptions ( ) ;
6638+ const now = yield * DateTime . now ;
6639+ const bashStatuses = ( ) =>
6640+ harness . events . flatMap ( ( event ) =>
6641+ event . type === "turn_item.updated" && event . turnItem . nativeItemRef ?. nativeId === BASH
6642+ ? [ `${ event . turnItem . type } :${ event . turnItem . status } ` ]
6643+ : [ ] ,
6644+ ) ;
6645+ yield * harness . runtime . startTurn (
6646+ makeClaudeTestTurnInput ( {
6647+ threadId : harness . threadId ,
6648+ providerThread : harness . providerThread ,
6649+ now,
6650+ attemptId : RunAttemptId . make ( "attempt-claude-idle-close-timeout" ) ,
6651+ text : "Audit in the background." ,
6652+ attachments : [ ] ,
6653+ } ) ,
6654+ ) ;
6655+ for ( const frame of [
6656+ makeSubagentTaskStartedFrame ( {
6657+ taskId : "task-idle-close-timeout" ,
6658+ toolUseId : TOOL_USE_ID ,
6659+ uuid : "00000000-0000-4000-8000-000000000985" ,
6660+ } ) ,
6661+ ...makeSubagentAssistantFrames ( {
6662+ parentToolUseId : TOOL_USE_ID ,
6663+ uuid : "00000000-0000-4000-8000-000000000986" ,
6664+ bashToolUseId : BASH ,
6665+ } ) ,
6666+ makeResultFrame ( {
6667+ uuid : "00000000-0000-4000-8000-000000000987" ,
6668+ result : "Auditing in the background." ,
6669+ } ) ,
6670+ ] ) {
6671+ yield * Queue . offer ( harness . sdkMessages , frame ) ;
6672+ }
6673+ yield * awaitUntil ( ( ) => harness . terminalEvents ( ) . length === 1 , "launch turn terminal" ) ;
6674+ assert . deepEqual ( bashStatuses ( ) , [ "command_execution:running" ] ) ;
6675+
6676+ const stop = yield * harness . runtime
6677+ . interruptTurn ( {
6678+ providerThread : harness . providerThread ,
6679+ providerTurnId : harness . terminalEvents ( ) [ 0 ] ! . providerTurnId ,
6680+ requestRuntimeRestart : true ,
6681+ } )
6682+ . pipe ( Effect . forkScoped ) ;
6683+ yield * TestClock . adjust ( "10 seconds" ) ;
6684+ yield * Fiber . join ( stop ) ;
6685+ assert . deepEqual ( bashStatuses ( ) , [
6686+ "command_execution:running" ,
6687+ "command_execution:interrupted" ,
6688+ ] ) ;
6689+ } ) . pipe ( Effect . provide ( Layer . merge ( IdAllocator . layer , NodeServices . layer ) ) ) ,
6690+ ) ,
6691+ ) ;
6692+
66306693 it . effect ( "releases held frames before the notification that first names the tool use" , ( ) =>
66316694 Effect . scoped (
66326695 Effect . gen ( function * ( ) {
0 commit comments