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.

fix(console): refresh produced files after turn settles (#608)

Hitesh_Ge1ccd15e585a
diff --git a/ui/src/lib/chat.ts b/ui/src/lib/chat.ts
index 58a99fb3..551de71b 100644
--- a/ui/src/lib/chat.ts
+++ b/ui/src/lib/chat.ts
@@ -101,6 +101,9 @@ export interface SessionTurn {
id: string; status: string; user: string; assistant: string;
/** What this turn alone took and cost; absent on turns from before the gateway kept them. */
elapsed?: number | null;
+ /** When the turn ended, Unix seconds: null while its stored record is still the running one. The
+ * record that says when it ended is the turn's last write, the one that holds its produced files. */
+ completed_at?: number | null;
user_files?: { name: string }[]; // caller-attached input files (names; bytes live in the workspace)
tools: { name: string; arguments: string; result?: string; output?: string; is_error?: boolean }[]; files: RespFile[];
}
diff --git a/ui/src/lib/conversation.test.tsx b/ui/src/lib/conversation.test.tsx
index 5df412dd..82c93f3c 100644
--- a/ui/src/lib/conversation.test.tsx
+++ b/ui/src/lib/conversation.test.tsx
@@ -299,6 +299,44 @@ describe('a send whose own stream ends before the turn does', () => {
expect(textOf(lastA(sid))).toBe('Partial, the middle, the end');
expect(lastA(sid)?.elapsed).toBe(12);
});
+
+ // What a gateway that keeps no elapsed answers while a turn is written (#451): the session already
+ // says the turn ended, so the record reads as ended, but it is still the running one (completed_at
+ // null) and its produced files are not in it yet. The turn's last write says when it ended and
+ // holds the files.
+ const report = { container_id: 'c1', file_id: 'f1', filename: 'report.csv' };
+ test('a produced file the record holds only once the turn is written whole shows without a reload', async () => {
+ const sid = await openIdle();
+ streamThatStops('Done');
+ const midWrite = turn({ id: 'r2', user: 'next', assistant: 'Done', completed_at: null, files: [] });
+ mockChat.load.mockResolvedValue(record([turn({ completed_at: 1 }), midWrite]));
+ await act(async () => { await api.send('next'); });
+ await tick();
+ expect(C.getConvState(sid).busy).toBe(false); // settled from the record read mid-write
+ await tick(2500); // the settled read: still mid-write
+ expect(lastA(sid)?.files).toEqual([]);
+ mockChat.load.mockResolvedValue(record([turn({ completed_at: 1 }), { ...midWrite, completed_at: 1793000000, files: [report] }]));
+ await tick(6000); // the next read finds the turn's last write
+ expect(lastA(sid)?.files).toEqual([report]);
+ expect(lastA(sid)?.elapsed).toBeUndefined();
+ expect(textOf(lastA(sid))).toBe('Done');
+ });
+
+ test('a record that does not hold this turn yet gives it nothing of the turn before', async () => {
+ const sid = await openIdle();
+ streamThatStops('Done');
+ mockChat.load.mockResolvedValue(record([turn({ completed_at: 1, files: [report] })]));
+ await act(async () => { await api.send('next'); });
+ await tick();
+ await act(async () => { mockChat.bus[0].onMsg({ session_id: sid, response_id: 'r2', event: { type: 'response.completed', response: {} } }); });
+ expect(C.getConvState(sid).busy).toBe(false);
+ await tick(2500); // the settled read: the record ends on the previous turn
+ expect(lastA(sid)?.files).toEqual([]);
+ mockChat.load.mockResolvedValue(record([turn({ completed_at: 1, files: [report] }),
+ turn({ id: 'r2', user: 'next', assistant: 'Done', completed_at: 1793000000, files: [] })]));
+ await tick(6000);
+ expect(lastA(sid)?.files).toEqual([]);
+ });
});
describe('one live feed per setup in a tab', () => {
diff --git a/ui/src/lib/conversation.ts b/ui/src/lib/conversation.ts
index 098b7ec1..aefd821e 100644
--- a/ui/src/lib/conversation.ts
+++ b/ui/src/lib/conversation.ts
@@ -679,6 +679,10 @@ export function useConversationTurn({ harnessId, sessionId, target, onRan, onSes
// took and cost is written by the gateway at settle, a moment after the terminal event. One
// read (and one retry, since the persist can trail the event by a couple of seconds) folds
// those figures into the last answer, so the per-turn line appears without a reload.
+ // The record is final when it says when the turn ended (completed_at) or what it took (elapsed):
+ // the gateway writes either with the turn's produced files, and a gateway that keeps no elapsed
+ // still says completed_at. Waiting for elapsed alone never folded the files there (#451): a turn
+ // settled from a record read mid-write kept no file card until a reload.
const settledRead = useRef<Set<string>>(new Set());
useEffect(() => {
if (busy) return;
@@ -696,8 +700,11 @@ export function useConversationTurn({ harnessId, sessionId, target, onRan, onSes
if (stop) return;
try {
const { turns } = await loadSessionTurns(sid);
- const t = turns[turns.length - 1];
- if (t && typeof t.elapsed === 'number') {
+ // a record that does not hold this answer's turn yet ends on the previous turn, whose end and
+ // files are not this one's
+ const asked = getConvState(convKeyRef.current).msgs.filter((x) => x.role === 'assistant').length;
+ const t = turns.length >= asked ? turns[turns.length - 1] : undefined;
+ if (t && (typeof t.elapsed === 'number' || typeof t.completed_at === 'number')) {
// a turn whose own stream ended before it did (_gapped): the record's whole answer, when the
// record holds just the turns this thread does (nothing unrecorded after it)
const whole = _gapped.has(sid) ? msgsFromTurns(turns).msgs : null;