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(lanes): Warteposition anzeigen, toten Code aus run-lanes.ts entfernt

purple975159304dfc
diff --git a/src/components/chat/ChatInput.tsx b/src/components/chat/ChatInput.tsx
index 7f1552f1..350b4c29 100644
--- a/src/components/chat/ChatInput.tsx
+++ b/src/components/chat/ChatInput.tsx
@@ -37,6 +37,13 @@ interface Props {
* queued, never for another one's.
*/
waitingForLocalLane?: boolean
+ /**
+ * This conversation's position in the local lane's queue (1 = next up),
+ * when known. Purely cosmetic: enriches the waiting line with a real
+ * number instead of a bare "it is waiting". `undefined`/`null` falls back
+ * to the plain sentence.
+ */
+ localLaneQueuePosition?: number | null
pendingApproval?: AgentToolCall | null
onApprove?: () => void
onReject?: () => void
@@ -104,7 +111,7 @@ function fileToImageAttachment(file: File): Promise<ImageAttachment> {
})
}
-export function ChatInput({ onSend, onStop, isGenerating, waitingForLocalLane, pendingApproval, onApprove, onReject, disabled, slashCommands, onAttachDocs, composerModel, composerActions, composerAbove }: Props) {
+export function ChatInput({ onSend, onStop, isGenerating, waitingForLocalLane, localLaneQueuePosition, pendingApproval, onApprove, onReject, disabled, slashCommands, onAttachDocs, composerModel, composerActions, composerAbove }: Props) {
const [input, setInput] = useState('')
const [images, setImages] = useState<ImageAttachment[]>([])
const [isDragOver, setIsDragOver] = useState(false)
@@ -464,6 +471,9 @@ export function ChatInput({ onSend, onStop, isGenerating, waitingForLocalLane, p
<div role="status" className={`${HINWEIS_ZEILE} ${HINWEIS_TEXT.ruhig} mb-1.5 px-1`} data-testid="composer-waiting-local-lane">
<span className="flex-1 min-w-0">
Waiting for the local model to finish another answer.
+ {!!localLaneQueuePosition && localLaneQueuePosition > 1 && (
+ ` ${localLaneQueuePosition - 1} more chat${localLaneQueuePosition - 1 === 1 ? '' : 's'} ahead of this one.`
+ )}
</span>
</div>
)}
diff --git a/src/components/chat/ChatView.tsx b/src/components/chat/ChatView.tsx
index a0c6bc98..466042aa 100644
--- a/src/components/chat/ChatView.tsx
+++ b/src/components/chat/ChatView.tsx
@@ -42,7 +42,7 @@ import { CodexView } from './CodexView'
import { useCodexStore } from '../../stores/codexStore'
import { useGenerationStore } from '../../stores/generationStore'
import { composerBusy } from '../../lib/composer-busy'
-import { useIsQueuedForLocalLane } from '../../lib/run-idle'
+import { useIsQueuedForLocalLane, useLocalLaneQueuePosition } from '../../lib/run-idle'
import { useRemoteStore } from '../../stores/remoteStore'
import { displayModelName } from '../../api/providers'
import { MONOGRAM, MONOGRAM_INVERT } from '../layout/brand'
@@ -135,6 +135,7 @@ export function ChatView() {
// it. Folded into `isGenerating` below so the composer shows Stop instead
// of Send while it waits.
const queuedForLocalLane = useIsQueuedForLocalLane(activeConversationId)
+ const localLaneQueuePosition = useLocalLaneQueuePosition(activeConversationId)
const docCount = useRAGStore((s) =>
activeConversationId ? (s.documents[activeConversationId] || []).length : 0
@@ -644,6 +645,7 @@ export function ChatView() {
onStop={stopGeneration}
isGenerating={busy.thisChat || queuedForLocalLane}
waitingForLocalLane={queuedForLocalLane}
+ localLaneQueuePosition={localLaneQueuePosition}
pendingApproval={pendingApproval}
onApprove={approveToolCall}
onReject={rejectToolCall}
diff --git a/src/components/chat/CodexView.tsx b/src/components/chat/CodexView.tsx
index 4507e5a6..39460703 100644
--- a/src/components/chat/CodexView.tsx
+++ b/src/components/chat/CodexView.tsx
@@ -45,7 +45,7 @@ import { CodexConfirmDialog } from './CodexConfirmDialog'
import { Hinweis } from '../ui/Hinweis'
import { HINWEIS_TEXT } from '../../lib/hinweis'
import { stripModelNoise } from '../../lib/strip-model-noise'
-import { useIsQueuedForLocalLane } from '../../lib/run-idle'
+import { useIsQueuedForLocalLane, useLocalLaneQueuePosition } from '../../lib/run-idle'
// Code always drives a tool loop, so the aggressive tier applies here.
const stripChannelTags = (text: string) => stripModelNoise(text, { aggressive: true })
@@ -104,6 +104,7 @@ export function CodexView() {
// in ChatView.tsx, now that a local second send queues visibly instead of
// racing the first one and a cloud second send just runs alongside it.
const queuedForLocalLane = useIsQueuedForLocalLane(activeConversationId)
+ const localLaneQueuePosition = useLocalLaneQueuePosition(activeConversationId)
// G8-3 (David): "sobald er fertig gedacht hat, hakt das so komisch ab und
// zoomt irgendwo ganz anders hin." The hand-rolled pin here only fired on
@@ -649,6 +650,7 @@ export function CodexView() {
// conversation, not the hook instance.
isGenerating={isRunning || codexGenerating || queuedForLocalLane}
waitingForLocalLane={queuedForLocalLane}
+ localLaneQueuePosition={localLaneQueuePosition}
slashCommands="agent"
composerModel={<ModelSelector openUpward surface="code" />}
// No plan lives here. The prompt window is the prompt window
diff --git a/src/components/chat/__tests__/composer-zeigt-warten-auf-lokale-spur.test.tsx b/src/components/chat/__tests__/composer-zeigt-warten-auf-lokale-spur.test.tsx
index c2bd3985..6a5ca5ea 100644
--- a/src/components/chat/__tests__/composer-zeigt-warten-auf-lokale-spur.test.tsx
+++ b/src/components/chat/__tests__/composer-zeigt-warten-auf-lokale-spur.test.tsx
@@ -20,12 +20,17 @@
* sperren nur noch die eigene Unterhaltung), also gibt es nichts mehr, das
* diese Wartezeile verdraengen koennte.
*
+ * Nachtrag Schritt 5 (Aufraeumen): `runQueuePosition` aus `lib/run-lanes.ts`
+ * hatte bis dahin keinen Aufrufer ausser seinem eigenen Test. Statt es zu
+ * loeschen, speist es jetzt die Wartezeile mit einer echten Zahl
+ * (`useLocalLaneQueuePosition`), belegt am Ende dieser Datei.
+ *
* Run: npx vitest run src/components/chat/__tests__/composer-zeigt-warten-auf-lokale-spur.test.tsx
*/
import { describe, it, expect, beforeEach, afterEach } from 'vitest'
import { cleanup, fireEvent, render, screen, renderHook, act } from '@testing-library/react'
import { ChatInput } from '../ChatInput'
-import { useIsQueuedForLocalLane } from '../../../lib/run-idle'
+import { useIsQueuedForLocalLane, useLocalLaneQueuePosition } from '../../../lib/run-idle'
import { admit, release, __resetRunLanesForTests } from '../../../lib/run-lanes'
beforeEach(() => __resetRunLanesForTests())
@@ -60,6 +65,46 @@ describe('ChatInput waehrend des Wartens auf die lokale Spur', () => {
expect(screen.getByRole('button', { name: 'Send message' })).toBeTruthy()
})
+ it('nennt die Zahl der Wartenden davor, wenn mehr als einer wartet', () => {
+ render(
+ <ChatInput onSend={() => {}} onStop={() => {}} isGenerating={true} waitingForLocalLane={true} localLaneQueuePosition={3} />,
+ )
+ const line = screen.getByTestId('composer-waiting-local-lane')
+ expect(line.textContent).toContain('2 more chats ahead of this one')
+ })
+
+ it('sagt nichts zur Position, wenn diese Unterhaltung als Naechste dran ist', () => {
+ render(
+ <ChatInput onSend={() => {}} onStop={() => {}} isGenerating={true} waitingForLocalLane={true} localLaneQueuePosition={1} />,
+ )
+ const line = screen.getByTestId('composer-waiting-local-lane')
+ expect(line.textContent).not.toMatch(/ahead of/)
+ })
+})
+
+describe('useLocalLaneQueuePosition reagiert auf die echte Warteschlange', () => {
+ it('zaehlt die Position hoch und wieder herunter, wenn Wartende dazukommen und abbrechen', () => {
+ const { result, rerender } = renderHook(({ id }: { id: string }) => useLocalLaneQueuePosition(id), {
+ initialProps: { id: 'conv-c' },
+ })
+ expect(result.current).toBeNull()
+
+ act(() => {
+ admit('local', 'conv-a', () => {})
+ admit('local', 'conv-b', () => {})
+ admit('local', 'conv-c', () => {})
+ })
+ rerender({ id: 'conv-c' })
+ expect(result.current).toBe(2)
+
+ act(() => {
+ // b gives up waiting before its turn: c moves up one place, a still
+ // holds the lane so c is not promoted yet.
+ release('conv-b')
+ })
+ rerender({ id: 'conv-c' })
+ expect(result.current).toBe(1)
+ })
})
describe('useIsQueuedForLocalLane reagiert auf die echte Warteschlange', () => {
diff --git a/src/lib/__tests__/run-lanes.test.ts b/src/lib/__tests__/run-lanes.test.ts
index 0aa501ce..0475720b 100644
--- a/src/lib/__tests__/run-lanes.test.ts
+++ b/src/lib/__tests__/run-lanes.test.ts
@@ -32,11 +32,8 @@ import {
localLaneHolder,
queuedRunIds,
subscribeRunLanes,
- localLaneSnapshot,
runQueuePosition,
- wouldQueue,
__resetRunLanesForTests,
- type RunLane,
} from '../run-lanes'
import { quelldateien, quelltext } from '../../components/__tests__/quelldateien'
@@ -312,35 +309,6 @@ describe('die Schlange sagt Bescheid, wenn sie sich aendert', () => {
})
})
-describe('die Momentaufnahme fuer die Oberflaeche', () => {
- it('nennt Halter und Wartende in ihrer Reihenfolge', () => {
- admit('local', 'a', () => {})
- admit('local', 'b', () => {})
- admit('local', 'c', () => {})
- expect(localLaneSnapshot()).toEqual({ holder: 'a', queued: ['b', 'c'] })
- })
-
- it('behaelt ihre Identitaet, solange sich nichts aendert', () => {
- // `useSyncExternalStore` vergleicht die Momentaufnahmen mit ===. Ein
- // frisches Objekt bei jedem Abruf ist dort kein Schoenheitsfehler,
- // sondern eine Endlosschleife im Render.
- admit('local', 'a', () => {})
- expect(localLaneSnapshot()).toBe(localLaneSnapshot())
- })
-
- it('wechselt die Identitaet, sobald sich etwas aendert', () => {
- admit('local', 'a', () => {})
- const vorher = localLaneSnapshot()
- admit('local', 'b', () => {})
- expect(localLaneSnapshot()).not.toBe(vorher)
- expect(localLaneSnapshot().queued).toEqual(['b'])
- })
-
- it('die leere Spur ist auch eine Momentaufnahme', () => {
- expect(localLaneSnapshot()).toEqual({ holder: null, queued: [] })
- })
-})
-
describe('die Warteposition, die das Plaettchen anzeigt', () => {
it('zaehlt ab eins, vorne zuerst', () => {
admit('local', 'a', () => {})
@@ -369,70 +337,3 @@ describe('die Warteposition, die das Plaettchen anzeigt', () => {
expect(runQueuePosition(undefined)).toBeNull()
})
})
-
-// ── Der Knopf muss die Antwort kennen, BEVOR er gedrueckt wird ──────────────
-//
-// Die Eingabe soll "Einreihen" statt "Senden" anbieten koennen. Dafuer
-// braucht sie dieselbe Entscheidung, die `admit` gleich treffen wird, nur
-// ohne sie zu treffen. Die naheliegende Fassung in der Oberflaeche waere
-// `laneOf(...) === 'local' && localLaneHolder() !== null`, und das ist genau
-// das Muster, das dieses Haus am haeufigsten Geld gekostet hat: dieselbe
-// Regel zweimal geschrieben, eine davon gepflegt. Also steht sie hier, neben
-// der echten, und ein Waechter vergleicht die beiden Fall fuer Fall.
-describe('die Vorschau auf die Entscheidung', () => {
- interface Lage {
- name: string
- aufbau: () => void
- lane: RunLane
- wer: string | null | undefined
- }
-
- const LAGEN: Lage[] = [
- { name: 'freie Spur, lokal', aufbau: () => {}, lane: 'local', wer: 'x' },
- { name: 'freie Spur, cloud', aufbau: () => {}, lane: 'cloud', wer: 'x' },
- {
- name: 'ein Fremder haelt die Spur, lokal',
- aufbau: () => { admit('local', 'halter', () => {}) },
- lane: 'local',
- wer: 'x',
- },
- {
- name: 'ein Fremder haelt die Spur, cloud faehrt trotzdem',
- aufbau: () => { admit('local', 'halter', () => {}) },
- lane: 'cloud',
- wer: 'x',
- },
- {
- name: 'man haelt die Spur selbst',
- aufbau: () => { admit('local', 'x', () => {}) },
- lane: 'local',
- wer: 'x',
- },
- {
- name: 'man steht schon in der Schlange',
- aufbau: () => { admit('local', 'halter', () => {}); admit('local', 'x', () => {}) },
- lane: 'local',
- wer: 'x',
- },
- { name: 'ohne Kennung', aufbau: () => { admit('local', 'halter', () => {}) }, lane: 'local', wer: '' },
- { name: 'ohne Gespraech', aufbau: () => {}, lane: 'local', wer: null },
- ]
-
- for (const lage of LAGEN) {
- it(`stimmt mit admit ueberein: ${lage.name}`, () => {
- __resetRunLanesForTests()
- lage.aufbau()
- const vorschau = wouldQueue(lage.lane, lage.wer)
- const echt = admit(lage.lane, lage.wer ?? '', () => {}) === 'queued'
- expect(vorschau).toBe(echt)
- })
- }
-
- it('und sie aendert nichts an der Spur, sonst waere sie keine Vorschau', () => {
- admit('local', 'halter', () => {})
- wouldQueue('local', 'x')
- wouldQueue('local', 'x')
- expect(localLaneHolder()).toBe('halter')
- expect(queuedRunIds()).toEqual([])
- })
-})
diff --git a/src/lib/run-idle.ts b/src/lib/run-idle.ts
index 2b1c8831..158095a8 100644
--- a/src/lib/run-idle.ts
+++ b/src/lib/run-idle.ts
@@ -61,7 +61,7 @@ import { useSyncExternalStore } from 'react'
import { useGenerationStore } from '../stores/generationStore'
import { useCodexStore } from '../stores/codexStore'
import { isRunStopped } from './run-stop'
-import { anyRunQueued, isRunQueued, subscribeRunLanes } from './run-lanes'
+import { anyRunQueued, isRunQueued, runQueuePosition, subscribeRunLanes } from './run-lanes'
import { isActiveCodexStatus, type CodexThreadStatus } from '../types/codex'
/**
@@ -206,6 +206,23 @@ export function useIsQueuedForLocalLane(conversationId: string | null | undefine
return useSyncExternalStore(subscribeRunLanes, () => isRunQueued(conversationId))
}
+/**
+ * React hook: which position does this conversation hold in the local
+ * lane's queue, if any? `null` when it is not waiting (running, or nothing
+ * booked at all). Same `subscribeRunLanes` wiring as
+ * `useIsQueuedForLocalLane`, kept as a separate hook rather than folded into
+ * it because most callers only need the boolean and would otherwise re-render
+ * on every position change of a queue they do not display a number for.
+ *
+ * Feeds the composer's waiting line with a real number instead of a bare "it
+ * is waiting": `lib/run-lanes.ts`'s `runQueuePosition` existed for exactly
+ * this since before Runde 4, wired up only now that a queue can actually
+ * form.
+ */
+export function useLocalLaneQueuePosition(conversationId: string | null | undefined): number | null {
+ return useSyncExternalStore(subscribeRunLanes, () => runQueuePosition(conversationId))
+}
+
/**
* Wake `listener` whenever ANY of the three sources moves: a generating flag,
* a coding thread's status, or the local lane's queue.
diff --git a/src/lib/run-lanes.ts b/src/lib/run-lanes.ts
index 2f4c426a..23529302 100644
--- a/src/lib/run-lanes.ts
+++ b/src/lib/run-lanes.ts
@@ -61,11 +61,15 @@
* Schlange, aendert das keinen von beiden: der Dialog wartete auf die
* naechste fremde Aenderung.
*
- * Deshalb gibt es `subscribeRunLanes` und eine Momentaufnahme mit STABILER
- * Identitaet. Das ist kein Spiegel des Zustands, sondern ein Fenster darauf:
- * gespeichert wird weiter nur hier, gelesen wird weiter nur hier. Ein
- * Spiegel waere genau der Grundfehler, gegen den `run-idle.ts` gebaut ist,
- * eine Tatsache an zwei Orten, die im Fenster dazwischen auseinanderlaufen.
+ * Deshalb gibt es `subscribeRunLanes`: der Weckruf fuer `useSyncExternalStore`,
+ * dessen zweites Argument dann eine der schmalen Fragen hier ist
+ * (`isRunQueued`, `runQueuePosition`). Eine gespeicherte Momentaufnahme mit
+ * eigener Identitaet braucht es dafuer nicht: jede dieser Fragen antwortet
+ * mit einem Boolean oder einer Zahl, und `===` vergleicht die schon richtig,
+ * ohne dass irgendwo ein Objekt zwischengehalten werden muesste. Gespeichert
+ * wird weiter nur hier, gelesen wird weiter nur hier. Ein Spiegel waere genau
+ * der Grundfehler, gegen den `run-idle.ts` gebaut ist, eine Tatsache an zwei
+ * Orten, die im Fenster dazwischen auseinanderlaufen.
*/
/** Woran ein Lauf rechnet: an der Karte des Nutzers oder woanders. */
@@ -100,29 +104,10 @@ let halter: string | null = null
/** Wer wartet, in der Reihenfolge des Anstellens. */
const warteschlange: Wartend[] = []
-/** Die lokale Spur, so wie eine Anzeige sie braucht. */
-export interface RunLaneSnapshot {
- /** Wer rechnet gerade auf der Karte, oder `null`, wenn sie frei ist. */
- readonly holder: string | null
- /** Wer wartet, der Naechste zuerst. */
- readonly queued: readonly string[]
-}
-
const beobachter = new Set<() => void>()
/**
- * Die zuletzt ausgegebene Momentaufnahme, oder `null`, wenn sie ungueltig ist.
- *
- * Sie wird gehalten und nicht bei jedem Abruf neu gebaut, weil
- * `useSyncExternalStore` die Momentaufnahmen mit `===` vergleicht. Ein
- * frisches Objekt bei jedem Abruf ist dort kein Schoenheitsfehler, sondern
- * eine Endlosschleife im Render.
- */
-let momentaufnahme: RunLaneSnapshot | null = null
-
-/**
- * An der Spur hat sich etwas geaendert: Momentaufnahme verwerfen, Leser
- * wecken.
+ * An der Spur hat sich etwas geaendert: alle Leser wecken.
*
* Der Fehler eines Lesers wird verschluckt, und das ist hier keine
* Bequemlichkeit. Die lokale Spur ist die gefaehrlichste Stelle der App: wer
@@ -131,7 +116,6 @@ let momentaufnahme: RunLaneSnapshot | null = null
* halb durchlaufenes `release` waere genau das.
*/
function veraendert(): void {
- momentaufnahme = null
for (const l of beobachter) {
try { l() } catch { /* die Anzeige ist kaputt, die Spur bleibt heil */ }
}
@@ -140,22 +124,14 @@ function veraendert(): void {
/**
* Bescheid sagen, wenn Halter oder Schlange sich aendern. Rueckgabe meldet ab.
*
- * Gedacht als erstes Argument von `useSyncExternalStore`, zusammen mit
- * `localLaneSnapshot` als zweitem.
+ * Gedacht als erstes Argument von `useSyncExternalStore`, zusammen mit einer
+ * der schmalen Fragen unten (`isRunQueued`, `runQueuePosition`) als zweitem.
*/
export function subscribeRunLanes(listener: () => void): () => void {
beobachter.add(listener)
return () => { beobachter.delete(listener) }
}
-/** Halter und Wartende, mit stabiler Identitaet bis zur naechsten Aenderung. */
-export function localLaneSnapshot(): RunLaneSnapshot {
- if (momentaufnahme === null) {
- momentaufnahme = { holder: halter, queued: warteschlange.map((w) => w.convId) }
- }
- return momentaufnahme
-}
-
/**
* Der wievielte Wartende ist dieser Lauf? Ab eins, der Naechste ist die Eins.
*
@@ -216,28 +192,6 @@ export function admit(lane: RunLane, convId: string, start: StartThunk): Admissi
return 'queued'
}
-/**
- * Wuerde dieser Lauf sich JETZT anstellen muessen? Ohne ihn anzustellen.
- *
- * Fuer den Senden-Knopf, der "Einreihen" statt "Senden" anbieten soll, und
- * fuer das Warteplaettchen, das erklaeren soll, warum. Die naheliegende
- * Fassung in der Oberflaeche waere `lane === 'local' && localLaneHolder()`,
- * und die ist zweimal dieselbe Regel: einmal hier, einmal dort, eine davon
- * gepflegt. Beim ersten Sonderfall, den `admit` dazubekommt (der Halter, der
- * noch einmal fragt, ist schon einer), stuende an der Eingabe "Einreihen",
- * waehrend der Lauf sofort losliefe.
- *
- * Deshalb steht die Vorschau hier, unmittelbar neben der Entscheidung, und
- * ein Waechter vergleicht die beiden Fall fuer Fall.
- */
-export function wouldQueue(lane: RunLane, conversationId: string | null | undefined): boolean {
- if (lane === 'cloud') return false
- if (!conversationId) return false
- if (halter === conversationId) return false
- if (warteschlange.some((w) => w.convId === conversationId)) return true
- return halter !== null
-}
-
/**
* Der Lauf ist vorbei (oder der Wartende will doch nicht mehr).
*
@@ -306,7 +260,6 @@ export function queuedRunIds(): string[] {
export function __resetRunLanesForTests(): void {
halter = null
warteschlange.length = 0
- momentaufnahme = null
// Die Beobachter bleiben stehen: sie gehoeren dem Test, der sie angemeldet
// hat, und der meldet sie selbst wieder ab. Wer sie hier mit abraeumte,
// naehme einem `beforeEach` still die Anmeldung aus dem Test davor weg.