Skip to content

Native chat: cross-turn overwrite + reasoning bubbles + exec.approval delivery + multi-segment dedup - #676

Merged
ranjeshj merged 8 commits into
openclaw:mainfrom
RBrid:user/rbrid/ReasoningReset2
Jun 10, 2026
Merged

ranjeshj merged 8 commits into
openclaw:mainfrom
RBrid:user/rbrid/ReasoningReset2

Conversation

@RBrid

@RBrid RBrid commented Jun 3, 2026 •

Copy link
Copy Markdown
Contributor

Five related fixes for chat timeline rendering and exec-approval delivery, plus a follow-up fix for the rejected exec.approval.resolve response path, all validated by adversarial dual-model code review (Opus 1M + GPT-5.3-Codex) until both converged on no remaining actionable issues.

  1. Cross-turn assistant overwrite (the original repro)

In a user → reply1 → tool-call → tool-output → reply2 flow, reply2 was silently overwriting reply1's text in place instead of appending a new bubble. Cause: the chat.message final for reply2 carried reconcilePrevious=true, and UpsertAssistant's fast-path merged into the most recent assistant entry unconditionally — including a previously finalised one.

Fix in ChatTimelineReducer.UpsertAssistant: narrow reconcile to only merge into entries that are still IsStreaming=true. A finalised assistant entry (IsStreaming=false) belongs to a completed turn and must not be overwritten. The byte-equal duplicate safety net remains unconditional so genuine duplicate emissions still collapse.

Defense-in-depth: extract ClearStreamingAtTurnBoundary helper and call from both AddLocalUser (production typed-input path) and ApplyUserMessage (gateway-injected path), hoisted above the nonce early-return. This handles the dropped-ChatTurnEndEvent scenario where a stale ActiveAssistantId could otherwise leak across turns.

  1. Concatenated thinking prose

The gateway emits a stream:"item", kind:"reasoning", phase:"end" bracket marker between distinct thinking passes within a single turn. Map it to a new ChatReasoningEndEvent that nulls ActiveReasoningId so the next reasoning chunk starts a fresh bubble instead of appending to / replacing the previous one. Also tag delta-state ChatMessageEvents with IsStreaming=true so the reducer's new reconcile guard distinguishes them from finals.

  1. Exec-approval delivery in native chat

Native WinUI chat was silently dropping exec.approval.requested / exec.approval.resolved because the gateway client only forwarded the agent stream, and the tray responder sent /approve as a slash command — which deadlocks while the agent is blocked waiting for that very approval. Net effect: the Allow/Deny banner never appeared, or appeared and did nothing.

  • Gateway client: HandleEvent now translates top-level exec.approval.requested / exec.approval.resolved events into synthetic AgentEventInfo (Stream="approval", phase derived locally from the event name — payload.phase is intentionally ignored). Multi-subscriber invoke isolates per-subscriber exceptions so one throwing handler can't suppress others.
  • New RPC path: IChatGatewayBridge.ResolveExecApprovalAsync calls the exec.approval.resolve RPC. Decision is allowlisted at the send site (allow-once | allow-always | deny).
  • Tray responder: RespondToPermissionAsync swaps the slash command for the RPC. On RPC failure the pending-permission banner is preserved so the user can retry instead of silently losing the prompt.
  1. Trace logging plumbing

Add IOpenClawLogger.Trace verbose channel with a default no-op so existing implementers (tests, console logger, setup logger) don't need updating. Logger.Trace in the tray is gated by OPENCLAW_TRAY_TRACE=1|true. Forward Trace through DiagnosticTeeLogger and AppLogger; SetupOpenClawLogger inherits the default no-op (no opt-in gate available in setup engine). OpenClawGatewayClient now surfaces item-event kind+phase metadata (no payload content) at trace level for shape diagnostics.

  1. Multi-segment chat-bubble duplication (last bubble repeats prior segments)

