Skip to content

fix: collapsing the sidebar can crash Companion after sessions or pinned pages change - #2172

Merged
bkudiess merged 1 commit into
openclaw:mainfrom
bkudiess:bkudiess-sidebar-row-retention
Nov 13, 2026
Merged

bkudiess merged 1 commit into
openclaw:mainfrom
bkudiess:bkudiess-sidebar-row-retention

Conversation

@bkudiess

Copy link
Copy Markdown
Collaborator

Related: #2171 (fix: pinned pages can crash Companion after Settings refreshes its agent list)

What Problem This Solves

Fixes: Companion can raise an unhandled COMException 0x80004005 "Unspecified error" (no managed stack), or crash with 0xC0000005, when the Workspace sidebar is collapsed or reopened after a pinned page was unpinned or a session left the sidebar. In fixture CI this shows up as "The real app wrote a crash log" with exactly that signature; the most recent case is Automations_DesignerValidationFocusAndDraftsStayIsolated on #2170 run 43443495532.

User Impact

User impact: unpinning and re-pinning pages, or sessions coming and going (new chats, deleted chats, cron and subagent runs), no longer leaves the sidebar in a state where the next pane collapse or reopen can crash Companion. Sidebar order, labels, selection, focus repair and Narrator names are unchanged. A re-pinned page shows its original row again.

Why This Change Was Made

This is the same WinUI bug that #2171 fixed for the Settings agent rows: microsoft/microsoft-ui-xaml#10757, fixed upstream by microsoft/microsoft-ui-xaml#12235 but not in Windows App SDK 2.6.5, which this app ships.

  • NavigationViewItem registers SplitView property callbacks that capture the raw item.
  • After a row is removed from a menu and reference tracking collects it, the next SplitView change (collapsing or reopening the pane) calls into the freed row.

The Workspace sidebar had two removal paths:

  • PinnedPageRows removed and forgot a row on unpin and created a new one on re-pin.
  • SyncSessionItems removed a session's row from MenuItems and dropped it from its cache.

