From ce943f3dff8ec8cd90c1f5718f9f3c2e78326398 Mon Sep 17 00:00:00 2001 From: Alain Schlesser Date: Tue, 3 Nov 2026 08:28:03 +0000 Subject: [PATCH] fix(ui-react): a read that could not answer is not a change, so a failure is announced once A recovery read that timed out or failed briefly made a tracker `can't check`, and the announcer measured the next read's same answer from it: the same failure of the same turn was announced a second time. Under load the parallel-sessions runtime case's fake-clock fast-forward aborted B's in-flight read (Playwright fakes `AbortSignal.timeout`), so B's failure was spoken twice. `can't check` and `unknown` no longer replace the state a change is measured from once a tracker has one. Work that moved on during the gap is still announced, and a tracker whose first answer was `can't check` still announces what it then learns. Closes #3414 Co-Authored-By: Claude Opus 5.5 --- .changeset/tracker-announce-after-unread.md | 5 +++++ .../design-kit/sessions-and-drafts.md | 5 ++++- .../ui-react/src/lib/tracker-announcer.ts | 10 +++++++++ .../ui-react/tests/tracker-announcer.test.ts | 21 +++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 .changeset/tracker-announce-after-unread.md diff --git a/.changeset/tracker-announce-after-unread.md b/.changeset/tracker-announce-after-unread.md new file mode 100644 index 0000000000..a291f4cf85 --- /dev/null +++ b/.changeset/tracker-announce-after-unread.md @@ -0,0 +1,5 @@ +--- +"@schlessera/brain-ui-react": patch +--- + +A tracker's failure, completion or question is no longer announced a second time after a recovery read that could not answer. A read that timed out or failed briefly turned the tracker into `can't check`, and the next read's same answer was announced again as a new change. The announcer now measures changes from the last state it saw settle, not from `can't check` or `unknown`, so work that moved on in the meantime is still announced. diff --git a/docs/decisions/design-kit/sessions-and-drafts.md b/docs/decisions/design-kit/sessions-and-drafts.md index 1ff8c85c02..318fd45e4b 100644 --- a/docs/decisions/design-kit/sessions-and-drafts.md +++ b/docs/decisions/design-kit/sessions-and-drafts.md @@ -471,7 +471,10 @@ kinds keep #910's rules and state footer, with no second indicator. > the case, not a change: one restored on load, taken in from another tab, > or made by leaving the session in view announces nothing then. Work that > starts in a session nobody is watching announces its first settled view. -> Changes that arrive together are each announced. +> Changes that arrive together are each announced. A read that could not +> answer (`can't check`) or that was contradicted (`unknown`) is not what a +> change is measured from: the same state of the same turn, read again +> after it, is not announced a second time (#3414). > - Opening a tracker moves focus once the session's replayed history is > complete (a chunk has come and none has followed it for 150ms) and, for > `needs you`, its card is drawn: 5 seconds at most, then with what is diff --git a/packages/ui-react/src/lib/tracker-announcer.ts b/packages/ui-react/src/lib/tracker-announcer.ts index ea59c0e982..c21c02ba70 100644 --- a/packages/ui-react/src/lib/tracker-announcer.ts +++ b/packages/ui-react/src/lib/tracker-announcer.ts @@ -6,6 +6,9 @@ export type AnnouncedState = Extract = new Set(["needs_you", "failed", "done"]); +/** States that say only that the work could not be read; they never become the baseline a change is measured from. */ +const UNREAD: ReadonlySet = new Set(["cant_check", "unknown"]); + export interface TrackerAnnouncement { sessionId: string; state: AnnouncedState; @@ -23,6 +26,12 @@ export interface TrackerAnnouncement { * anything before a tracker's view is `settled` (nothing has answered for it * yet). * + * A read that could not answer (`can't check`) or that contradicted what was + * known (`unknown`) says nothing new about the work, so it does not replace + * the state last seen to settle (#3414). The read after it that says the same + * thing again (the same failure of the same turn) announces nothing. Work + * that moved on during the gap is still a change. + * * The first settled view of a tracker is its baseline, not a change: a * tracker restored on load, taken in from another tab, or made by leaving a * session the reader was looking at says what was already the case. The one @@ -46,6 +55,7 @@ export function createTrackerAnnouncer() { present.add(view.sessionId); if (!view.settled) continue; const before = last.get(view.sessionId); + if (before !== undefined && UNREAD.has(view.state)) continue; last.set(view.sessionId, { state: view.state, turnId: view.turnId }); const first = before === undefined; const wasFresh = fresh.delete(view.sessionId); diff --git a/packages/ui-react/tests/tracker-announcer.test.ts b/packages/ui-react/tests/tracker-announcer.test.ts index cb88e4c7a4..c1978dad05 100644 --- a/packages/ui-react/tests/tracker-announcer.test.ts +++ b/packages/ui-react/tests/tracker-announcer.test.ts @@ -50,6 +50,27 @@ describe("the announcer", () => { expect(a.observe([view({ sessionId: B, state: "needs_you" })])).toEqual([]); }); + test("a read that could not answer is not a change: the same failure after it is not spoken again (#3414)", () => { + const a = createTrackerAnnouncer(); + a.observe([view({ state: "running" })]); + expect(a.observe([view({ state: "failed", outcome: "error" })])).toEqual([{ sessionId: A, state: "failed", outcome: "error" }]); + // A recovery read times out, then the next one says the same again. + expect(a.observe([view({ state: "cant_check", cantCheck: "host_unreachable" })])).toEqual([]); + expect(a.observe([view({ state: "failed", outcome: "error" })]), "the same failure, read again").toEqual([]); + // A contradicted read, then the same answer again. + expect(a.observe([view({ state: "unknown" })])).toEqual([]); + expect(a.observe([view({ state: "failed", outcome: "error" })]), "the same failure, after a rollback").toEqual([]); + // Work that moved on while it could not be read is still a change. + expect(a.observe([view({ state: "cant_check", cantCheck: "host_unreachable" })])).toEqual([]); + expect(a.observe([view({ state: "done", outcome: "success", turnId: "turn-2" })])).toEqual([{ sessionId: A, state: "done", outcome: "success" }]); + expect(a.observe([view({ state: "unknown", turnId: "turn-2" })])).toEqual([]); + expect(a.observe([view({ state: "failed", outcome: "error", turnId: "turn-3" })])).toEqual([{ sessionId: A, state: "failed", outcome: "error" }]); + // A tracker whose first answer was can't check announces what it then learns. + const b = createTrackerAnnouncer(); + b.observe([view({ state: "cant_check", cantCheck: "host_unreachable" })]); + expect(b.observe([view({ state: "done", outcome: "success" })])).toEqual([{ sessionId: A, state: "done", outcome: "success" }]); + }); + test("a cleared tracker says nothing, and a tracker that went starts over as a baseline", () => { const a = createTrackerAnnouncer(); a.observe([view({ state: "running" })]);