Repository navigation
fix(ui): continue self-woken work in the turn that started it - #200056
Conversation
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]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. What this changesThe 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.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Partial 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 Before merge
Findings
Tests
Agent review detailsHow this fits togetherThe 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]
Technical reviewBest 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:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against b23536513925. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceAcceptance criteria:
What I checked:
Likely related people:
PR surfaceSource +163, Tests +330, Docs +9. Total +502 across 19 files. Added test files: 1. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 16, 2026, 4:48 AM ET / 09:48 UTC. |
Real-Gateway E2E: passProof tier:
Steps (same on both sides)
Result (trial 2: the agent writes no text before each yield)
On the PR head the second prompt still starts its own block. 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 Gaps
|
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]>
Real-Gateway E2E: before and after (head
|
| 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_yieldacknowledgments, 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.sendfailed on both sides withsession 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.
|
Landed in 24385a2.
|
…aw#200056) ## What Problem This Solves Fixes: one piece of autonomous agent work renders as a stack of separate assistant blocks (each with its own avatar, gap and footer, often holding a single "4 commands" row) when a background command, a Gateway restart or a subagent wakes the session. ## User Impact User impact: work the agent picks up again on its own stays in the block of the prompt that started it. A thin **Resumed · 3m 40s later · Background command finished** rule marks each place it picked up again (other labels: **Gateway restarted**, **Agent finished**). An answer the agent already gave stays in place above the rule. A heartbeat, a scheduled automation, or a message from another person or session still starts its own block.  ## Why This Change Was Made **Root cause.** When a wake input is hidden, the Gateway projection stamps `__openclaw.turnBoundary: true` on the next visible row (`attachProjectedTurnBoundary` in `src/gateway/chat-display-projection.history.ts`). The Control UI reads that flag as "a new user turn", which closes the open frame before the existing `sessions_yield` handoff logic can join the resumed run (`chat-agent-run-grouping.ts`). openclaw#186323 extended the flag to exec wakes so a late completion would not fold the earlier answer away, and openclaw#193853 added restart. That undid openclaw#165542 ("continue a resumed answer in the block that handed off") and broke the documented contract in `docs/web/control-ui/chat.md` ("Its answer then continues in that same block, with one footer at the end"). Subagent-settle wakes had no flag but still split on the run change because no handoff was open. One flag was serving two meanings: "a hidden input happened" and "a new user turn starts". **Solution.** 1. **Gateway projection: a typed continuation fact.** `projectedHistoryTurnBoundary` (replaces `isProjectedHistoryTurnBoundaryMessage`) classifies the hidden input: a heartbeat starts a turn (`true`); an `internal_system` wake with `sourceTool` `exec` or `restart`, or an `inter_session` `subagent_settle` wake, is a continuation. The next visible row gets `__openclaw.continuation: { source: "exec" | "restart" | "subagent" }`. The pending state that already crosses page edges and live appends (`turnBoundaryPending`) carries the source, so live rows and reloaded history agree. The latest hidden wake decides, so a heartbeat after a resumed command still starts its own turn. Cron, forwarded `sessions_send` input, steering notes and other initiators are unchanged. 2. **Control UI: a continuation is a handoff, not a new turn.** `chatItemStartsUserTurn` no longer counts a row with a continuation fact (the fact takes precedence over `turnBoundary`); the grouper reuses the same predicate. `projectSessionsYieldItems` inserts the existing invisible handoff boundary before the resumed row when no `sessions_yield` already opened one, so `coalesceAgentRunFrames` joins the resumed run into the open frame through the path openclaw#165542 built. No parallel grouping path. 3. **A visible resume marker.** The frame draws the existing `ChatHandoffResume` rule (same component and CSS) above the first part of each continuation, labelled by source. A `sessions_yield` with a spoken acknowledgment keeps its existing rule and gets no second one. New strings are in `en.ts` only. 4. **Decision: a late completion after a final answer** joins the same block below a Resumed rule. The earlier answer stays visible in place. openclaw#186323's UI regression test (`chat-thread-grouping.test.ts`, "keeps the earlier answer visible when a late exec completion starts the follow-up turn") is unchanged and green. 5. **Decision: `restart` is a continuation.** 6. **One rule change to call out for review:** the docs promised that "tool activity that resumes with nothing written in between joins the activity row from before the handoff". Drawing a Resumed rule for every continuation puts something between them, so resumed tool activity now starts its own row under its rule. The old joining still applies to handoffs that have no rule (for example a public tool handoff). The docs now say so. If design prefers one joined row with a single rule, that is a small follow-up in `coalesceAgentRunFrames`. **Android: unchanged by construction.** Android reads only `__openclaw.turnBoundary` (`ChatController.kt`, used by `ChatTimeline*` and `ChatWorkedSummary*`). Exec and restart rows keep `turnBoundary: true` and gain only the extra `continuation` key, which Android ignores. Subagent-settle rows never had `turnBoundary` and still do not. So Android's inputs and output are the same as before; only the web UI lets the continuation fact take precedence. **No schema change, no migration, no transcript rewrite, nothing that reaches a provider request.** The fact is computed at read time, exactly like `turnBoundary`, so existing sessions get the new rendering. `SessionHistorySnapshot.turnBoundaryPending` is in-memory paging state; its type widens from `boolean` to `boolean | "exec" | "restart" | "subagent"`. **How it composes with openclaw#198133** (`brzezowski/chat-transcript-lifecycle`, not touched by this PR): that PR moves the grouper and makes collected-subagent completion reports visible, but does not change the boundary logic, so it leaves this symptom as is. The two compose: this PR supplies the grouping rule its completion rows lack. Files both PRs touch: `docs/web/control-ui/chat.md`, `src/gateway/chat-display-projection.core.ts`, `src/gateway/chat-display-projection.history.ts`, `src/gateway/chat-display-projection.visibility.test.ts`, `ui/src/i18n/locales/en.ts`, `ui/src/pages/chat/chat-thread-grouping-data.ts` (one line: the `startsProjectedTurn` check). `git merge-tree` against the current openclaw#198133 head reports one textual conflict, in `ui/src/pages/chat/components/chat-handoff-sessions.tsx` (`ChatHandoffResume` props); the rest merge cleanly. ## Evidence **Before / after screenshots.** Same production-shaped fixture, viewport (1280×1400), light theme and scroll position, rendered through the Control UI e2e harness (`ui/src/e2e/chat-continuation-wakes.e2e.test.ts`). The fixture is a raw transcript shaped like the real session's breaks: a prompt, an answer that hands off, two tool-only exec-wake runs ("4 commands", "2 commands · 1 subagent"), a subagent-completion wake, a late exec completion after the final answer, then a second real prompt. The **real Gateway projection** of each tree turns it into history rows, so the base side uses main's projection and the after side uses this PR's. The session is shown with the avatar gutter that shared sessions and multi-user Gateways use. - Before (merge base `e263be2efe0d`): 5 assistant blocks for 2 prompts; the subagent's work joins the previous run's activity row, and the late completion's answer gets its own block under "Worked". - After: 2 assistant blocks, one per prompt; 4 Resumed rules; the second prompt still starts a new block.   **Regression tests, red on the merge base and green on this head** (`ocx test`, vitest from source): - Gateway: `chat-display-projection.visibility.test.ts` "marks the row after a hidden {exec,restart,subagent,heartbeat} wake as continuing or starting a turn". Red on base for exec, restart and subagent (no `continuation` fact); the heartbeat case stays `turnBoundary` only. - UI: `chat-background-run-lifecycle.test.ts` "continues the answered block below a Resumed rule per wake, until the next prompt" runs the full transcript chain (`projectTranscriptChain`). On base it renders 3 frames instead of 2 (run against base with the new `partContinuation` helper stubbed, since base lacks it). - UI: `chat-background-run-lifecycle.test.ts` "keeps the Resumed rule when tool calls hide the row that carries it": an answered run, a hidden exec wake, a tool-only first row of the resumed run, then its answer, with tool calls hidden. Red before the repair commit (the tool-only row is dropped with its continuation fact, so no part opens a Resumed rule) and green on this head. - e2e: `chat-continuation-wakes.e2e.test.ts` asserts 2 assistant groups and the 4 rule labels. On base: `expected 5 to be 2`. The "… later" time counts from the last visible row before the wake (the hidden `sessions_yield` result is not shown, so it is not the reference). **Changed assertions in existing tests, with reasons:** - `chat-display-projection.visibility.test.ts` "starts a new turn after a hidden exec completion…" became the parameterized test above. The earlier answer still stays its own row; the follow-up row now also carries `continuation: { source: "exec" }`. - Same file, "keeps a exec completion boundary on a tool-shaped user row": the exec case now also expects `continuation: { source: "exec" }`; `turnBoundary` is unchanged; the heartbeat case is unchanged. - Same file, "hides internal subagent_settle inputs without hiding authored outcomes": the authored outcome now carries `continuation: { source: "subagent" }`. The input is still hidden and the outcome still shown. - `chat-display-projection.automation-repair.test.ts` restart case: the live pending state is now `"restart"` instead of `true`, and the history and live rows also carry `continuation: { source: "restart" }`. This also proves that the fact carries across live appends. **Suites run green on this head:** `src/gateway/chat-display-projection*.test.ts`, `src/gateway/session-history-*.test.ts`, `src/gateway/server.chat-history-cursor.test.ts`, `src/gateway/chat-history-*.test.ts`, and all of `ui/src/pages/chat` except `composer-native-drop.browser.test.ts`. That file fails the same 4 cases on the merge base, so this PR did not cause it. **Gates:** `pnpm check:test-types`, `pnpm tsgo:core`, `pnpm tsgo:ui`, oxlint and oxfmt on changed files (0 new findings), `pnpm ui:i18n:verify`, `pnpm check:test-lines-ratchet` (+352 of 400), `git diff --check`, `rg` for the removed `isProjectedHistoryTurnBoundaryMessage` (no references left). No CSS changed. `pnpm ui:check-performance:base` against the merge base: chat boot JS +979 B, new-session boot JS +390 B, largest JS chunk +232 B; the three budgets in `scripts/check-control-ui-performance.mts` are raised by those measured amounts plus 64 B. CSS and request-count warnings are inherited from `main` and unchanged by this PR. **Real-session check:** the design memo's scratch pipeline (real Gateway projection plus the real UI chain over the real 7-prompt session's rows, metadata only) goes from 14 assistant units on main to **7 units for 7 prompts** on this head, with a Resumed rule at each of the 6 wakes. **Proof tiers and gaps:** - Tier used: `ocx test` (vitest from source) plus the Control UI e2e harness (Vite from source, mocked Gateway transport, real Gateway projection code for the fixture). - **Real-Gateway E2E** (`ocx src`, isolated scratch Gateways, real model `openai/gpt-5.5` on the OpenClaw runtime), merge base vs this head with the same prompt: two background `exec` commands, each followed by `sessions_yield`, then more commands and an answer, then a second prompt. Base: 4 assistant blocks for 2 prompts, no Resumed rules. This head: 2 blocks with 2 "Resumed · … later · Background command finished" rules, and the same after a reload (history projection). Screenshots: openclaw#200056 (comment) - Not run live: subagent-settle and Gateway-restart wakes (covered by the projection and UI tests above); a group session with the avatar column (the fixture screenshots cover it). - Not covered: Android output was not re-run. It is unchanged by construction (see above). - Production delta (non-test, non-docs): +230 / −99 lines, much of it re-indentation in `chat-agent-run-frame.tsx`. Co-authored-by: Ayaan Zaidi <[email protected]>





What Problem This Solves
Fixes: one piece of autonomous agent work renders as a stack of separate assistant blocks (each with its own avatar, gap and footer, often holding a single "4 commands" row) when a background command, a Gateway restart or a subagent wakes the session.
User Impact
User impact: work the agent picks up again on its own stays in the block of the prompt that started it. A thin Resumed · 3m 40s later · Background command finished rule marks each place it picked up again (other labels: Gateway restarted, Agent finished). An answer the agent already gave stays in place above the rule. A heartbeat, a scheduled automation, or a message from another person or session still starts its own block.
Why This Change Was Made
Root cause. When a wake input is hidden, the Gateway projection stamps
__openclaw.turnBoundary: trueon the next visible row (attachProjectedTurnBoundaryinsrc/gateway/chat-display-projection.history.ts). The Control UI reads that flag as "a new user turn", which closes the open frame before the existingsessions_yieldhandoff 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 indocs/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.
projectedHistoryTurnBoundary(replacesisProjectedHistoryTurnBoundaryMessage) classifies the hidden input: a heartbeat starts a turn (true); aninternal_systemwake withsourceToolexecorrestart, or aninter_sessionsubagent_settlewake, 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, forwardedsessions_sendinput, steering notes and other initiators are unchanged.chatItemStartsUserTurnno longer counts a row with a continuation fact (the fact takes precedence overturnBoundary); the grouper reuses the same predicate.projectSessionsYieldItemsinserts the existing invisible handoff boundary before the resumed row when nosessions_yieldalready opened one, socoalesceAgentRunFramesjoins 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.ChatHandoffResumerule (same component and CSS) above the first part of each continuation, labelled by source. Asessions_yieldwith a spoken acknowledgment keeps its existing rule and gets no second one. New strings are inen.tsonly.chat-thread-grouping.test.ts, "keeps the earlier answer visible when a late exec completion starts the follow-up turn") is unchanged and green.restartis a continuation.coalesceAgentRunFrames.Android: unchanged by construction. Android reads only
__openclaw.turnBoundary(ChatController.kt, used byChatTimeline*andChatWorkedSummary*). Exec and restart rows keepturnBoundary: trueand gain only the extracontinuationkey, which Android ignores. Subagent-settle rows never hadturnBoundaryand 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.turnBoundaryPendingis in-memory paging state; its type widens frombooleantoboolean | "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: thestartsProjectedTurncheck).git merge-treeagainst the current #198133 head reports one textual conflict, inui/src/pages/chat/components/chat-handoff-sessions.tsx(ChatHandoffResumeprops); 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.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".Regression tests, red on the merge base and green on this head (
ocx test, vitest from source):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 (nocontinuationfact); the heartbeat case staysturnBoundaryonly.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 newpartContinuationhelper stubbed, since base lacks it).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.chat-continuation-wakes.e2e.test.tsasserts 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 hiddensessions_yieldresult 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 carriescontinuation: { source: "exec" }.continuation: { source: "exec" };turnBoundaryis unchanged; the heartbeat case is unchanged.continuation: { source: "subagent" }. The input is still hidden and the outcome still shown.chat-display-projection.automation-repair.test.tsrestart case: the live pending state is now"restart"instead oftrue, and the history and live rows also carrycontinuation: { 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 ofui/src/pages/chatexceptcomposer-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,rgfor the removedisProjectedHistoryTurnBoundaryMessage(no references left). No CSS changed.pnpm ui:check-performance:baseagainst the merge base: chat boot JS +979 B, new-session boot JS +390 B, largest JS chunk +232 B; the three budgets inscripts/check-control-ui-performance.mtsare raised by those measured amounts plus 64 B. CSS and request-count warnings are inherited frommainand 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:
ocx test(vitest from source) plus the Control UI e2e harness (Vite from source, mocked Gateway transport, real Gateway projection code for the fixture).ocx src, isolated scratch Gateways, real modelopenai/gpt-5.5on the OpenClaw runtime), merge base vs this head with the same prompt: two backgroundexeccommands, each followed bysessions_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)chat-agent-run-frame.tsx.