The all-in-one local AI studio for your desktop: chat, image and video generation and a coding agent in one free, open source app. Windows and Linux. No Docker, no terminal, no cloud required.
TypeScript agentai-chatai-studioall-in-onecoding-agentdesktop-appfluximage-generationlinuxllmlocal-ailocal-llmopen-sourceprivacyself-hostedstable-diffusionuncensoreduncensored-aivideo-generationwindows
fix(code): auto-apply follows the mode and lands only this run's changes
purple6708ab74071b
diff --git a/src/components/settings/SettingsPage.tsx b/src/components/settings/SettingsPage.tsxindex 61895672..e4bcf362 100644--- a/src/components/settings/SettingsPage.tsx+++ b/src/components/settings/SettingsPage.tsx@@ -1469,18 +1469,14 @@ function CodexAgentSettings() {{/* Stage + Review */}<div className="pt-1.5 border-t border-white/[0.04]" />+ {/* Staging is the mode's call (Ask stages file edits for review). The+ switch that used to sit here no longer decided anything and only+ hid this one, bug hunt 01.10.2026 (C5). */}<InlineToggle- label="Stage file_write changes (review before apply)"- enabled={settings.codexStageMode}- onChange={() => updateSettings({ codexStageMode: !settings.codexStageMode })}+ label="Auto-apply changes staged in Ask mode when the run finishes (no per-file clicking)"+ enabled={settings.codexAutoApply}+ onChange={() => updateSettings({ codexAutoApply: !settings.codexAutoApply })}/>- {settings.codexStageMode && (- <InlineToggle- label="Auto-apply staged changes when the run finishes (no per-file clicking)"- enabled={settings.codexAutoApply}- onChange={() => updateSettings({ codexAutoApply: !settings.codexAutoApply })}- />- )}<InlineTogglelabel="Code-Review mode (read-only)"enabled={settings.codexReviewMode}diff --git a/src/hooks/__tests__/codex-mode-wiring.test.ts b/src/hooks/__tests__/codex-mode-wiring.test.tsindex 2ab146eb..4ae0732f 100644--- a/src/hooks/__tests__/codex-mode-wiring.test.ts+++ b/src/hooks/__tests__/codex-mode-wiring.test.ts@@ -164,9 +164,9 @@ describe('runtime: a pick in one conversation leaves everything else alone', ()it('negative control: the preset-as-settings-write shape trips both assertions', () => {const before = JSON.stringify(useSettingsStore.getState().settings)// Exactly what C1 BINDUNG forbids: pushing the preset into the settings.- // Ask is the visible case (confirm on, stage on), and it would follow the- // user into every other conversation.- useSettingsStore.getState().updateSettings({ codexConfirmShell: true, codexStageMode: true })+ // Ask is the visible case (confirm on), and it would follow the user into+ // every other conversation.+ useSettingsStore.getState().updateSettings({ codexConfirmShell: true })expect(JSON.stringify(useSettingsStore.getState().settings)).not.toBe(before)// ... and it would have reached the Agent surface through the same object.useSettingsStore.getState().updateSettings({ codexCloudConfirmOptIn: true })diff --git a/src/hooks/useCodex.ts b/src/hooks/useCodex.tsindex d8dfddc6..55aa1d22 100644--- a/src/hooks/useCodex.ts+++ b/src/hooks/useCodex.ts@@ -679,7 +679,6 @@ export function useCodex() {settings: {codexConfirmShell: settings.codexConfirmShell,codexCloudConfirmOptIn: settings.codexCloudConfirmOptIn,- codexStageMode: settings.codexStageMode,codexReviewMode: settings.codexReviewMode,},providerId,@@ -2462,10 +2461,16 @@ export function useCodex() {// aborted run did not produce it, it was interrupted producing it. The// queue survives, so nothing is lost: the Pending panel still offers// every change for review.- if (settings.codexStageMode && settings.codexAutoApply && convId && !isRunStopped(convId)) {- const pending = useStagedChangesStore.getState().list(convId)+ //+ // Bug hunt 01.10.2026 (C5): the gate read settings.codexStageMode, a+ // switch the modes had replaced. Ask stages whatever that switch says,+ // so with it off the opt-in never fired, and with it on a Bypass run+ // applied what an EARLIER Ask run had left in the queue for review. The+ // mode decides now, and only what this run staged lands.+ if (knobs.stageWrites && settings.codexAutoApply && convId && !isRunStopped(convId)) {+ const pending = useStagedChangesStore.getState().list(convId).filter((c) => c.stagedAt >= turnStartMs)if (pending.length > 0) {- const applied = await applyAllStagedChanges(convId)+ const applied = await applyAllStagedChanges(convId, turnStartMs)if (applied.applied.length > 0) {fullContent += `\n\n_(auto-applied ${applied.applied.length} staged change${applied.applied.length === 1 ? '' : 's'}: ${applied.applied.join(', ')})_`}diff --git a/src/lib/__tests__/auto-apply-follows-the-mode-and-the-run.test.ts b/src/lib/__tests__/auto-apply-follows-the-mode-and-the-run.test.tsnew file mode 100644index 00000000..9e16fece--- /dev/null+++ b/src/lib/__tests__/auto-apply-follows-the-mode-and-the-run.test.ts@@ -0,0 +1,62 @@+/**+ * Bug hunt 01.10.2026 (C5). Auto-apply asked settings.codexStageMode, a switch+ * the modes had replaced: Ask stages whatever it says. With the switch off the+ * opt-in never fired; with it on, a Bypass run applied what an EARLIER Ask run+ * had left in the queue for the user to review. The switch decided nothing+ * else any more and is gone.+ */+import { describe, it, expect, vi, beforeEach } from 'vitest'+import { readFileSync } from 'node:fs'+import { resolve } from 'node:path'++vi.mock('../../api/backend', () => ({ backendCall: vi.fn(async () => ({ status: 'saved' })) }))+vi.mock('../../stores/chatStore', () => ({+ useChatStore: { getState: () => ({ addMessage: vi.fn(), conversations: [] }) },+}))++import { backendCall } from '../../api/backend'+import { applyAllStagedChanges } from '../staged-apply'+import { useStagedChangesStore } from '../../stores/stagedChangesStore'+import { useAgentModeStore } from '../../stores/agentModeStore'+import { DEFAULT_SETTINGS } from '../constants'++const CHAT = 'chat-c5'+const call = backendCall as unknown as ReturnType<typeof vi.fn>+const written = () => call.mock.calls.filter(([c]) => c === 'fs_write').map(([, a]) => (a as { path: string }).path)++beforeEach(() => {+ call.mockClear()+ useStagedChangesStore.getState().clear(CHAT)+ useAgentModeStore.setState({ workspaceSlugs: { [CHAT]: 'slug-c5' } })+})++describe('auto-apply', () => {+ it('lands only what this run staged, and leaves the earlier review queue alone', async () => {+ vi.useFakeTimers()+ vi.setSystemTime(1_000)+ useStagedChangesStore.getState().stage(CHAT, { path: 'earlier.ts', oldContent: '', newContent: 'a', diff: '' })+ vi.setSystemTime(5_000)+ const runStart = Date.now()+ useStagedChangesStore.getState().stage(CHAT, { path: 'this-run.ts', oldContent: '', newContent: 'b', diff: '' })+ vi.useRealTimers()++ const res = await applyAllStagedChanges(CHAT, runStart)+ expect(written()).toEqual(['this-run.ts'])+ expect(res.applied).toEqual(['this-run.ts'])+ expect(useStagedChangesStore.getState().list(CHAT).map((c) => c.path)).toEqual(['earlier.ts'])+ })++ it('follows the mode, not a settings switch', () => {+ const codex = readFileSync(resolve(__dirname, '../../hooks/useCodex.ts'), 'utf8')+ expect(codex).toContain('if (knobs.stageWrites && settings.codexAutoApply && convId && !isRunStopped(convId)) {')+ expect(codex).toMatch(/\.filter\(\(c\) => c\.stagedAt >= turnStartMs\)/)+ expect(codex).toContain('applyAllStagedChanges(convId, turnStartMs)')+ })++ it('the dead switch is gone, the opt-in is always reachable', () => {+ expect('codexStageMode' in DEFAULT_SETTINGS).toBe(false)+ const page = readFileSync(resolve(__dirname, '../../components/settings/SettingsPage.tsx'), 'utf8')+ expect(page).not.toContain('codexStageMode')+ expect(page).toContain('Auto-apply changes staged in Ask mode when the run finishes')+ })+})diff --git a/src/lib/__tests__/codex-mode.test.ts b/src/lib/__tests__/codex-mode.test.tsindex 6d8ab301..36cfcffe 100644--- a/src/lib/__tests__/codex-mode.test.ts+++ b/src/lib/__tests__/codex-mode.test.ts@@ -18,7 +18,6 @@ import { MUTATING_TOOLS } from '../mutating-tools'const SETTINGS = {codexConfirmShell: false,codexCloudConfirmOptIn: false,- codexStageMode: false,codexReviewMode: false,}@@ -63,14 +62,14 @@ describe('switch point 1: the exec confirm gate', () => {})describe('switch point 2: Stage-and-Approve for file_write / file_edit', () => {- it('Ask stages even when the setting is off', () => {- expect(knobs('ask', { codexStageMode: false }).stageWrites).toBe(true)+ it('Ask stages', () => {+ expect(knobs('ask', {}).stageWrites).toBe(true)})- it('Bypass does not stage even when the setting is on', () => {- expect(knobs('bypass', { codexStageMode: true }).stageWrites).toBe(false)+ it('Bypass does not stage', () => {+ expect(knobs('bypass', {}).stageWrites).toBe(false)})it('Plan does not stage, it has no writes to stage', () => {- expect(knobs('plan', { codexStageMode: true }).stageWrites).toBe(false)+ expect(knobs('plan', {}).stageWrites).toBe(false)})})@@ -129,7 +128,7 @@ describe('the cloud shell gate is an opt-in, not a fourth mode', () => {describe('the preset never writes anything', () => {it('leaves the settings object it was handed byte-identical', () => {- const settings = { ...SETTINGS, codexConfirmShell: true, codexStageMode: true }+ const settings = { ...SETTINGS, codexConfirmShell: true, codexReviewMode: false }const before = JSON.stringify(settings)for (const mode of CODEX_MODES) {codexModeKnobs({ mode, settings, providerId: 'lu-cloud', readOnlyTurn: false })@@ -140,8 +139,7 @@ describe('the preset never writes anything', () => {const settings = { ...SETTINGS }const before = JSON.stringify(settings)// This is the shape the plan forbids: the preset pushed into the settings.- ;(settings as { codexConfirmShell: boolean }).codexConfirmShell = false- ;(settings as { codexStageMode: boolean }).codexStageMode = true+ ;(settings as { codexConfirmShell: boolean }).codexConfirmShell = !settings.codexConfirmShellexpect(JSON.stringify(settings)).not.toBe(before)})})diff --git a/src/lib/__tests__/run-stop.test.ts b/src/lib/__tests__/run-stop.test.tsindex 1963e736..724c5e49 100644--- a/src/lib/__tests__/run-stop.test.ts+++ b/src/lib/__tests__/run-stop.test.ts@@ -125,7 +125,7 @@ describe('run-stop: both loop surfaces are wired to it', () => {// includes !abort.signal.aborted, so a Stop leaves through it), which meant a// run the user aborted mid-edit still wrote its half-finished changes to disk.expect(codex).toContain(- "settings.codexStageMode && settings.codexAutoApply && convId && !isRunStopped(convId)",+ "knobs.stageWrites && settings.codexAutoApply && convId && !isRunStopped(convId)",)})})diff --git a/src/lib/__tests__/settings-reset.test.ts b/src/lib/__tests__/settings-reset.test.tsindex 5d8c45d4..98dbef2d 100644--- a/src/lib/__tests__/settings-reset.test.ts+++ b/src/lib/__tests__/settings-reset.test.ts@@ -36,7 +36,7 @@ describe('SETTINGS_TAB_RESET_KEYS (#59)', () => {it('agent tab covers codex + search-provider + budget keys', () => {const a = SETTINGS_TAB_RESET_KEYS.agent- for (const k of ['searchProvider', 'braveApiKey', 'tavilyApiKey', 'codexStageMode', 'codexReviewMode', 'agentMaxToolCalls', 'agentMaxIterations'] as const) {+ for (const k of ['searchProvider', 'braveApiKey', 'tavilyApiKey', 'codexAutoApply', 'codexReviewMode', 'agentMaxToolCalls', 'agentMaxIterations'] as const) {expect(a, `agent tab missing ${k}`).toContain(k)}})diff --git a/src/lib/codex-mode.ts b/src/lib/codex-mode.tsindex ff8be439..551f2daf 100644--- a/src/lib/codex-mode.ts+++ b/src/lib/codex-mode.ts@@ -134,7 +134,6 @@ export interface CodexModeKnobInput {settings: {codexConfirmShell?: booleancodexCloudConfirmOptIn?: boolean- codexStageMode?: booleancodexReviewMode?: boolean}/** Provider driving this run, for the cloud arm of the shell gate. */diff --git a/src/lib/constants.ts b/src/lib/constants.tsindex 1345eb1e..f381a0a6 100644--- a/src/lib/constants.ts+++ b/src/lib/constants.ts@@ -123,7 +123,6 @@ export const DEFAULT_SETTINGS: Settings = {codexArchitectAllowCloud: false,codexRepoMapEnabled: false,codexRepoMapLimit: 20,- codexStageMode: false,codexAutoApply: false,codexReviewMode: false,// H2 security gate. OFF by default = the autonomous coding agent keepsdiff --git a/src/lib/settings-reset.ts b/src/lib/settings-reset.tsindex cdef386c..72a01ab5 100644--- a/src/lib/settings-reset.ts+++ b/src/lib/settings-reset.ts@@ -26,7 +26,7 @@ export const SETTINGS_TAB_RESET_KEYS: Record<SettingsTab, (keyof Settings)[]> ='agentMaxToolCalls', 'agentMaxIterations','searchProvider', 'braveApiKey', 'tavilyApiKey','codexArchitectMode', 'codexArchitectModel', 'codexArchitectAllowCloud',- 'codexRepoMapEnabled', 'codexRepoMapLimit', 'codexStageMode', 'codexAutoApply', 'codexReviewMode',+ 'codexRepoMapEnabled', 'codexRepoMapLimit', 'codexAutoApply', 'codexReviewMode',],'voice-remote': [],}diff --git a/src/lib/staged-apply.ts b/src/lib/staged-apply.tsindex e9c007c3..577467a2 100644--- a/src/lib/staged-apply.ts+++ b/src/lib/staged-apply.ts@@ -175,16 +175,17 @@ export async function applyStagedChange(chatId: string, change: StagedChange): Preturn true}-/** Apply every pending change for a chat, sequentially (fs_write serializes- * per path anyway). Failures stay in the queue for manual retry and are- * reported by path instead of throwing, so one bad write never blocks the- * rest. */+/** Apply the pending changes of a chat staged at or after `since` (all of+ * them without it), sequentially (fs_write serializes per path anyway).+ * Failures stay in the queue for manual retry and are reported by path+ * instead of throwing, so one bad write never blocks the rest. */export async function applyAllStagedChanges(chatId: string,+ since = 0,): Promise<{ applied: string[]; failed: string[] }> {const applied: string[] = []const failed: string[] = []- for (const change of [...useStagedChangesStore.getState().list(chatId)]) {+ for (const change of useStagedChangesStore.getState().list(chatId).filter((c) => c.stagedAt >= since)) {try {if (await applyStagedChange(chatId, change)) applied.push(change.path)} catch {diff --git a/src/lib/staged-overlay.ts b/src/lib/staged-overlay.tsindex f4333210..83ca975d 100644--- a/src/lib/staged-overlay.ts+++ b/src/lib/staged-overlay.ts@@ -1,5 +1,5 @@/**- * Read-your-writes for Stage-and-Approve (codexStageMode).+ * Read-your-writes for Stage-and-Approve (Ask mode, lib/codex-mode).** Staged file_write / file_edit calls never touch the disk — they sit in* stagedChangesStore until the user applies them. Without an overlay thediff --git a/src/types/settings.ts b/src/types/settings.tsindex 10f1a474..e60d7dd5 100644--- a/src/types/settings.ts+++ b/src/types/settings.ts@@ -298,16 +298,11 @@ export interface Settings {*/codexRepoMapLimit: number/**- * Multi-File Stage-and-Approve. When on, Codex `file_write` calls don't- * touch the disk — they queue as "pending changes" the user reviews and- * applies (or rejects) per-file.- */- codexStageMode: boolean- /**- * Auto-apply staged changes when the run finishes. Only meaningful while- * codexStageMode is on: every diff is still recorded and visible, but the- * user is not asked to click Apply per file — "auto on everything" then- * really means auto (first customer feedback, Morgan 2026-07-26).+ * Auto-apply the changes a run staged when it finishes. Whether a run+ * stages at all is its mode's call (Ask stages, Bypass and Plan do not,+ * lib/codex-mode). Every diff is still recorded and visible, but the user is+ * not asked to click Apply per file, so "auto on everything" really means+ * auto (first customer feedback, Morgan 2026-07-26).*/codexAutoApply: boolean/**