Skip to content

refactor(tray): extract final App orchestration owners - #1088

Open
bkudiess wants to merge 1 commit into
bkudiess-app-surface-ownersfrom
bkudiess-app-lifecycle-owners
Open

refactor(tray): extract final App orchestration owners#1088
bkudiess wants to merge 1 commit into
bkudiess-app-surface-ownersfrom
bkudiess-app-lifecycle-owners

Conversation

@bkudiess

@bkudiess bkudiess commented Aug 4, 2026

Copy link
Copy Markdown
Collaborator

Extracts the final safe App orchestration seams while keeping startup and service construction in App. This is layer 4 of native App stack #1083 and depends on #1085, #1082, and #1075.

Summary

  • Add ActivationRouter for launch, toast, deep-link, and forwarded single-instance activation planning, confirmation, redaction, current-user IPC, and lifecycle quiescence.
  • Reuse DeepLinkHandler and ToastActivationRouter as the only route tables; App applies one closed semantic route union through the existing A2 surface owners/services.
  • Add SettingsChangeCoordinator for detached-snapshot classification and exact post-save effect ordering through narrow App effect ports.
  • Serialize nested/concurrent settings requests through a FIFO single drainer; commit comparison/version state only after all effects succeed.
  • Add AppShutdownCoordinator for first-wins shared-task shutdown, ordered per-step catch/log/continue, and final Exit exactly once.
  • Keep App as the WinUI composition root and owner of startup service construction, application identity/mutex, resource fields, typed effect/sink adapters, shutdown-plan construction, and startup ordering.
  • Explicitly defer AppBootstrapper: current startup does not yet have construction seams that can move without creating a callback shell or replacement god coordinator.
  • Update architecture ledger authoritative/closed rows and anti-regression guards.

Ownership transfer

Old owner New owner Preserved invariant
App activation parsing, confirmation, IPC, and routing decisions IActivationRouter / ActivationRouter Current-user IPC, strict size/UTF-8 guards, redaction, confirmation, launch precedence, exact routes, and no dispatch after stop
App.OnSettingsSaved classification and effect order ISettingsChangeCoordinator / SettingsChangeCoordinator BrowserProxy/reconnect/MCP/hotkey/autostart/telemetry/surface order, retry-after-failure, FIFO reentrancy, MCP-only behavior, and credential precedence
App shutdown guard and safe-step executor IAppShutdownCoordinator / AppShutdownCoordinator First-wins published task, UI-thread continuation, field clearing on failure, failure continuation, null-before-await, and Exit once

App remains the sole composition root and startup owner. A0 shared state, A1 presentation, and A2 tray/window ownership remain unchanged.

Validation

  • ./build.ps1: all 5 projects passed, 0 errors/warnings
  • OpenClaw.Shared.Tests: 3,415 passed, 32 skipped
  • OpenClaw.Tray.Tests: 2,258 passed
  • OpenClaw.Connection.Tests: 529 passed
  • OpenClaw.SetupEngine.Tests: 703 passed
  • Functional UI: 19 passed
  • Gated Tray integration: 19 passed
  • Native UI: 117 passed
  • Accessibility: 19 passed
  • Real setup/connect E2E: 21 passed
  • Focused lifecycle/security/order proof: 137 passed

Real behavior proof

  • Isolated current-head MCP-only startup exposed 51 live tools and succeeded without gateway credentials.
  • Real app.settings.set calls produced UiOnly, NoOp, and NodeReconnectRequired impact paths while MCP remained running.
  • A true second current-head process forwarded openclaw://chat, exited 0, and the primary remained responsive.
  • Source-blind UI Automation confirmed the visible Connection fallback: Connect to gateway to start chatting; no pairing-incomplete silent no-op.
  • Real E2E covered pairing-required, node-pending, device-token, and paired transitions.
  • The real tray Close action exited naturally. Logs showed activation router, hotkey, chat, repair, connection, telemetry, node, voice, SSH, pairing, observers, A2 windows, tray menu, settings coordinator, provider, A2 tray icon, mutex, and final Exit exactly once and in order.

The non-interactive desktop returned a blank screenshot and blocked physical pointer injection, so visible evidence used source-blind Windows UI Automation names and exact runtime logs. Natural process exit and ordered shutdown evidence were obtained.

Adversarial review and fixes

  • Forwarded activation confirmation originally blocked later forwards and shutdown: dispatch is now tracked/nonblocking; stop cancels and drains all direct/forwarded work.
  • Direct toast/launch dispatch is rejected once stopping begins; toast unsubscribes and router field clears before disposal.
  • Settings effect failures no longer commit comparison/version state; same-version retry repeats the original reconnect classification.
  • Reentrant and concurrent settings requests now run FIFO; admitted work drains after disposal while new admission is rejected.
  • Shutdown preserves UI synchronization context, clears captured async fields in finally, publishes the shared shutdown task before reentrant callbacks, continues after failures, and exits once.
  • Settings coordinator disposal is ordered before provider disposal.

