Skip to content

fix(chat): keep final replies single after refresh and reconnect - #147080

Merged
obviyus merged 2 commits into
mainfrom
bugloop/chat-final-duplicate
Sep 13, 2026
Merged

obviyus merged 2 commits into
mainfrom
bugloop/chat-final-duplicate

Conversation

@obviyus

@obviyus obviyus commented Sep 13, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Final replies could appear twice after a mid-turn refresh or reconnect. Fixes #138735. Reported by @PanyhP.

Replaces #138887 with the remaining display fix; cursor recovery is already fixed on main.

Why This Change Was Made

One item-aware matcher in session-projection.ts decides which display row owns a final. The other writer of this state is history replay; item identity and transcript order decide adoption. Commentary and tool continuations cannot adopt an unkeyed final.

User Impact

A final appears once after refresh or reconnect. Distinct items with equal text remain separate.

Evidence

Real Gateway and built Control UI: mid-turn refresh/reconnect changed from two final blocks to one. Completed-turn refresh stays at one. Refresh command: bunx [email protected] --session "$session" reload.

Compatibility

Stored transcripts, protocol fields, schemas and preferences are unchanged. Apple decoding was inspected: its inputs and independent rows are unchanged; no device run is claimed.

Consumers

Control UI and terminal UI use the shared matcher.

Invalidation

Live delivery and full-history replay share item ownership; existing reconnect and history reset rules remain.

Tests

Client: 388 passed. Display projection: 143 passed. Terminal UI: 210; Control UI: 139 passed, on the merge with main. New reducer regressions failed before the fix and pass afterward.

node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-client.config.ts packages/gateway-client/src

Review scope and evidence

  • The reviewed head is f05f513, a fresh merge of fix 6768058 with main 9746e39.
  • The failing browser baseline is e735dcd. Real Gateway and matching built Control UI captures show two final blocks after a mid-turn refresh or reconnect on the baseline, and one on the reviewed head. Completed-turn refresh remains one; two separate same-text replies remain two.
  • The 880 focused tests passed on that merge: Gateway client 388, display projection 143, terminal UI 210, and Control UI 139. Full hosted checks also passed on this head in CI run 34762715688.

Ownership and compatibility

  • entryMatches in packages/gateway-client/src/session-projection.ts owns display-row adoption for live delivery and full-history replay. The existing snapshot terminal selector only narrows candidates admitted by that matcher. History, live events, pending sends, and sequenced error recovery retain their existing ordering rules.
  • The tool-continuation predicate also checks tool content, so missing or misleading stopReason values cannot make a tool row own an unkeyed final. The change adds 17 net production lines and 60 test lines.
  • The merged fix(ui): keep assistant messages intact while tools run #146554 behavior remains: tool activity does not retire an unfinished assistant stream. Its continuous-stream and completed-message assertions still pass.
  • Apple clients use independent Swift row identity and do not decode display-part item IDs. This PR changes neither their code nor their received payloads and does not restore the old multi-payload broadcast. Native conclusions are source-only; no device run is claimed.
  • Cursor commentary recovery is already fixed on main. Stored transcripts, commentary preferences, schemas, config keys, protocol fields, and public SDK contracts are unchanged. This replaces the remaining display work in fix(chat): keep replies stable across history refresh #138887.

@clawsweeper

clawsweeper Bot commented Sep 13, 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 size: S maintainer Maintainer-authored PR labels Sep 13, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 13, 2026
@clawsweeper

clawsweeper Bot commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 13, 2026, 10:32 AM ET / 14:32 UTC (Revision 2).

ClawSweeper review

What this changes

The shared chat client preserves distinct commentary items and prevents tool continuations from absorbing final replies during refresh and reconnect.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused repair; fetched main and the latest release still lack its matching safeguards. No blocking defect was found, and the prior draft-only blocker is resolved.

Priority: P2
Reviewed head: f05f513b69c158c77cf7cc6024610b7459851ce9

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused owner-level repair with meaningful reducer regressions and useful real-instance visual evidence; no blocking defect was found.
Proof confidence 🐚 platinum hermit (4/6) ✨ media proof bonus Sufficient (screenshot): The PR reports real Gateway/built Control UI refresh and reconnect runs yielding one final reply; inspected predecessor before/after screenshots corroborate that visible result and preserved commentary. Media provenance remains with the linked predecessor, and its videos were not independently inspected.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (screenshot): The PR reports real Gateway/built Control UI refresh and reconnect runs yielding one final reply; inspected predecessor before/after screenshots corroborate that visible result and preserved commentary. Media provenance remains with the linked predecessor, and its videos were not independently inspected.
Evidence reviewed 8 items Pinned change ownership: The complete host-provided merge-base-to-head patch establishes the introduced changes. The separately verified test merge preserves its main parent's unrelated work and changes only the same reconciliation files.
Repair remains necessary on fetched main: Comparison against fetched main shows that its matcher still checks transcript identity before commentary item identity and permits tool continuations to match unkeyed finals. Reading the complete patched matcher and terminal reconciliation owner found no competing implementation or introduced correctness defect.
Latest-release check: The v2026.9.4 matcher also lacks both safeguards. The local release object was unavailable, so its source was inspected through GitHub's contents API; no shipped fix is claimed.
Findings None None.
Security None None.

