Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(codex): refresh resumed product prompt (#2570)
tiammomo09e6d9ed58c4
diff --git a/apps/desktop/src/main/__tests__/codexHistoryPromptInit.test.ts b/apps/desktop/src/main/__tests__/codexHistoryPromptInit.test.tsindex d6d9c6e067..ecd372b390 100644--- a/apps/desktop/src/main/__tests__/codexHistoryPromptInit.test.ts+++ b/apps/desktop/src/main/__tests__/codexHistoryPromptInit.test.ts@@ -1,6 +1,9 @@import { describe, expect, it } from 'vitest';-import { initializeCodexHistoryPromptState } from '../localDb/codexHistoryPromptInit';+import {+ CODEX_PRODUCT_PROMPT_REVISION,+ initializeCodexHistoryPromptState,+} from '../localDb/codexHistoryPromptInit';function createFakeDb() {const meta = new Map<string, string | null>();@@ -77,6 +80,9 @@ describe('initializeCodexHistoryPromptState', () => {expect(fake.sessions.get('proxy')).toBe(false);expect(fake.meta.get('codex_history_has_product_prompt_initialized_v1')).toBe('done');expect(fake.meta.get('codex_history_cindy_memory_prompt_reset_v2')).toBe('done');+ expect(fake.meta.get('codex_history_product_prompt_revision')).toBe(+ CODEX_PRODUCT_PROMPT_REVISION,+ );});it('does not touch later rows after both one-time guards are set', () => {@@ -102,6 +108,28 @@ describe('initializeCodexHistoryPromptState', () => {expect(fake.meta.get('codex_history_cindy_memory_prompt_reset_v2')).toBe('done');});+ it('re-arms delivered histories once when the product prompt revision changes', () => {+ const fake = createFakeDb();+ fake.meta.set('codex_history_has_product_prompt_initialized_v1', 'done');+ fake.meta.set('codex_history_cindy_memory_prompt_reset_v2', 'done');+ fake.meta.set('codex_history_product_prompt_revision', '2');+ fake.sessions.set('delivered', true);+ fake.sessions.set('pending', false);++ initializeCodexHistoryPromptState(fake.db as never);++ expect(fake.sessions.get('delivered')).toBe(false);+ expect(fake.sessions.get('pending')).toBe(false);+ expect(fake.meta.get('codex_history_product_prompt_revision')).toBe(+ CODEX_PRODUCT_PROMPT_REVISION,+ );++ // Simulate a successful one-shot delivery. The same revision must not re-arm it.+ fake.sessions.set('delivered', true);+ initializeCodexHistoryPromptState(fake.db as never);+ expect(fake.sessions.get('delivered')).toBe(true);+ });+it('skips initialization when the codex history column is missing', () => {const fake = createFakeDb();fake.sessions.set('old', null);@@ -120,5 +148,6 @@ describe('initializeCodexHistoryPromptState', () => {expect(fake.sessions.get('old')).toBeNull();expect(fake.meta.get('codex_history_has_product_prompt_initialized_v1')).toBeUndefined();expect(fake.meta.get('codex_history_cindy_memory_prompt_reset_v2')).toBeUndefined();+ expect(fake.meta.get('codex_history_product_prompt_revision')).toBeUndefined();});});diff --git a/apps/desktop/src/main/localDb/codexHistoryPromptInit.ts b/apps/desktop/src/main/localDb/codexHistoryPromptInit.tsindex 2474bc6183..58f6dd89ff 100644--- a/apps/desktop/src/main/localDb/codexHistoryPromptInit.ts+++ b/apps/desktop/src/main/localDb/codexHistoryPromptInit.ts@@ -5,6 +5,14 @@ import { createLogger } from '../logger';const log = createLogger('localDb/codex-history-prompt-init');const LEGACY_INIT_META_KEY = 'codex_history_has_product_prompt_initialized_v1';const CINDY_MEMORY_PROMPT_RESET_META_KEY = 'codex_history_cindy_memory_prompt_reset_v2';+const PRODUCT_PROMPT_REVISION_META_KEY = 'codex_history_product_prompt_revision';++/**+ * Bump whenever the Cindy-owned Codex developer-instruction snapshot changes.+ * The startup initializer will re-arm each delivered direct-resume thread once;+ * a successful native delivery flips that session's existing boolean back to true.+ */+export const CODEX_PRODUCT_PROMPT_REVISION = '3';function hasColumn(db: Database.Database, table: string, column: string): boolean {const rows = db.prepare(`PRAGMA table_info(${table})`).all() as Array<{ name?: unknown }>;@@ -29,13 +37,13 @@ export function initializeCodexHistoryPromptState(db: Database.Database): void {.get(key) as { value: string | null } | undefined;return row?.value;};- const writeMeta = (key: string): void => {+ const writeMeta = (key: string, value = 'done'): void => {db.prepare(`INSERT INTO migration_meta (key, value) VALUES (?, ?)ON CONFLICT(key) DO UPDATE SET value=excluded.value`,)- .run(key, 'done');+ .run(key, value);};if (readMeta(LEGACY_INIT_META_KEY) !== 'done') {@@ -70,4 +78,25 @@ export function initializeCodexHistoryPromptState(db: Database.Database): void {})();log.info('codex history prompt state reset for cindy_memory rename', { updated });}++ // The per-session delivery flag deliberately remains boolean: migration_meta owns+ // the product revision globally. A revision mismatch re-arms only sessions that+ // previously completed native delivery; false/unknown rows keep their fail-safe state.+ if (readMeta(PRODUCT_PROMPT_REVISION_META_KEY) !== CODEX_PRODUCT_PROMPT_REVISION) {+ const updated = db.transaction(() => {+ const result = db+ .prepare(`+ UPDATE sessions+ SET codex_history_has_product_prompt = 0+ WHERE codex_history_has_product_prompt = 1+ `)+ .run();+ writeMeta(PRODUCT_PROMPT_REVISION_META_KEY, CODEX_PRODUCT_PROMPT_REVISION);+ return result.changes;+ })();+ log.info('codex history prompt state reset for product prompt revision', {+ revision: CODEX_PRODUCT_PROMPT_REVISION,+ updated,+ });+ }}diff --git a/apps/desktop/src/main/localDb/schema.ts b/apps/desktop/src/main/localDb/schema.tsindex e9b5c3e9c6..3be7d4bbf7 100644--- a/apps/desktop/src/main/localDb/schema.ts+++ b/apps/desktop/src/main/localDb/schema.ts@@ -544,6 +544,7 @@ export const sessionPrRefs = sqliteTable(* - schema_version (string,"0" / "1" / ...)* - codex_history_has_product_prompt_initialized_v1 ('done')* - codex_history_cindy_memory_prompt_reset_v2 ('done')+ * - codex_history_product_prompt_revision (current explicit revision)** 历史 keys(只读遗留,不再写入):cloud_migration_*——chat-data 云端迁移已随* 主 server 退役(2026-07),存量库里可能残留这组键,无消费方。