This PR moves both onto KeyedMenuRows (added in #2171), extended so it works inside the shared sidebar menu:

  • Shared menu support: it places its rows at a start index and removes only rows it owns, so Home, the separator, headers and the other section are untouched.
  • Pinned pages (at most 7 catalog entries): rows are kept per tag and never released. Unpin removes the row from the menu; re-pin shows the same row again. PinnedPageRows still reports removed rows and whether the focused row was removed, using focus captured before any detach.
  • Sessions: rows use a pool. A row that leaves the sidebar stays referenced, and a new session takes a retired row first and is rebound to it (IsSelected cleared, AutomationId, Tag, content, context menu, Name, tooltip and ItemStatus reset). A pooled row is only reused after the sync that retired it, so a reused row is never still in the menu.
  • Settings agent menu: it now adopts the XAML DefaultAgentNavItem (agent:main) instead of replacing it on the first sync. This resolves a LOW note from the fix: pinned pages can crash Companion after Settings refreshes its agent list #2171 review.
  • Settings exit focus: if a session row had focus when Settings opened, leaving Settings restores focus to that row only if it still shows the same session. Otherwise a pooled row could carry focus to a different conversation.

Memory tradeoff (retained rows)

These are estimates from both reviewers, not measurements:

  • A realized session row (NavigationViewItem template, session content grid, unopened context menu) costs roughly 20 to 100 KB of native memory. A context menu that has been opened keeps its items, which can add more.
  • Without pooling (plain retention by key), retained rows would grow with every distinct session ever shown for the life of the window. The sidebar shows every session of the selected agent (sessions.list has no page limit here), and cron and subagent runs create new session keys continuously. For example, an hourly automation over two weeks is about 340 sessions, roughly 7 to 34 MB, and it keeps growing.
  • With pooling (this PR), the number of rows is bounded by the largest union of two consecutive sidebar lists, that is at most 2× the largest number of sessions shown at once. It does not grow with session churn. A user with 50 sessions for an agent keeps at most about 100 rows (roughly 2 to 10 MB). Switching between two agents with 100 sessions each keeps about 200 rows, the same as the peak the sidebar already had to render.
  • Pinned pages are bounded by the 7-entry catalog; Settings agent rows by the agent roster.

Once a Windows App SDK release includes #12235, KeyedMenuRows can stop retaining removed rows. As of 2026-11-13, neither the 2.6.5 nor the 2.6.6-experimental release notes mention #10757 or #12235.

Evidence

  • Deterministic RED/GREEN (temporary local probe, not committed): unpin and re-pin Dashboards 12 times, then collapse and reopen the Workspace pane 20 times.
  • A second probe switched agents 8 times (which removes and re-adds session rows), then toggled the pane 20 times. It did not reproduce on main (0 of 6), so the session-row change is covered by the same mechanism, unit tests, and 7 of 7 clean runs on this PR.
  • Review: dual-model Hanselman review on base 3cc72800f (Claude Opus 5.5 and GPT-6 Astra long-context, both high effort), plus a delta review of the fixes. Neither found a CRITICAL or HIGH issue. Applied:
    • Settings exit focus could follow a pooled row to a different session (Astra MEDIUM, Opus LOW).
    • KeyedMenuRows.Sync keeps every row owned if a create or rebind callback throws (Opus LOW).
    • A pooling instance requires a rebind callback (Opus LOW).
    • Delta review: a rebind that throws partway returns the row to the pool so a retry for the same key rebinds it (Astra MEDIUM, Opus LOW); the Settings exit-focus check also recognizes focus on a descendant of a session row (Opus LOW). Neither delta review found a CRITICAL or HIGH 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 sidebar, pinned-page and Settings 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
Sidebar crash probe (pin churn, then pane toggles) main+#2171: 4 of 6 crash logs; this PR: 23/23 clean
Session churn probe (agent switches, then pane toggles) 7/7 clean (did not reproduce on main, 0/6)
DashboardsRenderNativeReportsTabsAndFailureStates 2/2 on the final source, 5/5 and 5/5 on earlier revisions
SettingsPane_KeepsToggleChoiceAcrossPinnedPagesAndRestart 2/2 on the final source, 3/3 and 3/3 on earlier revisions
HomeSidebar_CustomizeDoesNotNavigate_AndHomeRestoresCanonicalConversation 2/2 on the final source, 3/3 earlier
Full fixture UI set, non-keyboard (Category=GatewayFixture&KeyboardProof!=Required, pre-review head) 124/125. The one failure is Automations_ScopesToAgentsAndCoversMainStates, an Axe BoundingRectangleSizeReasonable violation that happens only locally at 175% DPI and also fails on main here.
Full fixture UI set, keyboard proof (KeyboardProof=Required, pre-review head) 5/9. The same 4 tests fail identically on main on this machine.
KeyedMenuRowsTests, PinnedPageRowsTests (new and updated cases) passed (part of the Tray run below)
  • .\scripts\validate-test-timing-patterns.ps1: passed.
  • ./build.ps1: all builds succeeded.
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj: 5862 passed, 0 failed, 29 skipped.
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj: 6453 passed, 0 failed (final source).

Real Behavior Proof

  • Environment tested: local Windows x64 desktop, 175% DPI, isolated profiles, Windows App SDK 2.6.5.
  • PR head or commit tested: e9ce8f3 (rebased onto main e9ed3ba with no upstream changes to the touched files; validated on the identical pre-rebase source).
  • Exact steps or command run: dotnet test tests/OpenClaw.Tray.UITests -c Debug -r win-x64 -p:DevBuild=false --no-build --filter "<test>" with OPENCLAW_RUN_GATEWAY_FIXTURE_UI=1 for each test above, plus the two probes described under Evidence.
  • Evidence after fix: the pass counts above, and no app crash log in any probe run.
  • Observed result: pins and sessions update in place, and collapsing and reopening the sidebar stays stable.
  • 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.
    • The memory figures are reviewer estimates, not native heap measurements.
    • No fixture UI test exercises pooled session-row reuse (a session leaving the list and a new one arriving); it is covered by unit tests.
    • Accepted LOW note: a reused row could briefly keep a stale hover highlight until the pointer moves.

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.

…ned pages change

The Workspace sidebar removed NavigationViewItems when a session left the list
or a page was unpinned. WinUI keeps SplitView callbacks on removed rows
(microsoft/microsoft-ui-xaml#10757, fixed upstream by #12235 but not in Windows
App SDK 2.6.5). Once a removed row is collected, the next pane change calls
into it and raises an unhandled E_FAIL or an access violation.

KeyedMenuRows now works inside a shared menu: it places rows at a start index,
removes only the rows it owns, can adopt an existing row and can pool retired
rows. Pinned-page rows come from it, so a re-pin shows the original row again.
Session rows use a pool, so a new session reuses a retired row and memory stays
close to the most rows shown at once. The Settings agent menu adopts its XAML
"main" row instead of replacing it.

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 retains removed sidebar rows and reuses retired session rows to prevent crashes during later pane changes.

Example: Unpin and re-pin Dashboards 12 times, then collapse and reopen the sidebar 20 times.

  • Before: Removed navigation rows can be collected while WinUI still holds callbacks, causing E_FAIL or an access violation.
  • After: Removed rows remain referenced, and re-pinning restores the original Dashboards row.

Review scores

Measure Result What it means
Overall readiness 🧂 unranked krab (1/6) The focused patch has no identified correctness defect, but reported local runs lack inspectable evidence of the changed native behavior.
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: Collapsing or reopening the sidebar after pins or sessions change can crash Companion.
Reason: The maintainer-authored repair restores ordinary navigation without adding configuration or changing the intended sidebar experience.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR addresses a concrete sidebar crash path still present on main; source review found no actionable introduced defects.

Priority: P1
Reviewed head: e9ce8f355f7c0b31dd6c2583107564163fdf9c93

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: Provide viewable current-head runtime diagnostics or a recording covering pin churn followed by pane toggles and pooled session-row reuse with correct actions and Settings-return focus; committed-test base-failing execution is not shown.
Agent review details

How this fits together

Workspace and Settings turn session, pin, and agent lists into native NavigationView rows; reconciliation updates menu order, selection, accessibility metadata, and focus.

flowchart TD
 A[Session and pin lists] --> B[WorkspaceWindow]
 C[Agent roster] --> D[SettingsShellView]
 B --> E[KeyedMenuRows]
 D --> E
 E --> F[Retained and pooled rows]
 F --> G[Native NavigationView]
Loading

Technical review

Best possible solution:

Extend the existing keyed-row owner to retain removed pins and pool session rows while preserving menu order, selection, accessibility, and focus identity.

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

Main's row-removal paths and the verified upstream callback defect support the reported trigger; the author describes base-versus-fix reproduction, but this read-only review did not independently reproduce the native crash.

Is this the best way to solve the issue?

The patch fixes the lifetime cause through the existing owner rather than catching the resulting exception; pooling addresses continuous session churn, and the focus check preserves conversation identity when a row is rebound.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Session sidebar reconciliation keeps the original intent (791574d: The session-sidebar feature reconciled rows by key to preserve containers and avoid repeated selection and layout work; the new pool preserves that behavior for visible keys.)
  • Pinned-page row identity and focus keeps the original intent (7967d50: Pinned pages reused native navigation and keyed rows to preserve focus across preference changes; the patch retains removal reporting and extends identity preservation across re-pinning.)
  • Settings agent-row lifetime keeps the original intent (3cc7280: The preceding crash repair retained agent rows to prevent callbacks into collected items; adopting the XAML row and supporting shared menus preserve that invariant.)
  • Settings exit focus restoration keeps the original intent (4e31031: The unified Workspace restored the control focused before Settings opened; checking the captured session key prevents pooled-row reuse from restoring focus to another conversation.)

Testing

Proof path: unit tests only.

Security

None.

Evidence

What I checked:

Likely related people:

  • Barbara Kudiess: Raw commit 3cc7280 adds src/OpenClaw.Tray.WinUI/Presentation/KeyedMenuRows.cs:23 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 3cc72800f118; files: src/OpenClaw.Tray.WinUI/Presentation/KeyedMenuRows.cs)
  • Pedro Larroy: Raw commit 791574d adds src/OpenClaw.Tray.WinUI/Windows/WorkspaceWindow.xaml.cs:27 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 791574ddf557; files: src/OpenClaw.Tray.WinUI/Windows/WorkspaceWindow.xaml.cs)
  • Karen: Raw commit 3a58bf3 adds src/OpenClaw.Tray.WinUI/Windows/WorkspaceWindow.xaml.cs:26 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: medium; commits: 3a58bf34902f; files: src/OpenClaw.Tray.WinUI/Windows/WorkspaceWindow.xaml.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 +116/-53; tests +136/-7 Growth extends the existing lifetime owner and covers shared-menu isolation, row adoption, bounded reuse, recovery, and re-pinning without adding another service.

Labels

Label changes:

  • add P1: Ordinary pin or session changes can leave subsequent sidebar collapse or reopening crashing Companion.
  • 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: Ordinary pin or session changes can leave subsequent sidebar collapse or reopening crashing Companion.
  • 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, 12:24 PM ET / 17:24 UTC.

@bkudiess
bkudiess merged commit 9065324 into openclaw:main Nov 13, 2026
33 checks passed
karkarl added a commit to karkarl/openclaw-windows-node that referenced this pull request Nov 13, 2026
Resolves conflicts with openclaw#2173 (session dashboard tab beside chat), openclaw#2176, openclaw#2175, openclaw#2116 and openclaw#2172:

- ReactorBoardView: embedded board keeps main's compact 12/0 padding, standalone pages keep the shared PageResponsiveLayout PaddingTop/PaddingBottom.
- Resources.resw (all 6 locales): keep this PR's PageAction_Refresh keys and main's Chat_Panel_Dashboard.
- TestTimingPatternBaseline.json: main's counts, then lowered for this branch.

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