Skip to content

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.

fix(code): ein Lauf, der nicht mehr laeuft, haelt den Ordner nicht fest

purple01036fcb2e88
diff --git a/src/components/chat/CodexView.tsx b/src/components/chat/CodexView.tsx
index 80064808..49646db3 100644
--- a/src/components/chat/CodexView.tsx
+++ b/src/components/chat/CodexView.tsx
@@ -114,10 +114,12 @@ export function CodexView() {
// found none. The header always shows the folder, so it also carries the way
// to give it back. Locked, not hidden, while a coding turn is in flight, and
// the verdict is the shared one so the two buttons cannot drift apart.
+ // Beide Karten, aus demselben Grund wie im Explorer: ein Faden, der auf
+ // 'running' stehengeblieben ist, sperrt den Ordner nicht mehr allein.
const sendsInFlight = useCodexStore((s) => s.sendsInFlight)
const threads = useCodexStore((s) => s.threads)
const loop = useAgentLoopStore((s) => s.loop)
- const lockReason = codexBusyReason({ sendsInFlight, threads, loop })
+ const lockReason = codexBusyReason({ sendsInFlight, threads, generating: generatingMap, loop })
// Where the agent goes while no folder is picked: a per-chat workspace or
// settings.defaultWorkspace both beat an empty picker, so the header and the
diff --git a/src/components/chat/ExplorerPanel.tsx b/src/components/chat/ExplorerPanel.tsx
index 84c7c08b..f5cb279f 100644
--- a/src/components/chat/ExplorerPanel.tsx
+++ b/src/components/chat/ExplorerPanel.tsx
@@ -40,6 +40,7 @@ import {
} from 'lucide-react'
import { useCodexStore } from '../../stores/codexStore'
import { useAgentLoopStore } from '../../stores/agentLoopStore'
+import { useGenerationStore } from '../../stores/generationStore'
import { useAgentModeStore } from '../../stores/agentModeStore'
import { useSettingsStore } from '../../stores/settingsStore'
import { useUIStore } from '../../stores/uiStore'
@@ -89,10 +90,16 @@ export function ExplorerPanel({ onApprovePlan }: Props) {
//
// Only Coding Agent signals count. Reading every conversation's generating
// flag locked this column whenever any Chat tab was streaming (review S3).
+ //
+ // Der Status eines Fadens allein ist kein Beweis, dass noch etwas laeuft:
+ // Stop raeumt die Erzeugungsfahne sofort, der Status kommt erst zurueck,
+ // wenn der Lauf sich abgewickelt hat. Beide Karten kommen deshalb herein und
+ // werden in `codexBusyReason` versoehnt.
const sendsInFlight = useCodexStore((s) => s.sendsInFlight)
const threads = useCodexStore((s) => s.threads)
+ const generating = useGenerationStore((s) => s.generating)
const loop = useAgentLoopStore((s) => s.loop)
- const lockReason = codexBusyReason({ sendsInFlight, threads, loop })
+ const lockReason = codexBusyReason({ sendsInFlight, threads, generating, loop })
const lockTitle = lockReason ? CODEX_WORKDIR_LOCK_TITLE[lockReason] : null
// Read up here because the workspace fallback below needs it too. The plan
@@ -336,6 +343,21 @@ export function ExplorerPanel({ onApprovePlan }: Props) {
</button>
</div>
+ {/* Warum die beiden Knoepfe darueber tot sind, in Worten.
+ Der Grund hing bisher nur als `title` an ihnen, und ein `disabled`
+ Knopf nimmt keine Mauszeiger-Ereignisse an: der Hinweis ist also nie
+ erschienen. Uebrig blieben zwei graue Knoepfe ohne Erklaerung. Ruhiger
+ Ton, keine Warnfarbe: gesperrt ist kein Fehler, sondern ein Zustand,
+ der von selbst endet (`lib/hinweis.ts`). */}
+ {lockTitle && (
+ <p
+ data-testid="explorer-workdir-lock"
+ className={`px-1.5 py-1 text-[0.45rem] leading-relaxed border-b border-gray-200 dark:border-white/[0.04] ${HINWEIS_TEXT.ruhig}`}
+ >
+ {lockTitle}
+ </p>
+ )}
+
<div className={`overflow-y-auto scrollbar-thin p-1 ${selected ? 'max-h-[45%] shrink-0' : 'flex-1 min-h-0'}`}>
{!root ? (
<p
diff --git a/src/components/chat/__tests__/the-header-can-let-the-folder-go.test.ts b/src/components/chat/__tests__/the-header-can-let-the-folder-go.test.ts
index 4ba949f9..13666119 100644
--- a/src/components/chat/__tests__/the-header-can-let-the-folder-go.test.ts
+++ b/src/components/chat/__tests__/the-header-can-let-the-folder-go.test.ts
@@ -137,12 +137,30 @@ describe('the header shows the folder, so it also gives it back', () => {
await show()
const button = removeButton() as HTMLButtonElement
expect(button.disabled).toBe(true)
- expect(button.getAttribute('title')).toContain('Wait for the current run to finish')
+ expect(button.getAttribute('title')).toContain('Wait for it to finish or press Stop')
fireEvent.click(button)
expect(useCodexStore.getState().workingDirectory).toBe(WINDOWS_PATH)
})
+ it('and lets go again once the run is no longer alive', async () => {
+ // Ein Faden bleibt auf 'running' stehen, bis der Lauf sich abgewickelt
+ // hat. Haengt der Schwanz des Laufs, sperrte er diesen Knopf bis zum
+ // Neustart der App, und der Grund hing als `title` an einem `disabled`
+ // Knopf, der ihn nie zeigt.
+ act(() => {
+ useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH)
+ useCodexStore.getState().initThread('conv-1', WINDOWS_PATH)
+ useCodexStore.getState().setThreadStatus('conv-1', 'running')
+ })
+ useGenerationStore.setState({ generating: {} })
+ await show()
+ const button = removeButton() as HTMLButtonElement
+ expect(button.disabled).toBe(false)
+ fireEvent.click(button)
+ expect(useCodexStore.getState().workingDirectory).toBe('')
+ })
+
it('is locked between two loop passes as well', async () => {
act(() => useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH))
useAgentLoopStore.setState({
diff --git a/src/components/chat/__tests__/the-working-directory-can-be-removed.test.ts b/src/components/chat/__tests__/the-working-directory-can-be-removed.test.ts
index 7cd62128..e7467824 100644
--- a/src/components/chat/__tests__/the-working-directory-can-be-removed.test.ts
+++ b/src/components/chat/__tests__/the-working-directory-can-be-removed.test.ts
@@ -169,7 +169,25 @@ describe('a run in flight holds it', () => {
const button = removeButton()!
expect(button).not.toBeNull()
expect((button as HTMLButtonElement).disabled).toBe(true)
- expect(button.getAttribute('title')).toContain('Wait for the current run to finish')
+ expect(button.getAttribute('title')).toContain('Wait for it to finish or press Stop')
+ })
+
+ it('and says it where a disabled button cannot: in the column itself', () => {
+ // Der Grund hing nur als `title` an den beiden Knoepfen, und ein
+ // `disabled` Knopf nimmt keine Mauszeiger-Ereignisse an, also erschien er
+ // nie. Uebrig blieben zwei graue Knoepfe ohne ein Wort dazu.
+ act(() => {
+ useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH)
+ useCodexStore.getState().beginSend()
+ })
+ show()
+ const zeile = screen.getByTestId('explorer-workdir-lock')
+ expect(zeile.textContent).toContain('Stop')
+ // Negative Probe: ohne Sperre steht die Zeile nicht da.
+ cleanup()
+ act(() => useCodexStore.getState().endSend())
+ show()
+ expect(screen.queryByTestId('explorer-workdir-lock')).toBeNull()
})
it('holds it from the first synchronous moment of the send, before any await', () => {
@@ -194,12 +212,45 @@ describe('a run in flight holds it', () => {
expect(useCodexStore.getState().workingDirectory).toBe(WINDOWS_PATH)
})
- it('a thread the store still calls running counts as a run too', () => {
+ it('a thread that is really streaming counts as a run too', () => {
act(() => {
useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH)
useCodexStore.getState().initThread('conv-1', WINDOWS_PATH)
useCodexStore.getState().setThreadStatus('conv-1', 'running')
})
+ useGenerationStore.setState({ generating: { 'conv-1': true } })
+ show()
+ expect((removeButton() as HTMLButtonElement).disabled).toBe(true)
+ })
+
+ it('but a run that is no longer alive lets the folder go again', () => {
+ // Der Haenger. `stopCodex` raeumt die Erzeugungsfahne SOFORT, der Status
+ // des Fadens kommt erst im `finally` des Laufs zurueck auf 'idle', und ein
+ // Shell-Befehl, der das Abbruchsignal nicht beachtet, dehnt dieses Fenster
+ // beliebig weit. Solange es offen stand, waren beide Knoepfe tot, der
+ // Grund war unsichtbar, und es gab keinen Weg heraus: der Ordner blieb
+ // gesperrt, bis die App neu startete.
+ act(() => {
+ useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH)
+ useCodexStore.getState().initThread('conv-1', WINDOWS_PATH)
+ useCodexStore.getState().setThreadStatus('conv-1', 'running')
+ })
+ useGenerationStore.setState({ generating: {} })
+ show()
+ expect((removeButton() as HTMLButtonElement).disabled).toBe(false)
+ expect(pickButton().disabled).toBe(false)
+ expect(screen.queryByTestId('explorer-workdir-lock')).toBeNull()
+ fireEvent.click(removeButton()!)
+ expect(useCodexStore.getState().workingDirectory).toBe('')
+ })
+
+ it('a run waiting for an approval still holds it, it is not finished', () => {
+ act(() => {
+ useCodexStore.getState().setWorkingDirectory(WINDOWS_PATH)
+ useCodexStore.getState().initThread('conv-1', WINDOWS_PATH)
+ useCodexStore.getState().setThreadStatus('conv-1', 'awaiting_approval')
+ })
+ useGenerationStore.setState({ generating: { 'conv-1': true } })
show()
expect((removeButton() as HTMLButtonElement).disabled).toBe(true)
})
diff --git a/src/lib/__tests__/codex-workdir.test.ts b/src/lib/__tests__/codex-workdir.test.ts
index 8466f8bf..b35a68ca 100644
--- a/src/lib/__tests__/codex-workdir.test.ts
+++ b/src/lib/__tests__/codex-workdir.test.ts
@@ -81,7 +81,7 @@ describe('what the empty state is allowed to promise', () => {
})
describe('when the working directory is held', () => {
- const free = { sendsInFlight: 0, threads: {}, loop: null }
+ const free = { sendsInFlight: 0, threads: {}, generating: {}, loop: null }
it('is free when nothing at all is going on', () => {
expect(codexBusyReason(free)).toBeNull()
@@ -91,8 +91,55 @@ describe('when the working directory is held', () => {
expect(codexBusyReason({ ...free, sendsInFlight: 1 })).toBe('run')
})
- it('is held by a thread the store calls running', () => {
- expect(codexBusyReason({ ...free, threads: { a: { status: 'running' } } })).toBe('run')
+ it('is held by a thread that is really streaming', () => {
+ expect(codexBusyReason({
+ ...free,
+ threads: { a: { status: 'running' } },
+ generating: { a: true },
+ })).toBe('run')
+ })
+
+ it('and by one waiting for an approval or writing its staged changes', () => {
+ // Beides ist laufende Arbeit. Der Vergleich von Hand fragte `=== running`
+ // und liess genau diese beiden Zustaende als "nichts los" durch.
+ for (const status of ['awaiting_approval', 'applying', 'cancelling'] as const) {
+ expect(codexBusyReason({
+ ...free,
+ threads: { a: { status } },
+ generating: { a: true },
+ }), status).toBe('run')
+ }
+ })
+
+ it('but a thread left standing on running by a dead run holds nothing', () => {
+ // Der Fall, der den Ordner fuer den Rest der Sitzung sperrte: Stop raeumt
+ // die Erzeugungsfahne sofort, der Status kommt erst im `finally` des Laufs
+ // zurueck, und ein Shell-Befehl, der das Signal nicht beachtet, dehnt das
+ // Fenster beliebig weit. Der Status allein ist kein Beweis, dass noch
+ // etwas laeuft.
+ expect(codexBusyReason({
+ ...free,
+ threads: { a: { status: 'running' } },
+ generating: {},
+ })).toBeNull()
+ // Und eine Fahne, die auf false steht, ist dasselbe wie keine.
+ expect(codexBusyReason({
+ ...free,
+ threads: { a: { status: 'running' } },
+ generating: { a: false },
+ })).toBeNull()
+ })
+
+ it('a run in ANOTHER chat still holds it, a chat tab streaming does not', () => {
+ // Beide Haelften auf einmal: die Fahne zaehlt nur zusammen mit einem
+ // Faden des Coding-Agenten, sonst sperrte jeder streamende Chat-Reiter
+ // diese Spalte mit (Pruefung S3).
+ expect(codexBusyReason({
+ ...free,
+ threads: { a: { status: 'running' } },
+ generating: { a: true },
+ })).toBe('run')
+ expect(codexBusyReason({ ...free, threads: {}, generating: { chat: true } })).toBeNull()
})
it('is held between two loop passes, where the thread says idle', () => {
@@ -118,4 +165,13 @@ describe('when the working directory is held', () => {
expect(CODEX_WORKDIR_LOCK_TITLE.run).not.toBe(CODEX_WORKDIR_LOCK_TITLE.loop)
expect(CODEX_WORKDIR_LOCK_TITLE.loop).toContain('loop')
})
+
+ it('and every sentence names a way out, not just a wait', () => {
+ // Warten ist keine Auskunft, solange der Nutzer nicht weiss, worauf. Beide
+ // Saetze nennen deshalb den Knopf, der die Sperre wirklich loest: Stop
+ // raeumt die Erzeugungsfahne, und der Ordner ist im selben Augenblick frei.
+ for (const satz of Object.values(CODEX_WORKDIR_LOCK_TITLE)) {
+ expect(satz, satz).toContain('Stop')
+ }
+ })
})
diff --git a/src/lib/codex-workdir.ts b/src/lib/codex-workdir.ts
index c978e11d..67a468b4 100644
--- a/src/lib/codex-workdir.ts
+++ b/src/lib/codex-workdir.ts
@@ -6,6 +6,7 @@
* chain nobody could test, and "is a run in flight" was a different expression
* on every surface. They are pure functions here, with the tests next to them.
*/
+import { isActiveCodexStatus, type CodexThreadStatus } from '../types/codex'
export interface CodexWorkDirInput {
/** The folder pinned on this conversation's thread. */
@@ -68,7 +69,12 @@ export interface CodexBusyInput {
*/
sendsInFlight: number
/** codexStore.threads, for a turn that is past those awaits. */
- threads: Record<string, { status: string }>
+ threads: Record<string, { status: CodexThreadStatus }>
+ /**
+ * generationStore.generating, as the PROOF that a thread's status is about a
+ * run that is still alive. See below.
+ */
+ generating: Record<string, boolean>
/** agentLoopStore.loop, or null when no /loop is standing. */
loop: unknown | null
}
@@ -77,16 +83,48 @@ export interface CodexBusyInput {
* Only Coding Agent signals count. The first cut read every conversation's
* generating flag, so a streaming Chat tab in another conversation locked the
* folder picker on Code for no reason at all.
+ *
+ * ── WARUM DIE FAHNE DAZUGEHOERT ──────────────────────────────────────────
+ * Ein Faden bleibt auf 'running' stehen, bis der Lauf sich abgewickelt hat.
+ * `stopCodex` raeumt die Erzeugungsfahne SOFORT (`abortConversation`), der
+ * Status kommt erst im `finally` des Laufs zurueck auf 'idle', und ein
+ * Shell-Befehl, der das Signal nicht beachtet, dehnt dieses Fenster beliebig
+ * weit. Solange es offen stand, waren beide Ordnerknoepfe tot, und der Grund
+ * hing als `title` an einem `disabled` Knopf, der keine Mauszeiger-Ereignisse
+ * annimmt, also nie erschienen ist. Fuer den Nutzer war der Ordner damit ohne
+ * Vorwarnung und ohne Ausweg gesperrt.
+ *
+ * Der Status allein ist also kein Beweis, dass etwas laeuft, und genau das ist
+ * der Fehler, gegen den `lib/run-idle.ts` fuer die ganze App geschrieben
+ * wurde: zwei Quellen, und keine von beiden ist fuer sich die Wahrheit. Hier
+ * ist es dieselbe Versoehnung, nur pro Gespraech und ohne Speicherzugriff, weil
+ * diese Funktion rein bleibt und ihre Aufrufer beide Karten ohnehin
+ * abonnieren.
+ *
+ * `isActiveCodexStatus` statt `=== 'running'`: die Wartefreigabe und das
+ * Schreiben der abgelegten Aenderungen sind genauso laufende Arbeit, und der
+ * Vergleich von Hand war der stille `else`, den AS-08 beschreibt.
+ *
+ * Gesperrt bleibt damit genau ein Lauf, der wirklich noch laeuft. Der Weg
+ * heraus ist der Stopp-Knopf, den der Lauf ohnehin hat: er raeumt die Fahne,
+ * und der Ordner ist im selben Augenblick wieder frei.
*/
-export function codexBusyReason({ sendsInFlight, threads, loop }: CodexBusyInput): CodexBusyReason | null {
+export function codexBusyReason({ sendsInFlight, threads, generating, loop }: CodexBusyInput): CodexBusyReason | null {
if (sendsInFlight > 0) return 'run'
- if (Object.values(threads).some((t) => t.status === 'running')) return 'run'
+ const alive = Object.entries(threads).some(
+ ([convId, t]) => isActiveCodexStatus(t.status) && generating[convId] === true,
+ )
+ if (alive) return 'run'
if (loop) return 'loop'
return null
}
-/** One sentence per reason, so the two buttons cannot drift apart. */
+/**
+ * One sentence per reason, so the two buttons cannot drift apart. Both name a
+ * way out: a disabled button cannot be waited out blindly, and a run whose
+ * tail hangs would otherwise hold the folder for the rest of the session.
+ */
export const CODEX_WORKDIR_LOCK_TITLE: Record<CodexBusyReason, string> = {
- run: 'Wait for the current run to finish, then you can change the folder.',
+ run: 'A coding run is in flight. Wait for it to finish or press Stop, then you can change the folder.',
loop: 'A loop is still running. Stop it first, then you can change the folder.',
}