Skip to content

fix: previous chat answer stays hidden when a late exec completion arrives - #186323

Merged
obviyus merged 7 commits into
openclaw:mainfrom
DonnieFi:fix/186255-late-exec-answer-fold
Oct 28, 2026
Merged

obviyus merged 7 commits into
openclaw:mainfrom
DonnieFi:fix/186255-late-exec-answer-fold

Conversation

@DonnieFi

@DonnieFi DonnieFi commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

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 a055ff33bbe74d95357f5d77bedc2cebdbd89c48 twice 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.

  • Identical consolidated Gateway regressions: main has 7 intended failures; candidate 153/153 passing across 8 files.
  • UI grouping/history-reload tests: 21/21 passing.
  • Changed-test Oxlint, formatting, and git diff --check: passing.
  • Test/support growth is 0, reduced from +174; no ratchet ceiling change.
  • Production remains the contributor's shared-owner repair: +152/−23 (net +129). The linear import-placement pass replaces the earlier repeated per-import local scan.

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.

…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
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: S labels Oct 27, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

Preserves 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.

  • Before: An unmatched CLI import can reorder the completion, and the previous answer folds into the follow-up's Worked disclosure.
  • After: Both answers remain separately visible before and after reload, while the internal exec notice stays hidden.

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A focused shared-owner repair with matching production-entry-point visual proof, reported red/green regressions, preserved controls, and no identified findings; ordinary exact-head CI remains pending.
Proof confidence 🦞 diamond lobster (5/6) ✨ media proof bonus Sufficient (screenshot): Inspected matching main/candidate screenshots and the linked collaborator account exercise production-built Control UI through real isolated Gateways, native CLI import, chat.history, and reload with the reported backdated sequence; both candidate answers remain visible and internal exec notices remain hidden, with ordinary-folding and real-user controls reported.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: A completed answer appears to disappear into the following turn's collapsed work disclosure after a delayed background command completion.
Reason: The official-release report identifies a concrete source failure, and recorded owner engagement supports repairing both causes while retaining existing presentation defaults.

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
Reviewed head: 69365146a9eeacbae94a25aac7f95ce8efcc6b90

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway 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
Loading

Technical review

Best 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

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

PR surface

Source +129, Tests 0. Total +129 across 13 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 8 152 23 +129
Tests 5 249 249 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 401 272 +129

Review metrics

Metric Value Why it matters
Production versus test/support LOC Production +152/-23, net +129; tests/support +249/-249, net 0 Production growth implements deterministic shared import placement and carries existing boundary semantics through affected consumers; fixture consolidation avoids net test growth.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #186255
Summary: This PR is the candidate repair for the canonical late-exec answer-folding report; earlier presentation and visibility repairs cover adjacent contracts.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.
  • remove status: 📣 needs proof: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P2: A completed answer becomes misleadingly folded into another turn, but users can recover it by expanding the disclosure.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • proof: sufficient: Contributor real behavior proof is sufficient.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

History

Review history (3 earlier review cycles)
  • reviewed 2026-10-27T21:41:30.225Z sha fb3127b :: needs real behavior proof before merge. :: [P2] Use a consistent ordering when merging local and imported rows
  • reviewed 2026-10-27T22:30:33.030Z sha 2ec8d67 :: needs real behavior proof before merge. :: [P2] Avoid scanning every local row for each unmatched import
  • reviewed 2026-10-28T00:01:14.672Z sha 5ac1e88 :: needs real behavior proof before merge. :: none

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
@DonnieFi

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 27, 2026
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.
@steipete

Copy link
Copy Markdown
Contributor

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 checks-fast-baseline-ratchets job is the repository-wide test-line budget (Test lines: 6290072; ceiling: 6288829; over by: 1243; net delta: +174). Main is already over its ceiling, so any PR that adds net test lines fails this check, and maintainers aren't raising the ceiling right now. Please offset the +174 by consolidating tests in the files you touch: table-drive repeated cases and share duplicated fixture setup, keeping every behavioral assertion. Today's other merges reached net 0 or below that way.

For review, it would help to have:

  • the reporter's four-row sequence with one unmatched CLI import, replayed through both index implementations (in-memory and worker), showing both answers stay visible before and after a reload
  • a sanitized before/after Control UI screenshot of the late-completion case, since this changes what the chat shows
  • confirmation that ordinary commentary folding under "Worked for" is unchanged

@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Added the missing same-scenario pre-fix visual comparison using production-built Control UI served by real isolated Gateways.

  • Main: a055ff33bbe74d95357f5d77bedc2cebdbd89c48.
  • Contributor production code: 5ac1e88f6421d48c6aefbf3e1a1ce2656649113d; the repair on top changes test setup only.
  • Node 24.22.1, real Chromium, 1280×900 viewport, task-owned state, no real-provider key.

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:

user:      Review the change                         t+50ms
assistant: Long final answer …                       t+200ms
user:      Exec completed … [internal_system/exec]   t+100ms
assistant: Should I fix points 1-4?                   t+300ms

An unmatched Claude CLI import precedes all local timestamps. The synthetic transcript and native CLI file exercise real history import, chat.history, page loading and reload; neither Gateway responses nor browser rendering were mocked or rewritten. This is a deterministic transcript replay, not a claim that a native background process was run.

Observed in Chromium Main, repeat 1 Main, repeat 2 Candidate, repeat 1 Candidate, repeat 2
Previous answer visible before reload No No Yes Yes
Previous answer visible after reload No No Yes Yes
Completed-work disclosures 1 1 0 0
Raw exec notice visible No No No No

Expanding main's work disclosure reveals the previous answer, confirming it was folded rather than missing from history. Candidate chat.history carries turnBoundary:true on the follow-up; main does not.

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; git diff --check passes. Screenshots attached below were inspected and contain synthetic content only.

Main before reload folds the previous answer under Worked

Candidate before reload keeps the previous answer visible

Main after reload still folds the previous answer

Candidate after reload still keeps both answers visible

@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 28, 2026
@obviyus
obviyus merged commit 189e653 into openclaw:main Oct 28, 2026
143 of 144 checks passed
@obviyus

obviyus commented Oct 28, 2026

Copy link
Copy Markdown
Collaborator

Landed in 189e653. Thanks @DonnieFi. A late exec completion no longer hides the previous answer.

github-actions Bot pushed a commit to Shiran20016061/openclaw that referenced this pull request Oct 28, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…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]>
vyctorbrzezowski added a commit that referenced this pull request Oct 30, 2026
…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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 31, 2026
…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]>
obviyus added a commit that referenced this pull request Nov 16, 2026
## 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.

![Before | after, same fixture](https://github.com/user-attachments/assets/f172c77d-6fdb-43e9-9ec6-c3da3485d655)

## 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.

![Before: main](https://github.com/user-attachments/assets/6f8f9009-f4f7-486c-bf9a-d24542da4256)
![After: this PR](https://github.com/user-attachments/assets/e11bce59-9370-422b-b2ae-00b32a4b46c0)

**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]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 17, 2026
…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.

![Before | after, same fixture](https://github.com/user-attachments/assets/f172c77d-6fdb-43e9-9ec6-c3da3485d655)

## 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.

![Before: main](https://github.com/user-attachments/assets/6f8f9009-f4f7-486c-bf9a-d24542da4256)
![After: this PR](https://github.com/user-attachments/assets/e11bce59-9370-422b-b2ae-00b32a4b46c0)

**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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: L status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Control UI hides the final answer in the next turn's "Worked for" fold when a late exec completion arrives

3 participants