Skip to content

fix(chat): reject stale sends and approvals after reconnect - #1828

Closed
bkudiess wants to merge 4 commits into
mainfrom
bkudiess-conversation-control-parity
Closed

bkudiess wants to merge 4 commits into
mainfrom
bkudiess-conversation-control-parity

Conversation

@bkudiess

@bkudiess bkudiess commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: a delayed chat send, Stop request or exec-approval response can act on a replacement connection, and reset confirmation can apply after the user has left the conversation.

User Impact

User impact: stale operations fail closed instead of moving to another connection. Accepted sends remain accepted after navigation, clear only their submitted draft revision and attachment identities, and preserve later edits. Reset confirmation no longer authorizes a conversation the user has since left.

This is a bounded transport-safety prerequisite, not complete web chat parity. Steer, uncertain-delivery reconciliation, plugin/system approvals and interactive questions are separate work. Rendered reset-confirmation/approval-banner behavior and real Gateway reconnect behavior remain not verified / blocked.

Why This Change Was Made

Conversation state captures the existing client's ready connection epoch at admission. The production bridge forwards it to the existing send, abort and exec-approval APIs; the transport compares it before a generation-bound socket write. Epoch-bound chat sends and aborts require an explicit session key rather than silently falling back to the Gateway's main session. Stop completion and approval dismissal are fenced against replacement runs and connection generations.

The owners stay unchanged: ChatConversationState owns atomic conversation mutations, OpenClawGatewayClient owns the socket write, and ChatComposerController owns reset confirmation and revision-safe draft cleanup. The provider-test fixture now injects temporary tool, attachment, last-chat-state and aborted-message paths.

Evidence

At clean head 5691fc16bb812d71966f776f936536c7512c9f60, the full build passed all five targets, Shared passed 4,666 cases with 25 ordinary skips, and Tray passed 4,508 with no failures or skips. Focused transport checks also passed Shared 22/22 and Tray 98/98: real loopback-client and production-bridge rejection of old-epoch mutations without a write to the current socket, explicit-session validation, missed-status recovery, stale Stop completion, and send/compact acceptance versus navigation.

The candidate includes the separately reviewed test-isolation guard from 734aa41aa11f61c1dcca6f314196bdbc518a7e97; its seven files are byte-identical to that dependency.

The dedicated independent reviewer cleared material P0-P3 source findings after the acceptance/navigation P1 correction. A separate rubber-duck tool review found no blocking implementation/proof-plan issue. Neither review is runtime or visual proof. The shared autoreview installation was unavailable; no helper-isolation claim is made.

The final required run used fresh task-owned profile roots, disabled .NET first-use certificate generation, and disabled process-local MSBuild node/server/compiler reuse. Compiled path preflight verified the owned roots. Real-profile metadata manifests before and after the complete serial build/Shared/Tray run were byte-identical (SHA256 DEDDB5E7BFD7012FD32D1DD9457AA45DC9FAF5E8B3800126B259388860E09472).

Earlier unsafe default-profile test execution and separate unattributed 365-byte real-log appends were reported and excluded from safe closeout evidence. The current unchanged interval does not retroactively attribute or erase those incidents. No personal file contents or credentials are included.

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs or instructions
  • Tests or validation
  • Security hardening
  • Chore or infrastructure

Scope

  • Tray or WinUI UX
  • Windows node capability
  • Local MCP or winnode
  • Gateway, connection, or pairing
  • Setup or onboarding
  • Permissions, privacy, or security
  • Tests, CI, or docs

Required proof pools

  • windows-winui-interactive: rendered reset-confirmation, draft and approval-banner recovery workflow. Not run; no native app launch is included in this proof.
  • windows-wsl-gateway-e2e: connection-generation safety affects Gateway reconnect/recovery. Not run; synthetic loopback transport proof is not product Gateway recovery proof.
  • windows-wsl-mxc: exec-approval response transport changed. Not run; no live command, MXC host or containment claim.

Validation