When a turn produced 3+ assistant segments split by tool calls (A1 → Tool → A2 → Tool → A3), the gateway emits cumulative-for-turn chat.message frames containing every prior segment. The fast-path strip already handled this while ActiveAssistantId was live, but late frames arriving AFTER ApplyTurnEnd cleared ActiveAssistantId came through the scan-back reconcile branch, which wrote the raw cumulative text into the last bubble verbatim. Users observed A3 render correctly first, then mutate to repeat A1+A2's content.

  • ChatTimelineReducer scan-back reconcile merge now calls StripCumulativeTurnPrefix (with excludeIndex=li) so the merge target retains only its own segment tail.
  • Symmetric empty-result guard mirroring the new-bubble path's duplicate-resend skip: if a stale / duplicate cumulative frame is fully consumed by other priors, leave the streaming candidate intact instead of blanking it.
  • StripCumulativeTurnPrefix excludeIndex caller contract documented in xml-doc (self-peel hazard).
  1. exec.approval.resolve response-await + rejected-resolve banner-preserve (ClawSweeper P1 follow-up, commit 77a707f)

Round 5 of the ClawSweeper review flagged that ResolveExecApprovalAsync used SendTrackedRequestAsync, which returns once the WS frame leaves the socket. An ok:false rejection from the gateway was logged and dropped while the chat banner silently cleared, leaving the agent blocked with no retry path.

  • Register a per-requestId TaskCompletionSource in _pendingApprovalResolves and route ok:true / ok:false in HandleResponse so the caller awaits the actual gateway verdict.
  • Disconnect cleanup faults pending TCSes with OperationCanceledException (matches the _pendingWizardResponses cleanup taxonomy). Explicit contract comment notes callers must catch System.Exception (not narrow OCE) to preserve banner-preserve UX, because RunFireAndForget swallows OCE silently.
  • 15s bounded timeout (approval-resolve traverses gateway → operator → optional UI confirm → ack; longer budget than the 5s chat.send sibling). Timeout / send-fail branches call RemovePendingRequest so _pendingRequestMethods does not leak.
  • Task.WhenAny followed by an IsCompleted check rather than a returned-task identity compare, to avoid a same-tick race that would surface a real ok:true / ok:false response as a spurious TimeoutException.
  • Post-send !IsConnected re-check using a TryRemove-first idiom: if we win the race and pull the TCS out of the dict, throw InvalidOperationException immediately (no exception is ever set on the discarded TCS, so no UnobservedTaskException risk); if the cleanup loop already claimed the entry and faulted it with OCE, fall through to the WhenAny path so the cleanup-set exception is observed by the caller. Closes a narrow window where a disconnect between the up-front IsConnected guard and TCS registration would otherwise have stranded the caller for the full 15s timeout.

Coverage matrix for the rejected-resolve / banner-preserve contract

Rejected-resolve path Pinned by test Test file
Gateway returns ok:false with error.message ResolveExecApproval_OkFalseResponse_SurfacesAsException tests/OpenClaw.Shared.Tests/OpenClawGatewayClientApprovalTranslationTests.cs
Gateway returns ok:false with no error.message ResolveExecApproval_OkFalseWithoutErrorMessage_UsesFallback tests/OpenClaw.Shared.Tests/OpenClawGatewayClientApprovalTranslationTests.cs
Gateway returns ok:true (happy path completes await) ResolveExecApproval_OkTrueResponse_CompletesCaller tests/OpenClaw.Shared.Tests/OpenClawGatewayClientApprovalTranslationTests.cs
Disconnected at call time ResolveExecApprovalAsync_ThrowsWhenDisconnected tests/OpenClaw.Shared.Tests/OpenClawGatewayClientApprovalTranslationTests.cs
Unknown decision value ResolveExecApprovalAsync_RejectsUnknownDecision tests/OpenClaw.Shared.Tests/OpenClawGatewayClientApprovalTranslationTests.cs
Tray UX: RPC throws → banner stays visible RespondToPermissionAsync_RpcThrows_BannerPreservedForRetry tests/OpenClaw.Tray.Tests/OpenClawChatDataProviderTests.cs
Tray UX: allow routes RPC + clears banner RespondToPermissionAsync_AllowRoutesAllowOnceThroughRpcAndClearsBanner tests/OpenClaw.Tray.Tests/OpenClawChatDataProviderTests.cs
Tray UX: deny routes RPC + clears banner RespondToPermissionAsync_DenyRoutesDenyThroughRpcAndClearsBanner tests/OpenClaw.Tray.Tests/OpenClawChatDataProviderTests.cs

Test coverage added (cumulative across the PR)

