Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tracker-announce-after-unread.md
Original file line number Diff line number Diff line change
@@ -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.
5 changes: 4 additions & 1 deletion docs/decisions/design-kit/sessions-and-drafts.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions packages/ui-react/src/lib/tracker-announcer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ export type AnnouncedState = Extract<TrackerState, "needs_you" | "failed" | "don

const ANNOUNCED: ReadonlySet<TrackerState> = new Set<AnnouncedState>(["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<TrackerState> = new Set<TrackerState>(["cant_check", "unknown"]);

export interface TrackerAnnouncement {
sessionId: string;
state: AnnouncedState;
Expand All @@ -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
Expand All @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions packages/ui-react/tests/tracker-announcer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" })]);
Expand Down
Loading