Repository navigation
Add DI composition root and navigation/activation seam for tray view models - #1008
Conversation
|
Codex review: needs maintainer review before merge. Reviewed July 17, 2026, 6:30 PM ET / 22:30 UTC. Summary Reproducibility: not applicable. This PR adds internal tray infrastructure rather than fixing a reported failure. Its intended present-day runtime behavior is explicitly no-op until pages are mapped to view models. Review metrics: 2 noteworthy metrics.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Next step before merge
Maintainer decision needed
Security Review detailsBest possible solution: Have a tray architecture owner explicitly sponsor the three authoritative seams, then merge this additive foundation and require later page-MVVM work to use these owners rather than creating parallel navigation or dispatcher paths. Do we have a high-confidence way to reproduce the issue? Not applicable: this PR adds internal tray infrastructure rather than fixing a reported failure. Its intended present-day runtime behavior is explicitly no-op until pages are mapped to view models. Is this the best way to solve the issue? Unclear: the implementation is internally coherent and addresses the prior lifecycle review, but whether these three seams are the best permanent tray ownership model requires maintainer architectural intent. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 4518dd87ed2b. Label changesLabel changes:
Label justifications:
Evidence reviewedWhat I checked:
Likely related people:
What the crustacean ranks mean
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
Review history (9 earlier review cycles; latest 8 shown)
|
4f5c74a to
cc86db2
Compare
The DI/navigation direction is reasonable, and the repository-wide reuse check found no existing service container, navigation service, dispatcher abstraction, or navigation-scope owner that this should have reused. The concern is lifecycle correctness before the first real page mapping makes this currently no-op seam active. Please address these items before merge:
Please strengthen behavioral tests rather than adding more source-shape assertions:
Current-head Windows proof should include launch, navigation/back navigation, Hub close/reopen, and clean process shutdown with service-provider initialization/disposal logs and no activation/disposal exceptions. The source-shape tests are acceptable as secondary architecture guards, but they do not prove runtime ownership. Fixing these lifecycle seams now is important because the empty page map only postpones the bugs until the next PR wires the first view model. |
cc86db2 to
1293894
Compare
|
@clawsweeper re-review — added ## Validation and ## Real behavior proof: current-head runtime evidence of DI composition-root build at launch ( |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
1293894 to
4ed8798
Compare
|
Thanks — addressed all four lifecycle items in 1. Dispose ordering. Shutdown now nulls 2. Navigation fault containment. 3. Window/scope lifetime. Added 4. Navigation contract/threading. Behavioral tests added: map A/B view models and assert Validation: Note on runtime proof: live Hub close/reopen + clean-shutdown disposal logs couldn't be captured from the automation host because it runs in a switched Windows session (session 2, not the active console), so the tray Close menu can't be driven there; those paths are covered by the tests above and can be captured from an interactive console session. |
|
@clawsweeper re-review — added live current-head (HEAD 4ed8798) runtime proof for the Hub close/reopen path to the PR body's Real behavior proof section:
Still test-covered (not live): the |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review — the clean-shutdown provider init/disposal live logs are now captured at current head (4ed8798) with no lifecycle exceptions. Driven by an interactive tray Close on the isolated build: Ordered sequence confirms the invariants live: windows/services disposed first → then |
The updated head resolves the major lifecycle concerns: Two items remain before this is uniformly above 90%:
Please also remove the duplicated Once those are addressed and the branch is rebased onto current main with green build/Tray tests, this should be ready for a quick final review. |
…models Introduce the dependency-injection and navigation plumbing that page view models will depend on: a root ServiceProvider owned by App, a navigation scope/activation seam, and a UI-thread dispatcher abstraction. This is additive infrastructure only -- no page is converted to MVVM and no existing App behavior is moved. Intended runtime behavior change: none. - Add Microsoft.Extensions.DependencyInjection (10.0.0). App builds one validated root ServiceProvider (ValidateScopes + ValidateOnBuild) after tray init, disposed via an ordered shutdown step. App-owned services (SettingsManager, IAppCommands) are registered as pre-built instances so the container never disposes them (no double-dispose). - Presentation/ WinUI-free core: IUiDispatcher, INavigationAware, INavigationService, IPageActivator, NavigationScopeManager, AppNavigationService, transient Settings/Permissions page-view-model placeholders. - Presentation/Adapters/ WinUI-bound: WinUIDispatcher, FramePageActivator. - HubWindow activation hook (empty page-to-view-model map => runtime no-op). - Ledger: three authoritative rows (ui-dispatcher, navigation-scope, composition-root) with behavioral guard tests; single-source-owner entries. - 20 presentation tests (unit + source-contract, incl. WinUI-free guard). Co-authored-by: Copilot App <[email protected]>
4ed8798 to
3ff1f43
Compare
|
Thanks — both remaining items and the nit are addressed in 1. UI-thread enforcement (now enforced via 2. Integration proof (behavioral, current head). Added
These complement the live Windows smoke transcript in the PR body (open → navigate → close → reopen → clean shutdown with the Nit: removed the duplicated Validation: |
Summary
Introduces the dependency-injection and navigation plumbing that page view models will depend on: a root
ServiceProviderowned byApp, a navigation scope/activation seam, and a UI-thread dispatcher abstraction. This is additive infrastructure only — no page is converted to MVVM and no existingAppbehavior is moved. Intended runtime behavior change: none.What this adds
Microsoft.Extensions.DependencyInjection(10.0.0).Appbuilds one rootServiceProviderwithValidateScopes+ValidateOnBuild, after tray initialization, and disposes it via an ordered shutdown step. App-owned services (SettingsManager,IAppCommands) are registered as pre-built instances, so the container never disposes them —Appkeeps sole ownership and there is no double-dispose. A build/validation failure is logged and leaves the provider null, so this plumbing can never prevent the tray from starting.Presentation/WinUI-free core:IUiDispatcher,INavigationAware,INavigationService,IPageActivator,NavigationScopeManager(owns the per-navigation DI scope and the view-model activate/deactivate/dispose lifetime; navigation is non-re-entrant and exception-safe),AppNavigationService(enforces UI-thread affinity — marshalsNavigate/GoBackthroughIUiDispatcher, fails fast on off-threadCanGoBackreads), and transientSettingsPageViewModel/PermissionsPageViewModelplaceholders. Hand-linked into the purenet10test project.Presentation/Adapters/WinUI-bound:WinUIDispatcher,FramePageActivator.HubWindow.OnContentFrameNavigated. The page→view-model map is empty, so it is a runtime no-op today: it only advances the navigation scope and never touches a page'sDataContext, navigation, back-stack, rail selection, or dedupe. HubWindow's existing navigation is untouched.Ownership / ledger
Adds three
authoritativerows with behavioral guard tests —ui-dispatcher(IUiDispatcher),navigation-scope(NavigationScopeManager),composition-root(AppServiceRegistration) — plus matching single-source-owner entries.Validation
build.ps1: pass (all projects)dotnet test OpenClaw.Shared.Tests: 2866 passed / 31 skipped (incl. architecture-ledger consistency)dotnet test OpenClaw.Tray.Tests: 1780 passed (incl. 38 presentation unit + integration + source-contract tests covering: no double-dispose of App-owned instances, transient view-model disposal with scope, non-re-entrant navigation,Activate/Deactivate-throws scope disposal,Reset()window-close teardown + re-navigation, A→B deactivate/dispose-before-activate ordering, UI-thread marshaling/fail-fast enforcement, full open→navigate→close→reopen→shutdown integration,ValidateOnBuild, the WinUI-free boundary, and the ordered shutdown-disposal step)Real behavior proof
Verified against a local Debug build of this branch (node reports
0.6.13-bkudiess-pr4-di-navigation-seam.1), non-isolated tray, real gateway node.Service provider initialized.on launch (observed across 3 launches). This is theInitializeServiceProvider()success line, provingBuildServiceProvider(ValidateScopes + ValidateOnBuild)succeeds in a real tray process after tray init, with no validation throw.caps=6, commands=25;winnode --list-toolsreturns 52 tools; node connected innodemode.ConnectionPagerendered;OnContentFrameNavigatedruns the new activation hook each time with no errors — confirming the hook is a safe no-op today.4ed87980): on an isolated temp profile (EnableMcpServer=true; real%APPDATA%untouched):[INFO] Service provider initialized.; startup logs[MCP] HTTP server listening on http://<host>:8765/,Started MCP-only node service without gateway connection,Application started (WinUI 3).winnode --command app.navigate {"page":"permissions"}→navigated:true(Companion window present inlist_apps).list_apps, i.e.HubWindow.Closedfired and theIPageActivator.Reset()path ran, with no exception logged.app.navigate {"page":"connection"}→navigated:true(fresh navigation afterReset()), no exception (only a benign, unrelated[WARN] [ConnectionPage] Could not subscribe to High Contrast changes).[ERROR]isPrevious session did not exit cleanly(from an earlierStop-Processkill of a prior probe instance, not PR code) — noObjectDisposedException, nofailed disposing, no lifecycle exceptions.SafeShutdownStepAsync("service provider", …)which nulls_servicesand then awaitsServiceProvider.DisposeAsync(). Captured live at current head (4ed87980) by clicking the tray Close on the isolated build:service provider→ then tray icon → single-instance mutex → deep link token source →Shutdown complete; calling Exit() now.disposed service providerappears exactly once (no double-dispose), there is noShutdown: failed disposingline and noObjectDisposedException, and the_services = nullbeforeawait DisposeAsync()fix ran cleanly (no lateFrame.Navigatedfault). Corroborated byPresentationSeamContractTests.App_DisposesServiceProvider_DuringShutdown,App_NullsServiceProviderField_BeforeAwaitingDisposal, andAppServiceRegistrationTests.Dispose_DoesNotDisposeAppOwnedInstanceSingletons.Follow-ups
OnContentFrameNavigatedactivation-hook body in try/catch-and-log so a misbehaving view modelActivate/Deactivatecannot surface as an unhandled exception in the frame-navigated handler.IUiDispatcherif/when a consumer needs it.