Skip to content

fix(web): fold the timeline per user message so a steer splits its turn - #10

Merged
orbitingflea merged 1 commit into
mainfrom
fix/steer-fold-segments
Sep 2, 2026
Merged

orbitingflea merged 1 commit into
mainfrom
fix/steer-fold-segments

Conversation

@orbitingflea

Copy link
Copy Markdown
Owner

What changed

A steer is a message you send while the agent is still working on its reply. The timeline collapses the agent's tool calls and thinking behind a single "Worked for X" row called the fold.

Your messages cut the timeline into segments. A segment is everything between one of your messages and the next. The timeline now folds per segment instead of per turn. Each finished segment folds on its own and shows at most three things: its "Worked for X" row; a "Ran N subagents" row when the agent started helper agents in that segment; and, when an assistant message ends the segment, a separator line followed by that message. A steer therefore splits its turn. The work it interrupted folds above the steer, and the work it caused folds below.

In practice:

  • The fold above a steer collapses as soon as the steer lands, while the turn is still running, because new work can only land in the last segment.
  • An assistant message that is the last entry before a steer stays visible, with its timestamp and copy button, because it closes its segment. Before, it was hidden inside the turn's fold.
  • A segment whose last entry is a tool call shows no separator and no reply.
  • The separator line used to sit under the fold row. It now sits above the reply, so it also sits below the "Ran N subagents" row.
  • A turn can now have several folds, so the timeline identifies a fold row by the first entry that row hides rather than by the turn id. Expanding one fold of a turn expands all of them, because the timeline tracks expansion per turn.
  • A segment's duration runs from the message that opened it to the end of its last entry. The turn's own start and stop times count only for the segment that ends the turn, so when you stop a turn that produced nothing after the steer, its "You stopped after X" row still lands in the right place.
  • The timeline still batches "Ran N subagents" into one row per turn, placed where the first spawn landed, so that row falls in whichever segment covers that point.

The change is in the web timeline logic that both Claude Code and Codex threads go through. Mobile keeps its own fold logic and is unchanged.

Folding by your messages assumes the timeline is in transcript order, the order in which the agent read and produced its entries. #8 made that true for assistant messages. A tool row still carries the time its tool finished, so a command that was still running when the steer arrived sorts below the steer and lands in the following segment.

Supersedes #9, which split the turn's fold at the steer instead of folding by segment.

Why

Before, a steered turn had one fold. Its "Worked for X" row sat above the steer while the final reply sat below, and expanding the fold spilled work both above and below the steer. Folding by segment keeps each fold directly above the work it covers, and the rule is the same for every provider.

Screenshots

The before column is main at commit 56e7c4c; the after column is main plus this branch. Both run in Docker from a production build, driven by the same script. The script's first message asks the agent to run a 5 s command and then a 30 s command. While the 30 s command is still running, the script sends a second message: "run one more 25 s command, then reply pong".

Before (main) After (this PR)
Claude Sonnet 5, collapsed A, one fold "Worked for 1m 8s" with the separator under it, B, pong A, "Worked for 8.6s", B, "Worked for 50s", separator, pong
Claude Sonnet 5, expanded A, one fold spanning both commands, B, pong A, first fold open (first command), B, second fold open (both later commands), separator, pong
Codex gpt-5.6-luna, collapsed A, one fold "Worked for 1m 12s" with the separator under it, B, pong A, "Worked for 12s", B, "Worked for 56s", separator, pong
Codex gpt-5.6-luna, expanded A, one fold spanning both commands, B, pong A, first fold open (first command), B, second fold open (both later commands), separator, pong

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes (not applicable)

Written by Claude Fable 5.1 running in Claude Code, driven from T3 Code.