How this fits together

The shared Gateway client combines saved conversation history with live messages for Control UI and terminal UI. Its reconciliation rules determine which displayed rows survive replay and which provisional replies are replaced by saved messages.

flowchart TD
  A[Saved conversation history] --> C[Shared chat reconciliation]
  B[Live messages and final replies] --> C
  C --> D{Same item and compatible row?}
  D -->|Yes| E[Retain authoritative saved row]
  D -->|No| F[Preserve distinct messages]
  E --> G[Control UI and terminal UI]
  F --> G
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +17, Tests +60. Total +77 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 26 9 +17
Tests 1 60 0 +60
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 86 9 +77

Review metrics

None.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #138735
Summary: This PR explicitly targets the reported display reconciliation defect; related open proposals overlap, while the merged stream-fragmentation repair addresses a different mechanism.

Members:

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

Technical review

Best possible solution:

Keep item-aware reconciliation in the shared client so saved rows, commentary, and final replies retain their distinct identities without changing stored transcripts or preferences.

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

Yes: current source exposes the shared-transcript-ID collision and overly broad final adoption, and the reducer regression supplies a concrete event sequence. This review did not execute a current-main reproduction.

Is this the best way to solve the issue?

Yes: tightening the existing shared matcher addresses both live delivery and history replay while retaining authoritative transcript identity and distinct equal-text items.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: This repairs duplicate and missing displayed chat content after refresh with a bounded client-side change and no transcript data loss.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (screenshot): The PR reports real Gateway/built Control UI refresh and reconnect runs yielding one final reply; inspected predecessor before/after screenshots corroborate that visible result and preserved commentary. Media provenance remains with the linked predecessor, and its videos were not independently inspected.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR reports real Gateway/built Control UI refresh and reconnect runs yielding one final reply; inspected predecessor before/after screenshots corroborate that visible result and preserved commentary. Media provenance remains with the linked predecessor, and its videos were not independently inspected.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. The PR reports real Gateway/built Control UI refresh and reconnect runs yielding one final reply; inspected predecessor before/after screenshots corroborate that visible result and preserved commentary. Media provenance remains with the linked predecessor, and its videos were not independently inspected.

Evidence

What I checked:

  • Pinned change ownership: The complete host-provided merge-base-to-head patch establishes the introduced changes. The separately verified test merge preserves its main parent's unrelated work and changes only the same reconciliation files. (packages/gateway-client/src/session-projection.ts:254, f05f513b69c1)
  • Repair remains necessary on fetched main: Comparison against fetched main shows that its matcher still checks transcript identity before commentary item identity and permits tool continuations to match unkeyed finals. Reading the complete patched matcher and terminal reconciliation owner found no competing implementation or introduced correctness defect. (packages/gateway-client/src/session-projection.ts:254, bec7b26b8d4c)
  • Latest-release check: The v2026.9.4 matcher also lacks both safeguards. The local release object was unavailable, so its source was inspected through GitHub's contents API; no shipped fix is claimed. (packages/gateway-client/src/session-projection.ts:246, 3a9d69db306c)
  • Producer and consumer contracts: Gateway commentary projection copies parent transcript metadata while assigning separate commentary item IDs. Control UI history-merge and terminal UI both consume the shared reducer. This is an OpenClaw display contract; the introduced patch does not depend on a Codex runtime or protocol change. (src/gateway/chat-display-projection.sanitize.ts:313, f05f513b69c1)
  • Regression coverage: The new reducer table covers live and snapshot arrival, missing or misleading tool stop reasons, equal-text distinct items, final replay, and subsequent history hydration. Existing coverage preserves ambiguous finals and authoritative commentary. The PR reports failing-before/passing-after regressions and focused client/UI/TUI suites; tests were not executed during this read-only review. (packages/gateway-client/src/session-projection-terminal-reconciliation.test.ts:27, f05f513b69c1)
  • Real visible behavior evidence: The captured PR body reports a real Gateway and built Control UI changing mid-turn refresh/reconnect from two final blocks to one, with completed-turn refresh retaining one. Prepared screenshots from the explicitly linked predecessor fix(chat): keep replies stable across history refresh #138887 were inspected: before shows “17 ×2”; after shows one “17”, retaining both commentary items and tool cards. Those media retain their predecessor provenance rather than being represented as fresh captures of this head. Video preparation failed because ffprobe was unavailable; video playback was not independently inspected.

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)
  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-13T14:24:28.516Z sha f05f513 :: needs changes before merge. :: none

