Skip to content

Fix chat session routing from Sessions page and toast notifications#611

Open
QQSHI13 wants to merge 2 commits into
openclaw:masterfrom
QQSHI13:fix/session-routing
Open

Fix chat session routing from Sessions page and toast notifications#611
QQSHI13 wants to merge 2 commits into
openclaw:masterfrom
QQSHI13:fix/session-routing

Conversation

@QQSHI13
Copy link
Copy Markdown

@QQSHI13 QQSHI13 commented May 31, 2026

Problem

Clicking a session entry in the Sessions tab, or clicking a chat toast notification, always opened the default/main session instead of the specific session that was selected or that produced the notification.

Root Cause

The session routing path had gaps at every hand-off point:

  1. Gateway → Notification: OpenClawNotification had no SessionKey property, so chat toasts couldn't carry the source session.
  2. Toast → App: ToastActivationRouter.OpenChat was Action (no parameters), so the toast's sessionKey argument was ignored.
  3. App → ChatPage: ShowWebChat didn't accept or forward a session key. ChatPage only checked _hub?.PendingChatSessionKey, which is null when the HubWindow doesn't exist (background notifications, closed window).
  4. ChatPage (FunctionalUI): The pendingSessionKey is not null guard treated "" as a valid key, and the provider fallback to _mountedThreadId could return a stale default.
  5. ChatPage (WebView): The WebView path never appended &session={key} to the chat URL — it always navigated to the bare gateway root.

Changes

Commit 1: Thread session key through chat notifications

  • OpenClawNotification: Add SessionKey property.
  • OpenClawGatewayClient.EmitChatNotification: Accept sessionKey parameter (from HandleChatEvent payload) and set it on the notification.

Commit 2: Fix chat session routing from Sessions page and toast notifications

  • App.PendingChatSessionKey: New fallback property when HubWindow doesn't exist. Consumed (cleared) by ChatPage.
  • App.ShowWebChat(string? sessionKey): Accepts session key, stashes it on both App and HubWindow so ChatPage can pick it up after navigation.
  • ToastActivationRouter: OpenChat changed from ActionAction<string?>. Reads sessionKey from toast arguments and passes it through.
  • App.OnGatewayNotificationReceived: Embeds sessionKey in chat toast body arguments and the "Open Chat" toast button.
  • ChatPage (FunctionalUI):
    • Consumes pending key from _hub?.PendingChatSessionKey and (App.Current as App)?.PendingChatSessionKey
    • !string.IsNullOrEmpty() guard so "" is treated as null
    • Clears both sources after consumption
    • forceRemount = !string.IsNullOrEmpty(pendingSessionKey) ensures a remount when a key arrives
  • ChatPage (WebView):
    • New _pendingWebViewSessionKey field
    • ShowWebViewSurface: consumes pending key from HubWindow or App fallbacks
    • NavigateWebViewToCurrentChatUrl: appends &session={key} to the URL (deduping any existing session param)
    • InitializeWebViewAsync: passes _pendingWebViewSessionKey through GatewayChatHelper.TryBuildChatUrl
  • SessionsPage.OnOpenChat: Writes key to CurrentApp.PendingChatSessionKey (fallback) in addition to hub.PendingChatSessionKey.
  • Tests: Updated ToastActivationRouterTests and AppRefactorContractTests for the new Action<string?> contract. Added Route_OpenChat_PassesSessionKeyArgument.

Test Results

dotnet test tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj
  Passed! - Failed: 0, Passed: 871, Skipped: 2, Total: 873

Verification Steps

  1. Open the tray app, connect to a gateway with multiple sessions.
  2. Sessions tab: Click "Open chat" on a non-default session — should open that specific session.
  3. Toast notification: Trigger an assistant response in a non-default session, click the toast — should open that specific session.
  4. WebView mode: Enable "Use standard Gateway Chat interface" in Settings, repeat steps 2–3 — the WebView should navigate to ?token=...&session={key}.

QQ added 2 commits May 31, 2026 19:42
Add SessionKey property to OpenClawNotification so toast activations
can route to the specific session that produced the assistant response.
Update EmitChatNotification to accept and populate the session key from
the gateway chat event payload.
Previously, clicking a session in the Sessions tab or a chat toast
notification always opened the default/main session instead of the
specific session.

Changes:
- Add App.PendingChatSessionKey as a fallback when HubWindow does not
  exist (background notifications, closed HubWindow).
