Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
e03843d
fix(provider-acp): background subagents no longer hold a Grok run who…
juliusmarminge Oct 10, 2026
2588e17
test(server): narrow the Waiting roster's subagent entry in the Grok …
juliusmarminge Oct 10, 2026
e9436e1
test(server): ACP subagent carryover tests interrupt a prompting root
juliusmarminge Oct 10, 2026
a69e36b
test(server): settled-soft ACP interrupt tests hold the root with a m…
juliusmarminge Oct 10, 2026
ba1f00a
test(server): only the first ACP runtime holds the root in settled-so…
juliusmarminge Oct 10, 2026
45abd8b
test(server): ACP held-root tests with in-turn subagent terminals hol…
juliusmarminge Oct 10, 2026
fefe667
fix(provider-acp): a Grok subagent's tool calls before its session is…
juliusmarminge Oct 10, 2026
d9250c8
refactor(provider-acp): drop the unreachable nested-subagent carryove…
juliusmarminge Oct 10, 2026
307dfab
test(server): Grok lineage replay checks each child thread's exact it…
juliusmarminge Oct 10, 2026
55f95c4
Merge origin/main into fix/grok-held-turns
juliusmarminge Oct 11, 2026
3e22727
Merge origin/main into fix/grok-held-turns
juliusmarminge Oct 16, 2026
0e6ce1d
fix(provider-acp): Stop ends a carried-over subagent's open tool calls
juliusmarminge Oct 16, 2026
dfc6320
Merge remote-tracking branch 'origin/main' into fix/grok-held-turns
juliusmarminge Oct 16, 2026
7cb520a
Merge remote-tracking branch 'origin/main' into fix/grok-held-turns
juliusmarminge Oct 19, 2026
e3752a2
test(acp): reduce Grok background subagent lifecycle coverage
juliusmarminge Oct 19, 2026
0ff9d6a
refactor(provider-acp): carry child tools with their subagent
juliusmarminge Oct 19, 2026
1c2883b
test(grok): preserve early child tools after long assistant streams
juliusmarminge Oct 19, 2026
04672e8
fix(provider-acp): preserve child tools across long assistant streams
juliusmarminge Oct 19, 2026
1ff96db
Merge origin/main and use native child tool projection for Grok carry…
juliusmarminge Oct 20, 2026
2005fda
chore(provider-acp): remove unused child replay session read
juliusmarminge Oct 20, 2026
aa21bbc
Merge origin/main into fix/grok-held-turns
juliusmarminge Nov 22, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 168 additions & 0 deletions apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9501,6 +9501,174 @@ describe("AcpAdapterV2", () => {
}).pipe(Effect.provide(layerTest)),
);

