Skip to content

Commit 21b4706

Browse files
jahoomaclaude
andauthored
Load queue depths on freebuff landing so picker doesn't flash "No wait" (#532)
Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 52fc32e commit 21b4706

2 files changed

Lines changed: 28 additions & 8 deletions

File tree

cli/src/components/freebuff-model-selector.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ export const FreebuffModelSelector: React.FC = () => {
4949
// subtract. In-queue ('queued'): for the user's queue, "ahead" is
5050
// `position - 1` (themselves don't count); for every other queue, switching
5151
// would land them at the back, so it's that queue's full depth. Null before
52-
// any snapshot so the UI doesn't flash misleading zeros.
52+
// any snapshot so the UI doesn't flash misleading zeros — in particular,
53+
// landing mode after a session ends initially sets status='none' with no
54+
// queueDepthByModel; returning null here keeps the hint blank until the
55+
// fetch lands, instead of showing "No wait" on every row.
5356
const aheadByModel = useMemo<Record<string, number> | null>(() => {
5457
if (session?.status === 'none') {
55-
const depths = session.queueDepthByModel ?? {}
58+
if (!session.queueDepthByModel) return null
59+
const depths = session.queueDepthByModel
5660
const out: Record<string, number> = {}
5761
for (const { id } of FREEBUFF_MODELS) out[id] = depths[id] ?? 0
5862
return out

cli/src/hooks/use-freebuff-session.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -438,13 +438,29 @@ export function useFreebuffSession(): UseFreebuffSessionResult {
438438
// doesn't bounce a 'landing' restart straight back to 'ended'.
439439
previousStatus = null
440440
if (mode === 'landing') {
441-
// Land on the picker without a probe GET. If the preceding
442-
// DELETE hasn't propagated, a GET here could still see
443-
// queued/active and trip the startup-takeover branch below into
444-
// an auto-POST — the exact silent-rejoin this mode exists to
445-
// avoid. Polling resumes when the user commits to a model via
446-
// joinFreebuffQueue.
441+
// Land on the picker immediately. We can't go through the normal
442+
// tick/apply path because a server-side row that hasn't been
443+
// swept yet would trip the startup-takeover branch into an
444+
// auto-POST — the exact silent-rejoin this mode exists to
445+
// prevent. But the picker still needs live queue depths for its
446+
// "N ahead" hints, so kick off a fire-and-forget GET and extract
447+
// just queueDepthByModel from the response, ignoring whatever
448+
// status it claims. Polling resumes when the user commits to a
449+
// model via joinFreebuffQueue.
447450
apply({ status: 'none' })
451+
const fetchController = abortController
452+
callSession('GET', token, { signal: fetchController.signal })
453+
.then((response) => {
454+
if (cancelled || fetchController.signal.aborted) return
455+
const depths =
456+
response.status === 'none' || response.status === 'queued'
457+
? response.queueDepthByModel
458+
: undefined
459+
if (depths) apply({ status: 'none', queueDepthByModel: depths })
460+
})
461+
.catch(() => {
462+
// Silent — blank hints are acceptable if the fetch fails.
463+
})
448464
return
449465
}
450466
nextMethod = 'POST'

0 commit comments

Comments
 (0)