@obviyus
obviyus marked this pull request as ready for review September 13, 2026 14:27
@obviyus

obviyus commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator Author

landpr-approve-admin-merge
pr: 147080
head: f05f513
scope: owner-review

@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 13, 2026
@obviyus
obviyus merged commit 908e919 into main Sep 13, 2026
195 checks passed
@obviyus
obviyus deleted the bugloop/chat-final-duplicate branch September 13, 2026 14:47
@obviyus

obviyus commented Sep 13, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @PanyhP!

Proof: Refreshing or reconnecting during a tool-using turn now shows one final answer. Separate replies with identical text remain separate.

  • Bug: A mid-turn refresh or reconnect could show the final answer twice.
  • Fix: Shared chat reconciliation preserves item identity and excludes commentary and tool continuations from final-answer adoption.
Before After
Two copies of the final answer One final answer

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 14, 2026
…nclaw#147080)

## What Problem This Solves

Final replies could appear twice after a mid-turn refresh or reconnect. Fixes openclaw#138735. Reported by @PanyhP.

Replaces openclaw#138887 with the remaining display fix; cursor recovery is already fixed on main.

## Why This Change Was Made

One item-aware matcher in `session-projection.ts` decides which display row owns a final. The other writer of this state is history replay; item identity and transcript order decide adoption. Commentary and tool continuations cannot adopt an unkeyed final.

## User Impact

A final appears once after refresh or reconnect. Distinct items with equal text remain separate.

## Evidence

Real Gateway and built Control UI: mid-turn refresh/reconnect changed from two final blocks to one. Completed-turn refresh stays at one. Refresh command: `bunx [email protected] --session "$session" reload`.

## Compatibility

Stored transcripts, protocol fields, schemas and preferences are unchanged. Apple decoding was inspected: its inputs and independent rows are unchanged; no device run is claimed.

## Consumers

Control UI and terminal UI use the shared matcher.

## Invalidation

Live delivery and full-history replay share item ownership; existing reconnect and history reset rules remain.

## Tests

Client: 388 passed. Display projection: 143 passed. Terminal UI: 210; Control UI: 139 passed, on the merge with main. New reducer regressions failed before the fix and pass afterward.

`node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-client.config.ts packages/gateway-client/src`

## Review scope and evidence

- The reviewed head is f05f513, a fresh merge of fix 6768058 with main 11d57c2.
- The failing browser baseline is 3d98f68. Real Gateway and matching built Control UI captures show two final blocks after a mid-turn refresh or reconnect on the baseline, and one on the reviewed head. Completed-turn refresh remains one; two separate same-text replies remain two.
- The 880 focused tests passed on that merge: Gateway client 388, display projection 143, terminal UI 210, and Control UI 139. Full hosted checks also passed on this head in [CI run 34762715688](https://github.com/openclaw/openclaw/actions/runs/34762715688).

## Ownership and compatibility

- entryMatches in packages/gateway-client/src/session-projection.ts owns display-row adoption for live delivery and full-history replay. The existing snapshot terminal selector only narrows candidates admitted by that matcher. History, live events, pending sends, and sequenced error recovery retain their existing ordering rules.
- The tool-continuation predicate also checks tool content, so missing or misleading stopReason values cannot make a tool row own an unkeyed final. The change adds 17 net production lines and 60 test lines.
- The merged openclaw#146554 behavior remains: tool activity does not retire an unfinished assistant stream. Its continuous-stream and completed-message assertions still pass.
- Apple clients use independent Swift row identity and do not decode display-part item IDs. This PR changes neither their code nor their received payloads and does not restore the old multi-payload broadcast. Native conclusions are source-only; no device run is claimed.
- Cursor commentary recovery is already fixed on main. Stored transcripts, commentary preferences, schemas, config keys, protocol fields, and public SDK contracts are unchanged. This replaces the remaining display work in openclaw#138887.

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

maintainer Maintainer-authored PR 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: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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]: WebChat renders assistant replies twice and drops live text after page refresh (2026.9 segmented streaming)

1 participant