From e6afb3ebf9eee0757fd7ad8bee9da4020d0d3171 Mon Sep 17 00:00:00 2001 From: Factor Date: Thu, 19 Nov 2026 12:19:54 +0100 Subject: [PATCH] fix: an answer to a blocked agent goes ahead of the queue Co-Authored-By: Ovis Fast (Claude) --- mod/ovis-composer/main.js | 13 +++++++++---- mod/ovis-composer/view.js | 23 ++++++++++++++++++++++- tests/view.test.mjs | 19 +++++++++++++++++++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/mod/ovis-composer/main.js b/mod/ovis-composer/main.js index 6f8d5e8..48b4757 100644 --- a/mod/ovis-composer/main.js +++ b/mod/ovis-composer/main.js @@ -48,7 +48,6 @@ import { decide, shouldDrain, shouldStartCountdown, - queueBlocksDirectSend, parseSendArgs, sendNow as sendToTerminal, } from "./delivery.js"; @@ -94,6 +93,7 @@ import { queueLabel, shortPath, stillSameAgent, + directSendBlocked, statusText, targetAgent, } from "./view.js"; @@ -1066,9 +1066,14 @@ export default class Composer extends View { const allowed = mode === "now" || canAutoSend(this.draftReady, key); // A message that is on the wire, waits in the queue or counts down goes first: the // new one waits behind it in the queue instead of vanishing or jumping - // the line (Ctrl+Enter is the person's own order and does jump). - const busy = - this.draining.has(key) || (mode !== "now" && queueBlocksDirectSend(this.state.queue[key])); + // the line. Ctrl+Enter is the person's own order and does jump, and so is + // an answer to a blocked agent (see `directSendBlocked`). + const busy = directSendBlocked({ + draining: this.draining.has(key), + mode, + status: this.statusOf(agent), + queue: this.state.queue[key], + }); if (decision.kind === "send" && allowed && !busy) { // The person's own Enter answers an agent that waits for them: it goes // through even though the agent is blocked (`hc send --force`). Never diff --git a/mod/ovis-composer/view.js b/mod/ovis-composer/view.js index 3d7df56..e97feed 100644 --- a/mod/ovis-composer/view.js +++ b/mod/ovis-composer/view.js @@ -8,7 +8,7 @@ // belongs to an agent (the draft, the queue, the attachments) is keyed by the // agent's address, so two Claude Code agents never share a draft. -import { drain, gateAfter } from "./delivery.js"; +import { drain, gateAfter, queueBlocksDirectSend } from "./delivery.js"; import { LIMITS } from "./attachments.js"; /** @@ -495,3 +495,24 @@ export function canAutoSend(ready, key) { export function stillSameAgent({ before, after, target }) { return before !== "" && before === after && before === target; } + +/** + * Must a message that could go out now wait behind what is already in flight + * or in the queue? + * + * - a message on the wire always goes first (`draining`); + * - Ctrl+Enter (`mode "now"`) is the person's own order and does not wait; + * - an answer to an agent that is `blocked` does not wait either: the queue + * does not start while the agent waits for the person, so queueing the + * answer would leave the agent waiting for ever - it goes ahead (with + * `--force`) and the queue stays as it is; + * - otherwise it waits when a message is queued or counting down. + * + * @param {{draining:boolean, mode:string, status:string, queue:object[]|undefined}} input + * @returns {boolean} + */ +export function directSendBlocked({ draining, mode, status, queue }) { + if (draining) return true; + if (mode === "now" || status === "blocked") return false; + return queueBlocksDirectSend(queue); +} diff --git a/tests/view.test.mjs b/tests/view.test.mjs index 549483e..dc7b1b8 100644 --- a/tests/view.test.mjs +++ b/tests/view.test.mjs @@ -81,3 +81,22 @@ test("stillSameAgent: only when the field and the focus are on one agent", () => assert.equal(stillSameAgent({ before: "", after: "", target: "" }), false); assert.equal(stillSameAgent({ before: "", after: "t2", target: "t2" }), false); }); + +import { directSendBlocked } from "../mod/ovis-composer/view.js"; + +test("directSendBlocked: who must wait behind the queue", () => { + const queue = [{ state: "queued" }]; + // an answer to a blocked agent goes ahead of the queue + assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "blocked", queue }), false); + // an idle agent with a queue: the new message waits at the end + assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue }), true); + assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "done", queue }), true); + // Ctrl+Enter is the person's own order + assert.equal(directSendBlocked({ draining: false, mode: "now", status: "idle", queue }), false); + // a message on the wire always goes first + assert.equal(directSendBlocked({ draining: true, mode: "now", status: "blocked", queue: [] }), true); + assert.equal(directSendBlocked({ draining: true, mode: "auto", status: "idle", queue }), true); + // nothing waits + assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue: [] }), false); + assert.equal(directSendBlocked({ draining: false, mode: "auto", status: "idle", queue: [{ state: "held" }] }), false); +});