A turn steered mid-way had one fold: its "Worked for" row sat above the
steer while the work it covered continued below. The timeline is now in
transcript order, so user messages partition it into segments and each
settled segment folds on its own: the work a steer interrupted folds
above it, the work it caused folds below. A segment shows its fold, its
direct-spawn row, a separator and the assistant message that closes it.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Copilot AI lite review requested due to automatic review settings September 2, 2026 14:59
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-02T15:08:32.856344Z ef9cf55 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:L labels Sep 2, 2026
durationStart: string;
showAssistantMeta: boolean;
/** Draws the separator of the fold this message closes. */
showsTurnFoldSeparator: boolean;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

消息行新增一个布尔值:这条消息是不是某个折叠段的收尾回复。为 true 时在它上方画分隔线。分隔线从折叠行的下边框搬到了收尾消息的上边框,这样“Ran N subagents”行可以夹在折叠行和分隔线之间。

/** The segment's direct-spawn CTA, carrying every direct spawn the fold absorbed. */
spawnRow: { entryId: string; entry: WorkLogEntry } | null;
/** The assistant message that closes the segment, when one does. */
terminalEntryId: string | null;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

每个折叠记住自己的收尾助手消息 id(没有则为 null),供上面那个布尔值使用。

* Settled turns keep only their terminal assistant message visible.
* Everything before it folds behind a "Worked for ..." row anchored at the
* first hidden entry, so the duration leads directly into the final response.
* User messages cut the timeline into segments, and every settled segment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

