Skip to content

fix: preserve WebChat reply context after reloads - #122169

Merged
jalehman merged 10 commits into
mainfrom
fix/webchat-persisted-replies
Aug 11, 2026
Merged

jalehman merged 10 commits into
mainfrom
fix/webchat-persisted-replies

Conversation

@jalehman

@jalehman jalehman commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where WebChat users replying to an earlier message would lose the visible reply context after sending or reloading history. Replies to messages outside the currently loaded history window also had no reliable way to reveal their target.

Why This Change Was Made

The Gateway now persists bounded reply metadata with user turns, and WebChat reconstructs reply previews from persisted history. Selecting a reply preview resolves unloaded targets by fetching older history, then scrolls to and highlights the original message without changing the model-visible message text.

AI-assisted: Yes (Codex).

User Impact

Reply context remains visible after send, refresh, and session reload. Users can select a reply preview to navigate to its source even when that message was not initially loaded.

Evidence

  • Live-tested the send, reload, target-reveal, scroll, and highlight flows in WebChat.
  • Focused suites: 625 tests passed (217 Gateway, 364 UI, 44 isolated UI/unit).
  • Exact changed-file gate passed in Testbox tbx_01kzrwj8pbyaymepq1bbe7zag7, including core/core-test/UI typechecks, all lint shards, API baselines, dead-code, i18n, import-cycle, and policy guards.
  • Gate run: https://github.com/openclaw/openclaw/actions/runs/31515780870
  • Autoreview reported no actionable findings (0.98 confidence) on the complete feature diff before the metadata helper extraction. Two follow-up helper invocations failed at the Codex engine boundary without producing review findings; focused tests and the full repository gate passed after that extraction.

@clawsweeper

clawsweeper Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime size: XL maintainer Maintainer-authored PR labels Aug 11, 2026
@jalehman
jalehman force-pushed the fix/webchat-persisted-replies branch from 80dd8cb to 253cbfe Compare August 11, 2026 17:37
@jalehman
jalehman marked this pull request as ready for review August 11, 2026 17:37
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 11, 2026
@clawsweeper

clawsweeper Bot commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed August 11, 2026, 3:04 PM ET / 19:04 UTC.

ClawSweeper review

What this changes

The PR stores WebChat reply metadata in user-turn transcripts and adds reply previews that can fetch, reveal, and highlight source messages after reload or history pagination.

Merge readiness

⛔ Blocked by patch quality or review findings - 6 items remain

Keep this PR open: both blockers from the prior ClawSweeper review remain on the current head, so the advertised reload and navigation behavior is still incomplete.

Priority: P2
Reviewed head: 232d3be2a213db9702a512463eadc13fb545cdde

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The implementation has two reproducible correctness gaps in the durable reply flow despite the supplied test and live-test claims.
Proof confidence 🌊 off-meta tidepool Not applicable: The repository state identifies the author as a MEMBER; the PR body also reports live WebChat testing, but this maintainer PR is not subject to the external-contributor proof gate.
Patch quality 🦪 silver shellfish (2/6) 2 actionable review findings remain.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The repository state identifies the author as a MEMBER; the PR body also reports live WebChat testing, but this maintainer PR is not subject to the external-contributor proof gate.
Evidence reviewed 5 items Replacement write hooks still discard reply metadata: The transcript writer snapshots idempotency, ownership, transport, media, and layout before invoking a replacement hook, but does not snapshot or restore the new reply fields; a hook returning a fresh __openclaw object therefore loses replyToId and replyToPreview.
Existing hook fixture proves replacement is supported: The current persistence test deliberately returns a replacement user message with only hook-owned metadata, but its assertions cover the older protected fields and not the newly added reply fields.
Search-hidden targets take the silent navigation path: Navigation stops paging as soon as the target exists in unfiltered state.chatMessages, but the reveal map is built only from filtered transcript items; with active search hiding the source, revealMessage has no row and the click yields no visible outcome.
Findings 2 actionable findings [P1] Restore reply metadata after replacement write hooks
[P2] Reveal reply targets hidden by chat search
Security None None.

How this fits together

WebChat sends a user reply through the Gateway, which writes transcript metadata that is later projected into the Control UI history. The UI then renders the reply preview and either finds the source locally or loads older history before scrolling to it.

flowchart LR
A[WebChat reply action] --> B[Gateway chat send]
B --> C[User-turn transcript]
C --> D[History projection]
D --> E[Reply preview]
E --> F[Find or load source]
F --> G[Scroll and highlight]
Loading

