From efe70bccec0aa9b85af5ecc52c6cfefdd89ff9b2 Mon Sep 17 00:00:00 2001 From: g-but <41178744+g-but@users.noreply.github.com> Date: Sat, 16 May 2026 17:10:42 +0200 Subject: [PATCH] fix(queue): pure remove() updater + commander view consumes queue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Two behavioral fixes: 1. remove() side effects were inside the setQueue updater — React Strict Mode and concurrent mode can invoke updaters multiple times, causing double file writes and duplicate PUT requests to /api/beacon/queue. Moved localStorage write and writeToFile() call outside the updater; updater is now a pure filter. This matches the pre-existing pattern used by shift(). 2. ProjectCommanderCard.advance() bypassed the queue entirely — it went straight to onRunWithBrain("next_best") even when items were queued. Switching to commander view silently broke queue dispatch. Fixed: now calls shiftQueue() first, injects the queued item if present, falls back to next_best otherwise. Also surfaces queue state in the card: context line shows queue[0] when ready, button shows "Send (N)" with a count tooltip instead of plain "Continue". Co-Authored-By: Claude Sonnet 4.6 --- .../control/ProjectCommanderCard.tsx | 14 +++++++++-- src/hooks/use-prompt-queue.ts | 25 +++++++++---------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/components/control/ProjectCommanderCard.tsx b/src/components/control/ProjectCommanderCard.tsx index cda21fcb1..733eded9c 100644 --- a/src/components/control/ProjectCommanderCard.tsx +++ b/src/components/control/ProjectCommanderCard.tsx @@ -7,6 +7,7 @@ import type { ProjectState } from "@/lib/control-types"; import type { OrchestrationTaskIntentId } from "@/lib/orchestration"; import { getProjectDisplayState } from "./control-presenter"; import { useAutoContinue } from "@/hooks/use-auto-continue"; +import { usePromptQueue } from "@/hooks/use-prompt-queue"; export function ProjectCommanderCard({ project, @@ -24,6 +25,7 @@ export function ProjectCommanderCard({ const nowS = Math.floor(Date.now() / 1000); const display = getProjectDisplayState(project, zellijTabs, nowS); const { enabled: autoContinueEnabled, toggle: toggleAutoContinue } = useAutoContinue(project.tab); + const { queue, shift: shiftQueue } = usePromptQueue(project.tab); const [sending, setSending] = useState(false); const [talkOpen, setTalkOpen] = useState(false); @@ -50,6 +52,8 @@ export function ProjectCommanderCard({ const contextLine = isRunning && project.currentPrompt ? project.currentPrompt.label + : queue.length > 0 + ? queue[0] : project.session?.next ? project.session.next : project.session?.done ?? null; @@ -75,7 +79,12 @@ export function ProjectCommanderCard({ const advance = async () => { setSending(true); try { - await onRunWithBrain(project, "next_best"); + const queued = shiftQueue(); + if (queued) { + await onInject(project.tab, undefined, queued); + } else { + await onRunWithBrain(project, "next_best"); + } } finally { setSending(false); } @@ -130,10 +139,11 @@ export function ProjectCommanderCard({