Current required validation uses fresh isolated processes. Combined source is 5691fc16bb812d71966f776f936536c7512c9f60, clean. Missing session targets now take precedence over missing message text: the provider raises InvalidOperationException before optimistic admission, rather than invoking a bridge or silently selecting main.

Command Result
.\build.ps1 Passed all five targets in the current isolated required run.
dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore Passed 4,666, failed 0, skipped 25. All 25 actual skipped rows are retained in the local evidence inventory; they are not custom proof.
dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore Passed 4,508, failed 0, skipped 0.
dotnet restore .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --verbosity quiet Passed before required closeout, after consuming the new ProfileProbe project reference. This is dependency preparation, not test execution.
dotnet test .\tests\OpenClaw.Shared.Tests\OpenClaw.Shared.Tests.csproj --no-restore --filter "FullyQualifiedName~ChatMutation|FullyQualifiedName~EpochBoundChatMutation|FullyQualifiedName~ConfirmedMutation|FullyQualifiedName~ArchitectureLedgerConsistencyTests" --verbosity quiet Passed 22, failed 0, skipped 0.
dotnet test .\tests\OpenClaw.Tray.Tests\OpenClaw.Tray.Tests.csproj --no-restore --filter "FullyQualifiedName~ChatComposerControllerTests|FullyQualifiedName~ChatConversationStateTests|FullyQualifiedName~EpochChangesWithoutStatusDelivery|FullyQualifiedName~RespondToPermission|FullyQualifiedName~StopResponse|FullyQualifiedName~ProductionBridge_RejectsOldEpoch|FullyQualifiedName~PreHandshake_RefusesMissingSession" --verbosity quiet Passed 98, failed 0, skipped 0.
.\scripts\validate-docs.ps1 Passed 64 maintained Markdown files on the initial slice; required build repeats this check.
git diff --check Passed.

The pre-fix reset-confirmation regression failed before repair. Original failures remain in local evidence, including a corrected ledger guard reference, a GitVersion pre-execution failure, the provider's corrected missing-session exception contract, a runner stage-selection defect, and the missing-assets first run before restoring the new probe dependency. None is relabeled as a passed or safely isolated attempt.

Real Behavior Proof

  • Environment tested: Windows x64, real OpenClawGatewayClient and GatewayClientChatBridge against a session-owned synthetic loopback Gateway. No shared Gateway, private provider or native app was launched.
  • PR head or commit tested: 5691fc16bb812d71966f776f936536c7512c9f60, clean, full required run. Earlier focused transport source hashes match 298da7fc.
  • Exact steps or command run: the focused Shared and Tray commands above, with per-invocation TRX reports and compiled-path preflight.
  • Evidence after fix: ProductionBridge_RejectsOldEpochBeforeWritingMutation passed for chat.send, chat.abort and exec.approval.resolve; the server observed none of the rejected mutation methods and remained able to answer a history request. ChatMutation_RefusesCapturedEpochWithoutWritingOnCurrentSocket also verifies pending-request cleanup and a correlated health-response barrier.
  • Observed result: an operation captured for an old epoch is rejected before writing onto the replacement socket. This does not prove that an earlier already-written request was undelivered, or reconcile uncertain delivery.
  • Screenshot or artifact links verified? (Yes/No/N/A) N/A. Local logs/TRX/metadata manifests are retained; no private local path is represented as a publicly accessible proof link.
  • Not verified or blocked: rendered reset dialog, draft, approval-banner and navigation behavior; real Gateway reconnect; MXC behavior; live-provider delivery; all Steer/recovery/question parity claims. The earlier real-log writes remain unattributed. A passing synthetic transport test or unchanged metadata interval is not live provider, complete proof-pool, or visual acceptance.

