Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): proxy delegated ask responses through parents (#3700)

Casey Gowrieb21efb38f616
diff --git a/.changeset/secure-delegated-ask-steering.md b/.changeset/secure-delegated-ask-steering.md
new file mode 100644
index 000000000..75f7d87d1
--- /dev/null
+++ b/.changeset/secure-delegated-ask-steering.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Prevent parent-agent steering text from resolving a delegated child's pending `ctx.ask()` question. Human-facing parent sessions continue to proxy plain-text and structured answers to children by request ID.
diff --git a/e2e/fixtures/agent-subagents-hitl/agent/agent.ts b/e2e/fixtures/agent-subagents-hitl/agent/agent.ts
index b73e6c6e1..fca67b16d 100644
--- a/e2e/fixtures/agent-subagents-hitl/agent/agent.ts
+++ b/e2e/fixtures/agent-subagents-hitl/agent/agent.ts
@@ -2,6 +2,7 @@ import { e2eAgentConfig } from "@eve-e2e/config";
import { defineAgent } from "eve";
import { mockModel, type MockModelRequest, type MockModelResponse } from "eve/evals";
+const APPROVAL_MARKER = "PROXIED-ASK-APPROVED-6R9K";
const COLLISION_MARKER = "MIXED-PARK-COMPLETE-7K2M";
const STOCK_PRICE = "178.92";
@@ -14,6 +15,21 @@ function respond(request: MockModelRequest): MockModelResponse | string {
: JSON.stringify(audit.output);
}
const prompt = request.messages.map((entry) => entry.text).join("\n");
+ if (message.includes("Call the approval-child subagent exactly once")) {
+ return request.toolResults.some((result) => result.name === "approval-child")
+ ? "The approval child is waiting."
+ : {
+ toolCalls: [
+ {
+ input: { message: "Ask whether to deploy, then wait for the answer." },
+ name: "approval-child",
+ },
+ ],
+ };
+ }
+ if (prompt.includes("Background task reporting") && prompt.includes(APPROVAL_MARKER)) {
+ return APPROVAL_MARKER;
+ }
if (message.includes("Call the stock-price subagent exactly once")) {
return request.toolResults.some((result) => result.name === "stock-price")
? "The stock price is being fetched."
diff --git a/e2e/fixtures/agent-subagents-hitl/agent/subagents/approval-child/agent.ts b/e2e/fixtures/agent-subagents-hitl/agent/subagents/approval-child/agent.ts
new file mode 100644
index 000000000..b0b808a60
--- /dev/null
+++ b/e2e/fixtures/agent-subagents-hitl/agent/subagents/approval-child/agent.ts
@@ -0,0 +1,35 @@
+import { defineAgent } from "eve";
+import { mockModel } from "eve/evals";
+
+const MARKER = "PROXIED-ASK-APPROVED-6R9K";
+
+export default defineAgent({
+ description: "Ask for deployment approval and return a fixed marker after approval.",
+ model: mockModel(({ lastUserMessage, messages, toolResults }) => {
+ const result = toolResults.find((entry) => entry.name === "ask_question");
+ if (
+ result !== undefined ||
+ messages.some((entry) => entry.text.includes('"status":"answered"'))
+ ) {
+ return MARKER;
+ }
+ if (lastUserMessage?.includes("Ask whether to deploy") === true) {
+ return {
+ toolCalls: [
+ {
+ input: {
+ options: [
+ { description: "Deploy now.", label: "Approve" },
+ { description: "Do not deploy.", label: "Cancel" },
+ ],
+ question: "Approve the deployment?",
+ },
+ name: "ask_question",
+ },
+ ],
+ };
+ }
+ return `Mock reply: ${lastUserMessage ?? ""}`;
+ }),
+ modelContextWindowTokens: 1_000_000,
+});
diff --git a/e2e/fixtures/agent-subagents-hitl/agent/subagents/approval-child/tools/ask_question.ts b/e2e/fixtures/agent-subagents-hitl/agent/subagents/approval-child/tools/ask_question.ts
new file mode 100644
index 000000000..533cc8526
--- /dev/null
+++ b/e2e/fixtures/agent-subagents-hitl/agent/subagents/approval-child/tools/ask_question.ts
@@ -0,0 +1,3 @@
+import { askQuestion } from "eve/tools/ask_question";
+
+export default askQuestion();
diff --git a/e2e/fixtures/agent-subagents-hitl/evals/proxied-ask-text-response.eval.ts b/e2e/fixtures/agent-subagents-hitl/evals/proxied-ask-text-response.eval.ts
new file mode 100644
index 000000000..2a7e10f5d
--- /dev/null
+++ b/e2e/fixtures/agent-subagents-hitl/evals/proxied-ask-text-response.eval.ts
@@ -0,0 +1,82 @@
+import { defineEval, type EveEvalContext, type EveEvalSession } from "eve/evals";
+
+/** A human text answer resolves the child's proxied request at the parent by request ID. */
+export default defineEval({
+ description: "Plain-text approval at the parent resumes a delegated child's ctx.ask().",
+ timeoutMs: 90_000,
+ async test(t) {
+ const started = await t.send(
+ "Call the approval-child subagent exactly once. Acknowledge its receipt and relay its final result when it completes.",
+ );
+ let parent = started.session;
+ let called = started.events.find(
+ (event) => event.type === "subagent.called" && event.data.name === "approval-child",
+ );
+ if (called?.type !== "subagent.called") {
+ const live = watchNextTurn(t, parent, "approval child dispatch wait");
+ called = await live.waitForEvent("subagent.called", { data: { name: "approval-child" } });
+ parent = live.session;
+ }
+ if (called.type !== "subagent.called") throw new Error("Approval child was not called.");
+ const childTurn = t.target.watchTurn(called.data.childSessionId);
+ const pending = await waitForInput(t, parent);
+ const request = pending.requireInputRequest({
+ prompt: /Approve the deployment/i,
+ toolName: "ask_question",
+ });
+ const parkedChild = await childTurn.result();
+
+ const resumedChild = t.target.watchTurn(called.data.childSessionId, {
+ startIndex: parkedChild.session.state.streamIndex,
+ });
+ const approved = await pending.start("approve");
+ const resolution = await waitForObservedEvent(resumedChild, "input.resolved");
+ if (resolution.type !== "input.resolved") throw new Error("Question was not resolved.");
+ if (
+ !resolution.data.resolutions.some(
+ (entry) =>
+ entry.kind === "question" &&
+ entry.outcome === "answered" &&
+ entry.response?.optionId === request.options?.[0]?.id,
+ )
+ ) {
+ throw new Error("The child did not resolve the proxied question with the selected option.");
+ }
+ await approved.cancel();
+ t.noFailedActions();
+ },
+});
+
+async function waitForInput(t: EveEvalContext, initial: EveEvalSession): Promise<EveEvalSession> {
+ let session = initial;
+ for (let attempt = 0; attempt < 5; attempt += 1) {
+ if (
+ session.pendingInputRequests.some((request) => request.action.toolName === "ask_question")
+ ) {
+ return session;
+ }
+ const turn = await watchNextTurn(t, session, "proxied ask wait").result();
+ turn.noFailedActions();
+ session = turn.session;
+ }
+ throw new Error("Approval child did not surface its ctx.ask() request.");
+}
+
+async function waitForObservedEvent<TType extends "input.resolved">(
+ turn: ReturnType<EveEvalContext["target"]["watchTurn"]>,
+ type: TType,
+) {
+ for (let attempt = 0; attempt < 1_500; attempt += 1) {
+ const event = turn.events.find((candidate) => candidate.type === type);
+ if (event !== undefined) return event;
+ await new Promise((resolve) => setTimeout(resolve, 20));
+ }
+ throw new Error(`Child did not emit ${type}.`);
+}
+
+function watchNextTurn(t: EveEvalContext, session: EveEvalSession, operation: string) {
+ if (session.sessionId === undefined || session.state === undefined) {
+ throw new Error(`${operation} has no parent session cursor.`);
+ }
+ return t.target.watchTurn(session.sessionId, { startIndex: session.state.streamIndex });
+}
diff --git a/packages/eve/src/execution/delegated-session-context.ts b/packages/eve/src/execution/delegated-session-context.ts
new file mode 100644
index 000000000..1dc08a6bc
--- /dev/null
+++ b/packages/eve/src/execution/delegated-session-context.ts
@@ -0,0 +1,10 @@
+/** Returns whether this session was created as a delegated child behind a parent input proxy. */
+export function hasDelegatedSessionContext(
+ serializedContext: Readonly<Record<string, unknown>>,
+): boolean {
+ if (serializedContext["eve.sessionCallback"] !== undefined) return true;
+ const channel = serializedContext["eve.channel"];
+ return (
+ typeof channel === "object" && channel !== null && Reflect.get(channel, "kind") === "subagent"
+ );
+}
diff --git a/packages/eve/src/execution/proxied-deliver-step.ts b/packages/eve/src/execution/proxied-deliver-step.ts
index e608ef57c..a24a86439 100644
--- a/packages/eve/src/execution/proxied-deliver-step.ts
+++ b/packages/eve/src/execution/proxied-deliver-step.ts
@@ -1,4 +1,5 @@
import type { SessionInboxAddress } from "#execution/session-inbox/address.js";
+import { hasDelegatedSessionContext } from "#execution/delegated-session-context.js";
import type { DeliverHookPayload, DeliverPayload } from "#channel/types.js";
import { coalesceDeliverPayloads } from "#execution/deliver-payloads.js";
import {
@@ -69,7 +70,9 @@ export async function routeProxiedDeliverStep(input: {
let parentAction: { readonly kind: "cancel-turn" } | undefined;
// Only a person's own message may answer or skip a pending question.
const resolveMessage =
- sourceDelivery.caller === undefined && sourceDelivery.taskDeliveryId === undefined;
+ !hasDelegatedSessionContext(input.serializedContext ?? {}) &&
+ sourceDelivery.caller === undefined &&
+ sourceDelivery.taskDeliveryId === undefined;
// Every payload routes against the same state, so an answer-hook request
// resolved by an earlier payload is hidden from later ones; its hook accepts
// one answer, and later messages must reach the parent instead.
diff --git a/packages/eve/src/execution/session/entry.ts b/packages/eve/src/execution/session/entry.ts
index f654a59c0..cca5c09b6 100644
--- a/packages/eve/src/execution/session/entry.ts
+++ b/packages/eve/src/execution/session/entry.ts
@@ -12,6 +12,7 @@ import { isHookConflictError } from "#execution/hook-ownership.js";
import { createSessionInbox, type SessionInboxHandle } from "#execution/session-inbox/inbox.js";
import { sessionHookTokens } from "#execution/session/hook-tokens.js";
import { DEFAULT_SESSION_TIMEOUT_MS, sessionTimeoutDeadline } from "#execution/session/timeout.js";
+import { hasDelegatedSessionContext } from "#execution/delegated-session-context.js";
import type { DynamicSubagentAgentConfig } from "#runtime/subagents/dynamic-agent-config.js";
import { attachClientContext, readClientContext } from "#internal/client-context.js";
import { settleContinuationConflictStep } from "#execution/continuation-conflict-step.js";
@@ -127,7 +128,7 @@ async function bootInitialOwner(
inbox,
session: {
anchor: { kind: "self" },
- caller: hasDelegatedCallerContext(serializedContext)
+ caller: hasDelegatedSessionContext(serializedContext)
? await resolveInitialTurnCallerStep({ serializedContext })
: undefined,
capabilities: serializedContext["eve.capabilities"] as SessionCapabilities | undefined,
diff --git a/packages/eve/src/execution/session/turn-step.test.ts b/packages/eve/src/execution/session/turn-step.test.ts
index f12ce4d33..ddb521a0c 100644
--- a/packages/eve/src/execution/session/turn-step.test.ts
+++ b/packages/eve/src/execution/session/turn-step.test.ts
@@ -369,7 +369,7 @@ describe("routeProxiedDeliverStep", () => {
);
});
- it("answers a question once when one delivery carries several messages", async () => {
+ it("answers a root question once when one delivery carries several messages", async () => {
const session = upsertProxyInputRequests({
entries: [
[
@@ -407,6 +407,57 @@ describe("routeProxiedDeliverStep", () => {
});
});
+ it.each([
+ ["local", { "eve.channel": { kind: "subagent" } }],
+ [
+ "remote",
+ {
+ "eve.sessionCallback": {
+ callId: "parent-call",
+ subagentName: "research",
+ token: "parent-token",
+ url: "https://parent.example/eve/v1/callback/parent-token",
+ },
+ },
+ ],
+ ])("does not answer a delegated %s question from steering text", async (_, serializedContext) => {
+ const session = upsertProxyInputRequests({
+ entries: [
+ [
+ "ask-1",
+ {
+ answerHook: {
+ question: {
+ allowFreeform: false,
+ dismissible: false,
+ options: [{ id: "approve", label: "Approve" }],
+ },
+ runId: "run-1",
+ },
+ childContinuationToken: "answer-token",
+ kind: "question",
+ },
+ ],
+ ],
+ forChildContinuationToken: "answer-token",
+ session: createStubSession(),
+ });
+ installSessionStoreMocks([session]);
+
+ const result = await routeProxiedDeliverStep({
+ delivery: { kind: "deliver", payloads: [{ message: "Approve" }] },
+ serializedContext,
+ sessionWritable: createTestWritable(),
+ sessionState: createStubSessionState({ hasProxyInputRequests: true }),
+ });
+
+ expect(resumeHookMock).not.toHaveBeenCalled();
+ expect(result).toMatchObject({
+ kind: "continue",
+ remainder: { payloads: [{ message: "Approve" }] },
+ });
+ });
+
it("forwards descendant input responses as session send commands", async () => {
const auth = {
attributes: {},
@@ -769,6 +820,7 @@ describe("recordTaskInputRequestStep", () => {
childContinuationToken: "eve:workflow-tool-run-answer:run-1:0",
childRequestId: "request-1",
kind: "question",
+ question: {},
taskId: "task-1",
});
expect(result).toMatchObject({
diff --git a/packages/eve/src/execution/tasks/parent/hitl-proxy-steps.test.ts b/packages/eve/src/execution/tasks/parent/hitl-proxy-steps.test.ts
index f0f1c1e66..6d3be38ad 100644
--- a/packages/eve/src/execution/tasks/parent/hitl-proxy-steps.test.ts
+++ b/packages/eve/src/execution/tasks/parent/hitl-proxy-steps.test.ts
@@ -109,6 +109,7 @@ describe("recordTaskInputRequestStep", () => {
childContinuationToken: request.replyTo,
childRequestId: "req-1",
kind: "question",
+ question: {},
taskId: "task-1",
});
});
diff --git a/packages/eve/src/execution/tasks/parent/hitl-proxy-steps.ts b/packages/eve/src/execution/tasks/parent/hitl-proxy-steps.ts
index 70fb51e3f..f5069adc2 100644
--- a/packages/eve/src/execution/tasks/parent/hitl-proxy-steps.ts
+++ b/packages/eve/src/execution/tasks/parent/hitl-proxy-steps.ts
@@ -72,6 +72,12 @@ export async function recordTaskInputRequestStep(input: {
kind: request.kind,
taskId: input.request.taskId,
};
+ if (request.kind === "question") {
+ route.question = {
+ ...(request.allowFreeform !== undefined && { allowFreeform: request.allowFreeform }),
+ ...(request.options !== undefined && { options: [...request.options] }),
+ };
+ }
if (remoteResponseUrl !== undefined) route.childResponseUrl = remoteResponseUrl;
return [parentRequest.requestId, route] as const;
});
diff --git a/packages/eve/src/harness/proxy-input-requests.test.ts b/packages/eve/src/harness/proxy-input-requests.test.ts
index 87ab93799..036cca73d 100644
--- a/packages/eve/src/harness/proxy-input-requests.test.ts
+++ b/packages/eve/src/harness/proxy-input-requests.test.ts
@@ -204,6 +204,7 @@ describe("toProxyInputRequestEntries", () => {
},
childContinuationToken: "child-a",
kind: "question",
+ question: {},
},
],
[
diff --git a/packages/eve/src/harness/proxy-input-requests.ts b/packages/eve/src/harness/proxy-input-requests.ts
index dac11fa8d..a7e755937 100644
--- a/packages/eve/src/harness/proxy-input-requests.ts
+++ b/packages/eve/src/harness/proxy-input-requests.ts
@@ -44,6 +44,8 @@ export interface ProxyInputRequest {
/** Trusted parent-derived capability URL for a remote task child. */
readonly childResponseUrl?: string;
readonly kind: InputRequestKind;
+ /** Question metadata lets the human-facing parent resolve plain text before proxying by ID. */
+ readonly question?: AnswerHookQuestion;
/** Present when the route is authorized by a parent-owned durable task. */
readonly taskId?: string;
}
@@ -222,12 +224,19 @@ export function toProxyInputRequestEntries(
childSessionInbox?: SessionInboxAddress;
childResponseUrl?: string;
readonly kind: InputRequestKind;
+ question?: AnswerHookQuestion;
taskId?: string;
} & { readonly batch: ProxyInputRequestBatch } = {
batch,
childContinuationToken: payload.childContinuationToken,
kind: request.kind,
};
+ if (request.kind === "question") {
+ route.question = {
+ ...(request.allowFreeform !== undefined && { allowFreeform: request.allowFreeform }),
+ ...(request.options !== undefined && { options: [...request.options] }),
+ };
+ }
if (taskId !== undefined) route.taskId = taskId;
if (payload.childSessionInbox?.sessionId === payload.childSessionId) {
route.childSessionInbox = payload.childSessionInbox;
@@ -304,6 +313,8 @@ function parseProxyInputRequest(value: unknown, requestId: string): ProxyInputRe
const batch = "batch" in value ? parseProxyInputRequestBatch(value.batch) : undefined;
const answerHook = "answerHook" in value ? parseAnswerHookRoute(value.answerHook) : undefined;
if ("answerHook" in value && answerHook === undefined) return undefined;
+ const question = "question" in value ? parseAnswerHookQuestion(value.question) : undefined;
+ if ("question" in value && question === undefined) return undefined;
const childSessionInbox = "childSessionInbox" in value ? value.childSessionInbox : undefined;
if (childSessionInbox !== undefined && !isSessionInboxAddress(childSessionInbox))
return undefined;
@@ -315,6 +326,7 @@ function parseProxyInputRequest(value: unknown, requestId: string): ProxyInputRe
childRequestId?: string;
childResponseUrl?: string;
readonly kind: InputRequestKind;
+ question?: AnswerHookQuestion;
taskId?: string;
} = {
childContinuationToken: value.childContinuationToken,
@@ -325,6 +337,7 @@ function parseProxyInputRequest(value: unknown, requestId: string): ProxyInputRe
if (batch !== undefined && batch.requestIds.includes(requestId)) request.batch = batch;
if (typeof childRequestId === "string") request.childRequestId = childRequestId;
if (typeof childResponseUrl === "string") request.childResponseUrl = childResponseUrl;
+ if (question !== undefined) request.question = question;
if (typeof taskId === "string") request.taskId = taskId;
return request;
}
diff --git a/packages/eve/src/subagents/hitl-proxy.ts b/packages/eve/src/subagents/hitl-proxy.ts
index 6c20ff0bd..fa0555425 100644
--- a/packages/eve/src/subagents/hitl-proxy.ts
+++ b/packages/eve/src/subagents/hitl-proxy.ts
@@ -260,7 +260,7 @@ function resolveMessageAgainstQuestions(input: {
([requestId, route]) => route.kind === "question" && input.routable(requestId, route),
);
const questions = pending.flatMap(([requestId, route]) => {
- const question = route.answerHook?.question;
+ const question = route.answerHook?.question ?? route.question;
return question !== undefined ? [{ requestId, ...question }] : [];
});
if (questions.length === 0) return none;