Skip to content

fix(ui): continue self-woken work in the turn that started it - #200056

Merged
obviyus merged 2 commits into
mainfrom
obviyus/chat-continuation-wakes
Nov 16, 2026
Merged

obviyus merged 2 commits into
mainfrom
obviyus/chat-continuation-wakes

Conversation

@obviyus

@obviyus obviyus commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

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

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 improve: continue a resumed answer in the block that handed off #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. fix: previous chat answer stays hidden when a late exec completion arrives #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
After: this PR

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: fix(ui): continue self-woken work in the turn that started it #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.

When a background command, a Gateway restart or a child subagent wakes the
session, the Gateway projection now records a typed continuation fact on the
next visible row. The Control UI treats it like a sessions_yield handoff: the
work joins the block that started it, below a thin Resumed rule naming what
woke it. Heartbeats, automations and forwarded input still start their own
turns. Exec and restart rows keep turnBoundary for clients that read only it.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 16, 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 docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime size: L labels Nov 16, 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: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. 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 Nov 16, 2026
@clawsweeper

clawsweeper Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

The PR keeps work resumed by background commands, restarts, and subagents inside the existing assistant block and adds labeled resume markers.

Example: A docs-upgrade request resumes after three background commands and a subagent completion, followed by a second user prompt.

  • Before: The supplied browser fixture shows five assistant blocks for two prompts.
  • After: The same fixture shows two assistant blocks and four labeled Resumed rules, with the earlier answer still visible.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful visual and regression evidence supports the approach, with bounded implementation defects and incomplete runtime qualification.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Partial
User problem: One autonomous task appears as several disconnected assistant responses when background work wakes the session.
Reason: The change restores the documented same-block continuation behavior, and its maintainer authorship establishes direction.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep open: this maintainer-authored PR addresses a documented conversation-grouping defect, but needs focused repairs before merge.

Priority: P2
Reviewed head: 8b976eeeeceb6b3965e7e4da711c29a6cac5b2ce

Before merge

  • Preserve continuation facts when tool calls are hidden (P2) - With showToolCalls=false, consider an answered run followed by a hidden exec wake, a tool-only first message from the resumed run, and its final text answer, without sessions_yield. The Gateway puts continuation only on that first tool message, but chat-thread-build.ts:328-335 can discard it before this scan, and projectSessionsYieldItems:516 also filters tool-only rows before scanning. The final answer therefore has no continuation or synthesized handoff, so its different run ID creates another assistant block and no Resumed rule appears. Preserve the structural continuation through both visibility filters and cover this sequence with tool calls hidden.
  • Reduce the added chat boot JavaScript below the growth allowance (P2) - The exact-head control-ui-performance job fails its base comparison on chat boot JavaScript: 1283.0 KiB exceeds the permitted 1282.6 KiB. Its annotation records base at 1,313,308 bytes and permits only 64 additional bytes because base already exceeds the fixed cap. This is additional growth from the changed implementation, separate from the inherited CSS warnings. Reduce the continuation implementation's emitted chat code and pass the existing comparison without raising the budget.

Findings

  • [P2] Preserve continuation facts when tool calls are hidden — ui/src/pages/chat/chat-sessions-yield.ts:365-369
  • [P2] Reduce the added chat boot JavaScript below the growth allowance — ui/src/pages/chat/components/chat-agent-run-frame.tsx:274-281

Tests

  • Missing end-to-end proof: The PR owner should supply a redacted real-Gateway and real-model continuation flow, including reload, as the PR body acknowledges is still owed.
Agent review details

How this fits together

The Gateway projects canonical transcript inputs into display metadata, which the Control UI consumes to group messages, tool activity, and resumed runs into conversation blocks.

flowchart LR
  A[Canonical transcript] --> B[Gateway display projection]
  B --> C[History and live messages]
  C --> D[UI visibility filtering]
  D --> E[Handoff projection]
  E --> F[Run frame grouping]
  F --> G[Chat rendering]
Loading

Technical review

Best possible solution:

Preserve continuation structure independently of tool visibility, reuse the existing handoff and frame owners, and keep the added rendering within the existing bundle allowance.

Do we have a high-confidence way to reproduce the issue?

The original split follows from current-main hidden-input boundaries and run changes, and the supplied comparable browser captures demonstrate it; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Separating continuation facts from turn boundaries and feeding the existing handoff path is a focused repair, with the new metadata remaining a read-time projection rather than persisted state.

