Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(mcps): set_session_runtime 的 expected_generation 契约对齐为必填 (#3618)
fico-hubec05c2715974
diff --git a/packages/lizi-mcps/src/__tests__/sessionControlTools.test.ts b/packages/lizi-mcps/src/__tests__/sessionControlTools.test.tsindex ce1be09206..ed3830c62e 100644--- a/packages/lizi-mcps/src/__tests__/sessionControlTools.test.ts+++ b/packages/lizi-mcps/src/__tests__/sessionControlTools.test.ts@@ -113,17 +113,23 @@ describe('cindy_helper session control tools', () => {});it('requires a bound current session when session_id is omitted', async () => {+ // expected_generation 已是 schema 必填(#3535):带上合法值,隔离验证+ // 会话上下文缺失的分支。const { registry } = setup({ sessionId: undefined });expect(- parse(await registry.call('set_session_runtime', { effort: 'high' })),+ parse(await registry.call('set_session_runtime', { effort: 'high', expected_generation: 1 })),).toMatchObject({ ok: false, errorCode: 'NO_SESSION_CONTEXT' });});it('requires a read-before-write generation token', async () => {+ // #3535:schema 曾标 optional 而 handler 强制必传 —— 契约矛盾让缺参调用+ // 只拿到裸 INVALID_ARGS。现在 schema 即必填:zod 层拒绝并回吐 schema 与+ // 校验明细,调用方一轮自纠。const { registry } = setup();- expect(- parse(await registry.call('set_session_runtime', { effort: 'high' })),- ).toMatchObject({ ok: false, errorCode: 'INVALID_ARGS' });+ const result = parse(await registry.call('set_session_runtime', { effort: 'high' }));+ expect(result).toMatchObject({ ok: false, errorCode: 'INVALID_ARGS' });+ expect(JSON.stringify(result.data?.validation_errors ?? result)).toContain('expected_generation');+ expect(result.data?.schema).toBeTruthy();});it('updates and cancels only through the caller-bound ownership context', async () => {diff --git a/packages/lizi-mcps/src/xdt-helper/session_control.ts b/packages/lizi-mcps/src/xdt-helper/session_control.tsindex 35d65ac2d0..d67b1a23c4 100644--- a/packages/lizi-mcps/src/xdt-helper/session_control.ts+++ b/packages/lizi-mcps/src/xdt-helper/session_control.ts@@ -331,8 +331,9 @@ export function registerSetSessionRuntimeTool(.number().int().nonnegative()- .optional()- .describe('来自 get_session_runtime 的 generation。'),+ .describe(+ '必填:先调用 get_session_runtime 读取当前 generation 并原样传回,用于防止覆盖并发修改。',+ ),},handler: async ({ session_id, provider_id, model, effort, fast, expected_generation }) => {const targetSessionId = session_id ?? requireCallerSession(deps);@@ -348,7 +349,8 @@ export function registerSetSessionRuntimeTool(return errorPayload('INVALID_ARGS', '至少提供 provider_id、model、effort 或 fast 之一。');}if (expected_generation === undefined) {- return errorPayload('INVALID_ARGS', '请先调用 get_session_runtime,并传回 expected_generation。');+ // schema 已必填,此分支为纵深防御:任何绕过 zod 的调用路径仍拿到同一引导。+ return errorPayload('INVALID_ARGS', '请先调用 get_session_runtime 获取 generation,并作为 expected_generation 传回。');}const result = await deps.setSessionRuntime({targetSessionId,