// Process-group teardown uses the live clock; observations wait on provider events.
it.live.each(["idle", "adopted"] as const)(
"completes the root and stops child tools while the subagent is %s",
(stopWhile) =>
Effect.gen(function* () {
const instanceId = ProviderInstanceId.make("acp-test");
const threadId = ThreadId.make(`thread-acp-stop-child-${stopWhile}`);
const childSessionId = "mock-child-session-stop-tools";
const secondPromptEntered = yield* Deferred.make<void>();
let promptCount = 0;
type RuntimeService = AcpSessionRuntime.AcpSessionRuntime["Service"];
let sessionUpdateHandler: Parameters<RuntimeService["handleSessionUpdate"]>[0] | undefined;
const adapter = yield* makeAcpAdapterV2({
instanceId,
selfInvocation: yield* resolveSelfInvocation(),
flavor: {
driver: ACP_TEST_DRIVER,
capabilities: AcpProviderCapabilitiesV2,
deferFinalizeForBackgroundWork: true,
subagentsOutliveTurn: true,
restartRuntimeAfterInterrupt: true,
terminateRuntimeProcessGroupOnInterrupt: true,
preserveRuntimeOnSettledInterrupt: true,
extractSubagentUpdate: (toolCall) =>
toolCall.toolCallId === "tool-call-generic-1"
? {
nativeTaskId: "task-generic-1",
prompt: "background subagent",
title: "background subagent",
model: null,
status: "running",
childSessionId,
result: null,
}
: undefined,
makeRuntime: makeMockRuntime({
childProcessSpawner: yield* ChildProcessSpawner.ChildProcessSpawner,
mockAgentPath: yield* bundledMockAgentPath,
environment: { T3_ACP_EMIT_GENERIC_TOOL_PLACEHOLDERS: "1" },
ownDetachedProcessGroup: true,
wrapRuntime: (runtime) => ({
...runtime,
handleSessionUpdate: (handler) =>
Effect.sync(() => {
sessionUpdateHandler = handler;
}).pipe(Effect.andThen(runtime.handleSessionUpdate(handler))),
prompt: (payload) =>
++promptCount === 2
? Deferred.succeed(secondPromptEntered, undefined).pipe(
Effect.andThen(Effect.never),
)
: runtime.prompt(payload),
}),
}),
},
});
const runtimePolicy = ProviderAdapter.ProviderAdapterV2RuntimePolicy.make({
runtimeMode: "full-access",
interactionMode: "default",
cwd: process.cwd(),
});
const modelSelection = { instanceId, model: "default" } as const;
const runtime = yield* adapter.openSession({
threadId,
providerSessionId: ProviderSessionId.make(`session-acp-stop-child-${stopWhile}`),
modelSelection,
runtimePolicy,
});
const providerThread = yield* runtime.ensureThread({
threadId,
modelSelection,
runtimePolicy,
});
const startTurn = (ordinal: number) =>
DateTime.now.pipe(
Effect.flatMap((now) =>
runtime.startTurn(
makeTurnInput({
threadId,
providerThread,
instanceId,
runtimePolicy,
now,
ordinal,
}),
),
),
);
yield* startTurn(1);
const rootEvents = yield* runtime.events.pipe(
Stream.takeUntil((event) => event.type === "turn.terminal"),
Stream.runCollect,
);
const terminal = rootEvents.find((event) => event.type === "turn.terminal");
assert.isDefined(terminal);
assert.equal(terminal.status, "completed");
const subagent = rootEvents
.flatMap((event) =>
event.type === "turn_item.updated" && event.turnItem.type === "subagent"
? [event.turnItem]
: [],
)
.at(-1);
assert.isDefined(subagent);
assert.equal(subagent.status, "running");

assert.isDefined(sessionUpdateHandler);
yield* sessionUpdateHandler({
sessionId: childSessionId,
update: {
sessionUpdate: "tool_call",
toolCallId: "child-tool-call-1",
title: "Child read",
kind: "read",
status: "in_progress",
rawInput: {},
},
});
const isChildTool = (event: ProviderAdapter.ProviderAdapterV2Event) =>
event.type === "turn_item.updated" &&
event.turnItem.nativeItemRef?.nativeId?.includes("child-tool-call-1") === true;
const idleEvents = yield* runtime.events.pipe(
Stream.takeUntil(isChildTool),
Stream.runCollect,
);
const childTool = idleEvents.find(isChildTool);
assert.isDefined(childTool);
if (childTool.type !== "turn_item.updated") return yield* Effect.die("Missing child tool");
assert.notEqual(childTool.turnItem.threadId, threadId);
assert.equal(childTool.turnItem.status, "running");

const idAllocator = yield* IdAllocator.IdAllocatorV2;
let stoppedProviderTurnId = terminal.providerTurnId;
if (stopWhile === "adopted") {
yield* startTurn(2);
yield* Deferred.await(secondPromptEntered);
stoppedProviderTurnId = idAllocator.derive.providerTurn({
driver: ACP_TEST_DRIVER,
nativeTurnId: acpScopedNativeId(instanceId, "mock-session-1:turn:2"),
});
}
yield* runtime.interruptTurn({
providerThread,
providerTurnId: stoppedProviderTurnId,
requestRuntimeRestart: true,
});
const stoppedEvents = yield* runtime.events.pipe(
Stream.takeUntil((event) =>
stopWhile === "adopted"
? event.type === "turn.terminal" && event.providerTurnId === stoppedProviderTurnId
: isChildTool(event) &&
event.type === "turn_item.updated" &&
event.turnItem.status === "interrupted",
),
Stream.runCollect,
);
const childUpdates = [...rootEvents, ...idleEvents, ...stoppedEvents].flatMap((event) =>
isChildTool(event) && event.type === "turn_item.updated" ? [event.turnItem] : [],
);
assert.deepEqual(
childUpdates.map((item) => item.status),
["running", "interrupted"],
);
assert.isTrue(childUpdates.every((item) => item.threadId === childTool.turnItem.threadId));
assert.isTrue(childUpdates.every((item) => item.id === childTool.turnItem.id));
}).pipe(Effect.provide(layerTest), Effect.scoped),
);

