Skip to content

Commit 3554549

Browse files
committed
fix(ui): hold running-row subtitles across run rotation with a display floor
Live A/B on a dev gateway showed two residual subtitle defects: the hold was keyed to the exact active-run-id set, so the queued->running rotation still blanked the row, and racing ambient sources (observer digest, narration, work path) swapped the line A->B->A within a second. The hold now lives for the session's running lifetime and ambient replacements respect a 2s minimum display floor (matching the narration throttle); attention, agent status, and the queued explanation bypass the floor because the operator must act on them.
1 parent 8913cca commit 3554549

2 files changed

Lines changed: 113 additions & 27 deletions

File tree

‎ui/src/components/app-sidebar-session-projection.test.ts‎

Lines changed: 68 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ describe("SidebarSessionProjection running subtitle hold", () => {
318318
});
319319
});
320320

321-
it.each(["ended", "replaced", "preview-hidden"] as const)(
321+
it.each(["ended", "preview-hidden"] as const)(
322322
"clears held running activity when its run is %s",
323323
(change) => {
324324
const projection = new SidebarSessionProjection();
@@ -333,12 +333,7 @@ describe("SidebarSessionProjection running subtitle hold", () => {
333333
},
334334
}),
335335
);
336-
const changed =
337-
change === "ended"
338-
? sessionRow(running.key)
339-
: change === "replaced"
340-
? sessionRow(running.key, { hasActiveRun: true, activeRunIds: ["run-two"] })
341-
: running;
336+
const changed = change === "ended" ? sessionRow(running.key) : running;
342337
const showPreview = change !== "preview-hidden";
343338

344339
projection.project(
@@ -359,6 +354,72 @@ describe("SidebarSessionProjection running subtitle hold", () => {
359354
},
360355
);
361356

357+
it("holds the subtitle across a run-id rotation while the session stays running", () => {
358+
// Live repro: queued->running rotates activeRunIds; the row must not blank.
359+
const projection = new SidebarSessionProjection();
360+
const queued = sessionRow("running", {
361+
hasActiveRun: true,
362+
activeRunIds: ["run-one"],
363+
status: "queued",
364+
});
365+
projection.project(projectionInput([queued]));
366+
const rotated = sessionRow(queued.key, { hasActiveRun: true, activeRunIds: ["run-two"] });
367+
projection.project(projectionInput([rotated]));
368+
369+
expect(projection.resolveSubtitle(subtitleParams(rotated)).subtitle).toBe(
370+
"Waiting for a concurrency slot",
371+
);
372+
});
373+
374+
it("floors ambient subtitle replacement at the minimum display time", () => {
375+
let clock = 0;
376+
const projection = new SidebarSessionProjection(() => clock);
377+
const running = sessionRow("running", { hasActiveRun: true, activeRunIds: ["run-one"] });
378+
const withNarration = (line: string) => ({
379+
sidebarLiveActivity: true,
380+
showPreview: true,
381+
narrationLines: new Map([[running.key, line]]),
382+
observerDigests: new Map(),
383+
});
384+
projection.project(projectionInput([running], { subtitle: withNarration("First activity") }));
385+
386+
clock = 500;
387+
projection.project(projectionInput([running], { subtitle: withNarration("Second activity") }));
388+
expect(projection.resolveSubtitle(subtitleParams(running)).subtitle).toBe("First activity");
389+
390+
clock = 2_500;
391+
projection.project(projectionInput([running], { subtitle: withNarration("Second activity") }));
392+
expect(projection.resolveSubtitle(subtitleParams(running)).subtitle).toBe("Second activity");
393+
});
394+
395+
it("lets operator-critical text replace a held subtitle immediately", () => {
396+
let clock = 0;
397+
const projection = new SidebarSessionProjection(() => clock);
398+
const running = sessionRow("running", { hasActiveRun: true, activeRunIds: ["run-one"] });
399+
projection.project(
400+
projectionInput([running], {
401+
subtitle: {
402+
sidebarLiveActivity: true,
403+
showPreview: true,
404+
narrationLines: new Map([[running.key, "Ambient activity"]]),
405+
observerDigests: new Map(),
406+
},
407+
}),
408+
);
409+
410+
clock = 200;
411+
const queued = sessionRow(running.key, {
412+
hasActiveRun: true,
413+
activeRunIds: ["run-one"],
414+
status: "queued",
415+
});
416+
projection.project(projectionInput([queued]));
417+
418+
expect(projection.resolveSubtitle(subtitleParams(queued)).subtitle).toBe(
419+
"Waiting for a concurrency slot",
420+
);
421+
});
422+
362423
it("clears held narration when the user disables live activity", () => {
363424
const projection = new SidebarSessionProjection();
364425
const running = sessionRow("running", { hasActiveRun: true, activeRunIds: ["run-one"] });

‎ui/src/components/app-sidebar-session-projection.ts‎

Lines changed: 45 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ import {
1010
type SidebarSessionSortMode,
1111
type SidebarSessionStatusFilter,
1212
} from "./app-sidebar-session-types.ts";
13+
import { sessionAttentionSubtitle } from "./session-attention-presentation.ts";
1314
import { resolveSidebarSessionSubtitle } from "./session-row-subtitle.ts";
1415

1516
const SIDEBAR_CREATED_ORDER_CAP = 1_000;
17+
// Ambient subtitle sources (observer digest, narration, work path) race at
18+
// event rate; without a floor the line swaps A->B->A within a second. Matches
19+
// the narration throttle so replacement cadence stays consistent.
20+
const SIDEBAR_SUBTITLE_MIN_DISPLAY_MS = 2_000;
1621

1722
type SidebarExpansionMode = "collapsed-by-user" | "expanded" | "expanded-fully";
1823
type SidebarSubtitleParams = Parameters<typeof resolveSidebarSessionSubtitle>[0];
@@ -68,18 +73,26 @@ function baselineSessionRows(rows: readonly SidebarRecentSession[], limit: numbe
6873
});
6974
}
7075

71-
function sidebarRunIdentity(session: SidebarRecentSession): string {
72-
return `${session.sessionId ?? ""}\u0000${session.activeRunIds?.join("\u0000") ?? ""}`;
76+
/** Attention, agent-declared status, and the queued explanation are messages
77+
* the operator must act on; they replace a held subtitle immediately. */
78+
function isOperatorCriticalSubtitle(session: SidebarRecentSession): boolean {
79+
return Boolean(
80+
sessionAttentionSubtitle(session.attention) ||
81+
session.agentStatusNote ||
82+
(session.hasActiveRun && session.status === "queued"),
83+
);
7384
}
7485

7586
export class SidebarSessionProjection {
87+
constructor(private readonly now: () => number = () => Date.now()) {}
88+
7689
private readonly observedOrder = new Map<string, number>();
7790
private nextCreatedOrder = 0;
7891
private readonly stickySections = new Map<string, Set<string>>();
7992
private readonly childModes = new Map<string, SidebarExpansionMode>();
8093
private readonly heldSubtitles = new Map<
8194
string,
82-
{ identity: string; value: SidebarSubtitleValue; catalogValue?: SidebarSubtitleValue }
95+
{ value: SidebarSubtitleValue; catalogValue?: SidebarSubtitleValue; shownAt: number }
8396
>();
8497
private previousInput: Pick<
8598
SidebarProjectionInput,
@@ -307,15 +320,18 @@ export class SidebarSessionProjection {
307320
}
308321

309322
resolveSubtitle(params: SidebarSubtitleParams): SidebarSubtitleValue {
310-
const fresh = resolveSidebarSessionSubtitle(params);
311-
if (fresh.subtitle || !params.session.hasActiveRun || !params.showPreview) {
312-
return fresh;
323+
if (!params.session.hasActiveRun || !params.showPreview) {
324+
return resolveSidebarSessionSubtitle(params);
313325
}
326+
// While a run is live the held value is the display: observeSubtitle
327+
// refreshed it this update pass, applying the minimum-display floor.
314328
const held = this.heldSubtitles.get(params.session.key);
315-
if (held?.identity !== sidebarRunIdentity(params.session)) {
316-
return fresh;
329+
if (!held) {
330+
return resolveSidebarSessionSubtitle(params);
317331
}
318-
return params.hasDisplay ? (held.catalogValue ?? fresh) : held.value;
332+
return params.hasDisplay
333+
? (held.catalogValue ?? resolveSidebarSessionSubtitle(params))
334+
: held.value;
319335
}
320336

321337
private observeSubtitle(
@@ -326,10 +342,6 @@ export class SidebarSessionProjection {
326342
this.heldSubtitles.delete(session.key);
327343
return;
328344
}
329-
const identity = sidebarRunIdentity(session);
330-
if (this.heldSubtitles.get(session.key)?.identity !== identity) {
331-
this.heldSubtitles.delete(session.key);
332-
}
333345
if (!environment.sidebarLiveActivity && this.heldSubtitles.get(session.key)?.value.narration) {
334346
this.heldSubtitles.delete(session.key);
335347
}
@@ -343,13 +355,26 @@ export class SidebarSessionProjection {
343355
observerDigest: environment.observerDigests.get(session.key) ?? null,
344356
} satisfies SidebarSubtitleParams;
345357
const value = resolveSidebarSessionSubtitle(params);
346-
if (value.subtitle) {
347-
const catalogValue = resolveSidebarSessionSubtitle({ ...params, hasDisplay: true });
348-
this.heldSubtitles.set(session.key, {
349-
identity,
350-
value,
351-
...(catalogValue.subtitle ? { catalogValue } : {}),
352-
});
358+
if (!value.subtitle) {
359+
// Transient gaps between event updates keep the last shown line; the
360+
// hold dies with the run (the hasActiveRun branch above).
361+
return;
362+
}
363+
const held = this.heldSubtitles.get(session.key);
364+
const now = this.now();
365+
const replacing = held !== undefined && held.value.subtitle !== value.subtitle;
366+
if (
367+
replacing &&
368+
now - held.shownAt < SIDEBAR_SUBTITLE_MIN_DISPLAY_MS &&
369+
!isOperatorCriticalSubtitle(session)
370+
) {
371+
return;
353372
}
373+
const catalogValue = resolveSidebarSessionSubtitle({ ...params, hasDisplay: true });
374+
this.heldSubtitles.set(session.key, {
375+
value,
376+
...(catalogValue.subtitle ? { catalogValue } : {}),
377+
shownAt: held !== undefined && !replacing ? held.shownAt : now,
378+
});
354379
}
355380
}

0 commit comments

Comments
 (0)