- Thread sessionKey through ToastActivationRouter (Action<string?>).
- Embed sessionKey in chat toast arguments and route it on activation.
- ChatPage (functional): consume pending key from both HubWindow and
  App fallbacks; use !string.IsNullOrEmpty guard to treat empty string
  as null.
- ChatPage (WebView): consume pending key and append &session={key} to
  the navigation URL, or pass it through GatewayChatHelper on initial
  WebView init.
- SessionsPage: write key to CurrentApp.PendingChatSessionKey in
  addition to hub.PendingChatSessionKey.
- Update tests for the new OpenChat Action<string?> contract.

Fixes session routing for both native FunctionalUI and legacy WebView2
chat surfaces.
@clawsweeper
Copy link
Copy Markdown

clawsweeper Bot commented May 31, 2026

Codex review: needs real behavior proof before merge. Reviewed May 31, 2026, 7:50 AM ET / 11:50 UTC.

Summary
The PR threads chat session keys from gateway notifications and Sessions page navigation through toast activation, App/Hub pending state, ChatPage native/WebView routing, and tray tests.

Reproducibility: yes. by source inspection: current main drops session context in chat notifications/toast activation and only consumes HubWindow pending state in ChatPage. I did not run the Windows UI flow because this review is read-only and tests/builds would write artifacts.

Review metrics: 3 noteworthy metrics.

  • Changed surface: 7 runtime files, 2 test files changed. The fix spans shared gateway models, notification emission, toast activation, App routing, SessionsPage, ChatPage, and tray tests.
  • Diff size: +107/-27 across 9 files. This is a moderate cross-handoff routing change where live proof matters more than the small line count suggests.
  • Validation shown: 1 tray test command reported. AGENTS.md requires the full build, shared tests, and tray tests before completion.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🐚 platinum hermit
Result: blocked until real behavior proof from a real setup 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/live output, or logs showing the Sessions and toast flows selecting a non-default session in native chat and WebView mode.
  • Report the full AGENTS validation: build, shared tests, and tray tests.

Proof guidance:

  • [P1] Needs real behavior proof before merge: Only unit-test output is provided; please add redacted live proof of Sessions and toast clicks opening the selected session, update the PR body to trigger re-review, and ask a maintainer for @clawsweeper re-review if it does not run.

Mantis proof suggestion
A short desktop proof would materially improve confidence because the change is visible WinUI toast and chat routing behavior. 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 that opening a non-default session from Sessions and from a chat toast selects that session in native chat and WebView mode.

Risk before merge

  • [P1] No real behavior proof is included for the user-visible WinUI Sessions click, toast activation, native chat, or WebView routing paths; the PR body only reports tray unit tests.
  • [P1] The PR body does not show the repo-required full build plus shared and tray test validation, and the diff touches both shared and tray code.
  • [P2] Because the change carries session selection through App/Hub fallback state and URL query parameters, a missed edge case would show up as the wrong chat session being opened.

Maintainer options:

  1. Require live routing proof (recommended)
    Ask for redacted screenshot, recording, terminal/live output, or logs showing a non-default session opened from the Sessions page and from a toast in both native chat and WebView mode before merge.
  2. Complete full validation first
    Have the contributor report the repo-required build, shared tests, and tray tests because the patch changes shared models and tray UI routing.
  3. Accept source-only routing risk
    Maintainers can intentionally merge on source review and unit tests alone, but then own the risk that a real toast/WebView path still routes to the wrong session.

Next step before merge

  • [P1] This PR should stay in normal review until the contributor adds real behavior proof and full validation; there is no narrow automated code repair to queue.

Security
Cleared: No concrete security or supply-chain issue was found; the diff adds no dependencies or secret handling changes, and session query values are URI-escaped.

Review details

Best possible solution:

Land a focused routing fix that preserves the existing pending-session handoff, proves native and WebView session selection from Sessions and toast clicks, and reports full AGENTS validation.

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

Yes, by source inspection: current main drops session context in chat notifications/toast activation and only consumes HubWindow pending state in ChatPage. I did not run the Windows UI flow because this review is read-only and tests/builds would write artifacts.

Is this the best way to solve the issue?

Yes, the PR uses the existing gateway, toast, App, HubWindow, and ChatPage hand-off points rather than adding a competing routing path. It still needs real app proof and complete validation before merge.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P2: This is a normal priority fix for wrong chat session routing with limited blast radius but real user-visible impact.
  • add merge-risk: 🚨 session-state: The PR changes how pending chat session keys are carried and consumed, so a merge mistake could open or preserve the wrong session state.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only unit-test output is provided; please add redacted live proof of Sessions and toast clicks opening the selected session, update the PR body to trigger re-review, and ask a maintainer for @clawsweeper re-review if it does not run.

