Skip to content

Commit b113d35

Browse files
authored
Prioritize repeated-permission-denial context over generic missing-tool warning (#38036)
1 parent 925d647 commit b113d35

2 files changed

Lines changed: 55 additions & 4 deletions

File tree

actions/setup/js/handle_agent_failure.cjs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1110,13 +1110,22 @@ function loadMissingToolMessages(items) {
11101110
}
11111111
}
11121112

1113+
/**
1114+
* Determine whether a missing_tool message represents permission denial.
1115+
* @param {{tool: string|null, denied_commands: Array<string>}} message
1116+
* @returns {boolean}
1117+
*/
1118+
function isPermissionDeniedMissingTool(message) {
1119+
return message.tool === "tool/permission" && Array.isArray(message.denied_commands) && message.denied_commands.length > 0;
1120+
}
1121+
11131122
/**
11141123
* Build missing_tool context string for display in failure issues/comments.
11151124
* @param {Array<any>} [items] - Optional pre-loaded agent output items. When provided, avoids re-reading the output file.
11161125
* @returns {string} Formatted missing tool context
11171126
*/
11181127
function buildMissingToolContext(items) {
1119-
const missingToolMessages = loadMissingToolMessages(items);
1128+
const missingToolMessages = loadMissingToolMessages(items).filter(message => !isPermissionDeniedMissingTool(message));
11201129

11211130
if (missingToolMessages.length === 0) {
11221131
return "";
@@ -1142,9 +1151,7 @@ function buildMissingToolContext(items) {
11421151
*/
11431152
function buildPermissionDeniedContext(items, workflowId) {
11441153
const missingToolMessages = loadMissingToolMessages(items);
1145-
1146-
const isPermissionDeniedItem = m => m.tool === "tool/permission" && Array.isArray(m.denied_commands) && m.denied_commands.length > 0;
1147-
const permissionItems = missingToolMessages.filter(isPermissionDeniedItem);
1154+
const permissionItems = missingToolMessages.filter(isPermissionDeniedMissingTool);
11481155

11491156
if (permissionItems.length === 0) {
11501157
return "";

actions/setup/js/handle_agent_failure.test.cjs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2225,6 +2225,50 @@ describe("handle_agent_failure", () => {
22252225
expect(result).toContain("tool1");
22262226
expect(result).toContain("tool2");
22272227
});
2228+
2229+
it("suppresses generic context for repeated permission denied missing_tool entries", () => {
2230+
fs.writeFileSync(
2231+
path.join(tmpDir, "agent_output.json"),
2232+
JSON.stringify({
2233+
items: [{ type: "missing_tool", tool: "tool/permission", reason: "permission denied", denied_commands: ["go version 2>&1"] }],
2234+
})
2235+
);
2236+
vi.resetModules();
2237+
({ buildMissingToolContext } = require("./handle_agent_failure.cjs"));
2238+
expect(buildMissingToolContext()).toBe("");
2239+
});
2240+
2241+
it("does not suppress tool/permission entry when denied_commands is empty", () => {
2242+
fs.writeFileSync(
2243+
path.join(tmpDir, "agent_output.json"),
2244+
JSON.stringify({
2245+
items: [{ type: "missing_tool", tool: "tool/permission", reason: "permission queried", denied_commands: [] }],
2246+
})
2247+
);
2248+
vi.resetModules();
2249+
({ buildMissingToolContext } = require("./handle_agent_failure.cjs"));
2250+
const result = buildMissingToolContext();
2251+
expect(result).toContain("Missing Tools Reported");
2252+
expect(result).toContain("tool/permission");
2253+
});
2254+
2255+
it("keeps non-permission missing tools when permission-denied entries are present", () => {
2256+
fs.writeFileSync(
2257+
path.join(tmpDir, "agent_output.json"),
2258+
JSON.stringify({
2259+
items: [
2260+
{ type: "missing_tool", tool: "tool/permission", reason: "permission denied", denied_commands: ["go version 2>&1"] },
2261+
{ type: "missing_tool", tool: "bash", reason: "bash is not available" },
2262+
],
2263+
})
2264+
);
2265+
vi.resetModules();
2266+
({ buildMissingToolContext } = require("./handle_agent_failure.cjs"));
2267+
const result = buildMissingToolContext();
2268+
expect(result).toContain("Missing Tools Reported");
2269+
expect(result).toContain("bash");
2270+
expect(result).not.toContain("tool/permission");
2271+
});
22282272
});
22292273

22302274
// ──────────────────────────────────────────────────────

0 commit comments

Comments
 (0)