Skip to content

Commit f7cf1f3

Browse files
committed
fix(web): opened spawn rows keep their fold membership
Pinning an open row no longer recomposes the fold it sits in: the row stays a fold member and is simply not collapsed, so the fold row keeps its place and never disappears. Fold liveness also honors the workflow id, member rows get an accessible name, and zero or negative member metrics are not shown.
1 parent c079848 commit f7cf1f3

4 files changed

Lines changed: 41 additions & 23 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.logic.test.ts‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ describe("deriveMessagesTimelineRows", () => {
11711171
timelineEntries: typeof direct,
11721172
liveAgentTaskIds: ReadonlySet<string> | undefined,
11731173
expandedSpawnEntryIds?: ReadonlySet<string>,
1174+
expandedTurnIds?: ReadonlySet<TurnId>,
11741175
) =>
11751176
deriveMessagesTimelineRows({
11761177
timelineEntries,
@@ -1180,6 +1181,7 @@ describe("deriveMessagesTimelineRows", () => {
11801181
supportsConversationRollback: false,
11811182
liveAgentTaskIds,
11821183
expandedSpawnEntryIds,
1184+
...(expandedTurnIds ? { expandedTurnIds } : {}),
11831185
}).map((row) => row.id);
11841186
const folded = ["turn-fold:turn-1", "assistant-final-entry"];
11851187
const unfolded = ["turn-fold:turn-1", "spawn-entry", "assistant-final-entry"];
@@ -1189,9 +1191,19 @@ describe("deriveMessagesTimelineRows", () => {
11891191
// A workflow coordinator between phases keeps its batch out of the fold.
11901192
expect(derive(workflow, new Set(["wf-1"]))).toEqual(unfolded);
11911193
expect(derive(workflow, new Set())).toEqual(folded);
1192-
// The user has it open, or no live set is known.
1193-
expect(derive(direct, new Set(), new Set(["spawn-entry"]))).toEqual(unfolded);
1194+
// No live set is known.
11941195
expect(derive(direct, undefined)).toEqual(unfolded);
1196+
// The user has it open: it stays visible under the collapsed fold and
1197+
// keeps its place when the fold is expanded.
1198+
expect(derive(direct, new Set(), new Set(["spawn-entry"]))).toEqual(unfolded);
1199+
expect(
1200+
derive(direct, new Set(), new Set(["spawn-entry"]), new Set(["turn-1" as TurnId])),
1201+
).toEqual([
1202+
"turn-fold:turn-1",
1203+
"assistant-first-entry",
1204+
"spawn-entry",
1205+
"assistant-final-entry",
1206+
]);
11951207
});
11961208

11971209
it("only enables assistant copy for the terminal assistant message in a turn", () => {

‎apps/web/src/components/chat/MessagesTimeline.logic.ts‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,6 @@ function deriveTurnFolds(input: {
578578
latestTurn: TimelineLatestTurn | null;
579579
unfoldedTurnIds: ReadonlySet<TurnId>;
580580
liveAgentTaskIds: ReadonlySet<string> | undefined;
581-
expandedSpawnEntryIds: ReadonlySet<string> | undefined;
582581
}): ReadonlyMap<string, TurnFold> {
583582
interface TurnGroup {
584583
entries: Array<TimelineEntry>;
@@ -660,16 +659,18 @@ function deriveTurnFolds(input: {
660659
continue;
661660
}
662661
// Workflows outlive their launching turn (dynamic spawns, background
663-
// execution), so a spawn row with a live member stays outside the fold
664-
// instead of hiding a still-running fleet, as does one the user has
665-
// open. Settled spawns fold with the rest of the turn. Without a live
666-
// set (no agent panel model) every spawn row stays out.
662+
// execution), so a spawn row with a live member or coordinator stays
663+
// outside the fold instead of hiding a still-running fleet. Settled
664+
// spawns fold with the rest of the turn. Without a live set (no agent
665+
// panel model, as in the held paint during a thread switch) every
666+
// spawn row stays out.
667667
if (entry.kind === "work" && entry.entry.agentSpawn !== undefined) {
668668
const live = input.liveAgentTaskIds;
669+
const { workflowId, agentTaskIds } = entry.entry.agentSpawn;
669670
if (
670671
live === undefined ||
671-
entry.entry.agentSpawn.agentTaskIds.some((taskId) => live.has(taskId)) ||
672-
input.expandedSpawnEntryIds?.has(entry.id)
672+
(workflowId !== null && live.has(workflowId)) ||
673+
agentTaskIds.some((taskId) => live.has(taskId))
673674
) {
674675
continue;
675676
}
@@ -870,7 +871,7 @@ export function deriveMessagesTimelineRows(input: {
870871
* folds. Undefined means unknown, which keeps every spawn row out.
871872
*/
872873
liveAgentTaskIds?: ReadonlySet<string> | undefined;
873-
/** Spawn rows the user expanded; they stay outside turn folds too. */
874+
/** Spawn rows the user opened stay visible while their turn fold is collapsed. */
874875
expandedSpawnEntryIds?: ReadonlySet<string> | undefined;
875876
}): MessagesTimelineRow[] {
876877
const turnDiffSummaryByAssistantMessageId = new Map<MessageId, TurnDiffSummary>();
@@ -907,12 +908,14 @@ export function deriveMessagesTimelineRows(input: {
907908
latestTurn: input.latestTurn ?? null,
908909
unfoldedTurnIds: activeVisualResponseTurnIds,
909910
liveAgentTaskIds: input.liveAgentTaskIds,
910-
expandedSpawnEntryIds: input.expandedSpawnEntryIds,
911911
});
912912
const collapsedEntryIds = new Set<string>();
913913
for (const fold of foldsByAnchorEntryId.values()) {
914914
if (!input.expandedTurnIds?.has(fold.turnId)) {
915915
for (const entryId of fold.hiddenEntryIds) {
916+
// An opened spawn row keeps its fold membership but is not pulled
917+
// away mid-read when its last member settles.
918+
if (input.expandedSpawnEntryIds?.has(entryId)) continue;
916919
collapsedEntryIds.add(entryId);
917920
}
918921
}

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -465,8 +465,8 @@ export const MessagesTimeline = memo(function MessagesTimeline({
465465
}: MessagesTimelineProps) {
466466
const [expandedTurnIds, setExpandedTurnIds] = useState<ReadonlySet<TurnId>>(new Set());
467467
const [expandedWorkGroupIds, setExpandedWorkGroupIds] = useState<ReadonlySet<string>>(new Set());
468-
// Expanded spawn rows outlive virtualization and stay outside turn folds
469-
// until the user collapses them, so a settling fleet is not pulled away mid-read.
468+
// Expanded spawn rows outlive virtualization and stay visible while their
469+
// turn fold is collapsed, so a settling fleet is not pulled away mid-read.
470470
const [expandedSpawnEntryIds, setExpandedSpawnEntryIds] = useState<ReadonlySet<string>>(
471471
new Set(),
472472
);
@@ -3881,11 +3881,16 @@ function AgentSpawnMemberRow({
38813881
? Date.parse(agent.completedAt) - Date.parse(agent.startedAt)
38823882
: null;
38833883
const meta = [
3884-
durationMs !== null && Number.isFinite(durationMs) ? formatDuration(durationMs) : null,
3885-
agent.usage ? `${formatSubagentTokenCount(agent.usage.totalTokens)} tok` : null,
3884+
durationMs !== null && durationMs >= 0 ? formatDuration(durationMs) : null,
3885+
agent.usage && agent.usage.totalTokens > 0
3886+
? `${formatSubagentTokenCount(agent.usage.totalTokens)} tok`
3887+
: null,
38863888
]
38873889
.filter(Boolean)
38883890
.join(" · ");
3891+
const statusLabel = activeStatus
3892+
? AGENT_MEMBER_STATUS_LABEL[agent.status]
3893+
: meta || AGENT_MEMBER_STATUS_LABEL[agent.status];
38893894
const role =
38903895
agent.role && agent.role.trim().toLowerCase() !== agent.title.trim().toLowerCase()
38913896
? agent.role
@@ -3904,6 +3909,7 @@ function AgentSpawnMemberRow({
39043909
<div
39053910
role={canExpand ? "button" : undefined}
39063911
tabIndex={canExpand ? 0 : undefined}
3912+
aria-label={canExpand ? `${agent.title}, ${statusLabel}` : undefined}
39073913
aria-expanded={canExpand ? open : undefined}
39083914
onClick={canExpand ? toggleOpen : undefined}
39093915
onKeyDown={
@@ -3946,9 +3952,7 @@ function AgentSpawnMemberRow({
39463952
) : null}
39473953
</p>
39483954
<span className="shrink-0 font-mono text-[.7rem] tabular-nums text-muted-foreground">
3949-
{activeStatus
3950-
? AGENT_MEMBER_STATUS_LABEL[agent.status]
3951-
: meta || AGENT_MEMBER_STATUS_LABEL[agent.status]}
3955+
{statusLabel}
39523956
</span>
39533957
</div>
39543958
{!open && firstLine ? (

‎apps/web/src/session-logic.ts‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@ export interface WorkLogEntry {
8383
/** Agent role (subagent_type) for labeled timeline rows. */
8484
agentRole?: string;
8585
/**
86-
* Present on agent-spawn CTA rows: one per workflow run or per-turn batch
87-
* of direct spawns. The row renders as a call-to-action ("Kicked off N
88-
* subagents") whose live status is derived from the agent panel model at
89-
* render time; clicking opens the Agents panel.
86+
* Present on agent-spawn rows: one per workflow run or per-turn batch of
87+
* direct spawns. The row ("Kicked off N subagents") derives its live
88+
* status and member list from the agent panel model at render time.
9089
*/
9190
agentSpawn?: {
9291
/** Workflow coordinator taskId, or null for a direct-spawn batch. */
@@ -642,7 +641,7 @@ function toDerivedWorkLogEntry(activity: OrchestrationThreadActivity): DerivedWo
642641
/**
643642
* Spawn-group key for a subagent lifecycle row. Workflow members and their
644643
* coordinator share the coordinator's group; direct spawns batch per turn.
645-
* One CTA row per group (A1 design): "Kicked off N subagents".
644+
* One row per group: "Kicked off N subagents".
646645
*/
647646
function agentSpawnGroupKey(entry: DerivedWorkLogEntry): string {
648647
const taskId = entry.taskId ?? "";

0 commit comments

Comments
 (0)