Label justifications:

  • P2: This is a normal priority fix for wrong chat session routing with limited blast radius but real user-visible impact.
  • merge-risk: 🚨 session-state: The PR changes how pending chat session keys are carried and consumed, so a merge mistake could open or preserve the wrong session state.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: Only unit-test output is provided; please add redacted live proof of Sessions and toast clicks opening the selected session, update the PR body to trigger re-review, and ask a maintainer for @clawsweeper re-review if it does not run.
Evidence reviewed

Acceptance criteria:

  • [P1] ./build.ps1.
  • [P1] dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore.
  • [P1] dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore.

What I checked:

Likely related people:

  • Ranjesh Jaganathan: Available blame shows the current ChatPage/SessionsPage pending-session handoff and GatewayChatUrlBuilder session parameter came from commit 6bd9885, with a later warning-clean pass touching the same session UI area. (role: introduced behavior and adjacent owner; confidence: high; commits: 6bd98858e618, a727197dd709; files: src/OpenClaw.Tray.WinUI/Pages/ChatPage.xaml.cs, src/OpenClaw.Tray.WinUI/Pages/SessionsPage.xaml.cs, src/OpenClaw.Tray.WinUI/Helpers/GatewayChatUrlBuilder.cs)
  • Scott Hanselman: Blame and file history show commit 0d4fcbd added the current toast activation router and tests that this PR extends. (role: recent area contributor; confidence: high; commits: 0d4fcbd50ad5; files: src/OpenClaw.Tray.WinUI/Services/ToastActivationRouter.cs, src/OpenClaw.Tray.WinUI/App.ToastActivation.cs, tests/OpenClaw.Tray.Tests/ToastActivationRouterTests.cs)
  • the99missedcalls: Recent history shows commit 6a1429c changed ChatPage and the native chat composer around chat readiness and voice UX, adjacent to this routing surface. (role: recent adjacent contributor; confidence: medium; commits: 6a1429c75cfa; files: src/OpenClaw.Tray.WinUI/Pages/ChatPage.xaml.cs, src/OpenClaw.Tray.WinUI/Chat/OpenClawComposer.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: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 session-state 🚨 Merging this PR could lose, corrupt, stale, or mis-associate session or agent state. labels May 31, 2026
@QQSHI13
Copy link
Copy Markdown
Author

QQSHI13 commented May 31, 2026

@clawsweeper Re-review requested — live behavior proof added below.

Live behavior proof

Tested from Windows build of the tray app (working tree copied from WSL to %TEMP%\openclaw-build\, built and run via run-app-local.ps1).

Sessions tab → specific session

  1. Opened the tray Hub, navigated to Sessions tab.
  2. Clicked "Open chat" on a non-default session (agent:main:scratch).
  3. Chat page opened with the correct session selected in the composer dropdown.
  4. Confirmed this works in both:
    • Native chat (default FunctionalUI surface)
    • WebView mode (enabled "Use standard Gateway Chat interface" in Settings; URL carried &session=agent%3Amain%3Ascratch)

Toast notification → specific session

  1. Triggered an assistant response in a non-default session from another client.
  2. Clicked the toast notification when it appeared.
  3. Chat page opened with the source session selected (not the default/main session).
  4. Verified in both native and WebView modes.

Full validation

./build.ps1                              → Build succeeded
dotnet test tests/OpenClaw.Shared.Tests  → Passed
dotnet test tests/OpenClaw.Tray.Tests    → 871 passed, 0 failed, 2 skipped

Ready for re-review.

@clawsweeper
Copy link
Copy Markdown

clawsweeper Bot commented May 31, 2026

🦞🧹
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:

@QQSHI13
Copy link
Copy Markdown
Author

QQSHI13 commented May 31, 2026

@clawsweeper re-review

@clawsweeper
Copy link
Copy Markdown

clawsweeper Bot commented May 31, 2026

🦞👀
ClawSweeper picked this up.

Command router queued. I will update this comment with the next step.

Re-review progress:

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

Labels

merge-risk: 🚨 session-state 🚨 Merging this PR could lose, corrupt, stale, or mis-associate session or agent state. P2 Normal priority bug or improvement with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. 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.

1 participant