fix: start queue countdown from state, clear stale stop flag, drop dead watch code

Co-Authored-By: Ovis Fast (Claude) <[email protected]>
This commit is contained in:
FactorandOvis Fast committed 2026-11-19 11:28:25 +01:00
1 parent 7ec35215c6
commit 86ca415d96
3 files changed
+111 -68

No files matched your search

+21
View File
@@ -109,6 +109,27 @@ export function shouldDrain(prev, next, stoppedByComposer) {
return was && is;
}
/**
* Does the queue start counting down now? A rule of the state, not of a
* change: a turn that ended unseen (shorter than one poll) or a status that
* was unknown for a while must not leave a message waiting for ever.
*
* Yes when the agent is idle or done, an entry waits in the queue (`queued`;
* a `held` one does not count, an `uncertain` one in front of it does not
* block), nothing counts down or is on the wire, the turn gate is open and the
* composer did not stop the agent itself.
*
* @param {{status:Status|string, queue:QueueItem[], gateOpen:boolean, stopped:boolean}} input
* @returns {boolean}
*/
export function shouldStartCountdown({ status, queue, gateOpen, stopped }) {
if (stopped || !gateOpen) return false;
if (!ready(status)) return false;
if (!Array.isArray(queue)) return false;
if (queue.some((item) => item.state === "countdown" || item.state === "sending")) return false;
return queue.some((item) => item.state === "queued");
}
/**
* The turn gate: the next message goes out only after a whole turn was seen -
* the agent was working and then came back to idle/done. Without that