Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(codex): 保留旧模型别名预算并更新远程切模回归

Dashdc5d3ecb29da
diff --git a/apps/desktop/src/main/maker-host/__tests__/codexContextSwitch.native.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexContextSwitch.native.test.ts
index c487550e75..2cd773374e 100644
--- a/apps/desktop/src/main/maker-host/__tests__/codexContextSwitch.native.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/codexContextSwitch.native.test.ts
@@ -19,7 +19,7 @@ it.skipIf(!binary)('cold-resumes the same history, compacts with the larger mode
const root = await fs.mkdtemp(path.join(os.tmpdir(), 'cindy-context-switch-native-'));
const home = path.join(root, 'home');
const work = path.join(root, 'work');
- const windows: Record<string, number> = { 'fixture-wide': 500_000, 'fixture-small': 272_000 };
+ const windows: Record<string, number> = { 'codex/fixture-wide': 500_000, 'fixture-small': 272_000 };
const requests: Array<{ model: string; input: unknown[] }> = [];
const server = createServer(async (req, res) => {
if (req.method !== 'POST') { res.end('{"models":[]}'); return; }
@@ -44,7 +44,7 @@ it.skipIf(!binary)('cold-resumes the same history, compacts with the larger mode
await fs.mkdir(home); await fs.mkdir(work);
await new Promise<void>(resolve => server.listen(0, '127.0.0.1', resolve));
await fs.writeFile(path.join(home, 'models_cache.json'), JSON.stringify({ models: Object.keys(windows)
- .map(slug => nativeCodexFallbackModel(slug, 'You are a test assistant.')) }));
+ .map(slug => nativeCodexFallbackModel(slug.replace(/^codex\//, ''), 'You are a test assistant.')) }));
await fs.writeFile(path.join(home, 'config.toml'), [
'model_provider="fixture"', 'cli_auth_credentials_store="ephemeral"',
'check_for_update_on_startup=false', '[analytics]', 'enabled=false',
@@ -60,6 +60,7 @@ it.skipIf(!binary)('cold-resumes the same history, compacts with the larger mode
expect(ctx.customContextProviderId).toBe('cprov-fixture');
const catalog = await prepareCodexCustomContextCatalog({ binaryPath: binary!, codexHome: home,
modelId: ctx.customContextModel!, contextWindow: ctx.customContextWindow!,
+ modelIds: Object.keys(windows),
resolveContextWindow: model => windows[model] ?? null });
return { extraArgs: catalog.extraArgs, extraEnv: {}, codexProxyActive: true };
},
@@ -74,7 +75,7 @@ it.skipIf(!binary)('cold-resumes the same history, compacts with the larger mode
});
agent = makeAgent();
const options = { sessionId: 'context-switch', providerId: 'cprov-fixture', workingDir: work, makerMemoryEnabled: false };
- let handle = await agent.startSession({ ...options, model: 'fixture-wide' });
+ let handle = await agent.startSession({ ...options, model: 'codex/fixture-wide' });
const send = async (text: string) => {
const finished = (async () => {
for await (const event of handle.events()) {
@@ -95,7 +96,7 @@ it.skipIf(!binary)('cold-resumes the same history, compacts with the larger mode
handle = await agent.startSession({ ...options, model: 'fixture-small', resumeSessionId: threadId });
expect(handle.id).toBe(threadId);
await send('CONTINUE_MARKER');
- expect(requests.map(request => request.model)).toEqual(['fixture-wide', 'fixture-wide', 'fixture-small']);
+ expect(requests.map(request => request.model)).toEqual(['codex/fixture-wide', 'codex/fixture-wide', 'fixture-small']);
expect(JSON.stringify(requests[1]!.input)).toContain('ORIGINAL_HISTORY_MARKER');
expect(JSON.stringify(requests[1]!.input)).toContain('FIRST_REPLY');
expect(JSON.stringify(requests[2]!.input)).toContain('NATIVE_SUMMARY');
diff --git a/apps/desktop/src/main/maker-host/__tests__/codexCustomContextCatalog.test.ts b/apps/desktop/src/main/maker-host/__tests__/codexCustomContextCatalog.test.ts
index 6d84b6f1ae..c798044591 100644
--- a/apps/desktop/src/main/maker-host/__tests__/codexCustomContextCatalog.test.ts
+++ b/apps/desktop/src/main/maker-host/__tests__/codexCustomContextCatalog.test.ts
@@ -193,6 +193,28 @@ describe('Codex custom context model catalog', () => {
expect(catalog.models).toContainEqual(native);
});
+ // Unit: cold resume previously omitted an old wire alias absent from native
+ // discovery, hiding its larger saved budget. Exercise the persisted spawn catalog,
+ // including the smart Subagent base, while leaving the native sibling untouched.
+ it.each([false, true])('keeps the previous alias budget absent from native discovery (smart=%s)', async smart => {
+ const native = { slug: 'gpt-6-astra', context_window: 272_000, max_context_window: 872_000,
+ base_instructions: 'native prompt', comp_hash: 'opaque' };
+ const { root, binaryPath } = await createFixtureBinary({ models: [native] });
+ const result = await prepareCodexCustomContextCatalog({ binaryPath, codexHome: root,
+ modelId: 'gpt-6-astra-small', contextWindow: 500_000,
+ modelIds: ['codex/gpt-6-astra', 'gpt-6-astra-small'],
+ resolveContextWindow: model => model === 'codex/gpt-6-astra' ? 1_000_000 : null,
+ ...(smart ? { baseCatalog: { models: [{ slug: 'smart-route' }] } } : {}),
+ });
+ const catalog = JSON.parse(await fs.readFile(result.catalogPath, 'utf8'));
+ expect(catalog.models).toContainEqual({ ...native, slug: 'codex/gpt-6-astra',
+ context_window: 1_000_000, max_context_window: 1_000_000, auto_compact_token_limit: 900_000 });
+ expect(catalog.models).toContainEqual({ ...native, slug: 'gpt-6-astra-small',
+ context_window: 500_000, max_context_window: 872_000, auto_compact_token_limit: 450_000 });
+ if (smart) expect(catalog.models).toContainEqual({ slug: 'smart-route' });
+ else expect(catalog.models).toContainEqual(native);
+ });
+
it.each(['\n', '\r\n'] as const)('preserves verified native unknown-model behavior with %j line endings', async (lineEnding) => {
const { root, binaryPath } = await createFixtureBinary({ models: [{ slug: 'gpt-5.4' }] }, lineEnding);
const instructions = nativeFallbackPrompt.replace(/\r?\n/g, lineEnding);
diff --git a/apps/desktop/src/main/maker-host/codex-custom-context-catalog.ts b/apps/desktop/src/main/maker-host/codex-custom-context-catalog.ts
index 9764545be7..862b206d4a 100644
--- a/apps/desktop/src/main/maker-host/codex-custom-context-catalog.ts
+++ b/apps/desktop/src/main/maker-host/codex-custom-context-catalog.ts
@@ -352,6 +352,8 @@ export async function prepareCodexCustomContextCatalog(params: {
modelId: string;
contextWindow: number;
scanChunkBytes?: number;
+ /** Same-provider model IDs, including aliases absent from native discovery. */
+ modelIds?: readonly string[];
/** Same-provider budgets for native previous-model compaction after cold resume. */
resolveContextWindow?: (modelId: string) => number | null;
/** In-memory smart Subagent catalog to preserve in the one-session custom-context Host. */
@@ -361,7 +363,7 @@ export async function prepareCodexCustomContextCatalog(params: {
let base = params.baseCatalog === undefined
? bundled
: normalizeNativeCatalog(parseCodexModelCatalog(JSON.stringify(params.baseCatalog)));
- base = await catalogWithModels(base, bundled, [params.modelId], params.binaryPath);
+ base = await catalogWithModels(base, bundled, [params.modelId, ...(params.modelIds ?? [])], params.binaryPath);
const patched = patchCodexModelMaxContextWindow(
base,
params.modelId,
diff --git a/apps/desktop/src/main/maker-host/index.ts b/apps/desktop/src/main/maker-host/index.ts
index 3b94473df2..6bf265ccd2 100644
--- a/apps/desktop/src/main/maker-host/index.ts
+++ b/apps/desktop/src/main/maker-host/index.ts
@@ -2083,14 +2083,15 @@ export function getMaker(): Maker {
) {
throw new Error('custom-context Codex host is missing its model or context window');
}
+ const catalog = getDesktopSelectableCatalog();
+ const source = resolveDesktopModelContextProviderId(catalog, 'codex', ctx.customContextProviderId, modelId);
const customCatalog = await prepareCodexCustomContextCatalog({
binaryPath: codexPath,
codexHome: effectiveCodexHome,
modelId,
contextWindow,
+ modelIds: catalog.providers.find(provider => provider.id === source)?.models.codex?.map(model => model.id),
resolveContextWindow: (nativeModelId) => {
- const catalog = getDesktopSelectableCatalog();
- const source = resolveDesktopModelContextProviderId(catalog, 'codex', ctx.customContextProviderId, nativeModelId);
return (source ? readModelContextLimit('codex', source, nativeModelId) : null)
?? resolveModelDefaultContextWindow(catalog, 'codex', source, nativeModelId);
},
diff --git a/apps/desktop/src/main/maker-ipc/__tests__/orcaRemoteModelWindowSelection.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/orcaRemoteModelWindowSelection.test.ts
index 78042495b7..4d9c08fc14 100644
--- a/apps/desktop/src/main/maker-ipc/__tests__/orcaRemoteModelWindowSelection.test.ts
+++ b/apps/desktop/src/main/maker-ipc/__tests__/orcaRemoteModelWindowSelection.test.ts
@@ -95,7 +95,7 @@ function setup(agent: 'cc' | 'codex' | 'pi' = 'codex', role: string | null = 'wo
}
describe('Orca remote-Agent window protection at send', () => {
- const cases = (['cc', 'codex', 'pi'] as const).flatMap(agent => ['lead', 'worker'].flatMap(role =>
+ const cases = (['cc', 'pi'] as const).flatMap(agent => ['lead', 'worker'].flatMap(role =>
[false, true].map(cold => ({ agent, role, cold }))));
it.each(cases)('rechecks pressure for $agent $role cold=$cold and retains an unconfirmed intent', async ({ agent, role, cold }) => {
const h = setup(agent, role, cold);
@@ -122,6 +122,25 @@ describe('Orca remote-Agent window protection at send', () => {
}
});
+ // Unit: remote Orca dispatch must preserve Codex native history even when the
+ // fresh target window is smaller than the current turn or an old acknowledgement.
+ // Covers the production send adapter for both roles and cold/live runtimes.
+ it.each(['lead', 'worker'].flatMap(role => [false, true].map(cold => ({ role, cold }))))(
+ 'keeps native Codex history for $role cold=$cold despite target pressure', async ({ role, cold }) => {
+ const h = setup('codex', role, cold);
+ await h.stage(1000000);
+ h.state.tokens = 190000;
+ await h.send();
+ expect(h.readProviders).toHaveBeenCalledWith('executor', 'codex', 'new', 'provider');
+ expect(h.pending.get('s1')).toBeUndefined();
+ expect(h.persist).toHaveBeenCalledOnce();
+ expect(h.close).not.toHaveBeenCalled();
+ expect(h.rebuild).not.toHaveBeenCalled();
+ if (cold) expect(h.runtime.setModel).not.toHaveBeenCalled();
+ else expect(h.runtime.setModel).toHaveBeenCalledExactlyOnceWith('new', { providerId: 'provider', effort: 'high' });
+ },
+ );
+
it('does not treat an unverified catalog window or its old acknowledgement as permission to rebuild', async () => {
const h = setup();
await h.stage(200000);
@@ -157,7 +176,7 @@ describe('Orca remote-Agent window protection at send', () => {
});
it('does not substitute a stale acknowledged window for the fresh execution-device catalog', async () => {
- const h = setup();
+ const h = setup('cc');
await h.stage(1000000);
h.state.tokens = 190000;
await expect(h.send()).rejects.toThrow('select the model again');