Final independent Claude Opus 4.8 and GPT-5.6 Sol staged-diff reviews found no remaining actionable findings. Gemini and Sonnet review findings were also reconciled; the intentional early ActivationRouter drain is a tested correctness improvement.

Architecture

Adds authoritative and closed ledger rows for activation, settings coordination, and shutdown, and narrows A2 residue. Startup remains in App.OnLaunchedAsync; AppBootstrapper remains planned/deferred.

Stack

Directly based on A2 PR #1085. This is the fourth/final App architecture layer after #1075, #1082, and #1085.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. labels Aug 4, 2026
@clawsweeper

clawsweeper Bot commented Aug 4, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed August 6, 2026, 4:12 AM ET / 08:12 UTC.

ClawSweeper review

What this changes

The PR extracts deep-link and toast activation planning, post-save settings effects, and exactly-once shutdown sequencing from the native tray App into focused services while retaining App as the composition root.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep open. This collaborator-authored, stacked tray refactor has no discrete correctness finding in the reviewed patch; it needs normal maintainer integration after its three parent layers land or it is rebased onto current main.

Priority: P2
Reviewed head: 7a2b6b8c43e13c6554518d45c001aa6466f0ced2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) Strong targeted proof and regression coverage support a good lifecycle refactor, with final confidence appropriately gated on stacked integration.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (logs): The PR body provides exact-head runtime logs for MCP-only startup, settings effects, second-process deep-link forwarding, pairing states, UI Automation fallback, and ordered natural shutdown; redact sensitive values if additional artifacts are posted.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The PR body provides exact-head runtime logs for MCP-only startup, settings effects, second-process deep-link forwarding, pairing states, UI Automation fallback, and ordered natural shutdown; redact sensitive values if additional artifacts are posted.
Evidence reviewed 6 items Stacked branch remains unmerged: The PR head and its parent-layer base both diverge from current main at d2de615; current main does not contain this refactor, so it is not eligible for an implementation close.
Activation security boundary retained: The extracted router creates its named-pipe listener with CurrentUserOnly, validates payload size and deep-link syntax before forwarding, and cancels/drains dispatches at stop.
Lifecycle behavior has focused coverage: Added tests cover activation cancellation and forwarding, settings FIFO/retry semantics, and first-wins shutdown with ordered continuation after failures.
Findings None None.
Security None None.

How this fits together

The Windows tray App receives launch, toast, and settings events, then drives tray/window surfaces, gateway and local MCP runtime state, and orderly shutdown. The new services plan those lifecycle operations while App remains the platform-specific composition and effect-adapter boundary.

flowchart LR
A[Launch, toast, and settings events] --> B[Tray App composition root]
B --> C[Activation planning]
B --> D[Settings effect coordination]
B --> E[Shutdown sequencing]
C --> F[Tray and window surfaces]
D --> G[Gateway and local MCP runtime]
E --> H[Ordered process exit]
Loading

Before merge

Agent review details

Security

None.

Review metrics

Metric Value Why it matters
Patch size production +1,857 / -693 lines; tests +1,436 / -52 lines The substantial production extraction is accompanied by focused lifecycle, activation, and settings regression coverage.
Changed surface 26 files The patch spans App composition, route planning, settings effects, shutdown, architecture records, and tray tests.

Merge-risk options

Maintainer options:

  1. Integrate after the parent stack (recommended)
    Land or rebase the three parent ownership layers first, then rerun the documented exact-head lifecycle validation before merging this layer.
  2. Pause the stack
    Pause this layer if the parent stack is not accepted, because its composition adapters depend on those owners.

Technical review

Best possible solution:

Land the parent ownership layers in order, then rebase this final lifecycle layer onto main and preserve its activation, settings, and shutdown proof on the rebased head.

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

Not applicable as a refactor. The supplied exact-head runtime proof and focused tests exercise the behavior-equivalence paths rather than reproduce a pre-existing defect.

Is this the best way to solve the issue?

Yes. The extracted services retain App as composition root, use narrow effect ports, update the architecture ledger, and add focused guards; the collaborator's scope decision also resolves the earlier split concern.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against aac07abb1fbd.

Labels

Label justifications:

  • P2: This is a substantial but non-emergency native tray architecture refactor.
  • merge-risk: 🚨 security-boundary: The patch changes current-user deep-link IPC admission, confirmation, and shutdown fencing.
  • merge-risk: 🚨 availability: The patch changes startup routing, settings reconnect effects, and process teardown ordering.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The PR body provides exact-head runtime logs for MCP-only startup, settings effects, second-process deep-link forwarding, pairing states, UI Automation fallback, and ordered natural shutdown; redact sensitive values if additional artifacts are posted.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides exact-head runtime logs for MCP-only startup, settings effects, second-process deep-link forwarding, pairing states, UI Automation fallback, and ordered natural shutdown; redact sensitive values if additional artifacts are posted.