Full review comments:

  • [P2] Preserve continuation facts when tool calls are hidden — ui/src/pages/chat/chat-sessions-yield.ts:365-369
    With showToolCalls=false, consider an answered run followed by a hidden exec wake, a tool-only first message from the resumed run, and its final text answer, without sessions_yield. The Gateway puts continuation only on that first tool message, but chat-thread-build.ts:328-335 can discard it before this scan, and projectSessionsYieldItems:516 also filters tool-only rows before scanning. The final answer therefore has no continuation or synthesized handoff, so its different run ID creates another assistant block and no Resumed rule appears. Preserve the structural continuation through both visibility filters and cover this sequence with tool calls hidden.
    Confidence: 0.97
  • [P2] Reduce the added chat boot JavaScript below the growth allowance — ui/src/pages/chat/components/chat-agent-run-frame.tsx:274-281
    The exact-head control-ui-performance job fails its base comparison on chat boot JavaScript: 1283.0 KiB exceeds the permitted 1282.6 KiB. Its annotation records base at 1,313,308 bytes and permits only 64 additional bytes because base already exceeds the fixed cap. This is additional growth from the changed implementation, separate from the inherited CSS warnings. Reduce the continuation implementation's emitted chat code and pass the existing comparison without raising the budget.
    Confidence: 0.93

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against b23536513925.

Provenance checked

  • Hidden exec and restart boundaries changes intended behavior with a stated reason (189e653: Keep earlier answers visible when late background completions arrive; restart recovery later reused that boundary in 2336698.)
  • Handoff frame continuation and activity joining changes intended behavior with a stated reason (96667f3: Keep resumed work in one answer frame and join adjacent operations when no visible rule separates them.)
  • Paging and live pending-boundary propagation keeps the original intent (189e653: Carry hidden-input boundaries across history pages and live appends; this PR preserves that propagation while widening its runtime value.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pnpm test ui/src/pages/chat/chat-background-run-lifecycle.test.ts ui/src/pages/chat/chat-sessions-yield.test.ts ui/src/pages/chat/chat-thread-grouping.test.ts --maxWorkers=1
  • pnpm test src/gateway/chat-display-projection.visibility.test.ts src/gateway/chat-display-projection.automation-repair.test.ts --maxWorkers=1
  • pnpm tsgo:ui
  • pnpm ui:i18n:verify
  • git diff --check

What I checked:

Likely related people:

  • Shakker: Raw commit 96667f3 adds ui/src/pages/chat/chat-agent-run-grouping.ts:200 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 96667f3c70db; files: ui/src/pages/chat/chat-agent-run-grouping.ts)
  • Peter Steinberger: Raw commit 690c6f0 adds ui/src/pages/chat/chat-sessions-yield.ts:24 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 690c6f08025d; files: ui/src/pages/chat/chat-sessions-yield.ts)
  • Vyctor H. Brzezowski: Raw commit 2a87667 adds ui/src/pages/chat/chat-agent-run-grouping.ts:208 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 2a87667bb256; files: ui/src/pages/chat/chat-agent-run-grouping.ts)

PR surface

Source +163, Tests +330, Docs +9. Total +502 across 19 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 14 260 97 +163
Tests 4 348 18 +330
Docs 1 10 1 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 19 618 116 +502

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: Conversation grouping is confusing but answers remain available; the repair has a limited Control UI presentation scope.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

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.

Reviewed November 16, 2026, 4:48 AM ET / 09:48 UTC.

@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Real-Gateway E2E: pass

Proof tier: ocx src (CLI and Gateway from source), a real isolated scratch Gateway per side, and a real OpenAI model (openai/gpt-5.5, OpenClaw embedded runtime, API key). Control UI served by each Gateway and driven with headless Chromium at the same viewport (1280×2400, light theme).

  • Before: merge base 7f234bd91294
  • After: PR head 8b976eeeeceb

Steps (same on both sides)

  1. Created a group-kind session (…:webchat:group:…, so the avatar gutter shows) and sent one prompt from the Control UI. The prompt asked the agent to start sleep 20 && echo done with yieldMs: 1000, call sessions_yield, run date, uname -s and echo three after it woke, spawn one short subagent and sessions_yield on it, and then answer.
  2. Sent a second, plain prompt.
  3. Took a screenshot of the thread, reloaded the page, and took another screenshot.