核心模型变化:以前按 turn id 分组折叠,现在按用户消息把时间线切成“段”,每个已结束的段各折各的。因为时间线已经是 transcript 顺序(#8),steer 就只是开了一个新段,不需要任何特殊处理。

/** The turn id that opened the group; keeps the fold's identity stable. */
turnId: TurnId;
interface Segment {
/** Last turn id in the segment; folds expand per turn id. */

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

段本身不属于某个 turn,只记下段内最后一个带 turn id 的条目的 turn id,用作展开键。取最后一个而不是第一个,是因为上一轮的残留行(比如被打断后迟到的工具行)可能落在新用户消息之后、新一轮首行之前;取最后一个能保证这一段挂在新一轮上,停止时的自动展开(按 latestTurn.turnId)也就能命中。展开状态仍按 turn 记录,所以被 steer 切开的同一 turn 的两个折叠会一起展开,这是有意接受的取舍。


let pendingUserBoundary: string | null = null;
let lastGroup: TurnGroup | null = null;
const segments: Array<Segment> = [{ turnId: null, entries: [], startBoundary: null }];

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

切段循环:遇到用户消息就开新段(记下它的时间作为段的起点),其他条目一律追加到当前段,并用它的 turn id(若有)刷新段的 turn id。原来的 groupsByTurnId、pendingUserBoundary、lastGroup 三个状态,以及“无 turn id 的行挂到上一组”“新 turn id 但没有新用户消息则并入上一组”两个特殊分支都不再需要:无 turn id 的行自然落在它所在的段,续接 turn 也自然留在同一段。

const onToggleTurnFold = useCallback(
(turnId: TurnId) => {
suspendEndScrollMaintenanceForDisclosure(`turn-fold:${turnId}`);
(turnId: TurnId, anchorKey: string) => {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,直接用传进来的行 id。

row.kind === "message" && row.message.role === "assistant" ? "group/assistant" : null,
// The separator belongs to the fold above, below any spawn row it kept.
row.kind === "message" && row.showsTurnFoldSeparator
? "border-t border-border/60 pt-2"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

分隔线画在收尾消息的上方(原来是折叠行的下方)。样式值和原来一致,只是换了位置。


return (
<div className="border-b border-border/60 pb-2 pt-1">
<div className="pt-1">

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

折叠行不再自己画下边框。

aria-expanded={row.expanded}
data-scroll-anchor-ignore
onClick={() => ctx.onToggleTurnFold(row.turnId)}
onClick={() => ctx.onToggleTurnFold(row.turnId, row.id)}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

点击时把行 id 一起传出去。

});

it("keeps one fold across a same-turn steer and keeps both user messages visible", () => {
it("folds a same-turn steer as one segment per side of the steer", () => {

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试改动:折叠行 id 全部改成锚点形式;这条和下一条是 steer 场景的新预期(steer 两侧各一个折叠,turn 进行中时前一段已折叠,分隔线只在收尾回复上);“无 turn id 的行”测试改为落在所在段;被打断的测试改为用 completedAt 算时长。

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ef9cf558e8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines 423 to 426
for (const entry of input.timelineEntries) {
if (entry.kind === "message" && entry.message.role === "user") {
pendingUserBoundary = entry.message.createdAt;
segments.push({ turnId: null, entries: [], startBoundary: entry.message.createdAt });
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Split steered turns on mobile too

When a user steers a running turn from the mobile client, this new segmentation is never applied: the changed implementation is web-only, while apps/mobile/src/lib/threadActivity.ts:1260-1290 still groups entries solely by turn ID and lines 1292-1297 skip the entire unsettled turn. Consequently, mobile continues to combine pre- and post-steer work into one fold and cannot collapse the completed pre-steer segment while the agent continues, unlike web and desktop. Implement the equivalent segmentation in the mobile path or move it into shared client logic.

AGENTS.md reference: AGENTS.md:L67-L70

Useful? React with 👍 / 👎.

Comment on lines 398 to +404
/**
* Settled turns keep only their terminal assistant message visible.
* Everything before it folds behind a "Worked for ..." row anchored at the
* first hidden entry, so the duration leads directly into the final response.
* User messages cut the timeline into segments, and every settled segment
* folds behind one "Worked for ..." row anchored at its first hidden entry.
* A segment keeps only its direct-spawn CTA row and, when an assistant
* message closes it, that message. Because the timeline is in transcript
* order, a steer (a user message sent mid-turn) simply starts a new segment:
* the work it interrupted folds above it and the work it caused folds below.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Document the new timeline-fold semantics

This changes user-visible behavior—steers now create separate folds, durations and separators move, and intermediate assistant messages can remain visible—but the commit adds no corresponding docs/user/ update. Users and support documentation therefore retain no durable explanation of the new behavior after the PR description is gone; add the shipped-product documentation required for noticeable behavior changes.

AGENTS.md reference: AGENTS.md:L73-L75

Useful? React with 👍 / 👎.

Comment on lines +428 to +430
const segment = segments.at(-1)!;
segment.turnId = timelineEntryTurnId(entry) ?? segment.turnId;
segment.entries.push(entry);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Keep proposed-plan cards outside collapsed work

When a settled segment contains a proposed-plan entry, assigning every non-user entry to the segment here causes the plan to be added to hiddenEntryIds, because only a final assistant message and spawn rows are exempted below. This regresses the prior behavior where a plan arriving before the first assistant/work entry was not part of a fold: the first-class ProposedPlanCard, including its copy, download, and save actions, is now hidden by default behind “Worked,” whether the plan is followed by an assistant response or is the segment's last entry. Preserve proposed-plan entries as visible rows, similarly to the spawn-row exemption.

Useful? React with 👍 / 👎.

Comment on lines +442 to 445
for (const segment of segments) {
const { turnId } = segment;
if (turnId === null || segment === liveSegment) {
continue;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Fold segments containing only turnless activity

If a steer is followed only by turnless background/subagent activity and the turn then settles without another assistant or turn-owned work entry, the new post-steer segment retains a null turnId and is skipped here. Its activity therefore remains as ordinary visible work rather than receiving the segment fold, even though the same code intentionally assigns turnless rows to a segment when a later keyed entry happens to arrive. Associate such a settled tail segment with the latest turn so this case also folds per user message.

Useful? React with 👍 / 👎.

@orbitingflea
orbitingflea merged commit 292931c into main Sep 2, 2026
6 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:L vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants