Skip to content

Commit 7d62c15

Browse files
committed
fix(codex): preserve raw argument preparation
Signed-off-by: sallyom <[email protected]>
1 parent 1a57cfa commit 7d62c15

2 files changed

Lines changed: 34 additions & 34 deletions

File tree

‎extensions/codex/src/app-server/dynamic-tools.test.ts‎

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,15 @@ async function runSchemaToolCall(params: {
225225
name?: string;
226226
namespace?: SchemaToolNamespace;
227227
parameters?: AnyAgentTool["parameters"];
228+
prepareArguments?: AnyAgentTool["prepareArguments"];
228229
}) {
229230
const name = params.name ?? "strict_tool";
230231
const namespace = params.namespace ?? null;
231232
const execute = vi.fn(async () => textToolResult("done"));
232233
const tool = createTool({
233234
name,
234235
parameters: params.parameters ?? STRICT_INSTRUCTION_SCHEMA,
236+
prepareArguments: params.prepareArguments,
235237
execute,
236238
});
237239
const bridge = createCodexDynamicToolBridge({
@@ -339,31 +341,38 @@ describe("createCodexDynamicToolBridge", () => {
339341
expect((contentItem.text as string).length).toBeLessThanOrEqual(260);
340342
});
341343

342-
it.each([
343-
{ label: "number", arguments: 47 },
344-
{ label: "string", arguments: "unexpected" },
345-
{ label: "array", arguments: [] },
346-
{ label: "null", arguments: null },
347-
])(
348-
"rejects a $label root before optional-only object arguments are normalized",
349-
async (testCase) => {
350-
const { execute, response } = await runSchemaToolCall({
351-
arguments: testCase.arguments as JsonValue,
352-
callId: `call-non-object-${testCase.label}`,
353-
name: "optional_object_tool",
354-
parameters: {
355-
type: "object",
356-
properties: { note: { type: "string" } },
357-
additionalProperties: false,
358-
},
359-
namespace: CODEX_OPENCLAW_DIRECT_DYNAMIC_TOOL_NAMESPACE,
360-
});
344+
it("prepares raw null arguments before native Codex schema validation", async () => {
345+
const prepareArguments = vi.fn(function (this: AnyAgentTool, arguments_: unknown) {
346+
return arguments_ === null ? { preparedBy: this.name } : arguments_;
347+
});
348+
const { execute, response } = await runSchemaToolCall({
349+
arguments: null,
350+
callId: "call-null-compatibility",
351+
name: "optional_object_tool",
352+
parameters: {
353+
type: "object",
354+
properties: { preparedBy: { type: "string" } },
355+
additionalProperties: false,
356+
},
357+
prepareArguments,
358+
namespace: CODEX_OPENCLAW_DIRECT_DYNAMIC_TOOL_NAMESPACE,
359+
});
361360

362-
expectSchemaRejection(response, execute, "must be object");
363-
},
364-
);
361+
expect(prepareArguments).toHaveBeenCalledWith(null);
362+
expect(response).toEqual(expectInputText("done"));
363+
expectExecuteCall(execute, {
364+
callId: "call-null-compatibility",
365+
args: { preparedBy: "optional_object_tool" },
366+
});
367+
});
365368

366369
it.each([
370+
{
371+
label: "repairs primitive input",
372+
initial: 47,
373+
adjusted: { instruction: "repaired" },
374+
executes: true,
375+
},
367376
{
368377
label: "repairs invalid input",
369378
initial: { instruction: 47 },

‎extensions/codex/src/app-server/dynamic-tools.ts‎

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -679,18 +679,9 @@ export function createCodexDynamicToolBridge(params: {
679679
}
680680
};
681681
try {
682-
// Keep non-object roots intact long enough to validate them. The execution
683-
// boundary still uses record arguments, but normalizing first would turn
684-
// values such as `null`, arrays, or numbers into `{}` and could let them
685-
// satisfy schemas whose object properties are all optional.
686-
if (!isRecord(rawArguments) && shouldValidateCodexDynamicToolInput(tool)) {
687-
assertCodexDynamicToolInputMatchesSchema({
688-
toolName,
689-
schema: toolEntry.inputSchema,
690-
value: rawArguments,
691-
});
692-
}
693-
const toolArgs = tool.prepareArguments ? tool.prepareArguments(args) : args;
682+
// Compatibility preparation owns raw arguments; record coercion must not run first.
683+
const prepare = tool.prepareArguments;
684+
const toolArgs = prepare ? Reflect.apply(prepare, tool, [rawArguments]) : args;
694685
const preparedArgs =
695686
toolName === "message" && isRecord(toolArgs)
696687
? await prepareCodexRemoteWorkspaceMessageMedia({

0 commit comments

Comments
 (0)