@@ -2191,6 +2191,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { |
2191 | 2191 | readonly close?: (sdkMessages: Queue.Queue<SDKMessage>) => Effect.Effect<void>; |
2192 | 2192 | readonly interrupt?: Effect.Effect<void>; |
2193 | 2193 | readonly environment?: NodeJS.ProcessEnv; |
| 2194 | + readonly subagentLaunchToolUseId?: ClaudeAdapterV2.ClaudeAgentSdkQueryRunnerShape["subagentLaunchToolUseId"]; |
2194 | 2195 | // A CLI process opened after the first streams from its own queue, so the |
2195 | 2196 | // first one can exit (Queue.shutdown) and a later turn can start another. |
2196 | 2197 | readonly freshQueueOnReopen?: boolean; |
@@ -2291,7 +2292,7 @@ describe("ClaudeAdapterV2 background wake turns", () => { |
2291 | 2292 | }; |
2292 | 2293 | }), |
2293 | 2294 | forkSession: () => Effect.die("unused forkSession"), |
2294 | | - subagentLaunchToolUseId: () => Effect.succeed(null), |
| 2295 | + subagentLaunchToolUseId: options?.subagentLaunchToolUseId ?? (() => Effect.succeed(null)), |
2295 | 2296 | assertComplete: Effect.void, |
2296 | 2297 | }, |
2297 | 2298 | }); |
@@ -2359,6 +2360,79 @@ describe("ClaudeAdapterV2 background wake turns", () => { |
2359 | 2360 | }); |
2360 | 2361 | const makeWakeHarness = makeWakeHarnessWithOptions(); |
2361 | 2362 |
|
| 2363 | + it.effect("looks up a resumed subagent's launch in the instance's environment", () => |
| 2364 | + Effect.scoped( |
| 2365 | + Effect.gen(function* () { |
| 2366 | + const SEND = "toolu-instance-home-sendmessage"; |
| 2367 | + const lookups: Array<ClaudeAdapterV2.ClaudeAgentSdkSubagentLookupInput> = []; |
| 2368 | + const harness = yield* makeWakeHarnessWithOptions({ |
| 2369 | + environment: { CLAUDE_CONFIG_DIR: "/instance/claude-home" }, |
| 2370 | + subagentLaunchToolUseId: (input) => |
| 2371 | + Effect.sync(() => { |
| 2372 | + lookups.push(input); |
| 2373 | + return null; |
| 2374 | + }), |
| 2375 | + }); |
| 2376 | + yield* harness.runtime.startTurn( |
| 2377 | + makeClaudeTestTurnInput({ |
| 2378 | + threadId: harness.threadId, |
| 2379 | + providerThread: harness.providerThread, |
| 2380 | + now: yield* DateTime.now, |
| 2381 | + attemptId: RunAttemptId.make("attempt-claude-instance-home-resume"), |
| 2382 | + text: "Ask the auditor to check again.", |
| 2383 | + attachments: [], |
| 2384 | + }), |
| 2385 | + ); |
| 2386 | + // A subagent launched before a restart: its SendMessage resume names |
| 2387 | + // a task this session never saw start. |
| 2388 | + yield* harness.offerAndWait( |
| 2389 | + claudeSdkFrame({ |
| 2390 | + type: "assistant", |
| 2391 | + message: { |
| 2392 | + model: "claude-sonnet-4-6", |
| 2393 | + id: "msg_instance_home_sendmessage", |
| 2394 | + type: "message", |
| 2395 | + role: "assistant", |
| 2396 | + content: [ |
| 2397 | + { |
| 2398 | + type: "tool_use", |
| 2399 | + id: SEND, |
| 2400 | + name: "SendMessage", |
| 2401 | + input: { to: "task-before-restart", message: "Check again." }, |
| 2402 | + }, |
| 2403 | + ], |
| 2404 | + }, |
| 2405 | + parent_tool_use_id: null, |
| 2406 | + uuid: "00000000-0000-4000-8000-000000002101", |
| 2407 | + session_id: WAKE_NATIVE_SESSION, |
| 2408 | + }), |
| 2409 | + ); |
| 2410 | + yield* harness.offerAndWait( |
| 2411 | + claudeSdkFrame({ |
| 2412 | + type: "system", |
| 2413 | + subtype: "task_started", |
| 2414 | + task_id: "task-before-restart", |
| 2415 | + tool_use_id: SEND, |
| 2416 | + description: "Audit recent commits", |
| 2417 | + is_backgrounded: true, |
| 2418 | + task_type: "local_agent", |
| 2419 | + prompt: "Check again.", |
| 2420 | + uuid: "00000000-0000-4000-8000-000000002102", |
| 2421 | + session_id: WAKE_NATIVE_SESSION, |
| 2422 | + }), |
| 2423 | + ); |
| 2424 | + assert.deepEqual( |
| 2425 | + lookups.map((lookup) => lookup.environment?.CLAUDE_CONFIG_DIR), |
| 2426 | + ["/instance/claude-home"], |
| 2427 | + ); |
| 2428 | + }).pipe( |
| 2429 | + Effect.provide( |
| 2430 | + Layer.mergeAll(IdAllocator.layer, McpProviderSessions.layer, NodeServices.layer), |
| 2431 | + ), |
| 2432 | + ), |
| 2433 | + ), |
| 2434 | + ); |
| 2435 | + |
2362 | 2436 | it.effect.each([ |
2363 | 2437 | { isError: false, title: "Check weather" }, |
2364 | 2438 | { isError: true, title: "Check weather" }, |
|