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-tab): Stop toetet nicht mehr den Lauf einer anderen Unterhaltung

purplea50e36f9fffd
diff --git a/src/components/chat/__tests__/senden-und-stop-je-unterhaltung.test.tsx b/src/components/chat/__tests__/senden-und-stop-je-unterhaltung.test.tsx
index 5de75f6f..27b13981 100644
--- a/src/components/chat/__tests__/senden-und-stop-je-unterhaltung.test.tsx
+++ b/src/components/chat/__tests__/senden-und-stop-je-unterhaltung.test.tsx
@@ -130,6 +130,35 @@ describe('Stop bricht nur die eigene Erzeugung ab', () => {
expect(agent).not.toMatch(/drainApprovals\(stoppedConvId\)\s*\n\s*setIsAgentRunning\(false\)/)
})
+ /**
+ * R2-19: der dritte Hook mit demselben Griff. `stopCodex` brach ihn
+ * bedingungslos ab, und V2a hat nachgewiesen, dass `CodexView` beim
+ * Unterhaltungswechsel NICHT neu montiert wird (`ChatView.tsx` gibt ihm kein
+ * `key`). Ein Lauf in A, Wechsel nach B, Stop gedrueckt: A war tot.
+ */
+ it('useCodex bricht den Controller der Instanz nur fuer die eigene Unterhaltung ab', () => {
+ const codex = src('../../../hooks/useCodex.ts')
+ expect(codex).toMatch(/const abortConvRef = useRef<string \| null>\(null\)/)
+ expect(codex).toMatch(/if \(abortConvRef\.current === stoppedConvId\) \{/)
+ // Und der Ref wird gesetzt UND geleert, sonst bricht Stop nie etwas ab
+ // oder bricht einen laengst beendeten Lauf ab.
+ expect(codex).toMatch(/abortConvRef\.current = convId/)
+ expect(codex).toMatch(/abortConvRef\.current = null/)
+ // Der richtige Griff je Unterhaltung liegt weiter davor und bleibt
+ // bedingungslos: er trifft genau die gemeinte Unterhaltung.
+ expect(codex).toMatch(/stopRun\(stoppedConvId\)/)
+ expect(codex).toMatch(/abortConversation\(stoppedConvId\)/)
+ })
+
+ it('und CodexView wird beim Unterhaltungswechsel wirklich nicht neu montiert', () => {
+ // Die Voraussetzung des Befunds, damit sie nicht still verschwindet: gaebe
+ // es hier ein `key`, waere der Griff bei jedem Wechsel frisch und die
+ // Klammer oben ueberfluessig. Sie ist es nicht.
+ const view = src('../ChatView.tsx')
+ expect(view).toMatch(/<CodexView\b/)
+ expect(view).not.toMatch(/<CodexView[^>]*\skey=/)
+ })
+
it('der Komposer liest nicht mehr die app-weite Fahne', () => {
const view = src('../ChatView.tsx')
const composer = view.slice(view.indexOf('<ChatInput'), view.indexOf('composerActions='))
diff --git a/src/hooks/useCodex.ts b/src/hooks/useCodex.ts
index c2813027..075f958c 100644
--- a/src/hooks/useCodex.ts
+++ b/src/hooks/useCodex.ts
@@ -258,6 +258,16 @@ let codexLoopTimer: ReturnType<typeof setTimeout> | null = null
export function useCodex() {
const [isRunning, setIsRunning] = useState(false)
const abortRef = useRef<AbortController | null>(null)
+ /**
+ * Zu WELCHER Unterhaltung der Controller oben gehoert.
+ *
+ * R2-19: `stopCodex` brach ihn bedingungslos ab. Der Griff gehoert der
+ * Hook-INSTANZ und haelt den zuletzt gestarteten Lauf, egal wo, und
+ * `CodexView` wird beim Unterhaltungswechsel nicht neu montiert
+ * (`ChatView.tsx` gibt ihm kein `key`). Stop in B toetete damit den Lauf in
+ * A. Dieselbe Klammer wie in useChat und useAgentChat.
+ */
+ const abortConvRef = useRef<string | null>(null)
const runningRef = useRef(false)
// "The user pressed stop" lives in lib/run-stop, keyed by conversation, NOT
// in a ref of this hook instance. The Code view unmounts on every tab switch,
@@ -834,6 +844,7 @@ export function useCodex() {
// Setup
const abort = new AbortController()
abortRef.current = abort
+ abortConvRef.current = convId
// Hand Stop to everything this run starts, including the nested ReAct loop
// a delegate_task sub-agent runs (audit AGT-1). Assigned here rather than
// in beginAgentRun because the controller does not exist that early.
@@ -2393,6 +2404,7 @@ export function useCodex() {
useGenerationStore.getState().clearAborter(convId)
runningRef.current = false
abortRef.current = null
+ abortConvRef.current = null
// Close THIS run. The process-wide mirror is only cleared when this run
// still owns it, so a run that outlives us keeps its workspace and its
// read-only flag (plan C1 ERZWINGUNG, blocker S3).
@@ -2561,10 +2573,16 @@ export function useCodex() {
codexLoopTimer = null
}
useAgentLoopStore.getState().clear()
- runningRef.current = false
- abortRef.current?.abort()
- abortRef.current = null
- setIsRunning(false)
+ // NUR wenn der Controller dieser Instanz auch zu DIESER Unterhaltung
+ // gehoert. Gehoert er woanders hin, hat `abortConversation` oben schon den
+ // richtigen Griff gezogen, und der Lauf in der anderen Unterhaltung laeuft
+ // weiter.
+ if (abortConvRef.current === stoppedConvId) {
+ runningRef.current = false
+ abortRef.current?.abort()
+ abortRef.current = null
+ setIsRunning(false)
+ }
}, [])
return { sendInstruction, stopCodex, isRunning }