Before merge

  • Restore reply metadata after replacement write hooks (P1) - Snapshot and restore replyToId and replyToPreview with the other durable metadata. A supported before_message_write hook may return a fresh user message with its own __openclaw object, and the current protected-field merge omits both new fields, so reload loses the reply context this PR adds.
  • Reveal reply targets hidden by chat search (P2) - When search filters the source row out, it remains in state.chatMessages, so this loop stops before paging; however the transcript's row map has no filtered source and revealMessage returns false. Clear or relax the filter before reveal, or surface the unavailable state, so the click is not silent.
  • Resolve merge risk (P1) - Durable reply metadata changes session transcript state, so replacement write hooks must preserve it or upgraded users silently lose the newly promised context.
  • Resolve merge risk (P1) - The bug-fix branch has a production delta of +523 lines; the persistence and reveal behavior warrant some growth, but the two missing owner-boundary cases should be fixed before accepting that added surface.
  • Improve patch quality - Add a failing-before replacement-hook regression that verifies persisted reply metadata survives.
  • Improve patch quality - Add a search-active navigation regression that proves a clicked preview reaches its source or reports an intentional unavailable state.

Findings

  • [P1] Restore reply metadata after replacement write hooks — src/sessions/user-turn-transcript.ts:317-333
  • [P2] Reveal reply targets hidden by chat search — ui/src/pages/chat/chat-pane-history.ts:175-207
Agent review details

Security

None.

PR surface

Source +523, Tests +298, Generated 0. Total +821 across 43 files.

View PR surface stats
Area Files Added Removed Net
Source 19 731 208 +523
Tests 6 303 5 +298
Docs 0 0 0 0
Config 0 0 0 0
Generated 18 18 18 0
Other 0 0 0 0
Total 43 1052 231 +821

Review metrics

Metric Value Why it matters
Production versus test delta production +731/-208 (net +523); tests +303/-5; generated baselines +18/-18 The bug fix adds a substantial transcript-to-UI flow, so the two remaining owner-boundary failures should be resolved before accepting the production growth.

Stored data model

Persistent data-model change detected: serialized state: src/sessions/user-turn-transcript.metadata.ts, serialized state: src/sessions/user-turn-transcript.ts, serialized state: src/sessions/user-turn-transcript.types.ts, serialized state: ui/src/pages/chat/components/chat-thread.measure.test.ts, unknown-data-model-change: src/sessions/user-turn-transcript.metadata.ts, unknown-data-model-change: src/sessions/user-turn-transcript.ts, and 3 more. Confirm migration or upgrade compatibility proof before merge.

Mantis proof suggestion

A WebChat transcript can directly show reply context surviving reload and navigation to an initially unloaded source after the two code blockers are repaired. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis web UI chat proof: verify reply context survives reload and capture navigation from a reply preview to an initially unloaded source message.

Merge-risk options

Maintainer options:

  1. Repair persistence and filtered navigation (recommended)
    Restore reply metadata after replacement hooks and make an active search query reveal or intentionally report a clicked source before merging.

Technical review

Best possible solution:

Preserve replyToId and replyToPreview at the transcript writer's replacement-hook boundary, then make reply navigation reveal a source that search currently filters out rather than treating it as already visible.

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

Yes, from source: a supported before_message_write hook that returns a replacement user message drops the new reply fields, and an active chat search can hide an otherwise loaded reply target from navigation.

Is this the best way to solve the issue?

No: the transcript owner and existing Gateway lookup are the right seams, but the PR must preserve the new durable fields through replacement hooks and handle search-filtered targets before it is the best fix.

Full review comments:

  • [P1] Restore reply metadata after replacement write hooks — src/sessions/user-turn-transcript.ts:317-333
    Snapshot and restore replyToId and replyToPreview with the other durable metadata. A supported before_message_write hook may return a fresh user message with its own __openclaw object, and the current protected-field merge omits both new fields, so reload loses the reply context this PR adds.
    Confidence: 0.99
  • [P2] Reveal reply targets hidden by chat search — ui/src/pages/chat/chat-pane-history.ts:175-207
    When search filters the source row out, it remains in state.chatMessages, so this loop stops before paging; however the transcript's row map has no filtered source and revealMessage returns false. Clear or relax the filter before reveal, or surface the unavailable state, so the click is not silent.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 79701dfc84b9.

Labels

Label justifications:

  • P2: Reply context and navigation fail in supported but bounded WebChat scenarios rather than causing a general runtime outage.
  • merge-risk: 🚨 compatibility: The PR adds durable transcript metadata that must survive existing write-hook behavior and remain harmless for older history.
  • merge-risk: 🚨 session-state: Reply identity and preview data are persisted and reconstructed across session reloads.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🌊 off-meta tidepool and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Not applicable: The repository state identifies the author as a MEMBER; the PR body also reports live WebChat testing, but this maintainer PR is not subject to the external-contributor proof gate.

Evidence

Acceptance criteria:

  • [P1] node scripts/run-vitest.mjs src/sessions/user-turn-transcript.persistence.test.ts.
  • [P1] node scripts/run-vitest.mjs src/gateway/server-methods/chat.directive-tags.test.ts.
  • [P1] node scripts/run-vitest.mjs ui/src/pages/chat/components/chat-thread.measure.test.ts.
  • [P1] node scripts/run-vitest.mjs ui/src/pages/chat/chat-pane-history.test.ts.

