Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(pi): exclude explicit request validation failures

xuzini-xzn3496fd1f5a5c
diff --git a/packages/maker-core/src/agents/pi/__tests__/cache-recovery.test.ts b/packages/maker-core/src/agents/pi/__tests__/cache-recovery.test.ts
index eac2d97cb3..07810274f3 100644
--- a/packages/maker-core/src/agents/pi/__tests__/cache-recovery.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/cache-recovery.test.ts
@@ -274,6 +274,36 @@ describe('Pi native cache recovery', () => {
expect(h.sent).toHaveLength(1); expect(h.record()).toBeUndefined();
});
+ it.each([
+ { code: 'missing_required_parameter', message: 'Request validation failed' },
+ { type: 'invalid_type', message: 'Request validation failed' },
+ { code: 'invalid_type', param: null, message: 'Request validation failed' },
+ { message: "Missing required parameter: 'messages'." },
+ { message: 'messages: Field required' },
+ { message: 'Required field messages is missing' },
+ { message: 'Invalid type for messages' },
+ { message: 'Invalid parameter: temperature' },
+ { code: 'invalid_parameter', param: null, message: 'Invalid parameter: future_option' },
+ { message: "Parameter 'temperature' is invalid" },
+ { message: 'Invalid parameters: prompt_cache_key, temperature' },
+ ])('does not trial explicit required/type/other-field validation: %j', async error => {
+ const h = fixture(); h.fresh();
+ const event = failure('400: ' + JSON.stringify({ error }));
+ expect(await h.request([event, success])).toEqual([expect.objectContaining({ error: expect.objectContaining({ errorMessage: event.error.errorMessage }) })]);
+ expect(h.sent).toHaveLength(1); expect(h.record()).toBeUndefined();
+ });
+
+ it.each([
+ { code: 'invalid_parameter', message: 'Request validation failed' },
+ { type: 'invalid_parameter', param: null, message: 'Request validation failed' },
+ { message: 'Invalid parameter: prompt_cache_key' },
+ ])('keeps a non-specific validation label eligible for bounded contrast: %j', async error => {
+ const h = fixture(); h.fresh();
+ await h.request([failure('400: ' + JSON.stringify({ error })), success]);
+ expect(h.sent).toHaveLength(2);
+ expect(h.record()).toMatchObject({ evidence: 'opaque', expiresAt: 1086400000 });
+ });
+
it.each([
'Validation: Unsupported parameter(s): temperature',
'Unknown field: future_vendor_option',
diff --git a/packages/maker-core/src/agents/pi/cache-recovery-source.ts b/packages/maker-core/src/agents/pi/cache-recovery-source.ts
index 09776c69c1..5ccd427898 100644
--- a/packages/maker-core/src/agents/pi/cache-recovery-source.ts
+++ b/packages/maker-core/src/agents/pi/cache-recovery-source.ts
@@ -134,10 +134,24 @@ function installCindyCacheRecovery(pi) {
if (typeof data.message === 'string') body = data.message;
// Exclude known unrelated categories; unfamiliar gateway types stay opaque.
if ([data.code, data.type].some(value => typeof value === 'string'
- && /auth|permission|forbidden|quota|billing|rate.?limit|model.?not.?found|context|length|content.?filter|policy|invalid.?value/i.test(value))) return;
+ && /auth|permission|forbidden|quota|billing|rate.?limit|model.?not.?found|context|length|content.?filter|policy|invalid.?(?:value|type)|missing.?required/i.test(value))) return;
data = data.error;
}
if (/api.?key|unauthori[sz]ed|authentication|permission denied|quota|rate.?limit|model.{0,30}(?:not found|does not exist)|context.{0,25}(?:length|limit)|content.?filter|content.?policy|invalid.{0,15}value|鉴权|认证失败|额度|限流|模型不存在|上下文.{0,8}(?:超|长)|内容审核|参数值/i.test(body)) return;
+ // Removing optional cache fields cannot supply a required value or repair
+ // an explicitly invalid type. A generic invalid_parameter code alone does
+ // not establish either condition and must retain its bounded contrast.
+ if (/missing\s+required|(?:field|parameter|property|argument)\s+(?:is\s+)?required|required\s+(?:field|parameter|property|argument).{0,80}missing|invalid\s+type/i.test(body)) return;
+ for (const pattern of [
+ /invalid\s+(?:parameters?|fields?|arguments?|properties|property|options?)(?:\(s\))?[\s:=]*/gi,
+ /(?:parameter|field|argument|property|option)\s*[:=]?\s*['"\x60]?([a-z_][\w.-]*)['"\x60]?\s+(?:is\s+)?invalid/gi,
+ ]) {
+ for (const match of body.matchAll(pattern)) {
+ const invalid = match[1] ? [match[1].toLowerCase()]
+ : rejectedFieldList(body.slice(match.index + match[0].length));
+ if (invalid.some(field => !fields.includes(field))) return;
+ }
+ }
// A named rejection is evidence even when a gateway omits structured param.
// Parse the field relationship, never a list of vendor or parameter names.
let cacheRejected = false;