ChatTimelineReducerTests (Shared)

  • StaleStreamingPreview_DoesNotMergeAcrossUserBoundary
  • UserMessage_AsTurnBoundary_PreventsCrossTurnOverwrite
  • AddLocalUser_AsTurnBoundary_PreventsCrossTurnOverwrite
  • AddLocalUser_ClearsStaleStreamingPreviewAcrossTurns
  • IntraTurnLateReconcile_AfterTurnEnd_DoesNotPrependPriorSegments (id-equality assertion locks the test to the in-place merge path)
  • IntraTurnLateReconcile_RegressionCumulative_DoesNotBlankCandidate (defensive blank-guard)

OpenClawGatewayClientApprovalTranslationTests (Shared, 12 tests)

  • Phase mapping for exec.approval.requested / resolved
  • Decision allowlist (IsValidApprovalDecision) — rejects unknown decisions
  • IsConnected precheck — throws when disconnected before send
  • Slug / UUID alt-id wiring for terminal-event matching
  • Multi-subscriber isolation: first subscriber throws, second still invoked
  • Response routing: ok:true completes, ok:false surfaces InvalidOperationException, ok:false without error.message uses fallback

OpenClawChatDataProviderTests (Tray, 3 tests)

  • RespondToPermissionAsync_AllowRoutesAllowOnceThroughRpcAndClearsBanner
  • RespondToPermissionAsync_DenyRoutesDenyThroughRpcAndClearsBanner
  • RespondToPermissionAsync_RpcThrows_BannerPreservedForRetry

Validation (against commit 77a707f)

  • ./build.ps1: succeeds
  • OpenClaw.Shared.Tests: 2142 passed / 29 skipped
  • OpenClaw.Tray.Tests: 1004 passed

Review

Five rounds of adversarial dual-model review (Claude Opus 4.7 1M + GPT-5.3-Codex). Rounds 1–3 covered fixes 1–4. Round 4 on the multi-segment dedup surfaced 3 applied fixes (empty-result guard on the new strip site, id-equality assertion in the regression test, excludeIndex caller-contract xml-doc). Round 5 covered fix 6's ClawSweeper P1 follow-up and surfaced 5 applied fixes (Fix A leak in timeout branch, Fix B OCE taxonomy, Fix D 15s timeout, Fix E IsCompleted check, Fix G→H post-send re-check rework using TryRemove-first idiom) plus 1 documentation fix (Fix I contract comment on the cleanup-loop OCE). Each round converged on both models reporting "ready to commit."

Proof status (per ClawSweeper)

Code review labels: 🐚 platinum hermit (patch quality), 🦪 silver shellfish (overall, capped by proof). Test-only coverage for the rejected-resolve banner-preserve path is pinned by the coverage matrix above; live native-chat proof of a denied / rejected exec.approval.resolve keeping the banner visible is pending Mantis or manual QA. Maintainers may either request live proof, ask Mantis to capture it, or accept test-only coverage and re-review.

Deferred follow-ups (intentional, tracked outside this PR)

  • True bubble-splitting in native chat (rendering N visually separate bubbles per multi-segment turn) — this PR only ensures the merged final bubble contains the correct (last) segment's text without duplicating prior segments.
  • Plugin approvals (plugin.approval.*) — same shape, not exercised by current scenarios.
  • Full strict-send infrastructure replacing the silent-swallow behavior of SendRawAsync — acknowledged in code comments as best-effort.
  • Deeper integration tests for ResolveExecApprovalAsync exercising SerializeRequest, registration ordering, real timeout, and real disconnect paths (current tests use reflection seams against HandleResponse / _pendingApprovalResolves).
  • Sibling-wide hardening of the permissive ok:false detection pattern across _pendingChatSendRequests / _pendingWizardResponses — applying it only to exec.approval.resolve would create inconsistency; needs a focused PR.

Three related fixes for chat timeline rendering, validated by three rounds
of adversarial dual-model code review.

