Skip to content

fix: pinned pages can crash Companion after Settings refreshes its agent list - #2171

Merged
bkudiess merged 1 commit into
openclaw:mainfrom
bkudiess:bkudiess-dashboards-invoke-flake
Nov 13, 2026
Merged

bkudiess merged 1 commit into
openclaw:mainfrom
bkudiess:bkudiess-dashboards-invoke-flake

Conversation

@bkudiess

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: Companion can crash (0xC0000005) or silently fail to open a pinned page after Settings has refreshed its agent list. In CI, this shows up as the intermittent GatewayFixtureUiTests.DashboardsRenderNativeReportsTabsAndFailureStates failure COMException: Pattern not found (most recently main run 42980649021 and #2161 run 43404129857). It is also behind the SettingsPane_KeepsToggleChoiceAcrossPinnedPagesAndRestart "Pattern not found" failure that another session hit locally.

User Impact

User impact: opening a pinned page beside the sidebar (for example Dashboards or Connection) no longer risks crashing Companion or leaving it on a blank, half-applied Settings view. This happened after the Gateway had sent its agent list more than once, which is normal at startup and after reconnects. It is most reachable through UI Automation (Narrator and test automation) because those activate the row without moving focus first. The same path also runs for pointer clicks. Settings agent rows now keep their identity across agent-list refreshes, so their order and labels follow the Gateway as before.

Why This Change Was Made

SettingsShellView.RebuildAgentNavItems cleared AgentsNavItem.MenuItems and recreated every agent row on each AppState.AgentsList change. The fixture sends agents.list three times at startup.

This hits WinUI bug microsoft/microsoft-ui-xaml#10757:

  • NavigationViewItem registers SplitView property callbacks that capture the raw item.
  • Once a removed row has been collected, the next SplitView pane change calls into the freed item.
  • Upstream fixed this in microsoft/microsoft-ui-xaml#12235 (merged 2026-10-12) by resolving a weak reference first.

In our app, opening a pinned page runs OnPinItemInvoked → OpenSettings → SettingsShellView.ContentOnly = true → NavigationView.IsPaneVisible = false. That applies the PaneCollapsed visual state, which changes the SplitView and reaches the collected agent rows. A full crash dump shows this native stack: NavigationView::UpdatePaneVisibility → GoToState → NavigationViewItem::OnSplitViewPropertyChanged → NavigationViewItemPresenter::UpdateCompactPaneLength → access violation.

When the fault surfaces as E_FAIL instead of a crash, the exception escapes the ItemInvoked handler, and UIA returns it from SelectionItemPattern.Select() as "Pattern not found". The CI artifacts match this:

  • no board.get or sessions.list request follows the click;
  • the failure frame shows the half-applied state (Settings history bar only, empty content).

The fix adds KeyedMenuRows, which keeps one row per key, reuses it on every sync and never releases a row it created. Settings agent rows use it, so a refresh reorders or relabels rows in place instead of replacing them. A removed agent's row stays referenced, so WinUI never calls into a collected item, and the row is reused if that agent returns.

Windows App SDK status (checked 2026-11-13): this app ships Windows App SDK 2.6.5, and the crash reproduces on it. Neither the 2.6.5 nor the 2.6.6-experimental release notes mention #10757 or #12235. Once a Windows App SDK release includes #12235, KeyedMenuRows can drop the rows it keeps for removed keys.

This PR also fixes a separate one-shot UIA read in the same test (main run 43430233130, NullReferenceException at GatewayFixtureNativeDashboardsUiTests.cs:1343). After the unpin/re-pin loop, the test read the re-created WorkspacePinnedPage:dashboards row once. It now waits for that row to be present and selected. The selected-state requirement is unchanged.

The shared test Invoke helper is deliberately unchanged. The "Pattern not found" call had already reached product code, so retrying it could re-run a partly applied action and would hide this crash.

Not in this PR: the Workspace sidebar also removes NavigationViewItems (session rows in SyncSessionItems, pinned-page rows in PinnedPageRows). That is the same bug class, and it moves to a separate follow-up that reuses KeyedMenuRows.

Evidence

  • Root cause:
  • Deterministic RED/GREEN: a temporary local probe (not committed) navigated to Settings, gave a Settings pane control keyboard focus, navigated to chat, and immediately activated the Dashboards pin through UIA.
    • On main code, the app crashed in 5 of 8 runs with the native stack above.
    • With this fix, the app survived 20 of 20 runs, and the pin opened Dashboards each time.
  • Review: dual-model Hanselman review on base bd6a2dbd0 plus this diff (Claude Opus 5.5 and GPT-6 Astra long-context, both high effort). Neither found a CRITICAL, HIGH or MEDIUM issue.

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: covered by isolated fixture runs of the WinUI app for the affected flows. See Validation and Real Behavior Proof.

Validation

All runs were local on Windows x64 at 175% DPI, with isolated profiles. Metadata for the real %APPDATA%/%LOCALAPPDATA%\OpenClawTray was unchanged after every run.

Check Result
DashboardsRenderNativeReportsTabsAndFailureStates (Light and Dark) 5/5 passed on the final source (plus 5/5 and 5/5 on earlier revisions without the line-1343 change)
SettingsPane_KeepsToggleChoiceAcrossPinnedPagesAndRestart 5/5 passed
Crash probe (pin activation immediately after Settings → chat) main: 5 of 8 crashed; fix: 20/20 survived
KeyedMenuRowsTests (new) passed (part of the Tray run below)
Full fixture suite (scripts\test-gateway-fixture.ps1, current Debug app) integration (fixture-profile-app) 56/56 passed. UI tests without the keyboard requirement: 124/125 passed. The one failure is Automations_ScopesToAgentsAndCoversMainStates (Light), an Axe BoundingRectangleSizeReasonable violation that only occurs locally at 175% DPI. UI tests that require keyboard proof: 5/9 passed, and the same 4 fail identically on main bd6a2dbd0 on this machine. The UI sets were run directly with dotnet test and the same filters, because the script caps a run at 1800 s and the local UI set takes about 29 minutes.
  • .\scripts\validate-test-timing-patterns.ps1: passed. The one-shot UIA lookup baseline for GatewayFixtureNativeDashboardsUiTests.cs drops from 32 to 31.
  • ./build.ps1: all builds succeeded.
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj: 5862 passed, 0 failed, 29 skipped. An earlier run had 1 unrelated failure that passed on rerun; this PR changes no Shared code.
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj: 6444 passed, 0 failed.

Real Behavior Proof

  • Environment tested: local Windows x64 desktop, 175% DPI, isolated profiles, Windows App SDK 2.6.5 (the version this app ships).
  • PR head or commit tested: 158c7e1 (source identical to the validated tree).
  • Exact steps or command run:
    • dotnet test tests/OpenClaw.Tray.UITests -c Debug -r win-x64 -p:DevBuild=false --no-build --filter "FullyQualifiedName~DashboardsRenderNativeReportsTabsAndFailureStates" with OPENCLAW_RUN_GATEWAY_FIXTURE_UI=1.
    • The same command filtered to SettingsPane_KeepsToggleChoiceAcrossPinnedPagesAndRestart.
    • The crash probe described under Evidence.
  • Evidence after fix: the pass counts above. The probe showed no app exit in 20 of 20 runs, and no new Application Error (1000/1026) events for OpenClaw.Tray.WinUI.exe.
  • Observed result: the pinned page opens beside the sidebar, and the app stays alive.
  • Screenshot or artifact links verified? (Yes/No/N/A): N/A (local artifacts only).
  • Not verified or blocked:
    • The first-attempt CI result for this PR is pending.
    • Same-bug-class removal paths in the Workspace sidebar are not changed here (follow-up).
    • One-model LOW review notes (Opus), not applied:
      • The XAML DefaultAgentNavItem (agent:main) is replaced on the first sync rather than adopted. Its generated field keeps it alive, so it is not collected.
      • If an agent-list refresh moves or removes the selected agent row, the Settings rail shows no selection until the next navigation. The old Clear() did this on every refresh.

Security Impact

  • New permissions or capabilities? (Yes/No): No
  • Secrets or tokens handling changed? (Yes/No): No
  • New or changed network calls? (Yes/No): No
  • Command or tool execution surface changed? (Yes/No): No
  • Data access scope changed? (Yes/No): No
  • If any answer is Yes, explain the risk and mitigation: N/A

Compatibility and Migration

  • Backward compatible? (Yes/No): Yes
  • Config or environment changes? (Yes/No): No
  • Migration needed? (Yes/No): No
  • If yes, list the exact upgrade steps: N/A

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.

…ent list

SettingsShellView rebuilt its agent rows by clearing and recreating every
NavigationViewItem on each agents.list update. WinUI keeps SplitView callbacks
on those rows (microsoft/microsoft-ui-xaml#10757, fixed upstream by #12235 but
not in Windows App SDK 2.6.5). After a removed row is collected, hiding the
Settings pane for an embedded pinned page called into the freed row: an access
violation, or an E_FAIL that UIA reported as "Pattern not found" in the
DashboardsRenderNativeReportsTabsAndFailureStates CI flake.

KeyedMenuRows reuses rows by key and never releases a row it created, and the
Settings agent menu now uses it. The Dashboards test also waits for the
re-created pinned row to be present and selected instead of reading it once.

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

clawsweeper Bot commented Nov 13, 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 clawsweeper:intake:bug Preliminary submission classification; full source review pending. P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge.

What this changes

The PR preserves Settings agent-row identity across refreshes and waits for the re-pinned Dashboards row to become selected in the UI test.

Example: Settings receives the agents main and ops repeatedly, then the user opens the Dashboards pin.

  • Before: Replaced agent rows can be collected before a pane transition invokes their native callbacks, crashing Companion or interrupting navigation.
  • After: Agent rows remain referenced and are reused, allowing the pinned page to open safely.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The patch is focused and source review found no actionable defects, but reported local observations do not provide inspectable proof of the changed native crash path.
Proof confidence 🧂 unranked krab (1/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: Opening a pinned page after Settings refreshes its agent list can crash Companion or leave navigation half applied.
Reason: This focused maintainer-authored repair restores ordinary navigation without adding options or changing the intended experience; other Workspace row-removal paths are separately scoped.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a concrete crash path still present on main, and review found no actionable patch defects.

Priority: P1
Reviewed head: 158c7e1f8304a2bb8be32ae2da9f027643036f91

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide viewable current-head capture or runtime diagnostics of repeated agent refreshes followed by Settings-to-chat-to-pin activation, covering Debug and production-shaped Release; the reported RED/GREEN probe currently has no inspectable artifact.
Agent review details

How this fits together

SettingsShellView turns cached Gateway agent data into native navigation rows; Workspace pin activation hides that navigation pane while displaying an embedded Settings page.

flowchart TD
 A[Gateway agent list] --> B[SettingsShellView]
 B --> C[KeyedMenuRows]
 C --> D[Retained agent rows]
 E[Workspace pin activation] --> B
 B --> F[Embedded page and pane transition]
Loading

Technical review

Best possible solution:

Retain keyed Settings agent rows for the view lifetime while preserving Gateway order, labels, and existing embedded-page navigation.

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

Current-main source contains the row replacement and pane-transition trigger, corroborated by the upstream fix and the reported native stack; the intermittent crash was not independently executed during this read-only review.

Is this the best way to solve the issue?

The fix preserves the necessary invariant that removed rows remain alive during later pane callbacks, uses the existing ordering owner, and avoids hiding partially applied navigation behind retries.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Settings agent-row rebuilding keeps the original intent (f2fa038: The readable Companion refactor established hierarchical agent navigation; earlier introduction could not be verified because a historical git-show lookup encountered an unavailable object.)
  • Agent-row icons and labels keeps the original intent (b5d870e: The sidebar visual refresh introduced BuildAgentItemIcon; the patch retains that icon factory and Gateway-derived labels.)
  • Dashboards selected-row assertion and timing baseline keeps the original intent (feat(dashboards): add native Dashboards page with board widgets #1894: The native Dashboards test verifies selected-pin behavior; the patch preserves that assertion using the readiness pattern required by the later timing guard.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

Likely related people:

  • Barbara Kudiess: Raw commit 7967d50 adds src/OpenClaw.Tray.WinUI/Presentation/PinnedPageRows.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: 7967d509886f; files: src/OpenClaw.Tray.WinUI/Presentation/PinnedPageRows.cs)
  • Pedro Larroy: Raw commit 791574d adds src/OpenClaw.Tray.WinUI/Presentation/WorkspaceItemsSync.cs:10 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 791574ddf557; files: src/OpenClaw.Tray.WinUI/Presentation/WorkspaceItemsSync.cs)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Review metrics

Metric Value Why it matters
Production and test delta Production +60/-11; tests and test metadata +60/-3 Growth implements the required row-retention boundary and focused identity tests while reusing existing ordering machinery.

Labels

Label changes:

  • add P1: Normal agent-list refreshes can leave standard pinned-page navigation crashing Companion or failing before page content loads.
  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab 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:

  • P1: Normal agent-list refreshes can leave standard pinned-page navigation crashing Companion or failing before page content loads.
  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 November 13, 2026, 10:08 AM ET / 15:08 UTC.

@bkudiess
bkudiess merged commit 3cc7280 into openclaw:main Nov 13, 2026
32 checks passed
bkudiess added a commit to bkudiess/openclaw-windows-node that referenced this pull request Nov 14, 2026
GatewayFixtureNativeDashboardsUiTests.cs produced repeated CI flakes from
one-shot FindById(...)! reads after a re-render or resize (openclaw#2171, openclaw#2193).
Sweep the remaining 30 into bounded waits: invocations wait until the
control is present and enabled and invoke once, reads wait for presence
and keep the polled element, and lambdas inside waits treat a missing
peer as not ready.

A local run also showed DashboardsBackdropSpansGalleryAndBoardInBothThemes
failing with "Named backdrop host is missing": its stability wait polled a
helper that threw when the host peer was briefly absent during the
minimum-width resize. The backdrop and responsive stability waits now
treat a missing host as not ready, restart their stability window, and
return the settled width so callers do not re-read it once.

The one-shot lookup baseline entry for this file drops from 30 to 0.

Co-authored-by: Copilot App <[email protected]>
bkudiess added a commit that referenced this pull request Nov 14, 2026
…ion element is briefly missing after a re-render or resize (#2222)

* test(dashboards): wait for UIA peers instead of one-shot reads

GatewayFixtureNativeDashboardsUiTests.cs produced repeated CI flakes from
one-shot FindById(...)! reads after a re-render or resize (#2171, #2193).
Sweep the remaining 30 into bounded waits: invocations wait until the
control is present and enabled and invoke once, reads wait for presence
and keep the polled element, and lambdas inside waits treat a missing
peer as not ready.

A local run also showed DashboardsBackdropSpansGalleryAndBoardInBothThemes
failing with "Named backdrop host is missing": its stability wait polled a
helper that threw when the host peer was briefly absent during the
minimum-width resize. The backdrop and responsive stability waits now
treat a missing host as not ready, restart their stability window, and
return the settled width so callers do not re-read it once.

The one-shot lookup baseline entry for this file drops from 30 to 0.

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

* test(dashboards): give the widget pixel wait a named budget and report widget state

The new-test soak's CPU-contention run failed
DashboardsRenderNativeReportsTabsAndFailureStates with "Timed out waiting for
visible dashboard pixels: 99.97, Uptime". The failure frame shows the HTML
Service health widget still in the product's Slow state ("This widget is taking
longer than usual to load") 30.1 s after board.get. On CI, boards normally
render in 1.8-6.6 s (12 samples, 4 runs).

Replace the literal 30 s with DashboardPixelsTimeout (default 60 s, override
OPENCLAW_GATEWAY_FIXTURE_DASHBOARD_PIXELS_TIMEOUT_SECONDS, capped at 90 s):
one product frame retry after its 30 s load deadline plus a normal render,
inside the 150 s test body budget. On timeout, the message now names each
widget's Loading, Slow, Error or NeedsApproval state, so a slow load stays
distinguishable from a failed one. The diagnostic never replaces the timeout.

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

---------

Co-authored-by: Copilot App <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P1 Urgent regression or broken agent/channel workflow affecting real users now. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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