fix(codex): strip Unicode-property tool schema patterns Codex rejects
Codex's /responses validator has no Unicode property escapes, so a tool
`pattern` containing `\p{...}` 400s the whole request with `Invalid schema
for function ... is not a 'regex'` — identically on every account, costing a
full combo failover per turn (#3922).
- Add open-sse/utils/codexToolSchema.js: copy-on-write walk that drops only
`pattern` values carrying a property escape, returning the original
reference when nothing changed so the caller's schema stays intact for a
retry against another provider
- Treat `properties` keys as property names, so a field literally called
`pattern` is never read as the schema keyword; skip escaped literals via
backslash-parity counting
- Apply it in normalizeCodexTools for both function and namespace sub-tool
parameters, and log the strip count via dbg
- Add three cases to tests/unit/codex-tool-normalization.test.js
This commit is contained in:
@@ -118,6 +118,69 @@ describe("CodexExecutor tool normalization", () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it("strips only Unicode-property patterns rejected by Codex", () => {
|
||||
const unicodePattern = "^(?!__.*__$)[^\\p{Cc}\\p{Cf}\\p{Zl}\\p{Zp}]{1,200}$";
|
||||
const validPattern = "^[a-z][a-z0-9_-]{0,31}$";
|
||||
const sourceParameters = {
|
||||
type: "object",
|
||||
properties: {
|
||||
artifact: {
|
||||
type: "object",
|
||||
properties: {
|
||||
name: { type: "string", pattern: unicodePattern },
|
||||
slug: { type: "string", pattern: validPattern },
|
||||
},
|
||||
},
|
||||
// A property named "pattern" is data, not the schema keyword.
|
||||
pattern: { type: "string", pattern: validPattern },
|
||||
},
|
||||
allOf: [{ properties: { title: { type: "string", pattern: unicodePattern } } }],
|
||||
};
|
||||
const tools = normalizeTools([{
|
||||
type: "function",
|
||||
name: "Artifact",
|
||||
parameters: sourceParameters,
|
||||
}]);
|
||||
|
||||
expect(tools[0].parameters.properties.artifact.properties.name.pattern).toBeUndefined();
|
||||
expect(tools[0].parameters.properties.artifact.properties.slug.pattern).toBe(validPattern);
|
||||
expect(tools[0].parameters.properties.pattern.pattern).toBe(validPattern);
|
||||
expect(tools[0].parameters.allOf[0].properties.title.pattern).toBeUndefined();
|
||||
// Copy-on-write: the caller's schema remains available for another provider.
|
||||
expect(sourceParameters.properties.artifact.properties.name.pattern).toBe(unicodePattern);
|
||||
});
|
||||
|
||||
it("keeps escaped literal property text and schema identity when no strip is needed", () => {
|
||||
const parameters = {
|
||||
type: "object",
|
||||
properties: {
|
||||
literal: { type: "string", pattern: "^\\\\p{Cc}$" },
|
||||
simple: { type: "string", pattern: "^[A-Z]+$" },
|
||||
},
|
||||
};
|
||||
const tools = normalizeTools([{ type: "function", name: "probe", parameters }]);
|
||||
|
||||
expect(tools[0].parameters).toBe(parameters);
|
||||
expect(tools[0].parameters.properties.literal.pattern).toBe("^\\\\p{Cc}$");
|
||||
});
|
||||
|
||||
it("sanitizes nested namespace function schemas", () => {
|
||||
const tools = normalizeTools([{
|
||||
type: "namespace",
|
||||
name: "agent",
|
||||
tools: [{
|
||||
type: "function",
|
||||
name: "Artifact",
|
||||
parameters: {
|
||||
type: "object",
|
||||
properties: { name: { type: "string", pattern: "^\\p{Cc}+$" } },
|
||||
},
|
||||
}],
|
||||
}]);
|
||||
|
||||
expect(tools[0].tools[0].parameters.properties.name.pattern).toBeUndefined();
|
||||
});
|
||||
|
||||
it("preserves custom freeform tools with format payloads", () => {
|
||||
const tools = normalizeTools([
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user