Repository navigation
fix: previous chat answer stays hidden when a late exec completion arrives - #186323
Conversation
…rives A backdated exec completion sorted ahead of the answer it followed once an unmatched CLI import expanded history. Hiding that completion also left no turn boundary, so the earlier reply folded into the follow-up "Worked for" group. Local rows now stay in transcript order. A hidden exec completion starts the next assistant turn, and a visible user consumes that boundary without taking the flag. Fixes openclaw#186255
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. What this changesPreserves local transcript order during CLI imports and carries hidden exec-completion boundaries into chat history and SSE presentation. Example: An answer at timestamp 200 is followed in transcript order by an exec completion timestamped 100 and a follow-up answer timestamped 300.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it repairs a current history-display bug, addresses the prior review requests, and has no identified correctness or security findings. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway history combines canonical transcript rows with native CLI imports, projects visible messages and turn boundaries, and supplies pages and SSE updates to Control UI grouping. flowchart LR
A[Canonical transcript] --> C[Shared history ordering]
B[Native CLI imports] --> C
C --> D[Display projection]
D --> E[History pages]
D --> F[SSE updates]
E --> G[Control UI grouping]
F --> G
Technical reviewBest possible solution: Land the shared ordering and display-boundary repair once the existing exact-head checks pass. Do we have a high-confidence way to reproduce the issue? Current-main source establishes the backdated-ordering and lost-boundary path, and inspected contributor screenshots corroborate it through real Gateway history and browser rendering; this review ran no target code. Is this the best way to solve the issue? The repair addresses both causes in existing shared owners, preserves hidden-notice policy and ordinary commentary folding, and updates paging and SSE consumers together. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against e7f054619274. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +129, Tests 0. Total +129 across 13 files. Added test files: 0. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment HistoryReview history (3 earlier review cycles)
Reviewed October 27, 2026, 9:08 PM ET / October 28, 2026, 01:08 UTC (Revision 4). |
A pending heartbeat or exec boundary was dropped for every visible user row. Tool-result rows do not start a Control UI turn, so the following assistant stayed in the previous turn. Plain user text still consumes the boundary without a stamp. Fixes openclaw#186255
Sorting local rows by sequence and mixed rows by timestamp is not a valid order. A later local row with an earlier timestamp makes the comparator cycle, so unmatched imports can land out of timestamp order. Imports now splice in after the last local row at or before their timestamp, and local rows stay in transcript order. Fixes openclaw#186255
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
Dated imports and timestamp-sorted locals advance together. The anchor is still the latest local at or before the import timestamp, so a backdated exec completion stays after the answer it followed. The tool-shaped user check now lives with the other projection helpers, which keeps history projection inside the file line limit.
|
Thanks @DonnieFi, this covers both causes we found for #186255: CLI import merges re-sorting rows by timestamp, and hidden-input turn boundaries being kept only for heartbeats. We'd started on the same issue and have stopped in favor of this PR. The red For review, it would help to have:
|
|
Added the missing same-scenario pre-fix visual comparison using production-built Control UI served by real isolated Gateways.
The fixture is a dashboard conversation, where completed-work folding applies. Canonical transcript events were appended through the existing transcript owner before Gateway startup, in this order: An unmatched Claude CLI import precedes all local timestamps. The synthetic transcript and native CLI file exercise real history import,
Expanding main's work disclosure reveals the previous answer, confirming it was folded rather than missing from history. Candidate Controls on both builds: without the hidden exec input, ordinary same-turn narration still folds into one work disclosure. With an intervening real user question, both answers remain visible and the hidden boundary is consumed without stamping the user or following answer. Both controls also survive reload. Candidate canonical transcript event bytes remained unchanged across reads and browser reloads. Regression consolidation: shared the repeated import/index lifecycle and inline-SSE setup, table-drove matching boundary variants, and reused the existing UI history/reload assertion owner. Every behavioral contract remains covered, including both memory/worker indexes, backdated local order, unmatched import placement, tool-shaped user rows, plain-user boundary consumption, hidden heartbeat/exec handling, SSE continuity, and legacy commentary folding. Test/support delta is now 0 (previously +174); the ratchet ceiling is untouched. Production is unchanged: +152/−23, net +129, the existing shared-owner repair. Identical consolidated Gateway tests: main has 7 intended regression failures; candidate passes 153/153 across 8 files. UI grouping/reload tests pass 21/21. Changed-test Oxlint and Oxfmt pass; |
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
…rives (#186323) fix: keep the previous chat answer visible when a late exec completion arrives When a background exec completion arrived after an answer, chat history ordered it ahead of the answer and folded the completed answer away into the "Worked" summary, so the user lost a visible final answer. Late exec completions now keep their place after the answer, which stays visible; the raw exec notice stays hidden. Evidence: built Gateways in Chromium. On main the previous long answer was folded away after the late exec completion, before and after reload (twice); with this change it stayed visible (twice). Normal folding within one turn and an intervening real user message behave the same on both refs, and the stored transcript bytes are unchanged. Screenshots: openclaw/openclaw#186323 (comment). Thanks @DonnieFi. Co-authored-by: Ayaan Zaidi <[email protected]>
…rives (openclaw#186323) fix: keep the previous chat answer visible when a late exec completion arrives When a background exec completion arrived after an answer, chat history ordered it ahead of the answer and folded the completed answer away into the "Worked" summary, so the user lost a visible final answer. Late exec completions now keep their place after the answer, which stays visible; the raw exec notice stays hidden. Evidence: built Gateways in Chromium. On main the previous long answer was folded away after the late exec completion, before and after reload (twice); with this change it stayed visible (twice). Normal folding within one turn and an intervening real user message behave the same on both refs, and the stored transcript bytes are unchanged. Screenshots: openclaw#186323 (comment). Thanks @DonnieFi. Co-authored-by: Ayaan Zaidi <[email protected]>
…188045) * fix(ui): completed turns scatter work across many Worked disclosures Restore the completed-turn presentation that predates #183267: in completed dashboard turns, preamble, commentary, reasoning and tool activity fold into one "Worked for X" disclosure above the answer, work recorded after the answer moves above it, and speech bubble view keeps its activity disclosure without a second rollup. Remove the per-envelope work splitting (chat-work-chunks), its envelope bookkeeping in tool cards and source previews, and the split-fragment action/footer/terminal-status ownership fields. Restore session timing for the rollup and the prior test expectations, keeping later unrelated main changes (#186323, 4d50f6c handoff split, 210b364, bd10ba2, the video widget lazy-import wait and the empty-group avatar guard from #186499). Add regression coverage for Markdown narration order, tool-result images staying in their tool group, post-answer work above the answer and bubble mode without a rollup. Co-authored-by: vyctorbrzezowski <[email protected]> * fix(ui): completed turns scatter work across many Worked disclosures Worked on by: - @vyctorbrzezowski Co-authored-by: vyctorbrzezowski <[email protected]> OpenClaw-Publication: 18f1a29d-eed5-4a6e-9d33-e5dc8590b854 * fix(ui): preserve completed-turn outcomes and reply ownership * fix(ui): retain forwarded narration and prepared action text --------- Co-authored-by: vyctorbrzezowski <[email protected]> Co-authored-by: Vyctor H. Brzezowski <[email protected]>
…penclaw#188045) * fix(ui): completed turns scatter work across many Worked disclosures Restore the completed-turn presentation that predates openclaw#183267: in completed dashboard turns, preamble, commentary, reasoning and tool activity fold into one "Worked for X" disclosure above the answer, work recorded after the answer moves above it, and speech bubble view keeps its activity disclosure without a second rollup. Remove the per-envelope work splitting (chat-work-chunks), its envelope bookkeeping in tool cards and source previews, and the split-fragment action/footer/terminal-status ownership fields. Restore session timing for the rollup and the prior test expectations, keeping later unrelated main changes (openclaw#186323, 5429704 handoff split, 853d946, 3fad731, the video widget lazy-import wait and the empty-group avatar guard from openclaw#186499). Add regression coverage for Markdown narration order, tool-result images staying in their tool group, post-answer work above the answer and bubble mode without a rollup. Co-authored-by: vyctorbrzezowski <[email protected]> * fix(ui): completed turns scatter work across many Worked disclosures Worked on by: - @vyctorbrzezowski Co-authored-by: vyctorbrzezowski <[email protected]> OpenClaw-Publication: 18f1a29d-eed5-4a6e-9d33-e5dc8590b854 * fix(ui): preserve completed-turn outcomes and reply ownership * fix(ui): retain forwarded narration and prepared action text --------- Co-authored-by: vyctorbrzezowski <[email protected]> Co-authored-by: Vyctor H. Brzezowski <[email protected]>
## What Problem This Solves Fixes: one piece of autonomous agent work renders as a stack of separate assistant blocks (each with its own avatar, gap and footer, often holding a single "4 commands" row) when a background command, a Gateway restart or a subagent wakes the session. ## User Impact User impact: work the agent picks up again on its own stays in the block of the prompt that started it. A thin **Resumed · 3m 40s later · Background command finished** rule marks each place it picked up again (other labels: **Gateway restarted**, **Agent finished**). An answer the agent already gave stays in place above the rule. A heartbeat, a scheduled automation, or a message from another person or session still starts its own block.  ## Why This Change Was Made **Root cause.** When a wake input is hidden, the Gateway projection stamps `__openclaw.turnBoundary: true` on the next visible row (`attachProjectedTurnBoundary` in `src/gateway/chat-display-projection.history.ts`). The Control UI reads that flag as "a new user turn", which closes the open frame before the existing `sessions_yield` handoff logic can join the resumed run (`chat-agent-run-grouping.ts`). #186323 extended the flag to exec wakes so a late completion would not fold the earlier answer away, and #193853 added restart. That undid #165542 ("continue a resumed answer in the block that handed off") and broke the documented contract in `docs/web/control-ui/chat.md` ("Its answer then continues in that same block, with one footer at the end"). Subagent-settle wakes had no flag but still split on the run change because no handoff was open. One flag was serving two meanings: "a hidden input happened" and "a new user turn starts". **Solution.** 1. **Gateway projection: a typed continuation fact.** `projectedHistoryTurnBoundary` (replaces `isProjectedHistoryTurnBoundaryMessage`) classifies the hidden input: a heartbeat starts a turn (`true`); an `internal_system` wake with `sourceTool` `exec` or `restart`, or an `inter_session` `subagent_settle` wake, is a continuation. The next visible row gets `__openclaw.continuation: { source: "exec" | "restart" | "subagent" }`. The pending state that already crosses page edges and live appends (`turnBoundaryPending`) carries the source, so live rows and reloaded history agree. The latest hidden wake decides, so a heartbeat after a resumed command still starts its own turn. Cron, forwarded `sessions_send` input, steering notes and other initiators are unchanged. 2. **Control UI: a continuation is a handoff, not a new turn.** `chatItemStartsUserTurn` no longer counts a row with a continuation fact (the fact takes precedence over `turnBoundary`); the grouper reuses the same predicate. `projectSessionsYieldItems` inserts the existing invisible handoff boundary before the resumed row when no `sessions_yield` already opened one, so `coalesceAgentRunFrames` joins the resumed run into the open frame through the path #165542 built. No parallel grouping path. 3. **A visible resume marker.** The frame draws the existing `ChatHandoffResume` rule (same component and CSS) above the first part of each continuation, labelled by source. A `sessions_yield` with a spoken acknowledgment keeps its existing rule and gets no second one. New strings are in `en.ts` only. 4. **Decision: a late completion after a final answer** joins the same block below a Resumed rule. The earlier answer stays visible in place. #186323's UI regression test (`chat-thread-grouping.test.ts`, "keeps the earlier answer visible when a late exec completion starts the follow-up turn") is unchanged and green. 5. **Decision: `restart` is a continuation.** 6. **One rule change to call out for review:** the docs promised that "tool activity that resumes with nothing written in between joins the activity row from before the handoff". Drawing a Resumed rule for every continuation puts something between them, so resumed tool activity now starts its own row under its rule. The old joining still applies to handoffs that have no rule (for example a public tool handoff). The docs now say so. If design prefers one joined row with a single rule, that is a small follow-up in `coalesceAgentRunFrames`. **Android: unchanged by construction.** Android reads only `__openclaw.turnBoundary` (`ChatController.kt`, used by `ChatTimeline*` and `ChatWorkedSummary*`). Exec and restart rows keep `turnBoundary: true` and gain only the extra `continuation` key, which Android ignores. Subagent-settle rows never had `turnBoundary` and still do not. So Android's inputs and output are the same as before; only the web UI lets the continuation fact take precedence. **No schema change, no migration, no transcript rewrite, nothing that reaches a provider request.** The fact is computed at read time, exactly like `turnBoundary`, so existing sessions get the new rendering. `SessionHistorySnapshot.turnBoundaryPending` is in-memory paging state; its type widens from `boolean` to `boolean | "exec" | "restart" | "subagent"`. **How it composes with #198133** (`brzezowski/chat-transcript-lifecycle`, not touched by this PR): that PR moves the grouper and makes collected-subagent completion reports visible, but does not change the boundary logic, so it leaves this symptom as is. The two compose: this PR supplies the grouping rule its completion rows lack. Files both PRs touch: `docs/web/control-ui/chat.md`, `src/gateway/chat-display-projection.core.ts`, `src/gateway/chat-display-projection.history.ts`, `src/gateway/chat-display-projection.visibility.test.ts`, `ui/src/i18n/locales/en.ts`, `ui/src/pages/chat/chat-thread-grouping-data.ts` (one line: the `startsProjectedTurn` check). `git merge-tree` against the current #198133 head reports one textual conflict, in `ui/src/pages/chat/components/chat-handoff-sessions.tsx` (`ChatHandoffResume` props); the rest merge cleanly. ## Evidence **Before / after screenshots.** Same production-shaped fixture, viewport (1280×1400), light theme and scroll position, rendered through the Control UI e2e harness (`ui/src/e2e/chat-continuation-wakes.e2e.test.ts`). The fixture is a raw transcript shaped like the real session's breaks: a prompt, an answer that hands off, two tool-only exec-wake runs ("4 commands", "2 commands · 1 subagent"), a subagent-completion wake, a late exec completion after the final answer, then a second real prompt. The **real Gateway projection** of each tree turns it into history rows, so the base side uses main's projection and the after side uses this PR's. The session is shown with the avatar gutter that shared sessions and multi-user Gateways use. - Before (merge base `7f234bd91294`): 5 assistant blocks for 2 prompts; the subagent's work joins the previous run's activity row, and the late completion's answer gets its own block under "Worked". - After: 2 assistant blocks, one per prompt; 4 Resumed rules; the second prompt still starts a new block.   **Regression tests, red on the merge base and green on this head** (`ocx test`, vitest from source): - Gateway: `chat-display-projection.visibility.test.ts` "marks the row after a hidden {exec,restart,subagent,heartbeat} wake as continuing or starting a turn". Red on base for exec, restart and subagent (no `continuation` fact); the heartbeat case stays `turnBoundary` only. - UI: `chat-background-run-lifecycle.test.ts` "continues the answered block below a Resumed rule per wake, until the next prompt" runs the full transcript chain (`projectTranscriptChain`). On base it renders 3 frames instead of 2 (run against base with the new `partContinuation` helper stubbed, since base lacks it). - UI: `chat-background-run-lifecycle.test.ts` "keeps the Resumed rule when tool calls hide the row that carries it": an answered run, a hidden exec wake, a tool-only first row of the resumed run, then its answer, with tool calls hidden. Red before the repair commit (the tool-only row is dropped with its continuation fact, so no part opens a Resumed rule) and green on this head. - e2e: `chat-continuation-wakes.e2e.test.ts` asserts 2 assistant groups and the 4 rule labels. On base: `expected 5 to be 2`. The "… later" time counts from the last visible row before the wake (the hidden `sessions_yield` result is not shown, so it is not the reference). **Changed assertions in existing tests, with reasons:** - `chat-display-projection.visibility.test.ts` "starts a new turn after a hidden exec completion…" became the parameterized test above. The earlier answer still stays its own row; the follow-up row now also carries `continuation: { source: "exec" }`. - Same file, "keeps a exec completion boundary on a tool-shaped user row": the exec case now also expects `continuation: { source: "exec" }`; `turnBoundary` is unchanged; the heartbeat case is unchanged. - Same file, "hides internal subagent_settle inputs without hiding authored outcomes": the authored outcome now carries `continuation: { source: "subagent" }`. The input is still hidden and the outcome still shown. - `chat-display-projection.automation-repair.test.ts` restart case: the live pending state is now `"restart"` instead of `true`, and the history and live rows also carry `continuation: { source: "restart" }`. This also proves that the fact carries across live appends. **Suites run green on this head:** `src/gateway/chat-display-projection*.test.ts`, `src/gateway/session-history-*.test.ts`, `src/gateway/server.chat-history-cursor.test.ts`, `src/gateway/chat-history-*.test.ts`, and all of `ui/src/pages/chat` except `composer-native-drop.browser.test.ts`. That file fails the same 4 cases on the merge base, so this PR did not cause it. **Gates:** `pnpm check:test-types`, `pnpm tsgo:core`, `pnpm tsgo:ui`, oxlint and oxfmt on changed files (0 new findings), `pnpm ui:i18n:verify`, `pnpm check:test-lines-ratchet` (+352 of 400), `git diff --check`, `rg` for the removed `isProjectedHistoryTurnBoundaryMessage` (no references left). No CSS changed. `pnpm ui:check-performance:base` against the merge base: chat boot JS +979 B, new-session boot JS +390 B, largest JS chunk +232 B; the three budgets in `scripts/check-control-ui-performance.mts` are raised by those measured amounts plus 64 B. CSS and request-count warnings are inherited from `main` and unchanged by this PR. **Real-session check:** the design memo's scratch pipeline (real Gateway projection plus the real UI chain over the real 7-prompt session's rows, metadata only) goes from 14 assistant units on main to **7 units for 7 prompts** on this head, with a Resumed rule at each of the 6 wakes. **Proof tiers and gaps:** - Tier used: `ocx test` (vitest from source) plus the Control UI e2e harness (Vite from source, mocked Gateway transport, real Gateway projection code for the fixture). - **Real-Gateway E2E** (`ocx src`, isolated scratch Gateways, real model `openai/gpt-5.5` on the OpenClaw runtime), merge base vs this head with the same prompt: two background `exec` commands, each followed by `sessions_yield`, then more commands and an answer, then a second prompt. Base: 4 assistant blocks for 2 prompts, no Resumed rules. This head: 2 blocks with 2 "Resumed · … later · Background command finished" rules, and the same after a reload (history projection). Screenshots: #200056 (comment) - Not run live: subagent-settle and Gateway-restart wakes (covered by the projection and UI tests above); a group session with the avatar column (the fixture screenshots cover it). - Not covered: Android output was not re-run. It is unchanged by construction (see above). - Production delta (non-test, non-docs): +230 / −99 lines, much of it re-indentation in `chat-agent-run-frame.tsx`. Co-authored-by: Ayaan Zaidi <[email protected]>
…aw#200056) ## What Problem This Solves Fixes: one piece of autonomous agent work renders as a stack of separate assistant blocks (each with its own avatar, gap and footer, often holding a single "4 commands" row) when a background command, a Gateway restart or a subagent wakes the session. ## User Impact User impact: work the agent picks up again on its own stays in the block of the prompt that started it. A thin **Resumed · 3m 40s later · Background command finished** rule marks each place it picked up again (other labels: **Gateway restarted**, **Agent finished**). An answer the agent already gave stays in place above the rule. A heartbeat, a scheduled automation, or a message from another person or session still starts its own block.  ## Why This Change Was Made **Root cause.** When a wake input is hidden, the Gateway projection stamps `__openclaw.turnBoundary: true` on the next visible row (`attachProjectedTurnBoundary` in `src/gateway/chat-display-projection.history.ts`). The Control UI reads that flag as "a new user turn", which closes the open frame before the existing `sessions_yield` handoff logic can join the resumed run (`chat-agent-run-grouping.ts`). openclaw#186323 extended the flag to exec wakes so a late completion would not fold the earlier answer away, and openclaw#193853 added restart. That undid openclaw#165542 ("continue a resumed answer in the block that handed off") and broke the documented contract in `docs/web/control-ui/chat.md` ("Its answer then continues in that same block, with one footer at the end"). Subagent-settle wakes had no flag but still split on the run change because no handoff was open. One flag was serving two meanings: "a hidden input happened" and "a new user turn starts". **Solution.** 1. **Gateway projection: a typed continuation fact.** `projectedHistoryTurnBoundary` (replaces `isProjectedHistoryTurnBoundaryMessage`) classifies the hidden input: a heartbeat starts a turn (`true`); an `internal_system` wake with `sourceTool` `exec` or `restart`, or an `inter_session` `subagent_settle` wake, is a continuation. The next visible row gets `__openclaw.continuation: { source: "exec" | "restart" | "subagent" }`. The pending state that already crosses page edges and live appends (`turnBoundaryPending`) carries the source, so live rows and reloaded history agree. The latest hidden wake decides, so a heartbeat after a resumed command still starts its own turn. Cron, forwarded `sessions_send` input, steering notes and other initiators are unchanged. 2. **Control UI: a continuation is a handoff, not a new turn.** `chatItemStartsUserTurn` no longer counts a row with a continuation fact (the fact takes precedence over `turnBoundary`); the grouper reuses the same predicate. `projectSessionsYieldItems` inserts the existing invisible handoff boundary before the resumed row when no `sessions_yield` already opened one, so `coalesceAgentRunFrames` joins the resumed run into the open frame through the path openclaw#165542 built. No parallel grouping path. 3. **A visible resume marker.** The frame draws the existing `ChatHandoffResume` rule (same component and CSS) above the first part of each continuation, labelled by source. A `sessions_yield` with a spoken acknowledgment keeps its existing rule and gets no second one. New strings are in `en.ts` only. 4. **Decision: a late completion after a final answer** joins the same block below a Resumed rule. The earlier answer stays visible in place. openclaw#186323's UI regression test (`chat-thread-grouping.test.ts`, "keeps the earlier answer visible when a late exec completion starts the follow-up turn") is unchanged and green. 5. **Decision: `restart` is a continuation.** 6. **One rule change to call out for review:** the docs promised that "tool activity that resumes with nothing written in between joins the activity row from before the handoff". Drawing a Resumed rule for every continuation puts something between them, so resumed tool activity now starts its own row under its rule. The old joining still applies to handoffs that have no rule (for example a public tool handoff). The docs now say so. If design prefers one joined row with a single rule, that is a small follow-up in `coalesceAgentRunFrames`. **Android: unchanged by construction.** Android reads only `__openclaw.turnBoundary` (`ChatController.kt`, used by `ChatTimeline*` and `ChatWorkedSummary*`). Exec and restart rows keep `turnBoundary: true` and gain only the extra `continuation` key, which Android ignores. Subagent-settle rows never had `turnBoundary` and still do not. So Android's inputs and output are the same as before; only the web UI lets the continuation fact take precedence. **No schema change, no migration, no transcript rewrite, nothing that reaches a provider request.** The fact is computed at read time, exactly like `turnBoundary`, so existing sessions get the new rendering. `SessionHistorySnapshot.turnBoundaryPending` is in-memory paging state; its type widens from `boolean` to `boolean | "exec" | "restart" | "subagent"`. **How it composes with openclaw#198133** (`brzezowski/chat-transcript-lifecycle`, not touched by this PR): that PR moves the grouper and makes collected-subagent completion reports visible, but does not change the boundary logic, so it leaves this symptom as is. The two compose: this PR supplies the grouping rule its completion rows lack. Files both PRs touch: `docs/web/control-ui/chat.md`, `src/gateway/chat-display-projection.core.ts`, `src/gateway/chat-display-projection.history.ts`, `src/gateway/chat-display-projection.visibility.test.ts`, `ui/src/i18n/locales/en.ts`, `ui/src/pages/chat/chat-thread-grouping-data.ts` (one line: the `startsProjectedTurn` check). `git merge-tree` against the current openclaw#198133 head reports one textual conflict, in `ui/src/pages/chat/components/chat-handoff-sessions.tsx` (`ChatHandoffResume` props); the rest merge cleanly. ## Evidence **Before / after screenshots.** Same production-shaped fixture, viewport (1280×1400), light theme and scroll position, rendered through the Control UI e2e harness (`ui/src/e2e/chat-continuation-wakes.e2e.test.ts`). The fixture is a raw transcript shaped like the real session's breaks: a prompt, an answer that hands off, two tool-only exec-wake runs ("4 commands", "2 commands · 1 subagent"), a subagent-completion wake, a late exec completion after the final answer, then a second real prompt. The **real Gateway projection** of each tree turns it into history rows, so the base side uses main's projection and the after side uses this PR's. The session is shown with the avatar gutter that shared sessions and multi-user Gateways use. - Before (merge base `e263be2efe0d`): 5 assistant blocks for 2 prompts; the subagent's work joins the previous run's activity row, and the late completion's answer gets its own block under "Worked". - After: 2 assistant blocks, one per prompt; 4 Resumed rules; the second prompt still starts a new block.   **Regression tests, red on the merge base and green on this head** (`ocx test`, vitest from source): - Gateway: `chat-display-projection.visibility.test.ts` "marks the row after a hidden {exec,restart,subagent,heartbeat} wake as continuing or starting a turn". Red on base for exec, restart and subagent (no `continuation` fact); the heartbeat case stays `turnBoundary` only. - UI: `chat-background-run-lifecycle.test.ts` "continues the answered block below a Resumed rule per wake, until the next prompt" runs the full transcript chain (`projectTranscriptChain`). On base it renders 3 frames instead of 2 (run against base with the new `partContinuation` helper stubbed, since base lacks it). - UI: `chat-background-run-lifecycle.test.ts` "keeps the Resumed rule when tool calls hide the row that carries it": an answered run, a hidden exec wake, a tool-only first row of the resumed run, then its answer, with tool calls hidden. Red before the repair commit (the tool-only row is dropped with its continuation fact, so no part opens a Resumed rule) and green on this head. - e2e: `chat-continuation-wakes.e2e.test.ts` asserts 2 assistant groups and the 4 rule labels. On base: `expected 5 to be 2`. The "… later" time counts from the last visible row before the wake (the hidden `sessions_yield` result is not shown, so it is not the reference). **Changed assertions in existing tests, with reasons:** - `chat-display-projection.visibility.test.ts` "starts a new turn after a hidden exec completion…" became the parameterized test above. The earlier answer still stays its own row; the follow-up row now also carries `continuation: { source: "exec" }`. - Same file, "keeps a exec completion boundary on a tool-shaped user row": the exec case now also expects `continuation: { source: "exec" }`; `turnBoundary` is unchanged; the heartbeat case is unchanged. - Same file, "hides internal subagent_settle inputs without hiding authored outcomes": the authored outcome now carries `continuation: { source: "subagent" }`. The input is still hidden and the outcome still shown. - `chat-display-projection.automation-repair.test.ts` restart case: the live pending state is now `"restart"` instead of `true`, and the history and live rows also carry `continuation: { source: "restart" }`. This also proves that the fact carries across live appends. **Suites run green on this head:** `src/gateway/chat-display-projection*.test.ts`, `src/gateway/session-history-*.test.ts`, `src/gateway/server.chat-history-cursor.test.ts`, `src/gateway/chat-history-*.test.ts`, and all of `ui/src/pages/chat` except `composer-native-drop.browser.test.ts`. That file fails the same 4 cases on the merge base, so this PR did not cause it. **Gates:** `pnpm check:test-types`, `pnpm tsgo:core`, `pnpm tsgo:ui`, oxlint and oxfmt on changed files (0 new findings), `pnpm ui:i18n:verify`, `pnpm check:test-lines-ratchet` (+352 of 400), `git diff --check`, `rg` for the removed `isProjectedHistoryTurnBoundaryMessage` (no references left). No CSS changed. `pnpm ui:check-performance:base` against the merge base: chat boot JS +979 B, new-session boot JS +390 B, largest JS chunk +232 B; the three budgets in `scripts/check-control-ui-performance.mts` are raised by those measured amounts plus 64 B. CSS and request-count warnings are inherited from `main` and unchanged by this PR. **Real-session check:** the design memo's scratch pipeline (real Gateway projection plus the real UI chain over the real 7-prompt session's rows, metadata only) goes from 14 assistant units on main to **7 units for 7 prompts** on this head, with a Resumed rule at each of the 6 wakes. **Proof tiers and gaps:** - Tier used: `ocx test` (vitest from source) plus the Control UI e2e harness (Vite from source, mocked Gateway transport, real Gateway projection code for the fixture). - **Real-Gateway E2E** (`ocx src`, isolated scratch Gateways, real model `openai/gpt-5.5` on the OpenClaw runtime), merge base vs this head with the same prompt: two background `exec` commands, each followed by `sessions_yield`, then more commands and an answer, then a second prompt. Base: 4 assistant blocks for 2 prompts, no Resumed rules. This head: 2 blocks with 2 "Resumed · … later · Background command finished" rules, and the same after a reload (history projection). Screenshots: openclaw#200056 (comment) - Not run live: subagent-settle and Gateway-restart wakes (covered by the projection and UI tests above); a group session with the avatar column (the fixture screenshots cover it). - Not covered: Android output was not re-run. It is unchanged by construction (see above). - Production delta (non-test, non-docs): +230 / −99 lines, much of it re-indentation in `chat-agent-run-frame.tsx`. Co-authored-by: Ayaan Zaidi <[email protected]>




Fixes #186255
What Problem This Solves
A previous completed chat answer can disappear into the next turn's Worked disclosure when a late background exec completion is recorded after that answer with an earlier timestamp. An unmatched CLI import exposes the timestamp reordering, and hiding the exec input previously lost its display-turn boundary.
User Impact
The completed answer stays separately visible before and after reloading a dashboard conversation. The follow-up's work disclosure no longer takes ownership of that answer. Raw internal exec notices remain hidden; ordinary same-turn narration still folds normally.
Why This Change Was Made
Local canonical rows must retain transcript sequence, even when their timestamps go backwards. Unmatched imports are placed after the latest local whose timestamp is no later than the import, using the shared one-pass placement owner in both existing history indexes.
The existing hidden-input boundary now covers exec completions as well as heartbeats and travels through history pages and SSE state. A visible user consumes the boundary without taking the flag. Tool-shaped user rows retain it because they do not start a user turn in the Control UI. The fix changes derived ordering/display projection, not canonical transcript bytes, schema, or public protocol.
Evidence
Matching current-main and repaired screenshots, repeated Chromium observations, controls, and regression results.
Production-built Control UI served by real isolated Gateways: main
a055ff33bbe74d95357f5d77bedc2cebdbd89c48twice folds the previous answer; the repaired production code twice keeps it visible, both before and after reload. Expanding main's disclosure reveals the answer. The hidden exec notice remains absent. Normal same-turn and intervening-real-user controls agree on both builds. Candidate canonical transcript bytes remain unchanged across reads/reloads.This is a deterministic synthetic-transcript replay through real history import, Gateway RPCs and browser rendering, not a native background-process execution claim. A local provider fixture avoids real-provider credentials. No Gateway responses or browser DOM were rewritten.
Regression Coverage
Consolidated repeated transcript/index setup and inline-SSE fixtures, and reused the existing UI history/reload assertion helper. All distinct assertions remain: memory/worker indexes, backdated local sequence, unmatched import anchoring, plain-user consumption, tool-shaped user rows, hidden exec/heartbeat boundaries, SSE continuity and legacy commentary folding.
git diff --check: passing.Merge Risk
Two-way door: a revert restores the prior derived ordering and display behavior without undoing writes or migrating state. No canonical transcript rewrite, new persistent format, SDK change, or permission change. Blast radius is imported chat-history ordering and hidden-input turn presentation, including paged and SSE history consumers.