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 change rejected during Apply all is not written
purplea9ec77b699ff
diff --git a/src/lib/__tests__/reject-during-apply-all.test.ts b/src/lib/__tests__/reject-during-apply-all.test.tsnew file mode 100644index 00000000..e21956c3--- /dev/null+++ b/src/lib/__tests__/reject-during-apply-all.test.ts@@ -0,0 +1,63 @@+/**+ * Bug hunt 01.10.2026 (C2). "Apply all" walks a snapshot of the queue, one+ * write after the other. A Reject clicked while the first file was being+ * written removed the second from the list, and the loop wrote it anyway: the+ * file the user had just turned down landed on disk.+ */+import { describe, it, expect, vi, beforeEach } from 'vitest'++vi.mock('../../api/backend', () => ({ backendCall: vi.fn() }))+vi.mock('../../stores/chatStore', () => ({+ useChatStore: { getState: () => ({ addMessage: vi.fn(), conversations: [] }) },+}))++import { backendCall } from '../../api/backend'+import { applyAllStagedChanges, applyStagedChange } from '../staged-apply'+import { useStagedChangesStore } from '../../stores/stagedChangesStore'+import { useAgentModeStore } from '../../stores/agentModeStore'++const call = backendCall as unknown as ReturnType<typeof vi.fn>+const CHAT = 'chat-c2'+const store = () => useStagedChangesStore.getState()+const stage = (path: string) =>+ store().stage(CHAT, { path, oldContent: '', newContent: `content of ${path}`, diff: '' })+const written = () => call.mock.calls.filter(([cmd]) => cmd === 'fs_write').map(([, a]) => (a as { path: string }).path)++describe('a Reject during Apply all', () => {+ beforeEach(() => {+ call.mockReset()+ store().clear(CHAT)+ useAgentModeStore.setState({ workspaceSlugs: { [CHAT]: 'slug-c2' } })+ })++ it('keeps the rejected file off the disk', async () => {+ stage('one.py')+ stage('two.py')+ call.mockImplementation(async (cmd: string, args: { path: string }) => {+ // The user clicks Reject on two.py while one.py is being written.+ if (cmd === 'fs_write' && args.path === 'one.py') {+ const two = store().list(CHAT).find((c) => c.path === 'two.py')!+ store().remove(CHAT, two.id)+ }+ return { status: 'saved' }+ })++ const res = await applyAllStagedChanges(CHAT)++ expect(written()).toEqual(['one.py'])+ expect(res.applied).toEqual(['one.py'])+ expect(res.failed).toEqual([])+ })++ it('also when the Reject lands while that same file is being read for the drift check', async () => {+ stage('late.py')+ const change = store().list(CHAT)[0]+ call.mockImplementation(async (cmd: string) => {+ if (cmd !== 'fs_write') store().remove(CHAT, change.id)+ return { status: 'saved' }+ })++ expect(await applyStagedChange(CHAT, change)).toBe(false)+ expect(written()).toEqual([])+ })+})diff --git a/src/lib/staged-apply.ts b/src/lib/staged-apply.tsindex b394ab32..e9c007c3 100644--- a/src/lib/staged-apply.ts+++ b/src/lib/staged-apply.ts@@ -124,9 +124,21 @@ async function jailFor(chatId: string): Promise<string> {return resolveChatWorkspaceSlug(chatId, title)}-export async function applyStagedChange(chatId: string, change: StagedChange): Promise<void> {+/** True when the change is still queued. A Reject removes it from the store;+ * the Apply loops run over a snapshot and the reconcile read is async, so+ * without this check a change the user rejected mid "Apply all" was written+ * anyway. */+function stillPending(chatId: string, change: StagedChange): boolean {+ return useStagedChangesStore.getState().list(chatId).some((c) => c.id === change.id)+}++/** Writes one staged change. Returns false, without writing, when the user+ * rejected it before the write happened. */+export async function applyStagedChange(chatId: string, change: StagedChange): Promise<boolean> {+ if (!stillPending(chatId, change)) return falseconst jail = await jailFor(chatId)const { content, merged } = await reconcile(jail, change)+ if (!stillPending(chatId, change)) return falseconst res = await backendCall<{ status?: string; path?: string }>('fs_write', {path: change.resolvedPath || change.path,content,@@ -160,6 +172,7 @@ export async function applyStagedChange(chatId: string, change: StagedChange): Ptimestamp: Date.now(),notice: merged > 0 ? 'warn' : 'info',})+ return true}/** Apply every pending change for a chat, sequentially (fs_write serializes@@ -173,8 +186,7 @@ export async function applyAllStagedChanges(const failed: string[] = []for (const change of [...useStagedChangesStore.getState().list(chatId)]) {try {- await applyStagedChange(chatId, change)- applied.push(change.path)+ if (await applyStagedChange(chatId, change)) applied.push(change.path)} catch {failed.push(change.path)}