Chat queue: wake the runner when a scheduled head is unqueued; end a stale observed turn once the harness is idle
A prompt queued behind a scheduled prompt (the app's auto-continue at a usage limit's reset) stayed queued after that head was removed: unqueue never woke the runner, which slept until the removed prompt's send_at. unqueue now wakes it, and the runner re-checks a scheduled head at least every 30 s. Safety net: a due prompt held by a turn the room only observed (its end lost, or a reattach watcher that gave up) is delivered once the harness reports itself idle for a settle period and its probe confirms it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -37,6 +37,18 @@ var chatQueueBusyPoll = time.Second
|
||||
// through its stream.
|
||||
var chatQueueRecoverySettle = 1500 * time.Millisecond
|
||||
|
||||
// chatQueueScheduleRecheck bounds how long the runner sleeps on a scheduled
|
||||
// head before it looks at the queue again, so a head that changed without a
|
||||
// wake (it was removed, or a restart reordered nothing) never holds the
|
||||
// prompts behind it until the old send_at.
|
||||
var chatQueueScheduleRecheck = 30 * time.Second
|
||||
|
||||
// chatQueueStaleTurnSettle is how long a due queue head waits behind a turn
|
||||
// the room only observed (one it did not start) while the harness reports
|
||||
// itself idle, before that turn is treated as ended (its end event was lost)
|
||||
// and the queue proceeds.
|
||||
var chatQueueStaleTurnSettle = 10 * time.Second
|
||||
|
||||
// chatRecentOpsLimit bounds the remembered accepted operation ids used to
|
||||
// refuse a duplicate delivery of a client retry.
|
||||
const chatRecentOpsLimit = 256
|
||||
@@ -299,6 +311,9 @@ func (h *chatHub) unqueue(ctx context.Context, sessionID, operationID string) (b
|
||||
if p.acked && p.operationID == operationID {
|
||||
removed = p
|
||||
room.queue = append(room.queue[:i:i], room.queue[i+1:]...)
|
||||
// The runner may be asleep until the removed prompt's send_at;
|
||||
// the new head (often one due now) must not wait for it.
|
||||
signalWake(room.wake)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user