Result (trial 2: the agent writes no text before each yield)

Assistant blocks for 2 prompts Resume rules
Before 3 (the exec wake opens its own avatar block) none
After, live 2 Resumed · 20s later · Background command finished, Resumed · 3s later · Agent finished
After, reloaded 2 same two rules

On the PR head the second prompt still starts its own block.

Before: merge base, 3 assistant blocks
After: PR head, 2 assistant blocks with Resumed rules
After a reload: grouping and rules unchanged

Trial 1 (the agent writes "I'll wait…" before each yield): before had 3 blocks, after had 2. A reload kept the 2 blocks. On the PR head the exec-wake rule showed Resumed · 18s later with no source label. This is expected: a yield with a spoken acknowledgment keeps its existing rule and does not get a second one (Solution point 3).

Gaps

  • Only exec and subagent wakes were exercised. The restart wake (Gateway restart) and the late completion after a final answer were not run live.
  • Android was not run.

Mark continuations once per run before handoff projection, so the resumed
run's first row survives showToolCalls=false and still opens its Resumed
rule. The frame computes the rule from the last visible row before it,
scanning the whole run across virtualized fragments.

Co-authored-by: obviyus <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added the scripts Repository scripts label Nov 16, 2026
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Real-Gateway E2E: before and after (head 86b4a176c85e)

Proof tier: ocx src (Gateway from source, pinned Bun fork), a real Gateway, the Control UI from each side's own build, and a real OpenAI model (openai/gpt-5.5, OpenClaw runtime). Each side ran with its own isolated scratch state and port. Base: merge base 7f234bd91294.

Steps (same on both sides):

  1. In the Control UI main session, send one prompt. The agent starts sleep 20 && echo first-done with exec (yieldMs: 1000) and calls sessions_yield. When it wakes, it starts sleep 15 && echo second-done the same way and yields again. After the second wake it runs date, uname -s and echo checks-ok, then answers.
  2. Send a second, ordinary prompt.
  3. Count .chat-group.assistant and the Resumed rules, take a screenshot, reload the page and count again.

Both transcripts have the same input shape: 2 hidden exec wakes and 2 sessions_yield calls.

Result: pass

Assistant blocks (2 prompts) Resumed rules
Before (merge base) 4 none
After (this PR), live 2 Resumed · 21s later · Background command finished, Resumed · 16s later · Background command finished
After (this PR), after reload 2 the same 2 rules

The second prompt still starts its own block. The reload result matches the live result, so the history projection gives the same grouping.

Other trials:

  • With sessions_yield acknowledgments, the base showed 3 blocks for 2 prompts. The PR showed 2 blocks, and each wake had the existing acknowledgment rule (Resumed · 19s later) without a source label. This is the documented behavior.
  • On the first try with fresh state, the first chat.send failed on both sides with session changed before chat.send; retry the request. The failure was the same on the base and the PR, so this PR did not cause it. A retry worked.

Gaps: subagent-settle and Gateway-restart wakes were not exercised live (the unit and e2e fixtures cover them). This ran in a direct main session, not in a group session with the avatar gutter. Android was not run.

Before (merge base): 4 assistant blocks; after (PR head): 2 blocks with 2 Resumed rules

After reload on the PR head: same 2 blocks and Resumed rules

@obviyus
obviyus merged commit 24385a2 into main Nov 16, 2026
209 of 211 checks passed
@obviyus
obviyus deleted the obviyus/chat-continuation-wakes branch November 16, 2026 12:42
@obviyus

obviyus commented Nov 16, 2026

Copy link
Copy Markdown
Collaborator Author

Landed in 24385a2.

  • Bug: when a background command, a restart or a subagent woke the session, the next run opened a new assistant block. One piece of work showed up as a stack of separate replies.
  • Fix: the Gateway now marks those wakes as a typed continuation. The Control UI keeps the resumed work in the same block, under a thin "Resumed · … later" rule. Android output is unchanged.
  • Proof: real-Gateway E2E with a real model, before and after, on the exact head (comment above). Regression tests cover the projection, the grouping with tool calls hidden, and the browser e2e. The local review passed and CI is green.

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 docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. scripts Repository scripts size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant