Skip to content

fix(ui): prune the live cli-assistant segment when its row persists mid-run - #180956

Closed
A-Raphie wants to merge 2 commits into
openclaw:mainfrom
A-Raphie:fix/webchat-cli-row-prunes-live-segment
Closed

A-Raphie wants to merge 2 commits into
openclaw:mainfrom
A-Raphie:fix/webchat-cli-row-prunes-live-segment

Conversation

@A-Raphie

@A-Raphie A-Raphie commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #180927. In a Control UI webchat session on a CLI backend with block streaming off, the assistant reply appeared twice: the live stream bubble kept the partial text while the durable row, persisted mid-run, was admitted beside it. The reporter measured the corresponding gateway failure 360 times in one day.

The pane already clears the live stream when a persisted row owns the active run — but that ownership check requires an explicit envelope run id (event.runId / row metadata), and the mid-run transcript publish can omit it. CLI assistant rows are self-proving: the Gateway stamps the run id into the persisted idempotency key (cli-assistant:<runId>), which the projection layer already canonicalizes into the row's run id.

What Changed

ui/src/pages/chat/session-message-apply.ts only:

  • A persisted CLI assistant row (role: assistant, api: "cli") whose canonical idempotency-key run id is present now qualifies as producer-owned for the matching active run, even when the envelope omits the run id.
  • That ownership feeds the existing persistence path, which clears the live stream so the durable row replaces the bubble instead of duplicating it.

The first revision of this PR keyed a different stream owner (chatStreamSegments) that the CLI assistant flow does not write; that path is gone. No other surface changes: rows without CLI provenance keep the terminal-stream behavior, and no delivery path gains or loses a send.

Evidence

Red/green regression (session-message-apply.test.ts, real pane event path: live chatStream filled, then the persisted session.message row):

fix applied (9caa2aab):  ✓ 10 passed (10)
  - clears the live stream when a cli assistant row persists mid-run (without an envelope run id)
  - clears the live stream when a cli assistant row persists mid-run (with a matching envelope run id)
  - keeps the live stream for mid-run persisted rows without cli provenance

fix reverted, same tests:  × clears the live stream ... (without an envelope run id)
  Tests  1 failed | 9 passed (10)

Adjacent suites after the change:

session-message-apply + chat-pane-{session,snapshot}-hydration + tool-stream-fallback: 57 passed (57)

@clawsweeper

clawsweeper Bot commented Oct 22, 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.

@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 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR lets a persisted CLI assistant row replace its matching live reply without an explicit envelope run ID.

Example: Run cli-run-1 displays “Partial answer” when an assistant row with api=cli and idempotencyKey=cli-assistant:cli-run-1 arrives without an envelope or metadata run ID.

  • Before: The pane rejects the saved row and retains the live reply.
  • After: The pane admits the saved row and clears the live reply.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The corrected patch is focused and has no demonstrated introduced defect, but required behavior proof is absent and the deliberate terminal-contract exception awaits an owner decision.
Proof confidence 🧂 unranked krab (1/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Needs a maintainer decision · Fix scope: Partial
User problem: A CLI-backed Control UI turn reportedly shows the same answer twice despite a single saved assistant row.
Reason: The targeted transition is useful, but it broadens the terminal-reconciliation behavior deliberately established in #175570 without an owner decision approving that exception.

Merge readiness

⛔ Blocked before merge - 2 items remain

Keep this PR open: the earlier stream-owner finding is resolved, but the CLI exception changes an intentional reconciliation contract and needs an owner decision.

Priority: P2
Reviewed head: e232ab10c16f2f47be7c82cce633fa5f4339cdb7
Owner decision: Required. See Decision needed.

Decision needed

  • Question: Should a CLI assistant row retire the active live reply without the explicit outer terminal run identity required by the existing contract?
  • Recommendation: Preserve explicit terminal ownership: Retain the established retirement boundary and use the actual failing publication to locate any missing producer or terminal identity.
  • Why: The owner-authored terminal reconciliation deliberately preserves metadata-only continuations, and no owner approval on this PR or its linked issue authorizes the CLI exception.

Before merge

  • Add real behavior proof - The pane event harness seeds chatStream and synthetic persistence events, with reported red/green results supporting that transition; the inspected media covers older steering and progress fixes. Supply before/after screenshots or a recording with correlated Gateway event output for this CLI duplicate case, redacting IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.

Findings

None.

Tests

  • Missing end-to-end proof: Show the reported CLI-backed Control UI turn with block streaming off producing two visible copies before and one after, correlated with the actual saved row’s producer and terminal identities.
Agent review details

How this fits together

Gateway chat deltas populate the live reply while persisted session.message events enter the pane’s transcript reducer, which reconciles the copies shown in the conversation.

flowchart TD
  A[CLI backend] --> B[Gateway chat deltas]
  B --> C[Live reply]
  A --> D[Transcript persistence]
  D --> E[Session message event]
  E --> F[Pane reconciliation]
  C --> G[Visible conversation]
  F --> G
Loading

Technical review

Best possible solution:

Keep reconciliation in the existing pane owner and repair the demonstrated producer or terminal-identity gap unless its owner approves a CLI-specific retirement contract.

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

The synthetic pane event demonstrates the changed transition, but the current-main producer path supplies run metadata and no correlated product reproduction establishes the input responsible for the reported duplicate.

Is this the best way to solve the issue?

The revision uses the correct existing owner and adds no parallel machinery, but its inferred-identity exception should follow an owner decision about the intentional terminal boundary.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Patrick Erichsen: Raw commit 5a9d902 adds ui/src/pages/chat/session-message-apply.ts:83 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 5a9d9020fd37; files: ui/src/pages/chat/session-message-apply.ts)

PR surface

Source +15, Tests +73. Total +88 across 2 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 1 17 2 +15
Tests 1 73 0 +73
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 90 2 +88

Labels

Label changes:

No label changes.

Label justifications:

  • P2: The reported duplicate display confuses an otherwise functioning chat workflow without demonstrated message loss or a blocked first run.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

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 (2 earlier review cycles)
  • reviewed 2026-10-22T20:40:37.839Z sha 80dc20d86d5316977e953c5b78870b3f0f7b3f6c :: needs real behavior proof before merge. :: [P2] Target the CLI current-stream owner instead of keyed commentary
  • reviewed 2026-10-23T00:48:41.793Z sha 9caa2aa :: needs real behavior proof before merge. :: none

Reviewed October 22, 2026, 9:24 PM ET / October 23, 2026, 01:24 UTC (Revision 3).

A CLI-backed webchat turn showed its answer twice with block streaming
off: the live stream kept the partial text while the durable row was
admitted beside it, because producer ownership requires an explicit
envelope run id and the mid-run transcript publish can omit it. CLI
assistant rows carry the run id in their server-stamped idempotency key
(cli-assistant:<runId>), so accept that canonical run id as producer
ownership and let the existing persistence path replace the live stream.
Rows without CLI provenance keep the terminal-stream behavior.
@A-Raphie
A-Raphie force-pushed the fix/webchat-cli-row-prunes-live-segment branch from 80dc20d to 9caa2aa Compare October 23, 2026 00:41
@A-Raphie

Copy link
Copy Markdown
Contributor Author

Restructured per the review (head 9caa2aa): the keyed-segment fallback is removed — the review was right that CLI assistant deltas own chatStream, not keyed segments.

The actual gap: the pane's existing stream-clear requires an explicit envelope run id, and the mid-run transcript publish can omit it. CLI assistant rows are self-proving — the Gateway stamps the run id into the persisted idempotency key (cli-assistant:<runId>) and the projection layer already canonicalizes it — so the fix accepts that canonical run id as producer ownership inside session-message-apply.ts, and the existing persistence path clears the live stream. Rows without CLI provenance keep the terminal-stream behavior (covered by both the pre-existing test and a new guard).

Red/green: reverting the fix fails exactly the no-envelope-run-id regression; 10/10 in the file, 57/57 across the adjacent suites.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 23, 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 23, 2026
@A-Raphie

Copy link
Copy Markdown
Contributor Author

check-lint fix pushed (the new assertion read a dangling-underscore member; it now spells the expected metadata literally). CI should go green on this head.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 23, 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. labels Oct 23, 2026
@clawsweeper clawsweeper Bot removed clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 23, 2026
@A-Raphie

Copy link
Copy Markdown
Contributor Author

Friendly nudge: re-review was queued on this head (e232ab1) several days ago and no verdict has landed since. CI gate is fully green on the current head. @clawsweeper re-review

@roboclaw-bot

Copy link
Copy Markdown
Collaborator

Thanks @A-Raphie for identifying the CLI persistence/live-reply gap. Landed the focused replacement in #190655, preserving your co-author credit. The pane-event regression fails on main before the fix and passes afterward; exact-head CI is green. Closing this PR as superseded by the merged replacement.

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 P2 Normal backlog priority with limited blast radius. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebChat shows the CLI assistant reply twice when block streaming is off

2 participants