What I checked:

  • Replacement write hooks still discard reply metadata: The transcript writer snapshots idempotency, ownership, transport, media, and layout before invoking a replacement hook, but does not snapshot or restore the new reply fields; a hook returning a fresh __openclaw object therefore loses replyToId and replyToPreview. (src/sessions/user-turn-transcript.ts:317, 232d3be2a213)
  • Existing hook fixture proves replacement is supported: The current persistence test deliberately returns a replacement user message with only hook-owned metadata, but its assertions cover the older protected fields and not the newly added reply fields. (src/sessions/user-turn-transcript.persistence.test.ts:273, 232d3be2a213)
  • Search-hidden targets take the silent navigation path: Navigation stops paging as soon as the target exists in unfiltered state.chatMessages, but the reveal map is built only from filtered transcript items; with active search hiding the source, revealMessage has no row and the click yields no visible outcome. (ui/src/pages/chat/chat-pane-history.ts:175, 232d3be2a213)
  • The existing message lookup is an appropriate supported seam: Current main defines chat.message.get with bounded lookup parameters and explicit unavailable results, and its handler validates the selected agent and projects only visible history before returning a message. (packages/gateway-protocol/src/schema/logs-chat.ts:67, 79701dfc84b9)
  • Current-main and provenance check: Current main is 79701df and did not change the affected transcript or reply-navigation paths after this PR's base; blame attributes the current transcript hook-preservation implementation to the recent area history below. (src/sessions/user-turn-transcript.ts:304, 18f126326a39)

Likely related people:

  • steipete: Current-main blame attributes the transcript hook-preservation path to 18f1263, and recent UI history attributes the chat-thread path to e7ceb5a. (role: recent area contributor; confidence: high; commits: 18f126326a39, e7ceb5aeb03a; files: src/sessions/user-turn-transcript.ts, ui/src/pages/chat/components/chat-thread.ts, ui/src/pages/chat/chat-pane-history.ts)

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-08-11T18:10:27.911Z sha 253cbfeba31ea53809173db7bc1b3432d6cf9a7b :: found issues before merge. :: [P1] Preserve reply metadata after write hooks replace the turn | [P2] Handle a reply source hidden by chat search

@jalehman
jalehman force-pushed the fix/webchat-persisted-replies branch 3 times, most recently from 232d3be to 94731e6 Compare August 11, 2026 21:25
@jalehman
jalehman force-pushed the fix/webchat-persisted-replies branch from 94731e6 to 4ee9994 Compare August 11, 2026 21:28
@jalehman
jalehman enabled auto-merge (squash) August 11, 2026 21:38
@jalehman jalehman self-assigned this Aug 11, 2026
@jalehman

Copy link
Copy Markdown
Contributor Author

Resolved the current-main conflicts and every actionable item from the latest completed ClawSweeper review:

  • replacement before_message_write hooks now preserve replyToId and bounded replyToPreview metadata;
  • guarded transcript rows use the live reply-navigation callback, so a search-hidden source clears the filter before pane-owned navigation;
  • both cases have failing-before regressions;
  • 623 focused session/Gateway/UI tests pass;
  • Plugin SDK API baselines regenerate and verify cleanly;
  • exact-diff autoreview and trufflehog are clean.

The production growth is the durable history/navigation capability itself (+758/-214 production, +373/-5 tests, generated net 0); the blocker repairs reuse the existing transcript metadata and live render-context owners rather than adding parallel state or navigation paths. Exact-head CI for ef6b026a879d11d092c1088abb833696a9fe4e0e remains the final merge gate.

@jalehman
jalehman merged commit 5855038 into main Aug 11, 2026
120 checks passed
@jalehman
jalehman deleted the fix/webchat-persisted-replies branch August 11, 2026 22:42
vincentkoc added a commit that referenced this pull request Aug 11, 2026
* origin/main: (1725 commits)
  fix(agents): preserve reply cleanup when cancellation throws (#122252)
  fix(ui): render disallowed link schemes as plain text (#122311)
  fix(test): isolate gateway helper env stubs (#122319)
  fix(ui): keep chat Markdown block rhythm consistent (#122289)
  test(cli): trim duplicate Hooks process cases (#122278)
  fix(ui): retain identity while agent roster loads
  fix(ui): preserve configured agent labels
  fix(plugins): keep startup convergence read-only (#122330)
  fix: preserve WebChat reply context after reloads (#122169)
  fix(ui): make DONE moves visibly reversible (#122303)
  fix(ui): keep inline-code punctuation attached (#122291)
  fix(google-meet): publish exports atomically (#122306)
  fix(channels): preserve failed agent run reactions (#122009)
  fix(ui): label patch file operations accurately (#122287)
  fix(windows): preserve Unicode LAN route aliases (#122263)
  test(media): synchronize transcode pool completion (#122279)
  fix(android): keep completed subagent activity visible for sixty seconds (#122089)
  fix(ui): humanize bare GitHub item links (#122285)
  refactor(qqbot): install plugin from Tencent package (#107295)
  chore: scope SQLite session lifecycle CI (#121917)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 12, 2026
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 maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: XL 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