Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(codex): align Cindy compaction identity checks
liugaowei9d68064e11c9
diff --git a/apps/desktop/src/main/maker-host/__tests__/codexCredentialSwitch.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexCredentialSwitch.test.tsindex a97847f1d3..4ff1e55a92 100644--- a/apps/desktop/src/main/maker-host/__tests__/codexCredentialSwitch.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/codexCredentialSwitch.test.ts@@ -63,6 +63,21 @@ describe('shouldCloseSessionForCredentialSwitch codex mode', () => {expect(shouldCloseSessionForCredentialSwitch(input)).toBe(false);});+ it('keeps a local-compaction Cindy Codex thread when its independent subagent is incompatible', () => {+ const input = {+ agentKind: 'codex',+ currentProviderId: 'xd',+ nextProviderId: 'xd',+ currentModel: 'codex/gpt-5.5',+ nextModel: 'codex/gpt-5.6-sol',+ currentCodexProxyActive: true,+ currentCodexThreadModelProviderId: 'cindy_gateway',+ currentCodexCindyRemoteCompactionCompatible: false,+ } as const;+ expect(isCodexThreadModelProviderIdentityMismatch(input)).toBe(false);+ expect(shouldCloseSessionForCredentialSwitch(input)).toBe(false);+ });+it('keeps a proxy-active OAuth Codex session for oauth-family model changes', () => {expect(shouldCloseSessionForCredentialSwitch({agentKind: 'codex',diff --git a/apps/desktop/src/main/maker-host/codex-credential-switch.ts b/apps/desktop/src/main/maker-host/codex-credential-switch.tsindex 43843b37ef..372f2d9fe3 100644--- a/apps/desktop/src/main/maker-host/codex-credential-switch.ts+++ b/apps/desktop/src/main/maker-host/codex-credential-switch.ts@@ -33,6 +33,8 @@ export interface ShouldCloseSessionForCredentialSwitchInput {* 它是 thread 级冻结身份,不能用可能已被 UI 提前覆盖的 provider store 代替。*/currentCodexThreadModelProviderId?: string | null;+ /** 当前 host 的独立 Subagent 路由是否兼容 Cindy Codex 远程压缩。 */+ currentCodexCindyRemoteCompactionCompatible?: boolean | null;/*** 当前本地 Codex app-server spawn 的鉴权注入形态(getCodexProxyAuthInjectionState())。* 用于把隐式来源(resolveAgentCredentialMode 解析出 undefined)落到实际凭证家族,@@ -167,7 +169,9 @@ export function isCodexThreadModelProviderIdentityMismatch(providerId: nextProviderId,model: input.nextModel,})- ? CODEX_CINDY_COMPACT_PROVIDER_ID+ ? input.currentCodexCindyRemoteCompactionCompatible === false+ ? CODEX_GATEWAY_PROVIDER_ID+ : CODEX_CINDY_COMPACT_PROVIDER_ID: effectiveNextMode === 'oauth-bearer'? CODEX_OPENAI_COMPACT_PROVIDER_ID: effectiveNextMode !== undefineddiff --git a/apps/desktop/src/main/maker-ipc/__tests__/runtimeSetModel.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/runtimeSetModel.test.tsindex 19a1329f31..98c1b8a87e 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/runtimeSetModel.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/runtimeSetModel.test.ts@@ -242,6 +242,43 @@ describe('applyRuntimeSetModelChange', () => {expect(getSessionProvider(sessionId)).toBe('xd');});+ it('keeps an idle Cindy Codex thread local when its independent subagent is incompatible', async () => {+ const sessionId = rememberSession('runtime-set-model-cindy-local-compaction');+ setSessionProvider(sessionId, 'xd');+ const setModel = vi.fn(async () => {});+ const closeSession = vi.fn(async () => {});+ const maker: RuntimeSetModelMaker = {+ getSession: () => ({+ agentKind: 'codex',+ remoteHostId: null,+ codexProxyActive: true,+ codexThreadModelProviderId: 'cindy_gateway',+ codexCindyRemoteCompactionCompatible: false,+ model: 'codex/gpt-5.5',+ setModel,+ }),+ listActiveSessions: () => [{+ id: sessionId,+ agentKind: 'codex',+ remoteHostId: null,+ isTurnRunning: () => false,+ }],+ closeSession,+ };++ const result = await applyRuntimeSetModelChange({+ maker,+ sessionId,+ model: 'codex/gpt-5.6-sol',+ providerId: 'xd',+ });++ expect(result).toEqual({ status: 'applied' });+ expect(closeSession).not.toHaveBeenCalled();+ expect(setModel).toHaveBeenCalledWith('codex/gpt-5.6-sol', { providerId: 'xd' });+ expect(getSessionProvider(sessionId)).toBe('xd');+ });+it('soft-closes a local Codex session before switching into xAI provider OAuth routing', async () => {const sessionId = rememberSession('runtime-set-model-close-codex-xai');setSessionProvider(sessionId, 'xd');diff --git a/apps/desktop/src/main/maker-ipc/runtimeSetModel.ts b/apps/desktop/src/main/maker-ipc/runtimeSetModel.tsindex 3a04a27397..414692b8cd 100644--- a/apps/desktop/src/main/maker-ipc/runtimeSetModel.ts+++ b/apps/desktop/src/main/maker-ipc/runtimeSetModel.ts@@ -21,6 +21,7 @@ interface RuntimeSetModelSession {remoteHostId?: string | null;codexProxyActive?: boolean | null;codexThreadModelProviderId?: string | null;+ codexCindyRemoteCompactionCompatible?: boolean | null;model: string;setModel: (model: string, opts?: { providerId?: string | null; effort?: Effort }) => Promise<void>;}@@ -153,6 +154,8 @@ export async function applyRuntimeSetModelChange(nextModel: model,currentCodexProxyActive: sess.codexProxyActive,currentCodexThreadModelProviderId: sess.codexThreadModelProviderId,+ currentCodexCindyRemoteCompactionCompatible:+ sess.codexCindyRemoteCompactionCompatible,codexAuthInjection: input.codexAuthInjection,}): false;diff --git a/apps/desktop/src/main/scheduler-host/__tests__/runnerQueuedDispatch.test.ts b/apps/desktop/src/main/scheduler-host/__tests__/runnerQueuedDispatch.test.tsindex 6615e60982..6b7ff67870 100644--- a/apps/desktop/src/main/scheduler-host/__tests__/runnerQueuedDispatch.test.ts+++ b/apps/desktop/src/main/scheduler-host/__tests__/runnerQueuedDispatch.test.ts@@ -745,6 +745,42 @@ describe('MakerScheduleRunner queued dispatch (busy bound session)', () => {expect(mocks.setSessionProvider).not.toHaveBeenCalled();});+ it('排队 Cindy Codex 在独立 Subagent 不兼容时接受正确的本地压缩身份', async () => {+ mocks.getSessionRowSnapshot.mockResolvedValue({+ status: 'active',+ userSendAt: null,+ providerId: 'xd',+ });+ mocks.getSessionProvider.mockReturnValue('xd');+ const harness = createSessionHarness(async () => ({ accepted: true }));+ Object.defineProperties(harness.session, {+ agentKind: { value: 'codex' },+ model: { value: 'codex/gpt-5.6-sol', writable: true },+ codexProxyActive: { value: true },+ codexThreadModelProviderId: { value: 'cindy_gateway' },+ codexCindyRemoteCompactionCompatible: { value: false },+ });+ const queue = createQueueHarness({ busy: true });+ const { runner } = createRunnerHarness(harness.session, queue.deps, {+ metaModel: 'codex/gpt-5.6-sol',+ });++ const firePromise = runner.fire(+ heartbeatSchedule({+ agentKind: 'codex',+ model: 'codex/gpt-5.6-sol',+ providerId: 'xd',+ }),+ createFireContext(),+ );+ await vi.waitFor(() => expect(queue.enqueueCalls.length).toBe(1));+ await queue.accept();+ await vi.waitFor(() => expect(harness.listenerCount()).toBe(1));+ harness.emit({ type: 'done', data: {}, source: 'codex' });++ await expect(firePromise).resolves.toMatchObject({ sessionId: SESSION_ID });+ });+it('排队 Pi 每次派发都写 Fast=false,清掉复用会话的旧 bridge 状态', async () => {const harness = createSessionHarness(async () => ({ accepted: true }));(harness.session as { agentKind: string }).agentKind = 'pi';diff --git a/apps/desktop/src/main/scheduler-host/runner.ts b/apps/desktop/src/main/scheduler-host/runner.tsindex 446c5d9f45..b4ea69becf 100644--- a/apps/desktop/src/main/scheduler-host/runner.ts+++ b/apps/desktop/src/main/scheduler-host/runner.ts@@ -925,6 +925,8 @@ export class MakerScheduleRunner implements ScheduleRunner {nextModel: model,currentCodexProxyActive: liveSession.codexProxyActive,currentCodexThreadModelProviderId: liveSession.codexThreadModelProviderId,+ currentCodexCindyRemoteCompactionCompatible:+ liveSession.codexCindyRemoteCompactionCompatible,}: null;if (@@ -1344,6 +1346,8 @@ export class MakerScheduleRunner implements ScheduleRunner {nextModel: runtimeModel,currentCodexProxyActive: session.codexProxyActive,currentCodexThreadModelProviderId: session.codexThreadModelProviderId,+ currentCodexCindyRemoteCompactionCompatible:+ session.codexCindyRemoteCompactionCompatible,})) {throw new Error(@@ -2124,6 +2128,8 @@ export class MakerScheduleRunner implements ScheduleRunner {nextModel: live.model,currentCodexProxyActive: live.codexProxyActive,currentCodexThreadModelProviderId: live.codexThreadModelProviderId,+ currentCodexCindyRemoteCompactionCompatible:+ live.codexCindyRemoteCompactionCompatible,})) {throw new QueuedCodexThreadIdentityMismatchError(@@ -2140,6 +2146,8 @@ export class MakerScheduleRunner implements ScheduleRunner {nextModel: targetModel,currentCodexProxyActive: live.codexProxyActive,currentCodexThreadModelProviderId: live.codexThreadModelProviderId,+ currentCodexCindyRemoteCompactionCompatible:+ live.codexCindyRemoteCompactionCompatible,})) {// 早退 = 本轮沿用 live 当前路由派发:这条保留路由自己也要过停用裁决 ——diff --git a/packages/maker-core/src/agents/base-agent.ts b/packages/maker-core/src/agents/base-agent.tsindex 04926f6e12..6c3a651b30 100644--- a/packages/maker-core/src/agents/base-agent.ts+++ b/packages/maker-core/src/agents/base-agent.ts@@ -1673,6 +1673,8 @@ export interface AgentSessionHandle {* 这是 thread 级冻结身份,不随 thread/settings/update 的模型切换改变。*/readonly codexThreadModelProviderId?: string;+ /** Codex-only: 当前 host 的独立 Subagent 路由是否兼容 Cindy Codex 远程压缩。 */+ readonly codexCindyRemoteCompactionCompatible?: boolean;/*** Codex-only: start/resume 成功后,产品 prompt 这一次到底有没有进入* codex thread history。Maker 用这个事实更新 host 持久化 bit,避免再从diff --git a/packages/maker-core/src/agents/codex/index.test.ts b/packages/maker-core/src/agents/codex/index.test.tsindex 75f7416082..3c20d3f267 100644--- a/packages/maker-core/src/agents/codex/index.test.ts+++ b/packages/maker-core/src/agents/codex/index.test.ts@@ -3805,6 +3805,7 @@ describe('CodexAgent.startSession developerInstructions', () => {)?.[1] as { modelProvider?: string };expect(params.modelProvider).toBeUndefined();+ expect(handle.codexCindyRemoteCompactionCompatible).toBe(false);await handle.close();});diff --git a/packages/maker-core/src/agents/codex/index.ts b/packages/maker-core/src/agents/codex/index.tsindex 373069a585..cd905095e5 100644--- a/packages/maker-core/src/agents/codex/index.ts+++ b/packages/maker-core/src/agents/codex/index.ts@@ -5284,12 +5284,14 @@ export class CodexAgent extends BaseAgent {// 独立 Subagent 只在 proxy 层改写 Provider/model,Codex child thread 仍继承 root// 的 model provider identity。若 child 不是同一 Cindy Codex 后端,给 root 打开// remote compaction 会让 child 也错误调用不兼容上游;该组合保持本地压缩。- const cindyProviderRemoteCompaction = cindyProviderRemoteCompactionRequested && (+ const cindyProviderRemoteCompactionCompatible = (!independentSubagentRoute || isCindyProviderCodexRemoteCompactionRoute({providerId: independentSubagentRoute.providerId,model: independentSubagentRoute.catalogModel,}));+ const cindyProviderRemoteCompaction =+ cindyProviderRemoteCompactionRequested && cindyProviderRemoteCompactionCompatible;const threadCredentialFamily =credentialMode ?? this.hostEffectiveCredentialModes.get(currentHostKey);const threadModelProvider = opts.remoteHostId@@ -11082,6 +11084,9 @@ export class CodexAgent extends BaseAgent {get model() { return mutableModel; },get codexProxyActive() { return hostUsesCodexProxy; },get codexThreadModelProviderId() { return codexThreadModelProviderId; },+ get codexCindyRemoteCompactionCompatible() {+ return cindyProviderRemoteCompactionCompatible;+ },get codexProductPromptDelivery() { return codexProductPromptDelivery; },validateSendOptions(sendOpts: SendOptions) {diff --git a/packages/maker-core/src/session.ts b/packages/maker-core/src/session.tsindex 7ac3e03230..116f19f4a5 100644--- a/packages/maker-core/src/session.ts+++ b/packages/maker-core/src/session.ts@@ -1426,6 +1426,11 @@ export class Session {return this.handle.codexThreadModelProviderId;}+ /** Codex-only: 当前 host 的独立 Subagent 路由是否兼容 Cindy Codex 远程压缩。 */+ get codexCindyRemoteCompactionCompatible(): boolean | undefined {+ return this.handle.codexCindyRemoteCompactionCompatible;+ }+/** Snapshot used by temporary host overrides to avoid undoing a newer user change. */get permissionModeState(): PermissionModeState {return { ...this.permissionModeStateValue };