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): a second approval request waits instead of refusing the first
purple5c4ad2aaed61
diff --git a/src/api/agents/__tests__/hintergrund-fragt-nicht.test.ts b/src/api/agents/__tests__/hintergrund-fragt-nicht.test.tsindex 9cd32c3f..2eb8df18 100644--- a/src/api/agents/__tests__/hintergrund-fragt-nicht.test.ts+++ b/src/api/agents/__tests__/hintergrund-fragt-nicht.test.ts@@ -148,7 +148,7 @@ beforeEach(() => {auditRecord.mockClear()auditComplete.mockClear()resetApprovals()- useCodexConfirmStore.setState({ pending: null, resolve: null })+ useCodexConfirmStore.setState({ pending: null, resolve: null, queue: [] })})describe('Unterauftrag aus dem Code-Tab: das Preset entscheidet, nicht der Chat-Store', () => {diff --git a/src/lib/__tests__/build-workflow-approval-gate.test.ts b/src/lib/__tests__/build-workflow-approval-gate.test.tsindex 2ab9d109..37d1cc68 100644--- a/src/lib/__tests__/build-workflow-approval-gate.test.ts+++ b/src/lib/__tests__/build-workflow-approval-gate.test.ts@@ -40,7 +40,7 @@ function makeRun(over: Partial<AgentRunContext> = {}): AgentRunContext {beforeEach(() => {registerBuiltinTools(toolRegistry)resetApprovals()- useCodexConfirmStore.setState({ pending: null, resolve: null })+ useCodexConfirmStore.setState({ pending: null, resolve: null, queue: [] })})afterEach(() => {diff --git a/src/stores/__tests__/codexConfirmStore-abort.test.ts b/src/stores/__tests__/codexConfirmStore-abort.test.tsindex ea213e1b..3a2e21c5 100644--- a/src/stores/__tests__/codexConfirmStore-abort.test.ts+++ b/src/stores/__tests__/codexConfirmStore-abort.test.ts@@ -10,7 +10,7 @@ import { useCodexConfirmStore } from '../codexConfirmStore'const req = { toolName: 'shell_execute', command: 'rm -rf build', cloudReason: false }beforeEach(() => {- useCodexConfirmStore.setState({ pending: null, resolve: null })+ useCodexConfirmStore.setState({ pending: null, resolve: null, queue: [] })})describe('codexConfirmStore.ask with an abort signal', () => {diff --git a/src/stores/__tests__/codexConfirmStore.test.ts b/src/stores/__tests__/codexConfirmStore.test.tsindex f7f9369a..c90134fe 100644--- a/src/stores/__tests__/codexConfirmStore.test.ts+++ b/src/stores/__tests__/codexConfirmStore.test.ts@@ -12,7 +12,7 @@ const req = (command: string, cloudReason = false) => ({})beforeEach(() => {- useCodexConfirmStore.setState({ pending: null, resolve: null })+ useCodexConfirmStore.setState({ pending: null, resolve: null, queue: [] })})describe('codexConfirmStore', () => {@@ -36,15 +36,40 @@ describe('codexConfirmStore', () => {expect(useCodexConfirmStore.getState().resolve).toBeNull()})- it('never strands a resolver when a second request arrives', async () => {- // Two tools racing would otherwise leave the first awaiting forever, and- // that tool call hangs with no visible cause. Deny the older one.- const first = useCodexConfirmStore.getState().ask(req('first'))+ // Bug hunt 01.10.2026 (C4). A second request used to answer the first "no"+ // and take its place: a command the user never saw was refused in their+ // name. Two runs in two conversations, or a run and its sub-agent, ask at+ // the same time. The second waits behind the first; nobody is stranded.+ it('a second request waits behind the first instead of refusing it', async () => {+ let firstAnswer: boolean | null = null+ const first = useCodexConfirmStore.getState().ask(req('first')).then((a) => { firstAnswer = a; return a })const second = useCodexConfirmStore.getState().ask(req('second'))- await expect(first).resolves.toBe(false)+ await Promise.resolve()+ expect(firstAnswer).toBeNull()+ expect(useCodexConfirmStore.getState().pending?.command).toBe('first')++ useCodexConfirmStore.getState().answer(true)+ await expect(first).resolves.toBe(true)expect(useCodexConfirmStore.getState().pending?.command).toBe('second')++ useCodexConfirmStore.getState().answer(false)+ await expect(second).resolves.toBe(false)+ expect(useCodexConfirmStore.getState().pending).toBeNull()+ })++ it('a stopped run takes only its own request out of the line', async () => {+ const ac = new AbortController()+ const first = useCodexConfirmStore.getState().ask(req('first'))+ const second = useCodexConfirmStore.getState().ask(req('second'), ac.signal)+ const third = useCodexConfirmStore.getState().ask(req('third'))+ ac.abort()+ await expect(second).resolves.toBe(false)+ expect(useCodexConfirmStore.getState().queue.map((w) => w.req.command)).toEqual(['first', 'third'])+ useCodexConfirmStore.getState().answer(true)+ await expect(first).resolves.toBe(true)+ expect(useCodexConfirmStore.getState().pending?.command).toBe('third')useCodexConfirmStore.getState().answer(true)- await expect(second).resolves.toBe(true)+ await expect(third).resolves.toBe(true)})it('carries the cloud reason through, since it picks which setting to clear', () => {diff --git a/src/stores/codexConfirmStore.ts b/src/stores/codexConfirmStore.tsindex 79892c06..19245249 100644--- a/src/stores/codexConfirmStore.ts+++ b/src/stores/codexConfirmStore.ts@@ -33,36 +33,50 @@ export interface CodexConfirmRequest {cloudReason: boolean}+interface Waiting {+ req: CodexConfirmRequest+ resolve: (allow: boolean) => void+}+interface CodexConfirmState {+ /** The request on the card: the oldest one still waiting. */pending: CodexConfirmRequest | null- /** Resolver for the awaited approval. Null when nothing is pending. */+ /** Resolver of that request. Null when nothing is pending. */resolve: ((allow: boolean) => void) | null+ /** Every request waiting for an answer, oldest first. */+ queue: Waiting[]ask: (req: CodexConfirmRequest, signal?: AbortSignal) => Promise<boolean>answer: (allow: boolean) => void}+/** The card shows the head of the queue. */+const head = (queue: Waiting[]) => ({ queue, pending: queue[0]?.req ?? null, resolve: queue[0]?.resolve ?? null })+export const useCodexConfirmStore = create<CodexConfirmState>((set, get) => ({pending: null,resolve: null,+ queue: [],ask: (req, signal) =>new Promise<boolean>((resolve) => {// Audit A4: Stop while the dialog was open never resolved this promise,// so the run's finally never ran and the chat stayed wedged. An abort- // answers "no" and takes the dialog down with it.+ // answers "no" and takes the card down with it.if (signal?.aborted) {resolve(false)return}- // A second request while one is open would strand the first resolver and- // hang that tool call forever. Deny the older one and take the new.- const prev = get().resolve- if (prev) prev(false)- set({ pending: req, resolve })+ // A second request while one is open waits behind it (bug hunt+ // 01.10.2026, C4). It used to answer the OLDER one "no" and take its+ // place: a command the user never saw was refused in their name, and+ // the run went on as if they had said no. Two runs in two conversations,+ // or a run and its sub-agent, ask at the same time routinely.+ const entry: Waiting = { req, resolve }+ set(head([...get().queue, entry]))signal?.addEventListener('abort',() => {- if (get().resolve === resolve) set({ pending: null, resolve: null })+ set(head(get().queue.filter((w) => w !== entry)))resolve(false)},{ once: true },@@ -70,8 +84,8 @@ export const useCodexConfirmStore = create<CodexConfirmState>((set, get) => ({}),answer: (allow) => {- const { resolve } = get()- set({ pending: null, resolve: null })- resolve?.(allow)+ const [first, ...rest] = get().queue+ set(head(rest))+ first?.resolve(allow)},}))