Skip to content
Merged
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-recovery-announcements.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@schlessera/brain-ui-react": patch
---

Keep established tracker announcement baselines through unavailable or unknown reads, so recovery does not repeat a completion, failure or pending interaction. Discard unwatched-work markers when their tracker is removed.
6 changes: 6 additions & 0 deletions docs/decisions/design-kit/sessions-and-drafts.md
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,12 @@ kinds keep #910's rules and state footer, with no second indicator.
> 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.
> *(2026-11-11, #3973; also #3414.)* Once a tracker has a baseline,
> unavailable and unknown recovery observations do not replace it. Reading
> the same completion, failure or pending interaction again says nothing.
> A first settled view of `can't check` still establishes a baseline, so
> what the next successful read learns can announce. Work that moves on
> during a gap and new unwatched work keep their announcements.
> - 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
6 changes: 5 additions & 1 deletion packages/ui-react/src/lib/tracker-announcer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export interface TrackerAnnouncement {
* anything before a tracker's view is `settled` (nothing has answered for it
* yet).
*
* Once a tracker has a baseline, unavailable and unknown observations do not
* replace it: recovering the same facts is not new work.
*
* 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 @@ -44,7 +47,7 @@ export function createTrackerAnnouncer() {
const present = new Set<string>();
for (const view of views) {
present.add(view.sessionId);
if (!view.settled) continue;
if (!view.settled || (last.has(view.sessionId) && (view.state === "cant_check" || view.state === "unknown"))) continue;
const before = last.get(view.sessionId);
last.set(view.sessionId, { state: view.state, turnId: view.turnId });
const first = before === undefined;
Expand All @@ -56,6 +59,7 @@ export function createTrackerAnnouncer() {
// A tracker that went (seen, acknowledged, or the set deleted) starts
// over: if the session is tracked again, its first view is a baseline.
for (const id of [...last.keys()]) if (!present.has(id)) last.delete(id);
for (const id of fresh) if (!present.has(id)) fresh.delete(id);
return out;
},
};
Expand Down
36 changes: 36 additions & 0 deletions packages/ui-react/tests/tracker-announcer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,42 @@ describe("the announcer", () => {
expect(a.observe([view({ state: "done", settled: true })]), "a restored tracker's first answer").toEqual([]);
});

test("a first settled unavailable read keeps the existing baseline rule", () => {
const a = createTrackerAnnouncer();
expect(a.observe([view({ state: "cant_check", cantCheck: "host_unreachable", turnId: null })])).toEqual([]);
expect(a.observe([view({ state: "unknown", turnId: null })])).toEqual([]);
expect(a.observe([view({ state: "done", outcome: "success" })]), "FIRST_UNAVAILABLE_BASELINE_CAN_LEARN_COMPLETION")
.toEqual([{ sessionId: A, state: "done", outcome: "success" }]);
expect(a.observe([view({ state: "done", outcome: "success", turnId: "turn-2" })]), "a different turn still announces").toHaveLength(1);
});

test("recovery keeps the last known work state: real completion announces, repeated completion does not", () => {
const a = createTrackerAnnouncer();
a.observe([view({ state: "running" })]);
a.observe([view({ state: "cant_check", cantCheck: "host_unreachable" })]);
expect(a.observe([view({ state: "done", outcome: "success" })]), "a turn known to be running finished").toHaveLength(1);
a.observe([view({ state: "unknown" })]);
a.observe([view({ state: "cant_check", cantCheck: "host_unreachable" })]);
expect(a.observe([view({ state: "done", outcome: "success" })]), "RECOVERY_DOES_NOT_REPEAT_COMPLETION").toEqual([]);
});

test("failed reads cannot consume the first announcement for new unwatched work", () => {
const a = createTrackerAnnouncer();
a.background(B);
a.observe([view({ sessionId: B, state: "cant_check", cantCheck: "host_unreachable" })]);
a.observe([view({ sessionId: B, state: "unknown" })]);
expect(a.observe([view({ sessionId: B, state: "needs_you" })]), "NEW_UNWATCHED_WORK_STILL_ANNOUNCES")
.toEqual([{ sessionId: B, state: "needs_you", outcome: null }]);
});

test("discarding an unconfirmed tracker also discards its unwatched-work marker", () => {
const a = createTrackerAnnouncer();
a.background(B);
a.observe([view({ sessionId: B, state: "cant_check", settled: false })]);
a.observe([]);
expect(a.observe([view({ sessionId: B, state: "done", outcome: "success" })]), "DISCARDED_TRACKER_STARTS_AS_A_BASELINE").toEqual([]);
});

test("work that started unwatched announces its first settled view", () => {
const a = createTrackerAnnouncer();
a.background(B);
Expand Down
56 changes: 56 additions & 0 deletions packages/ui-react/tests/tracker-runtime.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,4 +316,60 @@ describe.skipIf(!executablePath)("mounted trackers", () => {
}
}, 90_000);
}

test("a failed read after cold recovery does not reannounce an old completion", async () => {
const context = await browser!.newContext(runs[4]!.options);
await context.route("**/*", route => new URL(route.request().url()).origin === origin ? route.continue() : route.abort());
const page = await context.newPage();
const prompt = "Read the voyage after the storm";
try {
await page.goto(origin);
await until(page, "f?.connected()");
const composer = page.locator("textarea.bk-composer");
await composer.fill(prompt);
await composer.locator("..").locator('[aria-label="Send"]').waitFor();
await composer.press("Enter");
await until(page, "f.activeSessionId() !== null && f.lastTurnId() !== null");
const sessionId = (await fixture(page, f => f.activeSessionId()))!;
await page.getByRole("button", { name: "New conversation", exact: true }).click();
await until(page, "f.views().length === 1");
await release(prompt);
await until(page, "f.views()[0]?.state === 'done' && f.views()[0]?.endedAt !== null");

await page.reload();
await until(page, "f?.connected()");
await until(page, "f.views()[0]?.state === 'done' && f.views()[0]?.endedAt !== null");
expect(await fixture(page, f => f.announced()), "cold recovery is a baseline").toBe("");

// Files covers Chat at this width while the Sessions pane stays usable.
// The answer cannot be seen while two later reads fail and recover.
await fixture(page, f => f.setFilePanel(true));
let available = false, refused = 0;
await page.route(`${origin}/api/sessions/${sessionId}/recovery`, route => {
if (available) return route.continue();
refused++;
return route.fulfill({ status: 503, contentType: "application/json", body: JSON.stringify({ error: "Recovery read unavailable" }) });
});
await fixture(page, f => f.resume(f.views()[0]!.sessionId));
await until(page, "f.views()[0]?.state === 'cant_check' && f.views()[0]?.settled === true");
expect(refused, "the later read actually failed").toBeGreaterThan(0);
expect(await fixture(page, f => f.views()[0]!.cleared), "covered Chat cannot clear its tracker").toBe(false);
expect(await fixture(page, f => f.announced())).toBe("");

available = true;
await page.getByRole("button", { name: "New conversation", exact: true }).click();
await until(page, "f.activeSessionId() === null");
await fixture(page, f => f.setFilePanel(true));
await fixture(page, f => f.resume(f.views()[0]!.sessionId));
await until(page, "f.views()[0]?.state === 'done' && f.views()[0]?.endedAt !== null");
await page.getByText("Day 60: the wax held, and the crew rowed on.").waitFor({ state: "attached" });
await page.waitForTimeout(300);
expect(await fixture(page, f => f.announced()), "RECOVERY_DOES_NOT_REANNOUNCE_OLD_COMPLETION").toBe("");
expect(turnsStarted.filter(id => id === sessionId), "recovery starts no work").toHaveLength(1);
} finally {
await context.close();
gates.get(prompt)?.();
gates.delete(prompt);
}
}, 90_000);
});
Loading