Evidence

What I checked:

  • Stacked branch remains unmerged: The PR head and its parent-layer base both diverge from current main at d2de615; current main does not contain this refactor, so it is not eligible for an implementation close. (7a2b6b8c43e1)
  • Activation security boundary retained: The extracted router creates its named-pipe listener with CurrentUserOnly, validates payload size and deep-link syntax before forwarding, and cancels/drains dispatches at stop. (src/OpenClaw.Tray.WinUI/Services/ActivationRouter.cs:182, 7a2b6b8c43e1)
  • Lifecycle behavior has focused coverage: Added tests cover activation cancellation and forwarding, settings FIFO/retry semantics, and first-wins shutdown with ordered continuation after failures. (tests/OpenClaw.Tray.Tests/AppShutdownCoordinatorTests.cs:57, 7a2b6b8c43e1)
  • Architecture-ledger transfer is explicit: The patch records activation routing, settings effect ordering, and ordered shutdown as authoritative focused owners and leaves startup sequencing planned in App. (docs/ARCHITECTURE.md:73, 7a2b6b8c43e1)
  • Feature-history routing: Recent App history includes Barbara Kudiess's gateway and settings work and Jeremy McKeehen's current App maintenance, making both appropriate reviewers for lifecycle compatibility. (src/OpenClaw.Tray.WinUI/App.xaml.cs, 8ac00c5f4977)
  • Real behavior proof supplied: The PR body reports exact-head MCP-only startup, live settings impact paths, forwarded deep-link handling, pairing transitions, UI Automation fallback behavior, and natural ordered shutdown. The prepared media artifacts belong to earlier stack layers, so this conclusion relies on the current-head runtime logs in this PR body. (7a2b6b8c43e1)

Likely related people:

  • Barbara Kudiess: Authored the current refactor and earlier current-main App settings and gateway lifecycle work found in feature history. (role: recent tray lifecycle contributor; confidence: high; commits: 7a2b6b8c43e1, bc210e048aa9, d2638ddbef57; files: src/OpenClaw.Tray.WinUI/App.xaml.cs, src/OpenClaw.Tray.WinUI/Services/ActivationRouter.cs, src/OpenClaw.Tray.WinUI/Services/SettingsChangeCoordinator.cs)
  • Jeremy McKeehen: Recent current-main App history includes the browser-token lifecycle fix, adjacent to the connection and settings paths this refactor preserves. (role: recent App-area contributor; confidence: medium; commits: 8ac00c5f4977; files: src/OpenClaw.Tray.WinUI/App.xaml.cs)

Rank-up moves

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

  • After the parent stack lands or this branch is rebased, rerun the documented build, shared/tray tests, and exact-head lifecycle proof.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • 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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-08-04T08:01:55.038Z sha 53a4d0b :: needs maintainer review before merge. :: none
  • reviewed 2026-08-05T06:27:34.574Z sha 53a4d0b :: found issues before merge. :: [P2] Split the independent App ownership transfers
  • reviewed 2026-08-05T21:58:19.944Z sha 7a2b6b8 :: found issues before merge. :: [P2] Split the independent lifecycle ownership transfers
  • reviewed 2026-08-05T22:28:00.819Z sha 7a2b6b8 :: needs maintainer review before merge. :: none

@bkudiess
bkudiess marked this pull request as draft August 5, 2026 06:23
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Aug 5, 2026
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@bkudiess
bkudiess force-pushed the bkudiess-app-lifecycle-owners branch from 53a4d0b to 7a2b6b8 Compare August 5, 2026 21:52
@bkudiess

bkudiess commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer scope decision: keep A3 as one final App-orchestration layer.

The product owner explicitly requested fewer consolidated PRs. Activation routing, post-save settings coordination, and ordered shutdown are the three remaining App-owned orchestration seams and share the same composition adapters, lifecycle fencing, disposal order, ledger closeout, current-head runtime proof, and rollback boundary. Each owner still has its own typed contract, authoritative/closed ledger rows, deterministic behavioral guards, focused tests, and independently reviewed invariants. Splitting this already validated final layer would add stack/cascade risk without changing runtime ownership or proof.

I accept the combined A3 scope for normal maintainer review. The branch remains mergeable; local exact-current build, Shared, Tray, Connection, Setup, FunctionalUI, Integration, Native UI, Accessibility, focused lifecycle, and SetupAndConnect E2E are green.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Aug 5, 2026

Copy link
Copy Markdown

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 5, 2026
@bkudiess
bkudiess marked this pull request as ready for review August 6, 2026 08:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 availability 🚨 Merging this PR could cause crashes, hangs, restart loops, stalls, or process outages. merge-risk: 🚨 security-boundary 🚨 Merging this PR could weaken sandboxing, authorization, credentials, or sensitive data. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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