Skip to content

fix(web): fold work before and after a mid-turn user message separately - #9

Closed
orbitingflea wants to merge 1 commit into
mainfrom
fix/steer-fold-split
Closed

orbitingflea wants to merge 1 commit into
mainfrom
fix/steer-fold-split

Conversation

@orbitingflea

Copy link
Copy Markdown
Owner

What Changed

A finished turn that read a user message mid-way (a steer) now folds in two parts. Work before the steer folds into its own "Worked for …" row that shows nothing else. Work after the steer folds into a second row with its own duration, followed by "Ran N subagents" when there were spawns, a separator line, and the final response. The separator line now belongs to the final response instead of the fold row, so it sits below the spawn row as well. Expanding a later fold restores scroll position like the first one; expansion stays per turn, so both parts open together.

Known limit: a tool row is stamped when the tool completes, so a command that was still running when the steer arrived sorts below the steer and lands in the second fold. Everything that finished before the steer folds above it.

Why

Before, a steered turn had one fold whose "Worked for 8m 29s" row sat above the steer while the response it summarised sat below it, and expanding it spilled work both above and below the steer. Splitting at the steer keeps each fold directly above the work it covers, for Claude Code and Codex alike, since it lives in the shared timeline logic.

UI Changes

Docker, same prompts on both builds: A runs a 5 s command then a 30 s command; B ("run one more 25 s command, then reply pong") is sent while the 30 s command runs.

Before After
Claude Sonnet 5, expanded: one fold spans both sides of B Claude Sonnet 5, expanded: A, Worked for 9.2s, B, Worked for 50s, separator, pong
Codex gpt-5.6-luna: one fold Codex: two folds

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.

Copilot AI lite review requested due to automatic review settings September 2, 2026 12:50

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.

@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-02T13:00:35.839087Z 5fcf77b 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.

@github-actions github-actions Bot added vouch:trusted Author is trusted by repo permissions or the VOUCHED list. size:M labels Sep 2, 2026

@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: 5fcf77b0b5

ℹ️ 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 +560 to +562
(closesLatestTurn && group.segmentIndex === 0 ? input.latestTurn?.startedAt : null) ??
group.startBoundary ??
firstEntry.createdAt,

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 Start the first steered segment at the turn start

When a prompt waits in the queue before its turn starts and is subsequently steered, the first segment fails closesLatestTurn because a later segment is now current, so this expression falls back to the original user-message timestamp. The resulting “Worked for …” label includes the entire queue delay—potentially minutes—even though the new unsteered path explicitly excludes it. Use latestTurn.startedAt for segment zero of the matching turn even when a later segment closes that turn.

Useful? React with 👍 / 👎.