1. Cross-turn assistant overwrite (the original repro)
   In a user -> reply1 -> tool-call -> tool-output -> reply2 flow, reply2
   was silently overwriting reply1's text in place instead of appending a
   new bubble. Cause: the chat.message final for reply2 carried
   reconcilePrevious=true, and UpsertAssistant's fast-path merged into the
   most recent assistant entry unconditionally - including a previously
   finalised one.

   Fix in ChatTimelineReducer.UpsertAssistant: narrow reconcile to only
   merge into entries that are still IsStreaming=true. A finalised
   assistant entry (IsStreaming=false) belongs to a completed turn and
   must not be overwritten. The byte-equal duplicate safety net remains
   unconditional so genuine duplicate emissions still collapse.

   Defense-in-depth: extract ClearStreamingAtTurnBoundary helper and
   call from both AddLocalUser (production typed-input path) and
   ApplyUserMessage (gateway-injected path), hoisted above the nonce
   early-return. This handles the dropped-ChatTurnEndEvent scenario
   where a stale ActiveAssistantId could otherwise leak across turns.

2. Concatenated thinking prose (Option B)
   The gateway emits a stream:"item", kind:"reasoning", phase:"end"
   bracket marker between distinct thinking passes within a single
   turn. Map it to a new ChatReasoningEndEvent that nulls
   ActiveReasoningId so the next reasoning chunk starts a fresh bubble
   instead of appending to / replacing the previous one. Also tag
   delta-state ChatMessageEvents with IsStreaming=true so the reducer's
   new reconcile guard distinguishes them from finals.

3. Trace logging plumbing
   Add IOpenClawLogger.Trace verbose channel with a default no-op so
   existing implementers (tests, console logger, setup logger) don't
   need updating. Logger.Trace in the tray is gated by
   OPENCLAW_TRAY_TRACE=1|true. Forward Trace through DiagnosticTeeLogger
   and AppLogger; SetupOpenClawLogger inherits the default no-op (no
   opt-in gate available in setup engine). OpenClawGatewayClient now
   surfaces item-event kind+phase metadata (no payload content) at
   trace level for shape diagnostics.

Test coverage added in ChatTimelineReducerTests:
- StaleStreamingPreview_DoesNotMergeAcrossUserBoundary
- UserMessage_AsTurnBoundary_PreventsCrossTurnOverwrite
- AddLocalUser_AsTurnBoundary_PreventsCrossTurnOverwrite
- AddLocalUser_ClearsStaleStreamingPreviewAcrossTurns

Validation:
- ./build.ps1: succeeds
- OpenClaw.Tray.Tests: 944 passed
- OpenClaw.Shared.Tests: 2045 passed / 29 skipped

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

clawsweeper Bot commented Jun 3, 2026 •

Copy link
Copy Markdown

Codex review: needs real behavior proof before merge. Reviewed June 9, 2026, 6:52 PM ET / 22:52 UTC.

Summary
The PR changes native chat timeline reconciliation, reasoning boundary handling, exec approval event translation/RPC resolution, trace logging, and shared/tray regression coverage.

Reproducibility: yes. source inspection gives a high-confidence path for the existing behavior: current main reconciles assistant finals broadly and sends approval responses as chat slash commands. I did not run the live native app in this read-only review.

Review metrics: 3 noteworthy metrics.

  • Changed surface: 14 files, +2365/-78. The PR touches shared gateway protocol handling, native chat timeline rendering, tray UI plumbing, and regression tests, so message-delivery review matters before merge.
  • Validation freshness: 3 required commands reported at 77a707f, current head 882a2e3. AGENTS.md requires build, shared tests, and tray tests after changes; later commits mean the body’s validation is stale for the current head.
  • Proof attachments: 3 screenshots inspected. The proof shows visible allowed approval/chat behavior but not the denied or rejected approval retry case that remains merge-relevant.

Merge readiness
Overall: 🦐 gold shrimp
Proof: 🦐 gold shrimp
Patch quality: 🦞 diamond lobster
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted screenshot, recording, terminal output, or logs showing denied or rejected exec.approval.resolve preserves the retry banner, then update the PR body so ClawSweeper re-reviews.
  • [P1] Report the required build, shared tests, and tray tests for head 882a2e3.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: Screenshots show allowed exec approvals and visible native chat bubbles, but not the denied or rejected exec.approval.resolve path preserving the retry banner after the PR changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Mantis proof suggestion
A short native desktop proof would materially show the approval banner behavior that unit tests cannot prove from the contributor's real setup. A maintainer can ask Mantis to capture proof by posting a new PR comment that starts with the OpenClaw Mantis account mention, followed by:

