Skip to content

Commit 4162327

Browse files
committed
fix(permission): key worker grants on the dispatched call
1 parent a25ce3c commit 4162327

1 file changed

Lines changed: 21 additions & 2 deletions

File tree

‎src/permission/reactor-authorize.ts‎

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import {
3131
type WorkerGrantStore,
3232
} from "./worker-grant.js";
3333
import { canonicalToolName } from "../agent/canonical-tool-name.js";
34+
import { prepareDispatchedToolCall } from "../agent/tool-aliases.js";
3435
import { getSubAgentIdentity } from "../subagent/identity-context.js";
3536
import {
3637
FLEET_VERBS,
@@ -100,6 +101,23 @@ function resolveWorkerCwd(cwd: string | undefined): string {
100101
return cwd ?? getSubAgentIdentity()?.cwd ?? process.cwd();
101102
}
102103

104+
/**
105+
* The call as DynamicToolRunner dispatches it: canonical engine name plus
106+
* hidden-alias argument coercion (gpt `shell` -> run_shell via
107+
* coerceShellArgs). Authorize sees the raw wire call; the middleware that
108+
* consumes an authorized retry sees the dispatched call. Keying both on the
109+
* dispatched shape keeps one fingerprint per executed call. Invalid hidden
110+
* arguments never dispatch, so they keep their raw shape.
111+
*/
112+
function dispatchedCall(call: ToolCallType): ToolCallType {
113+
const engine = canonicalToolName(call.name);
114+
try {
115+
return prepareDispatchedToolCall(call, engine);
116+
} catch {
117+
return { ...call, name: engine };
118+
}
119+
}
120+
103121
function workerCallIdentity(
104122
sessionId: string,
105123
call: ToolCallType,
@@ -110,10 +128,11 @@ function workerCallIdentity(
110128
args: Record<string, unknown>;
111129
cwd: string;
112130
} {
131+
const dispatched = dispatchedCall(call);
113132
return {
114133
sessionId,
115-
canonicalTool: canonicalToolName(call.name),
116-
args: (call.arguments ?? {}) as Record<string, unknown>,
134+
canonicalTool: dispatched.name,
135+
args: (dispatched.arguments ?? {}) as Record<string, unknown>,
117136
cwd,
118137
};
119138
}

0 commit comments

Comments
 (0)