Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): keep approvals pending across a same-step runtime action (#1200)

Rui1cd563b3538b
diff --git a/.changeset/hitl-runtime-action-collision.md b/.changeset/hitl-runtime-action-collision.md
new file mode 100644
index 000000000..692152a4b
--- /dev/null
+++ b/.changeset/hitl-runtime-action-collision.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+A model step that requests a tool approval (or question) and a subagent or remote-agent call in the same response no longer drops the approval. The harness now parks on both: the input request surfaces immediately, the delegation runs, and when its result arrives the turn re-parks on the still-pending approval instead of calling the model with a dangling tool call (`AI_MissingToolResultsError`).
diff --git a/e2e/fixtures/agent-subagents-hitl/agent/agent.ts b/e2e/fixtures/agent-subagents-hitl/agent/agent.ts
index 384bb0e2a..c1ec6829d 100644
--- a/e2e/fixtures/agent-subagents-hitl/agent/agent.ts
+++ b/e2e/fixtures/agent-subagents-hitl/agent/agent.ts
@@ -1,7 +1,42 @@
import { e2eAgentConfig } from "@eve-e2e/config";
import { defineAgent } from "eve";
+import type { MockModelRequest, MockModelResponse } from "eve/evals";
+
+const COLLISION_MARKER = "MIXED-PARK-COMPLETE-7K2M";
+
+function respond(request: MockModelRequest): MockModelResponse | string {
+ if (request.lastUserMessage?.includes(COLLISION_MARKER) !== true) {
+ return `Mock reply: ${request.lastUserMessage ?? ""}`;
+ }
+
+ const gateResults = request.toolResults.filter((result) => result.name === "collision-gate");
+ const subagentResults = request.toolResults.filter((result) => result.name === "collision-child");
+
+ if (gateResults.length === 0 && subagentResults.length === 0) {
+ return {
+ toolCalls: [
+ {
+ id: "collision-gate-call",
+ input: { marker: COLLISION_MARKER },
+ name: "collision-gate",
+ },
+ {
+ id: "collision-child-call",
+ input: { message: `Return ${COLLISION_MARKER}.` },
+ name: "collision-child",
+ },
+ ],
+ };
+ }
+
+ if (gateResults.length === 1 && subagentResults.length === 1) {
+ return COLLISION_MARKER;
+ }
+
+ throw new Error("Mixed runtime-action step resumed before both tool results were available.");
+}
export default defineAgent({
- ...e2eAgentConfig(),
+ ...e2eAgentConfig({ mock: respond }),
reasoning: "high",
});
diff --git a/e2e/fixtures/agent-subagents-hitl/agent/subagents/collision-child/agent.ts b/e2e/fixtures/agent-subagents-hitl/agent/subagents/collision-child/agent.ts
new file mode 100644
index 000000000..99a1e4f4e
--- /dev/null
+++ b/e2e/fixtures/agent-subagents-hitl/agent/subagents/collision-child/agent.ts
@@ -0,0 +1,7 @@
+import { e2eSubagentConfig } from "@eve-e2e/config";
+import { defineAgent } from "eve";
+
+export default defineAgent({
+ description: "Return the marker from the request without calling any tools.",
+ ...e2eSubagentConfig(),
+});
diff --git a/e2e/fixtures/agent-subagents-hitl/agent/subagents/collision-child/instructions.md b/e2e/fixtures/agent-subagents-hitl/agent/subagents/collision-child/instructions.md
new file mode 100644
index 000000000..1bbe0c625
--- /dev/null
+++ b/e2e/fixtures/agent-subagents-hitl/agent/subagents/collision-child/instructions.md
@@ -0,0 +1 @@
+Return the marker from the request without calling any tools.
diff --git a/e2e/fixtures/agent-subagents-hitl/agent/tools/collision-gate.ts b/e2e/fixtures/agent-subagents-hitl/agent/tools/collision-gate.ts
new file mode 100644
index 000000000..3b27872f6
--- /dev/null
+++ b/e2e/fixtures/agent-subagents-hitl/agent/tools/collision-gate.ts
@@ -0,0 +1,10 @@
+import { defineTool } from "eve/tools";
+import { always } from "eve/tools/approval";
+import { z } from "zod";
+
+export default defineTool({
+ description: "Return a marker after explicit approval.",
+ inputSchema: z.object({ marker: z.string() }),
+ approval: always(),
+ execute: ({ marker }) => ({ marker }),
+});
diff --git a/e2e/fixtures/agent-subagents-hitl/evals/mixed-runtime-action-approval.eval.ts b/e2e/fixtures/agent-subagents-hitl/evals/mixed-runtime-action-approval.eval.ts
new file mode 100644
index 000000000..20c42636d
--- /dev/null
+++ b/e2e/fixtures/agent-subagents-hitl/evals/mixed-runtime-action-approval.eval.ts
@@ -0,0 +1,42 @@
+import { defineEval } from "eve/evals";
+
+const COLLISION_MARKER = "MIXED-PARK-COMPLETE-7K2M";
+
+/**
+ * Regression coverage for https://github.com/vercel/eve/issues/1201.
+ *
+ * One model step requests an approval-gated tool and a subagent together.
+ * The child may finish first, but the root turn must retain the approval and
+ * re-park instead of resuming the model with an unanswered tool call.
+ */
+export default defineEval({
+ description: "A root approval and subagent call from one model step both survive parking.",
+ async test(t) {
+ const parked = await t.send(
+ [
+ `Call the collision-gate tool with marker "${COLLISION_MARKER}" and the collision-child subagent in the same assistant response.`,
+ "Do not wait for one call before making the other.",
+ `After both results arrive, reply with exactly ${COLLISION_MARKER}.`,
+ ].join("\n"),
+ );
+
+ parked.calledTool("collision-gate", { count: 1, status: "pending" });
+ parked.calledSubagent("collision-child", { count: 1, status: "completed" });
+ parked.eventOrder([
+ { type: "actions.requested" },
+ { type: "input.requested" },
+ { type: "subagent.completed" },
+ { type: "session.waiting" },
+ ]);
+ t.requireInputRequest({ display: "confirmation", toolName: "collision-gate" });
+
+ const resumed = await t.respondAll("approve");
+ resumed.expectOk();
+ resumed.messageIncludes(COLLISION_MARKER);
+
+ t.succeeded();
+ t.noFailedActions();
+ t.calledTool("collision-gate", { count: 1, status: "completed" });
+ t.calledSubagent("collision-child", { count: 1, status: "completed" });
+ },
+});
diff --git a/packages/eve/src/harness/tool-loop.test.ts b/packages/eve/src/harness/tool-loop.test.ts
index 1be53dbdd..3223568cc 100644
--- a/packages/eve/src/harness/tool-loop.test.ts
+++ b/packages/eve/src/harness/tool-loop.test.ts
@@ -1335,6 +1335,117 @@ describe("createToolLoopHarness", () => {
]);
});
+ it("parks on both batches when one step carries a runtime action and an approval", async () => {
+ const gateToolCall = {
+ input: { action: "run" },
+ toolCallId: "gate-1",
+ toolName: "add",
+ type: "tool-call" as const,
+ };
+ const delegateToolCall = {
+ input: { message: "probe" },
+ toolCallId: "delegate-1",
+ toolName: "delegate",
+ type: "tool-call" as const,
+ };
+ setupMockAgent({
+ content: [
+ gateToolCall,
+ { approvalId: "approval-1", toolCallId: "gate-1", type: "tool-approval-request" },
+ delegateToolCall,
+ ],
+ finishReason: "tool-calls",
+ response: {
+ messages: [
+ {
+ content: [
+ gateToolCall,
+ { approvalId: "approval-1", toolCallId: "gate-1", type: "tool-approval-request" },
+ delegateToolCall,
+ ],
+ role: "assistant",
+ },
+ ],
+ },
+ text: "",
+ toolCalls: [gateToolCall, delegateToolCall],
+ toolResults: [],
+ });
+
+ const { emit, events } = createEventCollector();
+ const runStep = createToolLoopHarness(
+ createTestConfig("conversation", emit, { tools: createDelegationToolMap() }),
+ );
+
+ const parked = await runStep(createTestSession(), { message: "Gate and delegate." });
+
+ expect(parked.next).toBeNull();
+ expect(getPendingRuntimeActionBatch(parked.session.state)?.actions).toEqual([
+ expect.objectContaining({ callId: "delegate-1", kind: "subagent-call" }),
+ ]);
+ expect(hasPendingInputBatch(parked.session.state)).toBe(true);
+ expect(events.filter((event) => event.type === "input.requested")).toHaveLength(1);
+
+ const parkedWithRunningDelegate = {
+ ...parked.session,
+ state: {
+ ...parked.session.state,
+ [AGENT_HANDLES_STATE_KEY]: {
+ handles: [
+ {
+ address: {
+ continuationToken: "delegate-token",
+ kind: "agent/local",
+ sessionId: "delegate-session",
+ },
+ identity: {
+ id: "ag_worker:delegate",
+ name: "worker",
+ nodeId: "workers",
+ },
+ operation: {
+ callId: "delegate-1",
+ id: "delegate-operation",
+ kind: "start",
+ parentTurnId: "turn_0",
+ },
+ phase: "running",
+ },
+ ],
+ },
+ },
+ } satisfies HarnessSession;
+ const reparked = await runStep(parkedWithRunningDelegate, {
+ runtimeActionResults: [
+ {
+ callId: "delegate-1",
+ kind: "subagent-result",
+ origin: "child",
+ outcome: {
+ kind: "terminal",
+ result: { kind: "succeeded", output: "delegated-done" },
+ usageDelta: {
+ cacheReadTokens: 0,
+ cacheWriteTokens: 0,
+ inputTokens: 0,
+ outputTokens: 0,
+ },
+ },
+ output: "delegated-done",
+ subagentName: "worker",
+ },
+ ],
+ });
+
+ expect(reparked.next).toBeNull();
+ expect(getPendingRuntimeActionBatch(reparked.session.state)).toBeUndefined();
+ expect(hasPendingInputBatch(reparked.session.state)).toBe(true);
+ const toolMessages = reparked.session.history.filter((message) => message.role === "tool");
+ expect(JSON.stringify(toolMessages)).toContain("delegated-done");
+ expect(events.filter((event) => event.type === "subagent.completed")).toHaveLength(1);
+ expect(events.at(-1)?.type).toBe("session.waiting");
+ });
+
it("publishes declared subagent calls from deeply nested sessions", async () => {
setupMockAgent({
finishReason: "tool-calls",
diff --git a/packages/eve/src/harness/tool-loop.ts b/packages/eve/src/harness/tool-loop.ts
index e5f5b69c4..5a2f7f4ce 100644
--- a/packages/eve/src/harness/tool-loop.ts
+++ b/packages/eve/src/harness/tool-loop.ts
@@ -952,6 +952,16 @@ export function createToolLoopHarness(config: ToolLoopHarnessConfig): StepFn {
stepInput: coordinated.stepInput,
});
if (pending.outcome === "unresolved") {
+ // The runtime-action batch owns the assistant messages. Once that batch
+ // resolves, commit its results before the still-pending HITL batch parks.
+ let parkedSession =
+ resolvedRuntimeActions.outcome === "resolved"
+ ? {
+ ...pending.session,
+ history: [...resolvedRuntimeActions.messages],
+ }
+ : pending.session;
+
if (
emit &&
config.mode === "conversation" &&
@@ -979,10 +989,18 @@ export function createToolLoopHarness(config: ToolLoopHarnessConfig): StepFn {
emissionState = await emitTurnEpilogue(emit, emissionState, config.mode);
return {
next: null,
- session: setHarnessEmissionState(pending.session, emissionState),
+ session: setHarnessEmissionState(parkedSession, emissionState),
};
}
+ if (resolvedRuntimeActions.outcome === "resolved") {
+ if (emit && config.mode === "conversation") {
+ emissionState = await emitTurnEpilogue(emit, emissionState, config.mode);
+ parkedSession = setHarnessEmissionState(parkedSession, emissionState);
+ }
+ return { next: null, session: parkedSession };
+ }
+
return { next: null, session: pending.session };
}
@@ -2445,21 +2463,62 @@ async function handleStepResult(input: {
// parked session carries the default emission state (turnId ""),
// because the post-preamble `setHarnessEmissionState` is dropped by
// the later `session = pending.session` / `maybeCompact` rebinds.
+ if (inputRequests.length === 0) {
+ return {
+ next: null,
+ session: setHarnessEmissionState(
+ setPendingRuntimeActionBatch({
+ actions: pendingRuntimeActions,
+ event: {
+ sequence: emissionState.sequence,
+ stepIndex: emissionState.stepIndex,
+ turnId: emissionState.turnId,
+ },
+ responseMessages,
+ session: { ...baseSession, history: [...promptMessages] },
+ }),
+ advanceStep(emissionState),
+ ),
+ };
+ }
+
+ let parkedSession = setPendingRuntimeActionBatch({
+ actions: pendingRuntimeActions,
+ event: {
+ sequence: emissionState.sequence,
+ stepIndex: emissionState.stepIndex,
+ turnId: emissionState.turnId,
+ },
+ responseMessages,
+ session: { ...baseSession, history: [...promptMessages] },
+ });
+
+ // The runtime-action batch already owns the shared assistant response.
+ parkedSession = appendPendingInputBatch({
+ event: {
+ sequence: emissionState.sequence,
+ stepIndex: emissionState.stepIndex,
+ turnId: emissionState.turnId,
+ },
+ requests: inputRequests,
+ responseMessages: [],
+ session: parkedSession,
+ });
+
+ if (emit) {
+ await emit(
+ createInputRequestedEvent({
+ requests: inputRequests,
+ sequence: emissionState.sequence,
+ stepIndex: emissionState.stepIndex,
+ turnId: emissionState.turnId,
+ }),
+ );
+ }
+
return {
next: null,
- session: setHarnessEmissionState(
- setPendingRuntimeActionBatch({
- actions: pendingRuntimeActions,
- event: {
- sequence: emissionState.sequence,
- stepIndex: emissionState.stepIndex,
- turnId: emissionState.turnId,
- },
- responseMessages,
- session: { ...baseSession, history: [...promptMessages] },
- }),
- advanceStep(emissionState),
- ),
+ session: setHarnessEmissionState(parkedSession, advanceStep(emissionState)),
};
}