visual task: verify native chat denied or gateway-rejected exec.approval.resolve keeps the approval banner visible for retry with private details redacted.

Risk before merge

  • [P1] The posted screenshots prove visible allowed approvals and chat bubbles, but not the denied or gateway-rejected exec.approval.resolve path that must preserve the retry banner.
  • [P1] The PR changes message reconciliation and approval event delivery; an unproven live edge case could still suppress, duplicate, overwrite, or prematurely clear visible chat or approval entries.
  • [P1] The PR body's reported validation is against 77a707f, while the current head is 882a2e3 after later approval timeline changes, so the AGENTS-required build/shared/tray validation should be refreshed or verified at head.

Maintainer options:

  1. Require approval retry proof (recommended)
    Ask for redacted native chat proof, or a Mantis visual proof, showing a denied or gateway-rejected exec.approval.resolve keeps the approval banner available for retry.
  2. Accept test-only coverage
    Maintainers can intentionally accept the remaining live-proof gap because the PR adds focused reducer, gateway, and tray tests, but that leaves the native transport edge case unproven.

Next step before merge

  • [P1] The remaining blocker is contributor or Mantis real-behavior proof plus maintainer acceptance of the message-delivery risk, not a mechanical code repair.

Security
Cleared: No concrete security or supply-chain concern was found; the diff does not add dependencies, CI execution, secret handling, or broad permission expansion.

Review details

Best possible solution:

Land this after redacted live or Mantis proof covers the approval failure/retry path and the required build, shared tests, and tray tests are reported for the current head.

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

Yes, source inspection gives a high-confidence path for the existing behavior: current main reconciles assistant finals broadly and sends approval responses as chat slash commands. I did not run the live native app in this read-only review.

Is this the best way to solve the issue?

Yes, the proposed code path appears to solve the bug at the right ownership boundary by changing the reducer, gateway translation, and tray approval bridge with targeted tests. The remaining gap is proof and current-head validation rather than an identified code defect.

AGENTS.md: found and applied where relevant.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 753828f63e96.

Label changes

Label justifications:

  • P1: This PR affects native chat message delivery and approval prompts, where regressions can block an active agent workflow for real users.
  • merge-risk: 🚨 message-delivery: Merging this changes timeline reconciliation and approval event routing, so a missed edge case could drop, duplicate, overwrite, or prematurely clear chat/approval messages.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦞 diamond lobster.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: Screenshots show allowed exec approvals and visible native chat bubbles, but not the denied or rejected exec.approval.resolve path preserving the retry banner after the PR changes. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • proof: 📸 screenshot: Contributor real behavior proof includes screenshot evidence. Screenshots show allowed exec approvals and visible native chat bubbles, but not the denied or rejected exec.approval.resolve path preserving the retry banner after the PR changes.
Evidence reviewed

What I checked:

  • Repository policy read: AGENTS.md was read fully; its required validation policy is relevant because this is a behavior-changing PR and the reported validation is not for the current head. (AGENTS.md:1, 753828f63e96)
  • Current main still has broad assistant reconciliation: Current main's UpsertAssistant still merges reconcilePrevious into the most recent assistant entry without the PR's streaming/frontier restrictions, so the timeline part of the PR is not obsolete. (src/OpenClaw.Chat/ChatTimelineReducer.cs:269, 753828f63e96)
  • Current main still resolves approvals through chat slash commands: Current main's RespondToPermissionAsync sends /approve or /deny through SendChatMessageAsync and then clears the banner optimistically; the PR's RPC delivery path is a real behavior change rather than duplicated main behavior. (src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs:852, 753828f63e96)
  • PR diff adds approval RPC response awaiting: The diff registers pending exec.approval.resolve requests, routes ok:true/ok:false responses, faults pending approvals on disconnect, and has focused tests for rejection and success paths. (src/OpenClaw.Shared/OpenClawGatewayClient.cs:399)
  • PR diff adds top-level approval translation: The diff translates top-level exec.approval.requested/resolved events into synthetic approval agent events and isolates subscriber exceptions, which matches the native banner delivery problem described in the PR body. (src/OpenClaw.Shared/OpenClawGatewayClient.cs)
  • Screenshot proof inspected: The latest screenshot shows native chat with visible exec approvals marked Allowed and multi-step chat bubbles, but it does not show a denied or gateway-rejected approval preserving the retry banner.