Comment on lines +455 to +456
if (group && turnId && pendingUserBoundary !== null && group.terminalEntry === null) {
group = null;

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 Don't treat interrupted-turn residue as a steer

When the preceding turn was interrupted before emitting any assistant message, a late completion row from that old turn can arrive after the next user message but before the new turn's first row. Because the old group has no terminalEntry, this condition opens a new segment under the old turn and consumes pendingUserBoundary; the actual new turn is then mistaken for a synthetic continuation and its fold is keyed to the old turn, causing unrelated folds to expand together. A late row from an already-ended turn needs to preserve the pending boundary even when that turn produced no assistant message.

Useful? React with 👍 / 👎.

Comment on lines +467 to +471
const segmentIndex = segmentCountByTurnId.get(turnId) ?? 0;
segmentCountByTurnId.set(turnId, segmentIndex + 1);
group = {
turnId,
segmentIndex,

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 Preserve the response identity when splitting a continuation

When a synthetic continuation turn has already been mapped into an existing response and the user then steers while that continuation is active, splitting clears the existing group but creates the replacement with the continuation's alias turnId and a fresh segment index. The pre-steer fold is consequently keyed to the original turn while the post-steer fold is keyed to the continuation, so expanding either fold no longer expands both parts of the same response. Carry the original group's canonical turn ID and next segment index through this split.

Useful? React with 👍 / 👎.

A steered turn used to fold into a single "Worked for" row whose contents
sat partly above and partly below the steer. The timeline now closes the
segment a steer interrupts and opens a new one below it, so each fold
covers only the work under it, and the fold's separator moved onto the
final response so it lands below the "Ran N subagents" row.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>

@orbitingflea orbitingflea left a comment

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.

精简版:非测试改动从 78 行降到 60 行(逻辑 46+/14−,渲染 9+/5−),去掉了段号计数和 id 三元表达式。每处改动的说明见行内评论。Codex 机器人三条意见:前两条已修,第三条不修,原因写在拆分那一行的评论里。

durationStart: string;
showAssistantMeta: boolean;
/** Draws the fold's separator above this message when a fold leads into it. */
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.

【给审查者的说明】消息行多一个布尔字段:这条最终回复上面要不要画分隔线。原来分隔线画在折叠行底部,会落在"Ran N subagents"行的上面;你要求的顺序是 折叠行、subagents 行、分隔线、最终回复,所以分隔线要挪到最终回复的顶部。渲染层一次只看一行,不知道上面有没有折叠,必须由这里算好告诉它。

hiddenEntryIds: ReadonlySet<string>;
label: string;
/** The terminal assistant message this fold leads into, when it has one. */
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.

【说明】折叠记录里记下它通向哪条最终回复。上面那个布尔字段就是靠这个算出来的。没有最终回复的折叠(steer 之前的那一段)这里是 null,于是不画分隔线,符合"上方折叠只显示 Worked for X"。

Comment on lines +402 to +403
* A user message that lands mid-turn (a steer) splits the turn into segments
* that fold separately, so each fold stays above the work it covers.

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.

【说明】只是把函数说明补一句:一个回合里出现 steer 时,会按 steer 前后分成几段,各自折叠。

Comment on lines +414 to +415
/** Opened by a steer, so it cannot read the turn's own start time. */
steered: 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.

【说明】分组多一个布尔:这一段是不是由 steer 开出来的。它只在算时长时用:由 steer 开出来的段,起点是 steer 那条消息,不能再用回合本身的开始时间。

Comment on lines +427 to +428
// Every segment in timeline order, plus the one each turn id writes into now.
const groups: Array<TurnGroup> = [];

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 → 分组"的表,一个回合拆成两段之后,后一段会把前一段从表里顶掉,前一段就再也折叠不到了。这个列表保证每一段都会被折叠。表本身保留,用来找"这个回合当前正在写入哪一段"。

openingVideoAttachmentId: string | null;
onOpenTurnDiff: (turnId: TurnId, filePath?: string) => void;
onToggleTurnFold: (turnId: TurnId) => void;
onToggleTurnFold: (turnId: TurnId, anchorKey: string) => void;

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 不再能从回合 id 推出来,所以点击回调要把行 id 一起传过来,给滚动位置保持逻辑用。

Comment on lines +381 to +382
(turnId: TurnId, anchorKey: string) => {
suspendEndScrollMaintenanceForDisclosure(anchorKey);

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 作为滚动锚点。

Comment on lines +1001 to +1004
// 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"
: 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.

【说明】分隔线的实际画法:带标记的最终回复顶部画一条线。


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 传给回调。

@orbitingflea

Copy link
Copy Markdown
Owner Author

"Ran N subagents" should be folded also as two separate segments, one before the steer, and one after the steer, omitted when no subagents were spawned during that time period. Is this behavior of "separate folding in two segments" for agent spawning messages the current behavior? (This idea is the same as the message or tool information folding---segments separated by user messages).

In addition, now that we have a total order of events, does it make sense to simply define folding segments as the segments partitioned by the user messages, and only show (1) a [working for xx time] at the beginning of the segment, (2) a [ran xx agents] if there are any during the segment, and (3) the final assistant message if that's the last event in this segment, (4) some additional handling of the last segment that is currently running? How's the code and logic complexity of implementing something similar to this idea compared to what we are doing currently? (I think a behavioral distinction is that now the last assistant message before the steer message will be visible, but that's not a big deal. If the final event is a tool calling instead of an assistant message, that's invisible. Are there other behavioral differences between the two methods?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 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