Security Impact

  • New permissions or capabilities? (Yes/No) No.
  • Secrets or tokens handling changed? (Yes/No) No.
  • New or changed network calls? (Yes/No) Yes, existing mutation APIs now accept the caller's expected connection epoch; wire methods and payloads are unchanged.
  • Command or tool execution surface changed? (Yes/No) No new execution surface; exec-approval resolution is now bound to its original connection.
  • Data access scope changed? (Yes/No) No.
  • If any answer is Yes, explain the risk and mitigation: stale actions cannot be redirected to a replacement socket. Existing call signatures retain optional compatibility; the production chat provider always uses the epoch-bound bridge methods and explicit chat session keys. Rejected approval responses preserve their banner and request an error notification.

Compatibility and Migration

  • Backward compatible? (Yes/No) Yes; no new Gateway method, wire field or minimum-version assumption.
  • Config or environment changes? (Yes/No) No product configuration changes.
  • Migration needed? (Yes/No) No.
  • If yes, list the exact upgrade steps: N/A.

This is a maintainer-authorized branch in the upstream repository, at the user's explicit request rather than a personal fork. The fork-only maintainer-edit toggle is not applicable; repository write permissions govern edits.

Review Conversations

  • I replied to or resolved every bot review conversation addressed by this PR.
  • I left unresolved only conversations that still need maintainer judgment.

bkudiess and others added 4 commits October 22, 2026 00:47
Bind sends, aborts and exec approvals to the transport epoch captured by conversation state. Preserve submitted drafts across navigation and fence stale confirmation and acknowledgement commits.

Co-authored-by: Copilot App <[email protected]>
Resolve independent review P1 by distinguishing pre-admission navigation fences from accepted send completion. Isolate provider test persistence paths, cover production bridge epoch forwarding and connection recovery, and fix the architecture guard reference.

Co-authored-by: Copilot App <[email protected]>
Keep pre-handshake missing-session refusal explicit and prevent optimistic state from being created for an empty session. Exercise the actual provider guard instead of supplying its failure from a fake.

Co-authored-by: Copilot App <[email protected]>
Guard default tray test processes before linked owners cache paths, preserve safe explicit roots and reject real profiles. Add a discovery-free subprocess regression and stop reading real settings contents in the settings isolation test.

Co-authored-by: Copilot App <[email protected]>
(cherry picked from commit 734aa41)
@clawsweeper

clawsweeper Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

🦞👀
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 P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 22, 2026
@clawsweeper

clawsweeper Bot commented Oct 22, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge.

What this changes

The PR binds chat sends, Stop requests, and approval responses to their original connection and rejects reset confirmation after navigation.

Example: A send for agent:test:session captures connection epoch 7, then the connection changes to epoch 8 before dispatch.

  • Before: The delayed operation can use the replacement connection.
  • After: The transport rejects epoch 7 before writing to epoch 8.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The repair is coherent and source review found no definite introduced defect, but supplied execution remains a partial transport harness and does not satisfy the scoped runtime and visible-proof requirements.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Delayed chat actions can reach a replacement connection, and reset confirmation can remain effective after leaving a conversation.
Reason: The bounded safety repair preserves established ownership and wire contracts; collaborator authorship supplies direction, including the test-only probe timeout environment override.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a source-confirmed connection race, and no definite introduced correctness bug was found.

Priority: P2
Reviewed head: 5691fc16bb812d71966f776f936536c7512c9f60

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Supply current-head reconnect and rendered reset/draft/approval evidence, including the required exec-approval Gateway/MXC path; base-failure evidence is reported only for reset confirmation.
Agent review details

How this fits together

The native chat controller submits user actions through conversation state and the Gateway bridge; the shared client converts admitted operations into generation-bound WebSocket requests.

flowchart LR
  A[Native chat actions] --> B[Composer controller]
  B --> C[Conversation state]
  C --> D[Gateway chat bridge]
  D --> E[Gateway client]
  E --> F[Generation bound socket]
  F --> G[Gateway]
Loading

Technical review

Best possible solution:

Retain the existing conversation and transport owners, with admission epochs enforced at the final socket write.

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

Main's delayed dispatch can acquire the replacement connection at invocation, and reset confirmation checks lifetime without checking navigation; source inspection establishes both paths, but no target code was executed.