Likely related people:

  • Christine Yan: Blame points the current main reducer and native chat approval response code to the v0.6.3 commit that introduced the relevant behavior. (role: introduced behavior; confidence: medium; commits: 85445c78066b; files: src/OpenClaw.Chat/ChatTimelineReducer.cs, src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs, src/OpenClaw.Shared/OpenClawGatewayClient.cs)
  • Régis Brid: Recent current-main history touches the gateway/native chat paths around exception logging, and the same person has prior merged-area context beyond only authoring this proposed branch. (role: recent area contributor; confidence: medium; commits: 753828f63e96; files: src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs, src/OpenClaw.Shared/OpenClawGatewayClient.cs)
  • Ranjesh: Recent current-main commits modified native chat behavior around attachment metadata and keyless-event diagnostics, making this a plausible adjacent routing candidate if chat timeline review needs another owner. (role: recent adjacent contributor; confidence: low; commits: 9a3a7a6131a8, 3d26594b4448; files: src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added 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. P1 Urgent regression or broken agent/channel workflow affecting real users now. labels Jun 3, 2026
@RBrid
RBrid marked this pull request as ready for review June 3, 2026 20:21
@clawsweeper clawsweeper Bot added the merge-risk: 🚨 message-delivery 🚨 Merging this PR could drop, duplicate, misroute, suppress, or wrongly target messages. label Jun 3, 2026
@RBrid
RBrid marked this pull request as draft June 4, 2026 23:29
Native WinUI chat was silently dropping exec.approval.requested/resolved
because the gateway client only forwarded the agent stream and the tray
responder sent /approve as a slash command (which deadlocks while the
agent is blocked on the approval). Result: Allow/Deny banner never
appeared, or appeared and did nothing.

Fixes:
- Gateway client now translates top-level exec.approval.requested and
  exec.approval.resolved into synthetic AgentEventInfo (Stream=approval,
  phase derived locally from the event name). MultiSubscriberInvoke
  isolates per-subscriber exceptions so one throwing handler can't
  suppress others.
- Add IChatGatewayBridge.ResolveExecApprovalAsync calling the
  exec.approval.resolve RPC. Decision is allowlisted at the send site
  (allow-once|allow-always|deny); IsConnected is checked both before
  send and after the await to narrow the disconnect-while-sending race
  (SendRawAsync silently swallows mid-flight cancellation/dispose, so
  this is acknowledged best-effort).
- Tray RespondToPermissionAsync swaps the slash command for the RPC.
  On RPC failure the pending-permission banner is preserved so the user
  can retry instead of silently losing the prompt.

Tests:
- OpenClawGatewayClientApprovalTranslationTests (new, Shared): 8 tests
  covering phase mapping, decision validation, disconnect guard,
  slug/UUID alt-id wiring, and multi-subscriber isolation under throw.
- OpenClawChatDataProviderTests (Tray): 3 new tests pinning
  RespondToPermissionAsync to the RPC path (allow->allow-once,
  deny->deny, throw->banner-preserved).

Validation: build green; Shared 2054 passed / 29 skipped;
Tray 947 passed. Reviewed via 3 rounds of dual-model adversarial
review (Opus 1M + GPT-5.3-Codex) until both converged on no remaining
actionable issues.

Co-authored-by: Copilot <[email protected]>
@RBrid RBrid changed the title Fix cross-turn assistant overwrite + separate reasoning bubbles Native chat: cross-turn overwrite + reasoning bubbles + exec.approval delivery Jun 5, 2026
When a turn produces 3+ assistant segments split by tool calls (A1 -> Tool -> A2 -> Tool -> A3), the gateway emits cumulative-for-turn chat.message frames containing every prior segment. The fast-path strip already handled this while ActiveAssistantId was live, but late frames arriving AFTER ApplyTurnEnd cleared ActiveAssistantId came through the scan-back reconcile branch, which wrote the raw cumulative text into the last bubble verbatim. Users saw A3 render correctly first, then mutate to repeat A1+A2's content.

Apply StripCumulativeTurnPrefix(excludeIndex=li) on the scan-back reconcile merge target so the bubble retains only its segment tail. Add a symmetric empty-result guard mirroring the new-bubble path's duplicate-resend skip, so a gateway regression / stale cumulative frame that's fully consumed by other priors leaves the streaming candidate intact rather than blanking it.

Tests: 2 new regression tests cover the in-place scan-back merge path (with id-equality assertion locking the test to that path) and the defensive blank-guard. Document the StripCumulativeTurnPrefix excludeIndex caller contract so future callers understand the self-peel hazard.

Co-authored-by: Copilot <[email protected]>
@RBrid RBrid changed the title Native chat: cross-turn overwrite + reasoning bubbles + exec.approval delivery Native chat: cross-turn overwrite + reasoning bubbles + exec.approval delivery + multi-segment dedup Jun 6, 2026
@RBrid

RBrid commented Jun 6, 2026

Copy link
Copy Markdown
Contributor Author

Screenshots of multi-bubbles / multi-tool-calls:

image image

@RBrid
RBrid marked this pull request as ready for review June 6, 2026 02:03
@clawsweeper clawsweeper Bot added the proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. label Jun 6, 2026
…eset2

# Conflicts:
#	tests/OpenClaw.Tray.Tests/OpenClawChatDataProviderTests.cs
@RBrid

RBrid commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

…er P1)

