Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(codex): extend hosted profile lifecycle deadlines
Lizia543157f16f8
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 5a3f5d2974..0f80e1f9b9 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@@ -445,6 +445,29 @@ describe('Codex device-hosted guest sessions', () => {await handle.close();});+ it('extends hosted workspace profile lifecycle requests with tunnel progress', async () => {+ const linkActivity = vi.fn(() => ({+ lastActivityAt: 1_234,+ execRequests: 4,+ execResponses: 3,+ execMaxInFlight: 2,+ httpInFlight: 0,+ }));+ const fixture = await startHosted({ guest: true, linkActivity });+ const handle = await fixture.started;+ 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: 60_000,+ extendWhileProgress: { idleMs: 30_000, maxMs: 300_000 },+ });+ await handle.close();+ });+it('keeps the fixed limit when the host provides no tunnel activity', async () => {const fixture = await startHosted({ guest: false });const handle = await fixture.started;diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.tsindex abf64a6b4e..e5965186fb 100644--- a/packages/maker-core/src/agents/codex/index.ts+++ b/packages/maker-core/src/agents/codex/index.ts@@ -6420,6 +6420,14 @@ 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 };+ return criticalThreadRpcOptions();+ }+function currentThreadWorkspaceConfig(contextLimit = currentContextLimit()): Pick<ThreadStartParams,| 'approvalPolicy'@@ -7280,12 +7288,15 @@ assertRouteCurrent();}: {action: 'refresh' | 'replacement';signal?: AbortSignal;- request: () => Promise<Response>;+ request: (options: { timeoutMs: number; extendWhileProgress?: RequestProgressDeadline }) => Promise<Response>;onLateResolve?: (response: Response) => Promise<void> | void;}): Promise<Response> =>new Promise<Response>((resolve, reject) => {let settled = false;let timer: ReturnType<typeof setTimeout> | null = null;+ const rpcOptions = profileLifecycleRpcOptions();+ const startedAt = Date.now();+ let extended = false;const cleanup = () => {if (timer) clearTimeout(timer);signal?.removeEventListener('abort', onAbort);@@ -7320,16 +7331,42 @@ assertRouteCurrent();onAbort();return;}- timer = setTimeout(() => {+ const expire = () => {+ const progress = rpcOptions.extendWhileProgress;+ if (progress) {+ const now = Date.now();+ let last: number | null = null;+ try {+ last = progress.lastProgressAt();+ } catch {+ last = null;+ }+ const idleLeft = last === null ? 0 : progress.idleMs - (now - last);+ const capLeft = progress.maxMs - (now - startedAt);+ if (idleLeft > 0 && capLeft > 0) {+ extended = true;+ timer = setTimeout(expire, Math.min(idleLeft, capLeft));+ timer.unref?.();+ return;+ }+ }+ let detail: string | undefined;+ try {+ detail = rpcOptions.extendWhileProgress?.describe?.();+ } catch {+ detail = undefined;+ }+ const waitedMs = extended ? Date.now() - startedAt : rpcOptions.timeoutMs;rejectOnce(new Error(- `Codex workspace permission profile ${action} did not acknowledge within ${PROFILE_LIFECYCLE_ACK_TIMEOUT_MS}ms`,+ `Codex workspace permission profile ${action} did not acknowledge within ${waitedMs}ms${detail ? ` (${detail})` : ''}`,),);- }, PROFILE_LIFECYCLE_ACK_TIMEOUT_MS);+ };+ timer = setTimeout(expire, rpcOptions.timeoutMs);timer.unref?.();try {- request().then(+ request(rpcOptions).then(resolveOnce,(error) => rejectOnce(error instanceof Error ? error : new Error(String(error)),@@ -7359,7 +7396,7 @@ assertRouteCurrent();const resp = await requestProfileLifecycle<ThreadStartResponse>({action: 'replacement',signal,- request: () => withMcpDiscoveryContext(() => host.request<ThreadStartResponse>(retainHistory ? Method.ThreadFork : Method.ThreadStart, {+ request: (options) => withMcpDiscoveryContext(() => host.request<ThreadStartResponse>(retainHistory ? Method.ThreadFork : Method.ThreadStart, {...(retainHistory ? { threadId: previousThreadId, excludeTurns: true } : {}),cwd: opts.workingDir,// Recovery belongs to the running send, whose catalog/window is already frozen.@@ -7370,7 +7407,7 @@ assertRouteCurrent();...(mutableModel && mutableModel !== 'gpt-5' ? { model: mutableModel } : {}),...(mutableServiceTier !== undefined ? { serviceTier: mutableServiceTier } : {}),...(developerInstructions && !useProxyChannel ? { developerInstructions } : {}),- })),+ }, options)),onLateResolve: async (lateResp) => {const lateThreadId = lateResp.thread.id;if (lateThreadId === previousThreadId) return;@@ -7502,7 +7539,7 @@ assertRouteCurrent();resp = await requestProfileLifecycle<ThreadResumeResponse>({action: 'refresh',signal,- request: () => host.request<ThreadResumeResponse>(Method.ThreadResume, {+ request: (options) => host.request<ThreadResumeResponse>(Method.ThreadResume, {threadId,...(resumeExcludeTurnsSupported ? { excludeTurns: true } : {}),cwd: opts.workingDir,@@ -7510,7 +7547,7 @@ assertRouteCurrent();...(threadModelProvider ? { modelProvider: threadModelProvider } : {}),...(mutableModel && mutableModel !== 'gpt-5' ? { model: mutableModel } : {}),...(mutableServiceTier !== undefined ? { serviceTier: mutableServiceTier } : {}),- }),+ }, options),});} catch (e) {if (!isExactNoRolloutThreadResumeError(e, threadId)) throw e;@@ -7560,7 +7597,7 @@ assertRouteCurrent();const workspaceConfig = currentThreadWorkspaceConfig(desired);const resp = await requestProfileLifecycle<ThreadResumeResponse>({action: 'refresh', signal,- request: () => host.request<ThreadResumeResponse>(Method.ThreadResume, {+ request: (options) => host.request<ThreadResumeResponse>(Method.ThreadResume, {threadId, cwd: opts.workingDir,...(resumeExcludeTurnsSupported ? { excludeTurns: true } : {}),...workspaceConfig,@@ -7568,7 +7605,7 @@ assertRouteCurrent();...(mutableModel && mutableModel !== 'gpt-5' ? { model: mutableModel } : {}),...(mutableServiceTier !== undefined ? { serviceTier: mutableServiceTier } : {}),...(developerInstructions && !useProxyChannel ? { developerInstructions } : {}),- }),+ }, options),onLateResolve: async () => {await runThreadCleanupOrRetire({cleanupThreadId: threadId, reason: 'late context settings refresh',