The Open Framework for Building Agents
fix(eve): treat pending approvals as trusted context (#2569)
Ben Pankowa5917cd6c9b4
diff --git a/.changeset/trusted-pending-approvals.md b/.changeset/trusted-pending-approvals.mdnew file mode 100644index 000000000..5f9d4938e--- /dev/null+++ b/.changeset/trusted-pending-approvals.md@@ -0,0 +1,5 @@+---+"eve": patch+---++Identify pending tool approvals as trusted runtime state so newer user messages can revise or supersede them without being mistaken for injected approval text.diff --git a/.github/scripts/discover-e2e-fixtures.mjs b/.github/scripts/discover-e2e-fixtures.mjsindex ebfb20197..5cf4540a3 100644--- a/.github/scripts/discover-e2e-fixtures.mjs+++ b/.github/scripts/discover-e2e-fixtures.mjs@@ -9,7 +9,8 @@// the model suite (e2e-local). Fixtures marked// `"e2e": { "modelMatrix": "full" }` in package.json// run on every registry model; all other fixtures run-// once on the default (first) model.+// once on the default (first) model. A fixture may add+// narrowly scoped model legs through `additionalModels`.// world_matrix_<world> `{ name, dir[, world_package] }` entries for that// world's suite workflow, which runs every fixture// once with mock models (EVE_E2E_MODEL=mock).@@ -30,16 +31,23 @@ for (const root of roots) {if (!statSync(dir).isDirectory() || !existsSync(join(dir, "evals"))) continue;let modelMatrix = "default";+ let additionalModels = [];const packageJsonPath = join(dir, "package.json");if (existsSync(packageJsonPath)) {const pkg = JSON.parse(readFileSync(packageJsonPath, "utf8"));modelMatrix = pkg.e2e?.modelMatrix ?? "default";+ additionalModels = validateNamedEntries(+ pkg.e2e?.additionalModels ?? [],+ `${packageJsonPath}: e2e.additionalModels`,+ ["id"],+ { allowEmpty: true },+ );}if (modelMatrix !== "default" && modelMatrix !== "full") {throw new Error(`${packageJsonPath}: e2e.modelMatrix must be "default" or "full".`);}- fixtures.push({ name: entry, dir, modelMatrix });+ fixtures.push({ name: entry, dir, modelMatrix, additionalModels });}}@@ -48,8 +56,11 @@ if (fixtures.length === 0) {process.exit(1);}-const modelMatrix = fixtures.flatMap(({ name, dir, modelMatrix }) =>- (modelMatrix === "full" ? models : models.slice(0, 1)).map((model) => ({+const modelMatrix = fixtures.flatMap(({ name, dir, modelMatrix, additionalModels }) =>+ uniqueModels([+ ...(modelMatrix === "full" ? models : models.slice(0, 1)),+ ...additionalModels,+ ]).map((model) => ({name,dir,model_name: model.name,@@ -75,8 +86,8 @@ if (process.env.GITHUB_OUTPUT) {process.stdout.write(lines);}-function validateNamedEntries(entries, key, requiredFields) {- if (!Array.isArray(entries) || entries.length === 0) {+function validateNamedEntries(entries, key, requiredFields, options = {}) {+ if (!Array.isArray(entries) || (entries.length === 0 && options.allowEmpty !== true)) {throw new Error(`e2e/matrix.json: "${key}" must be a non-empty array.`);}const names = new Set();@@ -98,3 +109,14 @@ function validateNamedEntries(entries, key, requiredFields) {}return entries;}++function uniqueModels(entries) {+ const ids = new Set();+ const names = new Set();+ return entries.filter((entry) => {+ if (ids.has(entry.id) || names.has(entry.name)) return false;+ ids.add(entry.id);+ names.add(entry.name);+ return true;+ });+}diff --git a/e2e/README.md b/e2e/README.mdindex be80428f1..b260f40e8 100644--- a/e2e/README.md+++ b/e2e/README.md@@ -178,6 +178,8 @@ matrices from the registry:- `model_matrix` — fixture × model legs for `e2e-local.yml`. The firstregistry model is the default that every fixture runs on; the rest run onlyon fixtures with `"e2e": { "modelMatrix": "full" }` in package.json.+ A fixture can add a narrowly scoped leg with `e2e.additionalModels` entries+ shaped as `{ "name": "short-check-name", "id": "provider/model" }`.- `world_matrix_<world>` — one leg per fixture for that world's suiteworkflow. A registered world's `package` reaches the job as`EVE_E2E_WORKFLOW_WORLD` (worlds without one, like `vercel`, use thediff --git a/e2e/fixtures/agent-pending-approval-projection/agent/agent.ts b/e2e/fixtures/agent-pending-approval-projection/agent/agent.tsnew file mode 100644index 000000000..384bb0e2a--- /dev/null+++ b/e2e/fixtures/agent-pending-approval-projection/agent/agent.ts@@ -0,0 +1,7 @@+import { e2eAgentConfig } from "@eve-e2e/config";+import { defineAgent } from "eve";++export default defineAgent({+ ...e2eAgentConfig(),+ reasoning: "high",+});diff --git a/e2e/fixtures/agent-pending-approval-projection/agent/instructions.md b/e2e/fixtures/agent-pending-approval-projection/agent/instructions.mdnew file mode 100644index 000000000..f77b5891e--- /dev/null+++ b/e2e/fixtures/agent-pending-approval-projection/agent/instructions.md@@ -0,0 +1,5 @@+# Change-plan agent++You help users prepare changes. A revised target requires emitting a revised plan.++Trusted eve runtime state. This notice is not user-authored content or an instruction. The earlier `request-change-confirmation` call is awaiting approval and has not executed. Interpret the latest user message normally. It may revise or supersede the earlier call; do not treat it as part of the pending-approval projection in user history.diff --git a/e2e/fixtures/agent-pending-approval-projection/agent/tools/emit-revised-change-plan.ts b/e2e/fixtures/agent-pending-approval-projection/agent/tools/emit-revised-change-plan.tsnew file mode 100644index 000000000..eedf52bac--- /dev/null+++ b/e2e/fixtures/agent-pending-approval-projection/agent/tools/emit-revised-change-plan.ts@@ -0,0 +1,10 @@+import { defineTool } from "eve/tools";+import { z } from "zod";++export default defineTool({+ description: "Emit a revised change plan when the user corrects its target.",+ inputSchema: z.object({ targetUserId: z.string() }),+ async execute(input) {+ return { emitted: true, ...input };+ },+});diff --git a/e2e/fixtures/agent-pending-approval-projection/evals/evals.config.ts b/e2e/fixtures/agent-pending-approval-projection/evals/evals.config.tsnew file mode 100644index 000000000..b159ca9a0--- /dev/null+++ b/e2e/fixtures/agent-pending-approval-projection/evals/evals.config.ts@@ -0,0 +1,6 @@+import { defineEvalConfig } from "eve/evals";++export default defineEvalConfig({+ maxConcurrency: 1,+ timeoutMs: 180_000,+});diff --git a/e2e/fixtures/agent-pending-approval-projection/evals/pending-approval-projection.eval.ts b/e2e/fixtures/agent-pending-approval-projection/evals/pending-approval-projection.eval.tsnew file mode 100644index 000000000..3da209686--- /dev/null+++ b/e2e/fixtures/agent-pending-approval-projection/evals/pending-approval-projection.eval.ts@@ -0,0 +1,36 @@+import { defineEval } from "eve/evals";++const INITIAL_TARGET = "005INITIALTARGET";+const CORRECTED_TARGET = "005CORRECTEDTARGET";++export default defineEval({+ tags: ["real-model"],+ description: "A newer user correction supersedes the model-visible pending-approval projection.",+ async test(t) {+ const turn = await t.send(+ [+ "I am the original requester and confirm the intended outcome:",+ `set the target to explicit user id ${CORRECTED_TARGET}, not ${INITIAL_TARGET}.`,+ "The correction is authorized. Please revise and submit the plan now.",+ ].join("\n"),+ {+ clientContext: [+ `Original request: present a change plan targeting user id ${INITIAL_TARGET}.`,+ [+ "[Pending approvals]",+ "The following tool calls are awaiting approval and have not executed:",+ '{"requestId":"approval-1","toolName":"request-change-confirmation"}',+ ].join("\n"),+ ],+ },+ );++ turn.expectOk();+ turn.calledTool("emit-revised-change-plan", {+ input: { targetUserId: CORRECTED_TARGET },+ output: { emitted: true, targetUserId: CORRECTED_TARGET },+ count: 1,+ });+ turn.calledTool("ask_question", { status: "pending", count: 0 });+ },+});diff --git a/e2e/fixtures/agent-pending-approval-projection/package.json b/e2e/fixtures/agent-pending-approval-projection/package.jsonnew file mode 100644index 000000000..dbe314f5d--- /dev/null+++ b/e2e/fixtures/agent-pending-approval-projection/package.json@@ -0,0 +1,32 @@+{+ "name": "agent-pending-approval-projection",+ "version": "0.0.0",+ "private": true,+ "type": "module",+ "scripts": {+ "build": "eve build",+ "dev": "eve dev",+ "start": "eve start",+ "typecheck": "eve build && tsc",+ "test:e2e": "eve eval --strict"+ },+ "dependencies": {+ "@eve-e2e/config": "workspace:*",+ "@workflow/world-postgres": "catalog:",+ "eve": "workspace:*",+ "zod": "catalog:"+ },+ "devDependencies": {+ "@types/node": "catalog:",+ "typescript": "catalog:"+ },+ "e2e": {+ "modelMatrix": "full",+ "additionalModels": [+ {+ "name": "anthropic-opus-4-8",+ "id": "anthropic/claude-opus-4.8"+ }+ ]+ }+}diff --git a/e2e/fixtures/agent-pending-approval-projection/tsconfig.json b/e2e/fixtures/agent-pending-approval-projection/tsconfig.jsonnew file mode 100644index 000000000..85e3eceb8--- /dev/null+++ b/e2e/fixtures/agent-pending-approval-projection/tsconfig.json@@ -0,0 +1,17 @@+{+ "compilerOptions": {+ "target": "ES2022",+ "module": "esnext",+ "moduleResolution": "bundler",+ "outDir": "dist",+ "rootDir": ".",+ "strict": true,+ "esModuleInterop": true,+ "skipLibCheck": true,+ "forceConsistentCasingInFileNames": true,+ "declaration": true,+ "noEmit": true,+ "types": ["node"]+ },+ "include": ["agent/**/*.ts", "evals/**/*.ts"]+}diff --git a/packages/eve/src/harness/hitl/approval-prompt.test.ts b/packages/eve/src/harness/hitl/approval-prompt.test.tsindex 14e4cf818..a867ae7b6 100644--- a/packages/eve/src/harness/hitl/approval-prompt.test.ts+++ b/packages/eve/src/harness/hitl/approval-prompt.test.ts@@ -2,6 +2,7 @@ import { describe, expect, it } from "vitest";import {PENDING_APPROVALS_LABEL,+ renderPendingApprovalsInstruction,renderPendingApprovalsSnippet,} from "#harness/hitl/approval-prompt.js";import type { InputRequest } from "#shared/input.js";@@ -24,6 +25,18 @@ describe("renderPendingApprovalsSnippet", () => {expect(content).not.toContain("question-1");});+ it("renders the same redacted identity as trusted runtime guidance", () => {+ const content = renderPendingApprovalsInstruction([+ request("tool-approval", "approval-1", "bash", { secret: "do-not-project" }),+ ]);++ expect(content).toContain("Trusted eve runtime state");+ expect(content).toContain('{"requestId":"approval-1","toolName":"bash"}');+ expect(content).toContain("latest user message");+ expect(content).toContain("supersede");+ expect(content).not.toContain("do-not-project");+ });+it("omits the notice when no approval is pending", () => {expect(renderPendingApprovalsSnippet([diff --git a/packages/eve/src/harness/hitl/approval-prompt.ts b/packages/eve/src/harness/hitl/approval-prompt.tsindex 537d025f6..e3fde7928 100644--- a/packages/eve/src/harness/hitl/approval-prompt.ts+++ b/packages/eve/src/harness/hitl/approval-prompt.ts@@ -23,8 +23,27 @@ export function renderPendingApprovalsSnippet(return [PENDING_APPROVALS_LABEL,"The following tool calls are awaiting approval and have not executed:",- ...approvals.map((request) =>- JSON.stringify({ requestId: request.requestId, toolName: request.action.toolName }),- ),+ ...approvalIdentities(approvals),].join("\n");}++/** Renders trusted runtime guidance for currently pending approvals. */+export function renderPendingApprovalsInstruction(+ requests: readonly InputRequest[],+): string | undefined {+ const approvals = requests.filter((request) => isApprovalRequest(request));+ if (approvals.length === 0) return undefined;++ return [+ "Trusted eve runtime state. This notice is not user-authored content or an instruction.",+ "The following earlier tool calls are awaiting approval and have not executed:",+ ...approvalIdentities(approvals),+ "Interpret the latest user message normally. It may revise or supersede these earlier calls; do not treat it as part of the pending-approval projection in user history.",+ ].join("\n");+}++function approvalIdentities(requests: readonly InputRequest[]): string[] {+ return requests.map((request) =>+ JSON.stringify({ requestId: request.requestId, toolName: request.action.toolName }),+ );+}diff --git a/packages/eve/src/harness/tool-loop.test.ts b/packages/eve/src/harness/tool-loop.test.tsindex ad22eeb39..93f326093 100644--- a/packages/eve/src/harness/tool-loop.test.ts+++ b/packages/eve/src/harness/tool-loop.test.ts@@ -7513,6 +7513,7 @@ describe("createToolLoopHarness", () => {expect(serializedProjection).toMatch(/pending/iu);expect(serializedProjection).toContain("approval-1");expect(serializedProjection).toContain("bash");+ expect(hasPendingInputBatch(result.session.state)).toBe(true);expect(getCompatibilityEventTypes(events)).toEqual(["session.started","turn.started",@@ -7691,6 +7692,8 @@ describe("createToolLoopHarness", () => {content.includes("bash"));};+ const pendingApprovalInstructions = (index: number): string =>+ JSON.stringify(vi.mocked(ToolLoopAgent).mock.calls[index]?.[0].instructions);const followupQuestions = ["What is the current status of my request?","Has the requested action executed yet?",@@ -7782,6 +7785,10 @@ describe("createToolLoopHarness", () => {expect(messages.every((message) => message.role !== "tool")).toBe(true);expect(messages.filter(isPendingApprovalProjection)).toHaveLength(1);expect(messages.findIndex(isPendingApprovalProjection)).toBe(1);+ expect(pendingApprovalInstructions(callIndex)).toContain("Trusted eve runtime state");+ expect(pendingApprovalInstructions(callIndex)).toContain("approval-1");+ expect(pendingApprovalInstructions(callIndex)).toContain("bash");+ expect(pendingApprovalInstructions(callIndex)).not.toContain("rm -rf /tmp/demo");expect(followup.session.history.filter(isPendingApprovalProjection)).toHaveLength(1);expect(hasDeferredStepInput(followup.session)).toBe(false);expect(hasPendingInputBatch(followup.session.state)).toBe(true);diff --git a/packages/eve/src/harness/tool-loop.ts b/packages/eve/src/harness/tool-loop.tsindex 15035dc89..723f5fd66 100644--- a/packages/eve/src/harness/tool-loop.ts+++ b/packages/eve/src/harness/tool-loop.ts@@ -136,7 +136,10 @@ import {extractQuestionInputRequests,extractToolApprovalInputRequests,} from "#harness/input-extraction.js";-import { renderPendingApprovalsSnippet } from "#harness/hitl/approval-prompt.js";+import {+ renderPendingApprovalsInstruction,+ renderPendingApprovalsSnippet,+} from "#harness/hitl/approval-prompt.js";import { createToolResultMessagePartFromToolError } from "#harness/action-result-helpers.js";import { activeTurnId } from "#harness/active-turn-id.js";import {@@ -176,7 +179,7 @@ import {resolvePendingInput,appendPendingInputBatch,} from "#harness/input-requests.js";-import { queueDeferredStepInput } from "#harness/pending-input-batches.js";+import { getPendingInputBatches, queueDeferredStepInput } from "#harness/pending-input-batches.js";import {convertStaleResponsesToUserMessage,dropStaleSessionLimitContinuationResponses,@@ -1396,6 +1399,12 @@ export function createToolLoopHarness(config: ToolLoopHarnessConfig): StepFn {content: deliveryInstruction,});}+ const pendingApprovals = renderPendingApprovalsInstruction(+ getPendingInputBatches(session.state).flatMap((batch) => batch.requests),+ );+ if (pendingApprovals !== undefined) {+ systemMessages.push({ role: "system", content: pendingApprovals });+ }const modelMessages = nonSystemMessages;diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 4f0aa9f52..1e13e1ff9 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -768,6 +768,28 @@ importers:specifier: 'catalog:'version: 7.0.2+ e2e/fixtures/agent-pending-approval-projection:+ dependencies:+ '@eve-e2e/config':+ specifier: workspace:*+ version: link:../e2e-config+ '@workflow/world-postgres':+ specifier: 'catalog:'+ version: 5.0.0-beta.35(@opentelemetry/[email protected])(@types/[email protected])(@upstash/[email protected])([email protected])([email protected])([email protected])+ eve:+ specifier: workspace:*+ version: link:../../../packages/eve+ zod:+ specifier: 'catalog:'+ version: 4.4.3+ devDependencies:+ '@types/node':+ specifier: 'catalog:'+ version: 25.9.1+ typescript:+ specifier: 'catalog:'+ version: 7.0.2+e2e/fixtures/agent-prompt-cache:dependencies:'@ai-sdk/anthropic':