Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(codex): keep profile lifecycle late responses past the acceptance deadline
MagicLizi0feece8b142c
diff --git a/packages/maker-core/src/agents/codex/__tests__/device-hosted-guest.test.ts b/packages/maker-core/src/agents/codex/__tests__/device-hosted-guest.test.tsindex 0f80e1f9b9..3c71b7113e 100644--- a/packages/maker-core/src/agents/codex/__tests__/device-hosted-guest.test.ts+++ b/packages/maker-core/src/agents/codex/__tests__/device-hosted-guest.test.ts@@ -461,10 +461,87 @@ describe('Codex device-hosted guest sessions', () => {const replacementCall = fixture.request.mock.calls.filter(([method]) => method === Method.ThreadStart)[1] as unknown as [string, unknown, unknown] | undefined;const replacement = replacementCall?.[2] as Record<string, unknown> | undefined;+ // 内层 host.request = 外层接受期限(60s 基准 / 30s 静默 / 5min 封顶,见+ // criticalThreadRpcOptions)+ 5min 晚到响应窗口:接受期限收口后内层还要能收到+ // 晚到响应跑 onLateResolve 清理,不能两层同上限(#5772 review)。expect(replacement).toMatchObject({- timeoutMs: 60_000,- extendWhileProgress: { idleMs: 30_000, maxMs: 300_000 },+ timeoutMs: 360_000,+ extendWhileProgress: { idleMs: 330_000, maxMs: 600_000 },});+ const progress = replacement?.extendWhileProgress as {+ lastProgressAt(): number | null;+ describe?(): string;+ };+ expect(progress.lastProgressAt()).toBe(1_234);+ expect(progress.describe?.()).toContain('execution environment answered 3/4 requests');+ await handle.close();+ });++ it('keeps the hosted profile lifecycle acceptance open with tunnel progress and cleans up late responses', async () => {+ let activityAt = 0;+ const linkActivity = vi.fn(() => ({+ lastActivityAt: activityAt,+ execRequests: 4,+ execResponses: 3,+ execMaxInFlight: 2,+ httpInFlight: 0,+ }));+ const fixture = await startHosted({ guest: true, linkActivity });+ const handle = await fixture.started;+ const host = await fixture.getHost.mock.results[0]!.value;+ const baseRequest = fixture.request.getMockImplementation()!;+ let replacementGated = false;+ let resolveReplacement: (response: unknown) => void = () => undefined;+ const replacement = new Promise((resolve) => {+ resolveReplacement = resolve;+ });+ fixture.request.mockImplementation(async (method: string, params: unknown) => {+ // startSession 的首次 thread/start 已经发完;此后唯一的 ThreadStart 就是 profile 替换。+ if (method === Method.ThreadStart && !replacementGated) {+ replacementGated = true;+ return replacement;+ }+ return baseRequest(method, params);+ });+ await handle.setExtraDirs?.(['/shared-profile']);+ activityAt = Date.now() + 45_000;+ vi.useFakeTimers();+ let sendSettled = false;+ try {+ const sendPromise = handle.send(+ { type: 'user', content: 'use the hosted profile' },+ { throwOnStartFailure: true },+ );+ void sendPromise.then(+ () => {+ sendSettled = true;+ },+ () => {+ sendSettled = true;+ },+ );+ await vi.advanceTimersByTimeAsync(60_000);+ // 基准 60s 到点时链路仍有往来:接受期限顺延,不收口。+ expect(sendSettled).toBe(false);+ activityAt = Date.now() + 10_000;+ await vi.advanceTimersByTimeAsync(40_000);+ // 往来停满 30s 才按超时收口(实际等了 100s,超过 60s 基准)。+ await expect(sendPromise).rejects.toThrow(/did not acknowledge within 100000ms/);+ expect(fixture.request.mock.calls.filter(+ ([method]) => method === Method.ThreadStart,+ )).toHaveLength(2);+ } finally {+ vi.useRealTimers();+ }+ // 接受期限收口后,晚到响应仍到达 onLateResolve:脱线线程被退订,+ // 而不是被同上限的内层超时丢弃。+ resolveReplacement({+ thread: { id: 'late-thread-id' },+ model: 'gpt-5.5',+ modelProvider: 'openai',+ cwd: '/repo',+ });+ await vi.waitFor(() => expect(host.unsubscribeThread).toHaveBeenCalledWith('late-thread-id'));await handle.close();});@@ -474,6 +551,14 @@ describe('Codex device-hosted guest sessions', () => {const options = requestOptions(fixture.request, Method.ThreadStart);expect(options).toMatchObject({ timeoutMs: 60_000 });expect(options).not.toHaveProperty('extendWhileProgress');+ // 生命周期请求同样走固定 60s 接受期限(不是本地会话的 10s),内层再留晚到响应窗口。+ await handle.setExtraDirs?.(['/shared-profile']);+ await handle.send({ type: 'user', content: 'use the hosted profile' });+ const replacementCall = fixture.request.mock.calls+ .filter(([method]) => method === Method.ThreadStart)[1] as unknown as [string, unknown, unknown] | undefined;+ const replacement = replacementCall?.[2] as Record<string, unknown> | undefined;+ expect(replacement).toMatchObject({ timeoutMs: 360_000 });+ expect(replacement).not.toHaveProperty('extendWhileProgress');await handle.close();});diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.tsindex 47f13eae78..35abb5a8e9 100644--- a/packages/maker-core/src/agents/codex/index.test.ts+++ b/packages/maker-core/src/agents/codex/index.test.ts@@ -4448,6 +4448,13 @@ describe('CodexAgent reference directories', () => {expect(host.request.mock.calls.filter(([method]) => method === Method.ThreadStart,)).toHaveLength(2);+ // 内层 host.request 的上限必须比外层 10s 接受期限活得久(#5772 review):+ // 两层同上限会让 AppServerClient 在同一时刻删掉 pending,晚到响应被丢弃,+ // onLateResolve 的清理永远不会执行。本地会话 = 10s 接受期限 + 5min 晚到响应窗口。+ const replacementCall = host.request.mock.calls.filter(+ ([method]) => method === Method.ThreadStart,+ )[1] as unknown as [string, unknown, { timeoutMs?: number }];+ expect(replacementCall[2]).toMatchObject({ timeoutMs: 310_000 });await vi.advanceTimersByTimeAsync(10_000);await failure;} finally {@@ -25112,10 +25119,12 @@ describe('CodexAgent rewind', () => {expect(methods).not.toContain(Method.ThreadFork);expect(methods).not.toContain(Method.ThreadTurnsList);expect(methods.filter((method) => method === Method.ThreadStart)).toHaveLength(2);+ // 生命周期替换的内层请求带晚到响应窗口(10s 接受期限 + 5min,见+ // PROFILE_LIFECYCLE_LATE_RESPONSE_GRACE_MS),不是无选项的裸调用。expect(host.request).toHaveBeenLastCalledWith(Method.ThreadStart,expect.objectContaining({ cwd: '/repo' }),- expect.objectContaining({ timeoutMs: 10_000 }),+ expect.objectContaining({ timeoutMs: 310_000 }),);expect(host.subscribeThread).toHaveBeenLastCalledWith('fresh-thread-id', expect.any(Object));expect(await nextEvent(iterator)).toMatchObject({diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.tsindex e5965186fb..93b2a63e11 100644--- a/packages/maker-core/src/agents/codex/index.ts+++ b/packages/maker-core/src/agents/codex/index.ts@@ -1182,6 +1182,13 @@ const TIGHTEN_INTERRUPT_ACK_TIMEOUT_MS = 10_000;// bounded so a live-but-unresponsive daemon cannot freeze the queued message or// ignore Stop.const PROFILE_LIFECYCLE_ACK_TIMEOUT_MS = 10_000;+// 生命周期请求内层 host.request 在接受期限之外保留的晚到响应窗口(#5772 review): 外层+// requestProfileLifecycle 到点按「did not acknowledge」收口, 但请求可能已在服务端执行+// (thread/start 可能已建出新线程)。内层必须严格晚于外层收口, 晚到响应才能到达 resolveOnce+// 的迟到分支跑 onLateResolve 清理(退订脱线线程 / 退役不确定的 host); 两层同上限会让+// AppServerClient 到点删除 pending、丢弃晚到响应, 清理永远不会执行。窗口到点后由+// AppServerClient 显式删除 pending, 作为超时响应的显式清理。+const PROFILE_LIFECYCLE_LATE_RESPONSE_GRACE_MS = 5 * 60_000;// The Browser fallback route is resolved before thread/start, so the app-server// can only answer its readiness query against the global MCP inventory. Keep@@ -6422,9 +6429,10 @@ assertRouteCurrent();function profileLifecycleRpcOptions(): { timeoutMs: number; extendWhileProgress?: RequestProgressDeadline } {// Profile refresh/replacement has its own acceptance wrapper. Keep the- // historical short bound for local sessions, but make the wrapper follow- // the same progress-aware deadline as thread/start on hosted links.- if (!hosted?.linkActivity) return { timeoutMs: PROFILE_LIFECYCLE_ACK_TIMEOUT_MS };+ // historical short bound for local sessions; hosted sessions follow the+ // same progress-aware deadline as thread/start (old wiring without tunnel+ // activity records keeps the fixed 60s bound).+ if (!hosted) return { timeoutMs: PROFILE_LIFECYCLE_ACK_TIMEOUT_MS };return criticalThreadRpcOptions();}@@ -7295,6 +7303,19 @@ assertRouteCurrent();let settled = false;let timer: ReturnType<typeof setTimeout> | null = null;const rpcOptions = profileLifecycleRpcOptions();+ // 内层 host.request 的三条边界(基准 / 静默 / 顺延封顶)都比外层接受期限多留一段+ // 晚到响应窗口, 保证任何收口路径下内层都严格晚于外层(见+ // PROFILE_LIFECYCLE_LATE_RESPONSE_GRACE_MS)。+ const lateResponseOptions: { timeoutMs: number; extendWhileProgress?: RequestProgressDeadline } = rpcOptions.extendWhileProgress+ ? {+ timeoutMs: rpcOptions.timeoutMs + PROFILE_LIFECYCLE_LATE_RESPONSE_GRACE_MS,+ extendWhileProgress: {+ ...rpcOptions.extendWhileProgress,+ idleMs: rpcOptions.extendWhileProgress.idleMs + PROFILE_LIFECYCLE_LATE_RESPONSE_GRACE_MS,+ maxMs: rpcOptions.extendWhileProgress.maxMs + PROFILE_LIFECYCLE_LATE_RESPONSE_GRACE_MS,+ },+ }+ : { timeoutMs: rpcOptions.timeoutMs + PROFILE_LIFECYCLE_LATE_RESPONSE_GRACE_MS };const startedAt = Date.now();let extended = false;const cleanup = () => {@@ -7366,7 +7387,7 @@ assertRouteCurrent();timer = setTimeout(expire, rpcOptions.timeoutMs);timer.unref?.();try {- request(rpcOptions).then(+ request(lateResponseOptions).then(resolveOnce,(error) => rejectOnce(error instanceof Error ? error : new Error(String(error)),