it.effect("projects completed-root carryover eagerly and drain cannot resurrect it", () =>
Effect.gen(function* () {
const childProcessSpawner = yield* ChildProcessSpawner.ChildProcessSpawner;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,18 @@
{"type":"emit_inbound","label":"notification:_x.ai/session_notification:subagent_progress","frame":{"kind":"notification","method":"_x.ai/session_notification","params":{"sessionId":"00000000-0000-4000-8000-000000000001","update":{"sessionUpdate":"subagent_progress","subagent_id":"00000000-0000-4000-8000-000000000002","attempt_id":"at1.bd80fbaa7c40408eb7999e19714ed4e1","parent_session_id":"00000000-0000-4000-8000-000000000001","child_session_id":"00000000-0000-4000-8000-000000000002","duration_ms":10066,"turn_count":1,"tool_call_count":0,"tokens_used":2912,"context_window_tokens":500000,"context_usage_pct":0,"tools_used":[],"error_count":0}}}}
{"type":"emit_inbound","label":"notification:_x.ai/task_backgrounded:task_backgrounded","frame":{"kind":"notification","method":"_x.ai/task_backgrounded","params":{"sessionId":"00000000-0000-4000-8000-000000000002","update":{"sessionUpdate":"task_backgrounded","tool_call_id":"call-d5448d70-380d-4a88-a7a0-2968806350ea-0","task_id":"call-d5448d70-380d-4a88-a7a0-2968806350ea-0","command":"sleep 20","cwd":"<workspace>","output_file":"/home/grok-replay/.grok/sessions/%3Cworkspace%3E/00000000-0000-4000-8000-000000000002/terminal/call-d5448d70-380d-4a88-a7a0-2968806350ea-0.log","description":"Sleep for 20 seconds as requested"},"_meta":{"eventId":"00000000-0000-4000-8000-000000000002-170","agentTimestampMs":1790321099801}}}}
{"type":"emit_inbound","label":"notification:_x.ai/session_notification:background_tasks","frame":{"kind":"notification","method":"_x.ai/session_notification","params":{"sessionId":"00000000-0000-4000-8000-000000000002","update":{"sessionUpdate":"background_tasks","tasks":[{"task_id":"call-d5448d70-380d-4a88-a7a0-2968806350ea-0","command":"sleep 20","description":"Sleep for 20 seconds as requested","cwd":"<workspace>","kind":"bash","status":"running","started_at":"2026-09-25T07:24:44.780647541+00:00","output_file":"/home/grok-replay/.grok/sessions/%3Cworkspace%3E/00000000-0000-4000-8000-000000000002/terminal/call-d5448d70-380d-4a88-a7a0-2968806350ea-0.log"}]},"_meta":{"eventId":"00000000-0000-4000-8000-000000000002-172","agentTimestampMs":1790321099801}}}}
{"type":"expect_outbound","label":"request:session/prompt:t3-xai-prompt-2","frame":{"kind":"request","method":"session/prompt","params":{"sessionId":"00000000-0000-4000-8000-000000000001","prompt":[{"type":"text","text":"Reply exactly QUEUED_DONE."}],"_meta":{"promptId":"t3-xai-prompt-2","requestId":"t3-xai-prompt-2"}}}}
{"type":"emit_inbound","label":"notification:session/update:agent_message_chunk:t3-xai-prompt-2","frame":{"kind":"notification","method":"session/update","params":{"sessionId":"00000000-0000-4000-8000-000000000001","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"QUEUED"}},"_meta":{"promptId":"t3-xai-prompt-2","agentTimestampMs":1790321085000,"updateType":"AgentMessageChunk","chunkId":1}}}}
{"type":"emit_inbound","label":"notification:session/update:agent_message_chunk:t3-xai-prompt-2","frame":{"kind":"notification","method":"session/update","params":{"sessionId":"00000000-0000-4000-8000-000000000001","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"_DONE"}},"_meta":{"promptId":"t3-xai-prompt-2","agentTimestampMs":1790321085001,"updateType":"AgentMessageChunk","chunkId":2}}}}
{"type":"emit_inbound","label":"notification:_x.ai/session_notification:turn_completed:t3-xai-prompt-2","frame":{"kind":"notification","method":"_x.ai/session_notification","params":{"sessionId":"00000000-0000-4000-8000-000000000001","update":{"sessionUpdate":"turn_completed","prompt_id":"t3-xai-prompt-2","stop_reason":"end_turn"}}}}
{"type":"emit_inbound","label":"notification:_x.ai/session/prompt_complete","frame":{"kind":"notification","method":"_x.ai/session/prompt_complete","params":{"sessionId":"00000000-0000-4000-8000-000000000001","promptId":"t3-xai-prompt-2","stopReason":"end_turn","agentResult":null}}}
{"type":"emit_inbound","label":"response:session/prompt","frame":{"kind":"response","method":"session/prompt","result":{"stopReason":"end_turn","_meta":{"sessionId":"00000000-0000-4000-8000-000000000001","requestId":"t3-xai-prompt-2","promptId":"t3-xai-prompt-2"}}}}
{"type":"expect_outbound","label":"request:session/prompt:t3-xai-prompt-3","frame":{"kind":"request","method":"session/prompt","params":{"sessionId":"00000000-0000-4000-8000-000000000001","prompt":[{"type":"text","text":"Reply exactly STEER_DONE."}],"_meta":{"promptId":"t3-xai-prompt-3","requestId":"t3-xai-prompt-3"}}}}
{"type":"emit_inbound","label":"notification:session/update:agent_message_chunk:t3-xai-prompt-3","frame":{"kind":"notification","method":"session/update","params":{"sessionId":"00000000-0000-4000-8000-000000000001","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"STEER"}},"_meta":{"promptId":"t3-xai-prompt-3","agentTimestampMs":1790321086000,"updateType":"AgentMessageChunk","chunkId":1}}}}
{"type":"emit_inbound","label":"notification:session/update:agent_message_chunk:t3-xai-prompt-3","frame":{"kind":"notification","method":"session/update","params":{"sessionId":"00000000-0000-4000-8000-000000000001","update":{"sessionUpdate":"agent_message_chunk","content":{"type":"text","text":"_DONE"}},"_meta":{"promptId":"t3-xai-prompt-3","agentTimestampMs":1790321086001,"updateType":"AgentMessageChunk","chunkId":2}}}}
{"type":"emit_inbound","label":"notification:_x.ai/session_notification:turn_completed:t3-xai-prompt-3","frame":{"kind":"notification","method":"_x.ai/session_notification","params":{"sessionId":"00000000-0000-4000-8000-000000000001","update":{"sessionUpdate":"turn_completed","prompt_id":"t3-xai-prompt-3","stop_reason":"end_turn"}}}}
{"type":"emit_inbound","label":"notification:_x.ai/session/prompt_complete","frame":{"kind":"notification","method":"_x.ai/session/prompt_complete","params":{"sessionId":"00000000-0000-4000-8000-000000000001","promptId":"t3-xai-prompt-3","stopReason":"end_turn","agentResult":null}}}
{"type":"emit_inbound","label":"response:session/prompt","frame":{"kind":"response","method":"session/prompt","result":{"stopReason":"end_turn","_meta":{"sessionId":"00000000-0000-4000-8000-000000000001","requestId":"t3-xai-prompt-3","promptId":"t3-xai-prompt-3"}}}}
{"type":"emit_inbound","label":"notification:session/update:tool_call_update:01a0d773-bfa9-72a1-b268-790ccebae43f","frame":{"kind":"notification","method":"session/update","params":{"sessionId":"00000000-0000-4000-8000-000000000002","update":{"sessionUpdate":"tool_call_update","toolCallId":"call-d5448d70-380d-4a88-a7a0-2968806350ea-0","status":"completed","title":"[bg] sleep 20 (call-d54)","content":[{"type":"content","content":{"type":"text","text":"Command \"Sleep for 20 seconds as requested\" has been automatically moved to background because it exceeded auto-background timeout limit of 15s. Process is still running."}}],"rawOutput":{"type":"BackgroundTaskStarted","task_id":"call-d5448d70-380d-4a88-a7a0-2968806350ea-0","task_type":"bash","output_file":"/home/grok-replay/.grok/sessions/%3Cworkspace%3E/00000000-0000-4000-8000-000000000002/terminal/call-d5448d70-380d-4a88-a7a0-2968806350ea-0.log","status":"running","command":"sleep 20","summary":"Command \"Sleep for 20 seconds as requested\" has been automatically moved to background because it exceeded auto-background timeout limit of 15s. Process is still running.","retrieval_hint":"Use get_command_or_subagent_output with task_ids=[\"call-d5448d70-380d-4a88-a7a0-2968806350ea-0\"] when you need the output.","pid":2584853}},"_meta":{"totalTokens":13313,"eventId":"00000000-0000-4000-8000-000000000002-173","agentTimestampMs":1790321099802,"promptId":"01a0d773-bfa9-72a1-b268-790ccebae43f","streamStartMs":1790321082753,"turnStartMs":1790321082313,"updateType":"ToolCallUpdate","updateParams":{"toolCallId":"call-d5448d70-380d-4a88-a7a0-2968806350ea-0","status":"Completed"}}}}}
{"type":"emit_inbound","label":"notification:_x.ai/session_notification:subagent_progress","frame":{"kind":"notification","method":"_x.ai/session_notification","params":{"sessionId":"00000000-0000-4000-8000-000000000001","update":{"sessionUpdate":"subagent_progress","subagent_id":"00000000-0000-4000-8000-000000000002","attempt_id":"at1.bd80fbaa7c40408eb7999e19714ed4e1","parent_session_id":"00000000-0000-4000-8000-000000000001","child_session_id":"00000000-0000-4000-8000-000000000002","duration_ms":18067,"turn_count":1,"tool_call_count":1,"tokens_used":13480,"context_window_tokens":500000,"context_usage_pct":2,"tools_used":["run_terminal_command"],"error_count":0}}}}
{"type":"emit_inbound","label":"notification:session/update:agent_thought_chunk:01a0d773-bfa9-72a1-b268-790ccebae43f","frame":{"kind":"notification","method":"session/update","params":{"sessionId":"00000000-0000-4000-8000-000000000002","update":{"sessionUpdate":"agent_thought_chunk","content":{"type":"text","text":"The"}},"_meta":{"totalTokens":13480,"eventId":"00000000-0000-4000-8000-000000000002-177","agentTimestampMs":1790321101461,"promptId":"01a0d773-bfa9-72a1-b268-790ccebae43f","streamStartMs":1790321100147,"turnStartMs":1790321082313,"updateType":"AgentThoughtChunk","chunkId":1}}}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,28 @@ import type { OrchestratorFixtureInput } from "../shared.ts";

export const GROK_BACKGROUND_SUBAGENT_PROMPT =
"Spawn one background subagent (run it in the background, do not wait for it) whose task is: run the shell command 'sleep 20' and then reply exactly SUBAGENT_DONE. As soon as the subagent is launched, end your turn by replying exactly ROOT_DONE without waiting for it.";
export const GROK_BACKGROUND_SUBAGENT_QUEUED_PROMPT = "Reply exactly QUEUED_DONE.";
export const GROK_BACKGROUND_SUBAGENT_STEER_PROMPT = "Reply exactly STEER_DONE.";

const GROK_SUBAGENT_WAKE_LABEL =
"notification:session/update:agent_message_chunk:subagent-completed-00000000-0000-4000-8000-000000000002";

// Hold run 1 until subagent_finished and the adapter's settlement debounce.
// The queued and steered exchanges are synthetic, based on the recorded Grok
// 1.0.41 second-prompt exchange in message_steering.
export function grokBackgroundSubagentInput(): OrchestratorFixtureInput {
return {
steps: [
{ type: "message", text: GROK_BACKGROUND_SUBAGENT_PROMPT },
{ type: "finish_held_run", targetRunIndex: 1, status: "completed" },
{ type: "queue_message", text: GROK_BACKGROUND_SUBAGENT_QUEUED_PROMPT },
{ type: "capture_shell_snapshot", key: "while-subagent-runs" },
{
type: "steer",
text: GROK_BACKGROUND_SUBAGENT_STEER_PROMPT,
targetRunIndex: 1,
targetReplyFinished: true,
},
{ type: "release_replay_gate", label: GROK_SUBAGENT_WAKE_LABEL },
{ type: "finish_held_run", targetRunIndex: 2, status: "completed" },
{ type: "finish_held_run", targetRunIndex: 4, status: "completed" },
],
};
}
Loading
Loading