ResolveExecApprovalAsync used SendTrackedRequestAsync, which returns once the WS frame is sent. ok:false rejections were logged and dropped while the chat banner silently cleared, leaving the agent blocked with no retry path.

Register a TCS per requestId in _pendingApprovalResolves, route ok:true / ok:false in HandleResponse, and fault pending TCSes on disconnect so the chat banner is preserved for retry.

Round-1 adversarial review fixes (Opus + Codex):

- A: RemovePendingRequest in timeout / send-fail branches (no _pendingRequestMethods leak; happy path is already cleaned via TakePendingRequestMethod in HandleResponse).

- B: Disconnect cleanup uses OperationCanceledException to match the _pendingWizardResponses taxonomy.

- D: Timeout 5s -> 15s; approval-resolve traverses gateway -> operator -> optional UI confirm -> ack.

- E: Check completion.Task.IsCompleted directly after Task.WhenAny instead of comparing returned task identity (avoids same-tick race that would discard a real ok:true / ok:false response as a spurious TimeoutException).

Round-2 follow-up fixes:

- H: Re-added post-send !IsConnected re-check using TryRemove-first idiom. Closes the race where ClearPendingRequests fires on an empty snapshot before the TCS is registered (Fix G left a 15s UX hang in this window). If we win TryRemove, throw immediately — no exception is set on the discarded TCS, so no UnobservedTaskException. If cleanup already claimed the entry, fall through to WhenAny so the OCE it set is observed by the caller.

- I: Explicit contract comment near the cleanup-loop OCE: callers MUST catch Exception (not narrow OCE) to preserve the banner-preserve UX. RunFireAndForget swallows OCE silently — a future caller refactor that lets OCE bubble to RunFireAndForget would silently clear the banner.

Deferred (tracked as PR follow-ups, not in this commit):

- C: Deeper integration test coverage exercising SerializeRequest, registration ordering, real timeout, and real disconnect paths. Current tests use reflection seams.

- F: Sibling-wide hardening of the permissive ok:false pattern across _pendingChatSendRequests / _pendingWizardResponses (would create inconsistency if applied only to approval-resolve).

Validation: ./build.ps1; Shared.Tests 2142 passed / 29 skipped; Tray.Tests 1004 passed.

Co-authored-by: Copilot <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jun 8, 2026
@RBrid

RBrid commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Jun 8, 2026 •

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

RBrid and others added 2 commits June 9, 2026 14:18
Preserve the gateway approval decision when terminal echoes race the local response, and dedupe slug/UUID twin approval events without losing alternate-id matching.

Co-authored-by: Copilot <[email protected]>
@RBrid

RBrid commented Jun 9, 2026

Copy link
Copy Markdown
Contributor Author

Latest screenshot:
image

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Jun 9, 2026
Co-authored-by: Copilot <[email protected]>
@ranjeshj
ranjeshj merged commit 5505a85 into openclaw:main Jun 10, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 message-delivery 🚨 Merging this PR could drop, duplicate, misroute, suppress, or wrongly target messages. P1 Urgent regression or broken agent/channel workflow affecting real users now. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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.

2 participants