Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(codex): verify scheduler during thread recovery
Dashb922de491b9b
diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.tsindex e184a10ada..bf53780591 100644--- a/packages/maker-core/src/agents/codex/index.test.ts+++ b/packages/maker-core/src/agents/codex/index.test.ts@@ -896,6 +896,9 @@ describe('Codex official OAuth host isolation', () => {describe('CodexAgent spawn configuration', () => {it('holds account session recovery until the MCP bridge replacement is ready', async () => {+ MockCodexTransport.onCreate = transport => transport.setMockResponse(Method.McpServerStatusList, {+ result: { data: [{ name: 'cindy_scheduler', tools: { list_tools: {}, call_tool: {} } }], nextCursor: null },+ });let endpoint = 'http://127.0.0.1:51359/mcp/cindy_scheduler';const prepare = vi.fn(async () => {const frozenEndpoint = endpoint;@@ -10054,12 +10057,14 @@ describe('CodexAgent MCP thread context hooks', () => {model: 'gpt-5.4', workingDir: '/repo',});const originalSubscription = host.subscribeThread.mock.results[0]!.value;- await handle.send({ type: 'user', content: 'Create the heartbeat.' });expect(originalSubscription.release).toHaveBeenCalledOnce();expect(host.subscribeThread).toHaveBeenCalledTimes(2);expect(host.request.mock.calls.filter(([method]) => method === Method.ThreadResume)).toHaveLength(2);const coldResume = host.request.mock.calls.filter(([method]) => method === Method.ThreadResume)[1]![1];expect(coldResume).toMatchObject({ threadId, config: { 'mcp_servers.cindy_scheduler.url': 'http://127.0.0.1:47100/mcp/cindy_scheduler' } });+ const checksBeforeSend = host.request.mock.calls.filter(([method]) => method === Method.McpServerStatusList).length;+ await handle.send({ type: 'user', content: 'Create the heartbeat.' });+ expect(host.request.mock.calls.filter(([method]) => method === Method.McpServerStatusList)).toHaveLength(checksBeforeSend);expect(host.request.mock.calls.map(([method]) => method).lastIndexOf(Method.McpServerStatusList)).toBeLessThan(host.request.mock.calls.findIndex(([method]) => method === Method.TurnStart));await handle.close();@@ -10085,12 +10090,56 @@ describe('CodexAgent MCP thread context hooks', () => {sessionId: 'session-scheduler-available', resumeSessionId: threadId,model: 'gpt-5.4', workingDir: '/repo',});+ const checksBeforeSend = host.request.mock.calls.filter(([method]) => method === Method.McpServerStatusList).length;await handle.send({ type: 'user', content: 'Continue.' });+ expect(host.request.mock.calls.filter(([method]) => method === Method.McpServerStatusList)).toHaveLength(checksBeforeSend);expect(host.request.mock.calls.filter(([method]) => method === Method.ThreadResume)).toHaveLength(1);expect(host.subscribeThread).toHaveBeenCalledOnce();await handle.close();});+ it('rechecks scheduler MCP on the next task resume after a transient status error', async () => {+ const threadId = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';+ const agent = new CodexAgent(createDeps());+ let checks = 0;+ const host = installFakeHost(agent, (method) => {+ if (method === Method.ThreadResume) return { thread: { id: threadId }, model: 'gpt-5.4', modelProvider: 'openai' };+ if (method === Method.McpServerStatusList) {+ if (++checks === 1) throw new Error('temporary status failure');+ return { data: [{ name: 'cindy_scheduler', tools: { list_tools: {}, call_tool: {} } }], nextCursor: null };+ }+ return undefined;+ }, {+ buildSessionMcpConfig: () => ({ 'mcp_servers.cindy_scheduler.url': 'http://127.0.0.1:47100/mcp/cindy_scheduler' }),+ });+ const first = await agent.startSession({ sessionId: 'scheduler-retry', resumeSessionId: threadId,+ model: 'gpt-5.4', workingDir: '/repo' });+ expect(checks).toBe(1);+ await first.close();+ const second = await agent.startSession({ sessionId: 'scheduler-retry', resumeSessionId: threadId,+ model: 'gpt-5.4', workingDir: '/repo' });+ expect(checks).toBe(2);+ expect(host.request.mock.calls.filter(([method]) => method === Method.ThreadResume)).toHaveLength(2);+ await second.close();+ });++ it('bounds scheduler MCP status pagination when Codex repeats a cursor', async () => {+ const threadId = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee';+ const agent = new CodexAgent(createDeps());+ const host = installFakeHost(agent, (method) => {+ if (method === Method.ThreadResume) return { thread: { id: threadId }, model: 'gpt-5.4', modelProvider: 'openai' };+ if (method === Method.McpServerStatusList) return { data: [], nextCursor: 'repeated' };+ return undefined;+ }, {+ buildSessionMcpConfig: () => ({ 'mcp_servers.cindy_scheduler.url': 'http://127.0.0.1:47100/mcp/cindy_scheduler' }),+ });+ const handle = await agent.startSession({ sessionId: 'scheduler-cursor', resumeSessionId: threadId,+ model: 'gpt-5.4', workingDir: '/repo' });+ expect(host.request.mock.calls.filter(([method]) => method === Method.McpServerStatusList)).toHaveLength(2);+ expect(host.request.mock.calls.filter(([method]) => method === Method.ThreadResume)).toHaveLength(1);+ await handle.close();+ });+it('does not recover a scheduler MCP explicitly disabled for the task', async () => {const agent = new CodexAgent(createDeps());const host = installFakeHost(agent, (method) => {diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.tsindex a7f2c60f59..631fdf80b6 100644--- a/packages/maker-core/src/agents/codex/index.ts+++ b/packages/maker-core/src/agents/codex/index.ts@@ -7331,11 +7331,8 @@ assertRouteCurrent();// The host-level MCP probe can be green while a loaded thread still has an// older per-thread catalog. Codex ignores MCP config on a loaded-thread// resume; the release + cold resume above is required to add the server.- let schedulerMcpChecked = false;- const ensureSchedulerMcpForNextTurn = (signal?: AbortSignal): Promise<void> | null => {- // A brand-new thread may still be connecting its MCPs before the first- // turn. Wait until it has a saved rollout so recovery can preserve it.- if (schedulerMcpChecked || reviewMode || !threadMayHaveRollout) return null;+ const ensureSchedulerMcpForResumedThread = (): Promise<void> | null => {+ if (reviewMode || !threadMayHaveRollout) return null;const config = currentThreadWorkspaceConfig().config;if ((typeof config?.['mcp_servers.cindy_scheduler.url'] !== 'string' &&typeof config?.['mcp_servers.cindy_scheduler.command'] !== 'string') ||@@ -7344,11 +7341,20 @@ assertRouteCurrent();const verifyAndRecover = async (): Promise<void> => {const hasScheduler = async (): Promise<boolean> => {let cursor: string | null = null;+ const seenCursors = new Set<string>();+ const deadline = Date.now() + 10_000;do {+ if (cursor !== null) {+ if (seenCursors.has(cursor)) throw new Error('Codex MCP status pagination repeated a cursor');+ seenCursors.add(cursor);+ }+ if (seenCursors.size >= 5) throw new Error('Codex MCP status pagination exceeded five pages');+ const remainingMs = deadline - Date.now();+ if (remainingMs <= 0) throw new Error('Codex MCP status pagination timed out');const status: CodexMcpServerStatusListResponse = await host.request<CodexMcpServerStatusListResponse>(Method.McpServerStatusList,{ cursor, limit: 100, detail: 'toolsAndAuthOnly', threadId },- { timeoutMs: 10_000 },+ { timeoutMs: remainingMs },);const scheduler = status.data.find((server) => server.name === 'cindy_scheduler');if (scheduler && Object.hasOwn(scheduler.tools, 'list_tools') &&@@ -7363,32 +7369,26 @@ assertRouteCurrent();available = await hasScheduler();} catch (error) {// A failed diagnostic must not prevent unrelated work.- schedulerMcpChecked = true;log.warn('scheduler MCP verification failed', {threadId,error: error instanceof Error ? error.message : String(error),});return;}- if (available) {- schedulerMcpChecked = true;- return;- }+ if (available) return;log.warn('expected scheduler MCP is missing from Codex thread; cold-resuming', { threadId });// The existing refresh path closes this handle if the cold resume cannot// be confirmed. Propagate that failure instead of sending on a stale one.- await ensureContextLimitForNextTurn(signal, true);+ await ensureContextLimitForNextTurn(undefined, true);try {available = await hasScheduler();} catch (error) {- schedulerMcpChecked = true;log.warn('scheduler MCP verification after cold resume failed', {threadId,error: error instanceof Error ? error.message : String(error),});return;}- schedulerMcpChecked = true;if (!available) {log.warn('scheduler MCP remains unavailable after Codex thread cold resume', { threadId });}@@ -13080,8 +13080,6 @@ assertRouteCurrent();if (contextRefresh) await contextRefresh;const profileRefresh = ensureWorkspacePermissionProfileForNextTurn(sendOpts?.signal);if (profileRefresh) await profileRefresh;- const schedulerRefresh = ensureSchedulerMcpForNextTurn(sendOpts?.signal);- if (schedulerRefresh) await schedulerRefresh;turnWorkspaceConfig = currentTurnWorkspaceConfig();// A stale-daemon retry must hydrate the exact thread-level profile// that matches this turn, not mutable settings changed while the@@ -14582,6 +14580,10 @@ assertRouteCurrent();},};+ if (opts.resumeSessionId && threadMayHaveRollout) {+ const schedulerRefresh = ensureSchedulerMcpForResumedThread();+ if (schedulerRefresh) await schedulerRefresh;+ }return handle;}