Is this the best way to solve the issue?

Capturing the transport epoch in existing state transactions and checking it through the existing generation-bound socket writer directly addresses the race without adding a competing production owner.

AGENTS.md: found and applied where relevant.

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

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned review and repository policy: Reviewed the introduced diff from the pinned main revision to the original PR head. Read the complete root, documentation, and WinUI AGENTS.md files. No maintainer-notes directory or pr-simplify skill was present. No helper, second reviewer, build, or test ran; the checkout remained clean. (AGENTS.md:1, 5691fc16bb81)
  • Current-main race: Main dispatches through the unbound bridge method after awaiting session-option work; its client captures the current transport generation at invocation rather than the conversation's admission epoch. The PR carries that earlier epoch through dispatch. (src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs:519, 51f18c1222c9)
  • Final socket boundary: The added epoch comparison feeds the existing SendRawAsync generation check, which checks the captured socket under the send lock before I/O. Explicit session validation prevents epoch-bound send and abort calls from falling back to main. (src/OpenClaw.Shared/OpenClawGatewayClient.cs:523, 5691fc16bb81)
  • Scoped transport coverage: The added tests exercise the production client and bridge against real loopback sockets, reject an injected stale epoch for all three mutation methods, and use a subsequent correlated request to observe that no rejected mutation was written. They do not perform an actual reconnect or render the changed UI. (tests/OpenClaw.Tray.Tests/InteractiveGatewayChatTests.cs:19, 5691fc16bb81)
  • Complete supplied proof and discussion: Read the complete PR body and both comments through REST, including the previously omitted body ranges. The captured body identity is ee5914728a1287ca43d202dec78cea149b5dedf4c6d1c4ba708d16d7e914d6ed. The body reports successful build, Shared, Tray, and focused runs at the reviewed head, while explicitly marking rendered UI, real Gateway reconnect, and MXC proof unverified. No media or public runtime artifact is linked. (5691fc16bb81)
  • Shared test-isolation contribution: fix(tests): keep tray tests out of real profiles #1827 (fix(tests): keep tray tests out of real profiles) owns the same test-isolation contribution. GitHub tree blob hashes match all seven corresponding files in this PR, confirming the stated dependency without treating it as a duplicate of the transport repair. (tests/OpenClaw.Tray.Tests/TrayTestProfileIsolation.cs:14, 5691fc16bb81)

Likely related people:

  • Barbara Kudiess: Raw commit f8a8825 adds src/OpenClaw.Tray.WinUI/Chat/ChatConversationState.cs:15 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: f8a8825ccbb4; files: src/OpenClaw.Tray.WinUI/Chat/ChatConversationState.cs)
  • Caleb Eden: Raw commit 02f2421 adds src/OpenClaw.Shared/OpenClawGatewayClient.cs:311 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 02f2421a5e75; files: src/OpenClaw.Shared/OpenClawGatewayClient.cs)
  • Scott Hanselman: Raw commit 8757b4d adds src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs:1877 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 8757b4d76940; files: src/OpenClaw.Tray.WinUI/Chat/OpenClawChatDataProvider.cs)

Review metrics

Metric Value Why it matters
Patch distribution Production +156/-51; tests +632/-38; docs +15/-1 Production changes remain in existing owners; most growth supplies race coverage and fresh-process profile-isolation checks.

Labels

Label changes:

  • add P2: The repair protects conditional reconnect and navigation races in native chat, without evidence of a widespread outage.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: The repair protects conditional reconnect and navigation races in native chat, without evidence of a widespread outage.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Show connection A being replaced by B while an admitted mutation is delayed, with rejected stale writes and successful fresh operations visible at the transport boundary.
  • Show reset confirmation after navigation and accepted-send draft/attachment cleanup in the mounted UI, plus the required exec-approval Gateway/MXC evidence.

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.

Reviewed October 22, 2026, 5:14 AM ET / 09:14 UTC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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.

1 participant