Skip to content

Commit e42bb23

Browse files
sunlit-dengobviyus
andauthored
fix(agents): guide denied plugin approvals (#130009)
Return one final denial outcome from the plugin approval owner for both embedded and Gateway paths. This tells the agent that the tool did not run, the closed request cannot be approved again, and the same call must not be retried. Co-authored-by: Ayaan Zaidi <[email protected]>
1 parent ecdc8b9 commit e42bb23

3 files changed

Lines changed: 36 additions & 21 deletions

File tree

‎src/agents/agent-tools.before-tool-call.approval.ts‎

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ import { callGatewayTool } from "./tools/gateway.js";
3939
type PluginApprovalRequest = NonNullable<PluginHookBeforeToolCallResult["requireApproval"]>;
4040
const log = createSubsystemLogger("agents/tools");
4141

42+
function pluginApprovalDeniedOutcome(baseParams: unknown): HookOutcome {
43+
return {
44+
blocked: true,
45+
kind: "failure",
46+
disposition: "blocked",
47+
deniedReason: "plugin-approval",
48+
reason: [
49+
"Denied by user. The tool call did not run.",
50+
"This denial is final: the approval request is closed. Do not mention /approve or any other approval command to the user.",
51+
"Do not run the tool call again or ask the user to approve it again.",
52+
"If the user still wants the action, explain that a new tool call will trigger a fresh approval request.",
53+
].join("\n"),
54+
params: baseParams,
55+
};
56+
}
57+
4258
function resolvePluginToolApprovalTimeoutMs(approval: PluginApprovalRequest): number {
4359
if (
4460
typeof approval.timeoutMs !== "number" ||
@@ -231,14 +247,7 @@ async function requestPluginToolApproval(params: {
231247
};
232248
}
233249
if (resolution === PluginApprovalResolutions.DENY) {
234-
return {
235-
blocked: true,
236-
kind: "failure",
237-
disposition: "blocked",
238-
deniedReason: "plugin-approval",
239-
reason: "Denied by user",
240-
params: params.baseParams,
241-
};
250+
return pluginApprovalDeniedOutcome(params.baseParams);
242251
}
243252
// Veto carries the plugin-supplied reason; plain timeouts record a
244253
// timed_out failure disposition for the audit ledger.
@@ -394,14 +403,7 @@ async function requestPluginToolApproval(params: {
394403
};
395404
}
396405
if (resolution === PluginApprovalResolutions.DENY) {
397-
return {
398-
blocked: true,
399-
kind: "failure",
400-
disposition: "blocked",
401-
deniedReason: "plugin-approval",
402-
reason: "Denied by user",
403-
params: params.baseParams,
404-
};
406+
return pluginApprovalDeniedOutcome(params.baseParams);
405407
}
406408
const fallbackTimeoutReason = approval.timeoutReason ?? "Approval timed out";
407409
const timeoutReason =

‎src/agents/agent-tools.before-tool-call.e2e.test.ts‎

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2719,7 +2719,7 @@ describe("before_tool_call requireApproval handling", () => {
27192719
);
27202720
});
27212721

2722-
it("blocks on deny decision", async () => {
2722+
it("uses tool-neutral guidance for a denied plugin tool call", async () => {
27232723
hookRunner.runBeforeToolCall.mockResolvedValue({
27242724
requireApproval: {
27252725
title: "Dangerous",
@@ -2731,14 +2731,22 @@ describe("before_tool_call requireApproval handling", () => {
27312731
mockCallGateway.mockResolvedValueOnce({ id: "server-id-2", decision: "deny" });
27322732

27332733
const result = await runBeforeToolCallHook({
2734-
toolName: "bash",
2735-
params: {},
2734+
toolName: "web_search",
2735+
params: { query: "OpenClaw" },
27362736
ctx: { agentId: "main", sessionKey: "main" },
27372737
});
27382738

27392739
expect(result.blocked).toBe(true);
27402740
expect(result).toHaveProperty("disposition", "blocked");
2741-
expect(result).toHaveProperty("reason", "Denied by user");
2741+
expect(result).toHaveProperty(
2742+
"reason",
2743+
[
2744+
"Denied by user. The tool call did not run.",
2745+
"This denial is final: the approval request is closed. Do not mention /approve or any other approval command to the user.",
2746+
"Do not run the tool call again or ask the user to approve it again.",
2747+
"If the user still wants the action, explain that a new tool call will trigger a fresh approval request.",
2748+
].join("\n"),
2749+
);
27422750
});
27432751

27442752
it("keeps the generic plugin approval timeout reason unchanged", async () => {

‎test/e2e/qa-lab/runtime/agent-tool-safety-approvals.e2e.test.ts‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,12 @@ describe("agent tool safety approvals", () => {
146146

147147
expect(denied).toMatchObject({
148148
name: "BeforeToolCallFailureError",
149-
message: "Denied by user",
149+
message: [
150+
"Denied by user. The tool call did not run.",
151+
"This denial is final: the approval request is closed. Do not mention /approve or any other approval command to the user.",
152+
"Do not run the tool call again or ask the user to approve it again.",
153+
"If the user still wants the action, explain that a new tool call will trigger a fresh approval request.",
154+
].join("\n"),
150155
});
151156
expect(getBeforeToolCallFailureDisposition(denied)).toBe("blocked");
152157
expect(execute).not.toHaveBeenCalled();

0 commit comments

Comments
 (0)