Skip to content

HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.

A task keeps taking messages after a turn settles off the stream (#120)

github-actions[bot]596021955e50
diff --git a/scripts/support-matrix/run.mjs b/scripts/support-matrix/run.mjs
index 785de673..6a28cdf5 100644
--- a/scripts/support-matrix/run.mjs
+++ b/scripts/support-matrix/run.mjs
@@ -126,7 +126,19 @@ try {
const a = await turn(`Create a file named hello-${h}.txt containing exactly the word HELLO, then reply DONE.`, { expectFiles: true });
// the file cards render from the settled read, a moment after the answer
let fl = await files(); for (let i = 0; i < 10 && fl.length < (a.turn_files || []).length; i++) { await sleep(1500); fl = await files(); }
- rec.artifact = { ...a, files: fl, ok: a.ok && fl.some((f) => f.includes(`hello-${h}.txt`)), why: a.ok && !fl.some((f) => f.includes(`hello-${h}.txt`)) ? `no file card (files: ${fl.join(',') || 'none'}); ${a.tail.slice(-160)}` : a.why };
+ // The cards the page renders must BE what the turn stored: the same names, the same count.
+ // Asking only whether SOME card carried the name let a file rendered twice pass as a produced
+ // artifact for months; the console showed two cards for one file until a reload (2026-09-07).
+ // A harness that produces files is measured on both halves, the record and what the reader sees.
+ const named = fl.some((f) => f.includes(`hello-${h}.txt`));
+ const want = (a.turn_files || []).slice().sort(), got = fl.slice().sort();
+ const agrees = want.length === got.length && want.every((w, i) => got[i].includes(w) || w.includes(got[i]));
+ rec.artifact = { ...a, files: fl, record_files: a.turn_files, cards_agree: agrees,
+ ok: a.ok && named && agrees,
+ why: !a.ok ? a.why
+ : !named ? `no file card (files: ${fl.join(',') || 'none'}); ${a.tail.slice(-160)}`
+ : !agrees ? `the cards do not match the record: cards [${fl.join(',') || 'none'}] vs record [${want.join(',') || 'none'}]`
+ : a.why };
log(`ARTIFACT ${k} ${rec.artifact.ok ? 'ok' : 'FAIL'} ${rec.artifact.s}s ${rec.artifact.why}`);
// the sandbox is let go on purpose (what the pool does between visits) and the next turn must
// carry on from the durable checkpoint: the history, the files, the resume id
diff --git a/ui/src/lib/conversation.ts b/ui/src/lib/conversation.ts
index 7038628c..ae80670b 100644
--- a/ui/src/lib/conversation.ts
+++ b/ui/src/lib/conversation.ts
@@ -167,6 +167,17 @@ export function turnIndexOf(msgs: Msg[]): number {
// lag) so the Recents "working" dot is accurate the instant a turn starts/ends.
export const _runningSids = new Set<string>();
const _busFn: Record<string, { name: string; callId: string }> = {};
+/** Add a produced file to an answer, once. The same file can reach a tab twice: its own POST stream
+ * renders it as the citation arrives, and the broadcast bus can deliver that same event a moment
+ * after the stream ended and its suppression was lifted. The turn record holds one file, so the
+ * duplicate was a transcript-only ghost that a reload cleared (2026-09-07). A file is identified by
+ * its container and id, so re-adding the one already shown is a no-op. */
+function withFile(files: RespFile[], f: RespFile): RespFile[] {
+ const same = (x: RespFile) => (f.file_id ? x.file_id === f.file_id && x.container_id === f.container_id
+ : x.filename === f.filename);
+ return files.some(same) ? files : [...files, f];
+}
+
function busUpdateLast(sid: string, fn: (a: AsstMsg) => void) {
setConvState(sid, (s) => {
const out = s.msgs.slice();
@@ -216,7 +227,7 @@ function applyBusEvent(sid: string, responseId: string, ev: Record<string, unkno
busUpdateLast(sid, (a) => { a.blocks = withText(a.blocks, ev.delta as string); }); break;
case 'response.output_text.annotation.added': {
const a = ev.annotation as Record<string, unknown>;
- if (a?.type === 'container_file_citation') busUpdateLast(sid, (m) => { m.files = [...m.files, { container_id: a.container_id as string, file_id: a.file_id as string, filename: a.filename as string }]; });
+ if (a?.type === 'container_file_citation') busUpdateLast(sid, (m) => { m.files = withFile(m.files, { container_id: a.container_id as string, file_id: a.file_id as string, filename: a.filename as string }); });
break;
}
case 'response.completed':
@@ -297,6 +308,17 @@ export function useConversationTurn({ harnessId, sessionId, target, onRan, onSes
// Stop is one-shot: disabled the moment it is clicked so a slow cancel cannot be spammed.
const [stopping, setStopping] = useState(false);
useEffect(() => { setStopping(false); }, [busy]);
+ // The send latch (sendingRef) collapses clicks that land in the same tick, before `busy` has
+ // re-rendered; send()'s finally releases it. But that finally only runs when the POST stream
+ // ends, and a turn can settle without it: the terminal event arrives on the broadcast bus, or
+ // the reconciliation poll reads it from the server, while the stream itself stays open. The
+ // latch then outlives its turn, and every later message is dropped by a send() that returns at
+ // the guard, with the composer looking perfectly enabled and no request ever leaving the tab
+ // (measured 2026-09-07: a task took three turns, then silently took no more until a reload).
+ // The conversation going idle is proof the turn is over, so the latch is released there too.
+ // This cannot weaken the double-click guard: the clicks it collapses land before any render,
+ // so no effect runs between them, and by the time this one runs `busy` is already true.
+ useEffect(() => { if (!busy) sendingRef.current = false; }, [busy]);
// The shape of a task, never its content. No prompt, no file name, no title.
const taskFacts = () => ({
@@ -496,7 +518,7 @@ export function useConversationTurn({ harnessId, sessionId, target, onRan, onSes
onToolCall: (name, args, callId) => updateLast((a) => { a.blocks = withStep(a.blocks, { name, args, callId }); }),
onToolResult: (callId, output) => updateLast((a) => { a.blocks = withResult(a.blocks, callId, output); }),
onTextDelta: (d) => updateLast((a) => { a.blocks = withText(a.blocks, d); }),
- onFile: (f) => updateLast((a) => { a.files = [...a.files, f]; }),
+ onFile: (f) => updateLast((a) => { a.files = withFile(a.files, f); }),
onError: (msg) => updateLast((a) => { a.blocks = withError(a.blocks, msg); }),
onDone: (status) => {
updateLast((a) => {