Skip to content

armgit / eve

Public Imported from GitHub
0

The Open Framework for Building Agents

fix(eve): default approval responses to the requesting principal (#4368)

roboeve[bot]9d42f05ceb6f
diff --git a/.changeset/approval-requester-default.md b/.changeset/approval-requester-default.md
new file mode 100644
index 000000000..83833b7c1
--- /dev/null
+++ b/.changeset/approval-requester-default.md
@@ -0,0 +1,5 @@
+---
+"eve": patch
+---
+
+Approvals without a `response` policy can now be approved or cancelled only by the principal whose turn requested the call, so a shared thread no longer lets another person run a tool under the requester's turn. Calls requested by unauthenticated or anonymous callers are unchanged. Tools that need other approvers define `approval.response`, which replaces the default.
diff --git a/docs/tools/human-in-the-loop.md b/docs/tools/human-in-the-loop.md
index b3d451d86..dacb6ffaf 100644
--- a/docs/tools/human-in-the-loop.md
+++ b/docs/tools/human-in-the-loop.md
@@ -84,7 +84,9 @@ Gating a side effect on approval is also how you make non-idempotent work safe a
### Authorizing approval responses
-You may also define an approval response policy that decides whether the authenticated person who selects **Approve** or **Cancel** may settle that specific call:
+By default, only the person whose turn requested a call can approve or cancel it.
+
+Define an approval response policy to change who may settle a call, for example, to specify a set of designated approvers who must approve a certain tool. A tool with a `response` policy replaces the default entirely, so return `{ status: "allowed" }` to let any responder through:
```ts title="agent/tools/refund_charge.ts"
import { defineTool } from "eve/tools";
diff --git a/packages/eve/src/execution/session/approval-caller.integration.test.ts b/packages/eve/src/execution/session/approval-caller.integration.test.ts
index 1c9304140..1bd406db0 100644
--- a/packages/eve/src/execution/session/approval-caller.integration.test.ts
+++ b/packages/eve/src/execution/session/approval-caller.integration.test.ts
@@ -8,7 +8,7 @@ import {
} from "#internal/testing/approval-resume.js";
import { defineAgent } from "#public/definitions/agent.js";
import { defineDynamic } from "#dynamic/definition.js";
-import type { Approval } from "#approval/definition.js";
+import type { Approval, ApprovalResponsePolicy } from "#approval/definition.js";
import { workflowEntry } from "#execution/session/entry.js";
import {
sessionCommandHookToken,
@@ -74,6 +74,10 @@ function testUser(principalId: string) {
const ALICE = testUser("alice");
const BOB = testUser("bob");
+// Without a response policy only the requester may respond, and these tests
+// need Bob to approve Alice's calls.
+const anyoneResponds: ApprovalResponsePolicy = () => ({ status: "allowed" });
+
/** Records `ctx.session.auth.current` for every tool that runs. */
function recordingTool(
name: string,
@@ -123,6 +127,7 @@ async function withChainRun(
name: string,
body: (run: ChainRun) => Promise<void>,
options: {
+ readonly firstApproval?: Approval;
readonly message?: string;
readonly model?: MockLanguageModelV4;
readonly modules?: NonNullable<Parameters<typeof createTestRuntime>[0]>["modules"];
@@ -153,7 +158,12 @@ async function withChainRun(
name,
},
modules: [
- recordingTool("deploy_change", seen, log, always()),
+ recordingTool(
+ "deploy_change",
+ seen,
+ log,
+ options.firstApproval ?? { request: always(), response: anyoneResponds },
+ ),
recordingTool("read_notes", seen, log),
recordingTool("publish_change", seen, log, secondApproval),
...(options.modules ?? []),
@@ -286,7 +296,7 @@ describe("approval caller", () => {
{
loadNamespace: async () => ({
default: defineWorkflowTool({
- approval: always(),
+ approval: { request: always(), response: anyoneResponds },
description: "Report who runs this.",
execute: reportCallerWorkflow as WorkflowExecuteToolDefinition["execute"],
inputSchema: {},
@@ -342,6 +352,7 @@ describe("approval caller", () => {
expect(filterEventsByType(refused, "input.resolved")).toEqual([]);
await run.approve(ALICE, "publish_change");
},
+ { firstApproval: always() },
);
expect(seen.map((entry) => entry.caller)).toEqual(["alice", "alice", "alice"]);
@@ -401,10 +412,13 @@ describe("approval caller", () => {
{
loadNamespace: async () => ({
default: defineWorkflowTool({
- approval: ({ toolInput }) =>
- (toolInput as { gated?: boolean } | undefined)?.gated === true
- ? "user-approval"
- : "not-applicable",
+ approval: {
+ request: ({ toolInput }) =>
+ (toolInput as { gated?: boolean } | undefined)?.gated === true
+ ? "user-approval"
+ : "not-applicable",
+ response: anyoneResponds,
+ },
description: "Report who runs this.",
execute: reportCallerWorkflow as WorkflowExecuteToolDefinition["execute"],
inputSchema: {},
diff --git a/packages/eve/src/execution/session/turn-connection-approval.integration.test.ts b/packages/eve/src/execution/session/turn-connection-approval.integration.test.ts
index 358b84f33..6fa7328f0 100644
--- a/packages/eve/src/execution/session/turn-connection-approval.integration.test.ts
+++ b/packages/eve/src/execution/session/turn-connection-approval.integration.test.ts
@@ -386,7 +386,7 @@ describe("turn connection approval restoration", () => {
await fixture.step({
delivery: {
kind: "deliver",
- auth: bob,
+ auth: alice,
payloads: [
{
inputResponses: requests.map((request) => ({
@@ -424,7 +424,7 @@ describe("turn connection approval restoration", () => {
await fixture.step({
delivery: {
kind: "deliver",
- auth: bob,
+ auth: alice,
payloads: [{ inputResponses: [{ requestId: request.requestId, optionId: "approve" }] }],
},
});
diff --git a/packages/eve/src/harness/approval-candidates.ts b/packages/eve/src/harness/approval-candidates.ts
index 00e4a2b6c..33ff46717 100644
--- a/packages/eve/src/harness/approval-candidates.ts
+++ b/packages/eve/src/harness/approval-candidates.ts
@@ -400,7 +400,7 @@ function projectResponder(responder: SessionAuthContext): ApprovalResponderIdent
};
}
-function sameResponder(
+export function sameResponder(
a: Pick<SessionAuthContext, "authenticator" | "issuer" | "principalId" | "principalType">,
b: Pick<SessionAuthContext, "authenticator" | "issuer" | "principalId" | "principalType">,
): boolean {
diff --git a/packages/eve/src/harness/approval-delivery-coordinator.test.ts b/packages/eve/src/harness/approval-delivery-coordinator.test.ts
index 418bb5449..63e117144 100644
--- a/packages/eve/src/harness/approval-delivery-coordinator.test.ts
+++ b/packages/eve/src/harness/approval-delivery-coordinator.test.ts
@@ -358,6 +358,62 @@ describe("coordinateApprovalDelivery", () => {
});
});
+describe("approval responses without a response policy", () => {
+ const alice: SessionAuthContext = { ...responder, principalId: "alice" };
+ const bob: SessionAuthContext = { ...responder, principalId: "bob" };
+
+ function parkedFor(requester: SessionAuthContext | null): HarnessSession {
+ const base = appendPendingInputBatch({
+ requests: [request],
+ responseMessages: [],
+ session: { ...parkedSession(), state: undefined },
+ });
+ if (requester === null) return base;
+ const ctx = new ContextContainer();
+ ctx.set(AuthKey, requester);
+ return contextStorage.run(ctx, () =>
+ appendPendingInputBatch({
+ requests: [request],
+ responseMessages: [],
+ session: { ...parkedSession(), state: undefined },
+ }),
+ );
+ }
+
+ function respond(session: HarnessSession, auth: SessionAuthContext, optionId = "approve") {
+ return coordinateApprovalDelivery({
+ now: 100,
+ session,
+ stepInput: {
+ attributedInputResponses: [{ auth, response: { optionId, requestId: request.requestId } }],
+ },
+ tools: new Map(),
+ });
+ }
+
+ it("lets the requester settle the call", async () => {
+ const result = await respond(parkedFor(alice), alice);
+ expect(result.feedback).toEqual([]);
+ expect(getApprovalAuditState(result.session.state).settlements).toHaveLength(1);
+ });
+
+ it.each(["approve", "cancel"])("rejects another principal's %s", async (optionId) => {
+ const result = await respond(parkedFor(alice), bob, optionId);
+ expect(result.feedback).toEqual([
+ "Only the person who requested this action can respond to this approval.",
+ ]);
+ expect(getApprovalAuditState(result.session.state).settlements).toEqual([]);
+ expect(result.stepInput?.inputResponses ?? []).toEqual([]);
+ expect(getPendingInputBatches(result.session.state)).toHaveLength(1);
+ });
+
+ it("lets anyone respond when the requester is unauthenticated", async () => {
+ const result = await respond(parkedFor(null), bob);
+ expect(result.feedback).toEqual([]);
+ expect(getApprovalAuditState(result.session.state).settlements).toHaveLength(1);
+ });
+});
+
describe("text approval replay preparation", () => {
function shouldPrepareApprovalReplayTools(input: {
session: HarnessSession;
diff --git a/packages/eve/src/harness/approval-delivery-coordinator.ts b/packages/eve/src/harness/approval-delivery-coordinator.ts
index 29f91815c..ecc42a68f 100644
--- a/packages/eve/src/harness/approval-delivery-coordinator.ts
+++ b/packages/eve/src/harness/approval-delivery-coordinator.ts
@@ -14,6 +14,7 @@ import {
getApprovalAuditState,
markApprovalCandidateAuthorizationRequired,
settleAllowedCandidate,
+ sameResponder,
settleDirectApprovalResponse,
type ActiveApprovalCandidate,
type ApprovalCandidateDecision,
@@ -32,6 +33,8 @@ import type { HarnessSession, HarnessToolMap, StepInput } from "#harness/types.j
import type { InputRequest } from "#shared/input.js";
const UNAUTHENTICATED_APPROVAL_FEEDBACK = "Authentication is required to respond to this approval.";
+const REQUESTER_ONLY_APPROVAL_FEEDBACK =
+ "Only the person who requested this action can respond to this approval.";
const APPROVAL_AUTHORIZER_TIMEOUT_MS = 10_000;
const APPROVAL_CANDIDATE_TTL_MS = 10 * 60_000;
@@ -144,6 +147,21 @@ export async function coordinateApprovalDelivery(input: {
? attributedResponder
: (context?.get(AuthKey) ?? context?.get(SessionKey)?.auth.current ?? null);
const decision = toCandidateDecision(response.optionId);
+ // Without a response policy, only the requester may settle the call. An
+ // unauthenticated or anonymous requester has no identity to match, so
+ // any responder may settle it. A tool opts into other responders by
+ // defining `approval.response`.
+ const requester = pendingInputRequester(session.state, response.requestId);
+ if (
+ responder !== null &&
+ decision !== undefined &&
+ requester !== null &&
+ !sameResponder(requester, responder)
+ ) {
+ consumed.add(response.requestId);
+ feedback.push(REQUESTER_ONLY_APPROVAL_FEEDBACK);
+ continue;
+ }
if (responder !== null && decision !== undefined) {
const settled = settleDirectApprovalResponse({
actor: responder,
diff --git a/packages/eve/src/internal/testing/channel-conformance/MATRIX.md b/packages/eve/src/internal/testing/channel-conformance/MATRIX.md
index 5843c2c87..c851ba4c8 100644
--- a/packages/eve/src/internal/testing/channel-conformance/MATRIX.md
+++ b/packages/eve/src/internal/testing/channel-conformance/MATRIX.md
@@ -79,7 +79,7 @@ pnpm --filter eve exec vitest run --config vitest.unit.config.ts channel-conform
| another person pressing Approve on a requester-only approval leaves it pending | —<sup>[18](#note-18)</sup> | —<sup>[18](#note-18)</sup> | ✅ | | —<sup>[19](#note-19)</sup> | ❌<sup>[17](#note-17)</sup> | | —<sup>[19](#note-19)</sup> | | ✅ | | ✅ | | ✅ | | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> |
| another person pressing Cancel on a requester-only approval leaves it pending | —<sup>[18](#note-18)</sup> | —<sup>[18](#note-18)</sup> | ✅ | | —<sup>[19](#note-19)</sup> | ❌<sup>[17](#note-17)</sup> | | —<sup>[19](#note-19)</sup> | | ✅ | | ✅ | | ✅ | | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> |
| another person's rejected press leaves the approval's buttons in place | —<sup>[18](#note-18)</sup> | —<sup>[18](#note-18)</sup> | ✅ | | —<sup>[19](#note-19)</sup> | ✅ | | —<sup>[19](#note-19)</sup> | | ✅ | | ✅ | | ✅ | | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> |
-| another person pressing Approve runs a tool with no response policy | —<sup>[18](#note-18)</sup> | —<sup>[18](#note-18)</sup> | ✅ | | —<sup>[19](#note-19)</sup> | ✅ | | —<sup>[19](#note-19)</sup> | | ✅ | | ✅ | | ✅ | | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> |
+| another person pressing Approve on an open approval runs the tool | —<sup>[18](#note-18)</sup> | —<sup>[18](#note-18)</sup> | ✅ | | —<sup>[19](#note-19)</sup> | ❌<sup>[17](#note-17)</sup> | | —<sup>[19](#note-19)</sup> | | ✅ | | ✅ | | ✅ | | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> | —<sup>[19](#note-19)</sup> |
## Notes
diff --git a/packages/eve/src/internal/testing/channel-conformance/conformance.ts b/packages/eve/src/internal/testing/channel-conformance/conformance.ts
index b03eef046..310637966 100644
--- a/packages/eve/src/internal/testing/channel-conformance/conformance.ts
+++ b/packages/eve/src/internal/testing/channel-conformance/conformance.ts
@@ -159,6 +159,7 @@ const DISCORD_BROKEN = {
"the requester pressing Approve on a requester-only approval runs the tool",
"another person pressing Approve on a requester-only approval leaves it pending",
"another person pressing Cancel on a requester-only approval leaves it pending",
+ "another person pressing Approve on an open approval runs the tool",
],
),
...noSignInRenderer(
diff --git a/packages/eve/src/internal/testing/channel-conformance/contract.ts b/packages/eve/src/internal/testing/channel-conformance/contract.ts
index 438c0fdba..1207736d4 100644
--- a/packages/eve/src/internal/testing/channel-conformance/contract.ts
+++ b/packages/eve/src/internal/testing/channel-conformance/contract.ts
@@ -6,6 +6,7 @@ import {
type ConversationOptions,
GATED_TOOL,
type GatedTool,
+ OPEN_GATED_TOOL,
PLAIN_TOOL,
type RenderedOption,
REQUESTER_GATED_TOOL,
@@ -103,6 +104,14 @@ async function askToReleaseHotfix(conversation: ChannelConversation) {
return await conversation.waitForQuestion(HOTFIX_PROMPT);
}
+const ROLL_BACK = `Use ${OPEN_GATED_TOOL} to undo the release.`;
+const ROLL_BACK_PROMPT = "Approve Roll back release?";
+
+async function askToRollBack(conversation: ChannelConversation) {
+ await conversation.say(ROLL_BACK);
+ return await conversation.waitForQuestion(ROLL_BACK_PROMPT);
+}
+
async function expectRan(conversation: ChannelConversation, tool: GatedTool, output: unknown) {
const outcome = await conversation.waitForToolOutcome(tool);
expect(outcome, `${tool} settled as ${JSON.stringify(outcome)}`).toEqual({
@@ -810,13 +819,13 @@ const signInRules = [
},
},
{
- rule: "another person pressing Approve runs a tool with no response policy",
+ rule: "another person pressing Approve on an open approval runs the tool",
source: "docs/tools/human-in-the-loop.md#authorizing-approval-responses",
requires: ["another-person", "buttons"],
async run(conversation) {
- const options = await askToDeploy(conversation);
+ const options = await askToRollBack(conversation);
await conversation.press(option(options, APPROVE_LABELS), "bob");
- await expectDeployed(conversation);
+ await expectRan(conversation, OPEN_GATED_TOOL, { rolledBack: true });
},
},
] as const satisfies readonly ContractRule[];
diff --git a/packages/eve/src/internal/testing/channel-conformance/harness.ts b/packages/eve/src/internal/testing/channel-conformance/harness.ts
index 76873f8c7..d761a77c9 100644
--- a/packages/eve/src/internal/testing/channel-conformance/harness.ts
+++ b/packages/eve/src/internal/testing/channel-conformance/harness.ts
@@ -299,7 +299,14 @@ export const SECOND_GATED_TOOL = "publish_notes";
*/
export const REQUESTER_GATED_TOOL = "release_hotfix";
-export type GatedTool = typeof GATED_TOOL | typeof SECOND_GATED_TOOL | typeof REQUESTER_GATED_TOOL;
+/** An always-gated tool whose response policy lets anyone approve or cancel the call. */
+export const OPEN_GATED_TOOL = "roll_back_release";
+
+export type GatedTool =
+ | typeof GATED_TOOL
+ | typeof SECOND_GATED_TOOL
+ | typeof REQUESTER_GATED_TOOL
+ | typeof OPEN_GATED_TOOL;
/** The test agent's plain tool: it runs without asking anyone. */
export const PLAIN_TOOL = "look_up_notes";
@@ -535,6 +542,7 @@ async function converse(
const runs: Record<CountedTool, number> = {
[GATED_TOOL]: 0,
[REQUESTER_GATED_TOOL]: 0,
+ [OPEN_GATED_TOOL]: 0,
[SECOND_GATED_TOOL]: 0,
[PLAIN_TOOL]: 0,
read_calendar: 0,
@@ -619,6 +627,15 @@ async function converse(
? { status: "allowed" }
: { reason: "Only the person who asked can respond.", status: "rejected" },
),
+ gatedTool(
+ OPEN_GATED_TOOL,
+ "Rolls back a release.",
+ () => {
+ runs[OPEN_GATED_TOOL] += 1;
+ return { rolledBack: true };
+ },
+ () => ({ status: "allowed" }),
+ ),
{
logicalPath: `tools/${TWO_QUESTIONS_TOOL}.ts`,
loadNamespace: async () => ({