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): accept null param in cache rejection errors

xde82e9609abe2
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/contextOverflowRollover.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/contextOverflowRollover.test.ts
index c0183486b2..9e26721226 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/contextOverflowRollover.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/contextOverflowRollover.test.ts
@@ -1180,7 +1180,12 @@ describe('createContextOverflowRollover', () => {
return deps;
}
- it('learns the per-model compat fix once and replays the failed turn', async () => {
+ it.each([
+ rejection,
+ ...['prompt_cache_key', 'prompt_cache_retention'].map(field => '400: ' + JSON.stringify({
+ code: null, message: `Validation: Unsupported parameter(s): \`${field}\``, param: null, type: 'invalid_request_error',
+ })),
+ ])('learns the per-model compat fix once and replays the failed turn: %s', async (rejection) => {
const deps = makePiDeps([
msg('user', '继续修这个 bug', 'u1', 1),
msg('assistant', '改完了,正在跑测试', 'a1', 2),
diff --git a/packages/maker-core/src/agents/pi/__tests__/cache-compatibility.integration.test.ts b/packages/maker-core/src/agents/pi/__tests__/cache-compatibility.integration.test.ts
index b8c81af737..7135e269b8 100644
--- a/packages/maker-core/src/agents/pi/__tests__/cache-compatibility.integration.test.ts
+++ b/packages/maker-core/src/agents/pi/__tests__/cache-compatibility.integration.test.ts
@@ -13,7 +13,13 @@ const binary = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '../..
const logger: Logger = { trace() {}, debug() {}, info() {}, warn() {}, error() {}, fatal() {}, child: () => logger };
describe.skipIf(!existsSync(binary))('Pi cache learning over real HTTP and native RPC', () => {
- it.each(['normal', 'api.openai.com', 'retry-failure'])('rebuilds with a learned fix and preserves one active input: %s', async (suffix) => {
+ it.each(['normal', 'api.openai.com', 'retry-failure'].flatMap(suffix => [
+ { suffix, errorFormat: 'omitted param', rejection: { message: 'Validation: Unsupported parameter(s): prompt_cache_key', type: 'invalid_request_error' } },
+ ...['prompt_cache_key', 'prompt_cache_retention'].map(field => ({
+ suffix, errorFormat: `null param (${field})`,
+ rejection: { error: { code: null, message: `Validation: Unsupported parameter(s): \`${field}\``, param: null, type: 'invalid_request_error' } },
+ })),
+ ]))('rebuilds with a learned fix and preserves one active input: $suffix / $errorFormat', async ({ suffix, rejection }) => {
const root = mkdtempSync(path.join(os.tmpdir(), 'cindy-cache-integration-'));
const received: Array<Record<string, unknown>> = [];
let rejectCacheFields = true;
@@ -24,7 +30,7 @@ describe.skipIf(!existsSync(binary))('Pi cache learning over real HTTP and nativ
received.push(data);
if (rejectCacheFields && (data.prompt_cache_key !== undefined || data.prompt_cache_retention !== undefined)) {
res.writeHead(400, { 'content-type': 'application/json' });
- res.end(JSON.stringify({ message: 'Validation: Unsupported parameter(s): prompt_cache_key', type: 'invalid_request_error' }));
+ res.end(JSON.stringify(rejection));
return;
}
if (suffix === 'retry-failure' && received.length === 2) {
@@ -83,6 +89,10 @@ describe.skipIf(!existsSync(binary))('Pi cache learning over real HTTP and nativ
onTranscriptUserEntry: async id => { userEntry = id; },
});
expect(userEntry).not.toBe(originalUserEntry);
+ expect(received).toHaveLength(2);
+ expect(received[1]).not.toHaveProperty('prompt_cache_key');
+ expect(received[1]).not.toHaveProperty('prompt_cache_retention');
+ expect((received[1].messages as Array<{ role: string }>).filter((m) => m.role === 'user')).toHaveLength(1);
if (suffix === 'retry-failure') {
expect(succeeded.some(event => event.type === 'error')).toBe(true);
const manual = await run({ retryTranscriptUserEntryId: userEntry });
@@ -93,10 +103,6 @@ describe.skipIf(!existsSync(binary))('Pi cache learning over real HTTP and nativ
}
expect(succeeded.some((event) => event.type === 'error')).toBe(false);
expect(succeeded.find((event) => event.type === 'done')?.data).toMatchObject({ result: 'OK' });
- expect(received).toHaveLength(2);
- expect(received[1]).not.toHaveProperty('prompt_cache_key');
- expect(received[1]).not.toHaveProperty('prompt_cache_retention');
- expect((received[1].messages as Array<{ role: string }>).filter((m) => m.role === 'user')).toHaveLength(1);
await handle.close();
handle = await agent.startSession({ ...opts, sessionId: 'new-task' });
expect((await run({})).some((event) => event.type === 'error')).toBe(false);
diff --git a/packages/maker-core/src/agents/shared/unsupported-request-option-error.test.ts b/packages/maker-core/src/agents/shared/unsupported-request-option-error.test.ts
index 5fb84f5eba..6eebb44c2a 100644
--- a/packages/maker-core/src/agents/shared/unsupported-request-option-error.test.ts
+++ b/packages/maker-core/src/agents/shared/unsupported-request-option-error.test.ts
@@ -53,6 +53,42 @@ describe('unsupported request option error', () => {
).toBe(true);
});
+ // #6570: a nullable param means no parameter was specified, as does an omitted key.
+ describe.each(['prompt_cache_key', 'prompt_cache_retention'])('structured rejection of %s', (field) => {
+ describe.each([false, true])('wrapped in error: %s', (wrapped) => {
+ it.each(['omitted', 'null', 'named'] as const)('accepts param %s', (paramForm) => {
+ const error = {
+ code: null,
+ message: `Validation: Unsupported parameter(s): \`${field}\``,
+ type: 'invalid_request_error',
+ ...(paramForm === 'omitted' ? {} : { param: paramForm === 'null' ? null : field }),
+ };
+ const message = '400: ' + JSON.stringify(wrapped ? { error } : error);
+ expect(isUnsupportedRequestOptionErrorMessage(message)).toBe(true);
+ expect(unsupportedRequestOptionCompatOverride(message)).toEqual({ supportsLongCacheRetention: false });
+ });
+
+ it.each(['temperature', 'prompt_cache_options', '', 0, false, [], {}].map(param => ({ param })))('rejects non-cache param $param', ({ param }) => {
+ const error = { code: null, param, type: 'invalid_request_error', message: `Unsupported parameter(s): ${field}` };
+ const message = '400: ' + JSON.stringify(wrapped ? { error } : error);
+ expect(isUnsupportedRequestOptionErrorMessage(message)).toBe(false);
+ expect(unsupportedRequestOptionCompatOverride(message)).toBeUndefined();
+ });
+ });
+ });
+
+ it.each([
+ [400, 'invalid_request_error', 'Invalid value for prompt_cache_key'],
+ [400, 'invalid_request_error', 'Unsupported parameter(s): temperature'],
+ [400, 'authentication_error', 'Unsupported parameter(s): prompt_cache_key'],
+ [401, 'invalid_request_error', 'Unsupported parameter(s): prompt_cache_key'],
+ [429, 'invalid_request_error', 'Unsupported parameter(s): prompt_cache_key'],
+ ])('keeps null param from bypassing rejection criteria: %s %s %s', (status, type, message) => {
+ const rejection = `${status}: ` + JSON.stringify({ error: { code: null, param: null, type, message } });
+ expect(isUnsupportedRequestOptionErrorMessage(rejection)).toBe(false);
+ expect(unsupportedRequestOptionCompatOverride(rejection)).toBeUndefined();
+ });
+
it.each([
['generic invalid request', '400: {"error":{"message":"invalid api key"}}'],
['rate limit', '429: rate limit exceeded, retry later'],
diff --git a/packages/maker-core/src/agents/shared/unsupported-request-option-error.ts b/packages/maker-core/src/agents/shared/unsupported-request-option-error.ts
index bbdd997163..bf696fb4b5 100644
--- a/packages/maker-core/src/agents/shared/unsupported-request-option-error.ts
+++ b/packages/maker-core/src/agents/shared/unsupported-request-option-error.ts
@@ -11,8 +11,8 @@
* 不接受该字段,改写 models.json 的 compat 后重放同一轮请求(PI provider compat 自愈)。
*
* 判据只认「被点名的可选字段 + 明确的 not supported/unsupported 措辞」同时出现:
- * 普通 400(鉴权/参数值错误/未点名已知字段)不满足;结构化错误里出现 `param` 时,
- * 它必须点名这两类字段之一,避免把别的参数错误误判成「不支持」。
+ * 普通 400(鉴权/参数值错误/未点名已知字段)不满足;结构化错误的 `param` 缺省或为 null
+ * 表示未指定参数;非 null 时必须点名这两类字段之一,避免误判其他参数错误。
*/
export const UNSUPPORTED_REQUEST_OPTION_REASON = 'unsupported-request-option';
@@ -40,7 +40,7 @@ export function isUnsupportedRequestOptionErrorMessage(message: string): boolean
for (let depth = 0; depth < 3; depth++) {
if (!value || typeof value !== 'object' || Array.isArray(value)) return false;
const error = value as Record<string, unknown>;
- if (Object.hasOwn(error, 'param') && !CACHE_FIELDS.some((field) => field === error.param)) return false;
+ if (Object.hasOwn(error, 'param') && error.param !== null && !CACHE_FIELDS.some((field) => field === error.param)) return false;
if (error.type !== undefined && !['invalid_request_error', 'unsupported_parameter'].includes(String(error.type))) return false;
if (typeof error.message === 'string') { text = error.message; break; }
value = error.error;