Skip to content

feat(notifications): add focus-aware delivery modes - #133393

Open
roboclaw-bot wants to merge 1 commit into
mainfrom
roboclaw/turn-notification-focus-policy
Open

roboclaw-bot wants to merge 1 commit into
mainfrom
roboclaw/turn-notification-focus-policy

Conversation

@roboclaw-bot

@roboclaw-bot roboclaw-bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #133392

What Problem This Solves

Browser push categories were binary on/off. Users actively reading a destination chat still received a redundant push for that chat, while turning the category off also removed useful background notifications.

Why This Change Was Made

This adds one delivery-mode contract across every browser push category: Never, Only when unfocused, and Always. Account defaults and per-device overrides share the same choices. Existing stored booleans normalize to the equivalent canonical modes.

The preference RPC remains additive across rolling Gateway/UI upgrades. Older open Control UI clients can continue writing booleans and, because they omit the new deliveryModes read capability, receive Boolean-compatible preference responses. Current clients advertise deliveryModes: true and receive canonical modes. Writes normalize immediately; durable state stays mode-only.

The service worker owns device-local focus suppression. For a notification with a destination, it suppresses only when a visible, focused OpenClaw window reports the exact route. Destination-less notifications use any focused OpenClaw window. Missing, stale, malformed, cross-origin, or unresponsive client state fails open and shows the notification. Focus state never leaves the browser and one device cannot silence another.

Defaults remain conservative and compatible: approval requests are Always; agent turns, questions, scheduled-task failures, and background-task failures remain Never until enabled.

User Impact

Users can enable turn and other browser notifications without being alerted for work they are already viewing. They can choose different urgency per category and override the account choice on an individual browser or app. Already-open pre-upgrade Control UI tabs retain correct checkbox reads and saves after the Gateway updates.

Before: binary category checkboxes

Before: browser notification categories use binary checkboxes

After: account delivery modes

After: every account category offers Never, Only when unfocused, and Always

After: per-device overrides

After: device overrides use the same modes plus account inheritance

Evidence

  • node scripts/run-vitest.mjs src/gateway/approval-web-push.test.ts src/gateway/event-web-push.test.ts src/gateway/server-methods/push.test.ts src/infra/push-web-preferences.test.ts src/infra/push-web.test.ts ui/src/app/service-worker-cache.test.ts ui/src/app/web-push.test.ts ui/src/pages/config/notifications-section.test.ts — 170 tests passed across four Vitest shards, including old/new read negotiation and legacy account/device writes.
  • node scripts/check-changed.mjs — passed core, core-test, and UI formatting, typecheck, lint, i18n, dependency, storage, and architecture gates after both compatibility repairs.
  • .agents/skills/autoreview/scripts/autoreview --mode local --base 42396a01eba0c732d6618c3f88d37a1909529324 — complete PR candidate scoped clean; no accepted/actionable P0 findings.
  • Exact-head hosted CI passed on each prior head; final head 4b630039216d295a50f5331d4c1077430af8e83c is being revalidated separately.
  • Real Chromium screenshots captured at 1440×1000 in dark mode against the repository's mocked Control UI server. The before image uses exact parent 42396a01eba; after images use the same UI implementation retained in the final head. Every attached image was inspected at full resolution.
  • Production LOC: +312/-80 (net +232), adding the delivery-mode protocol, negotiated rolling-upgrade contract, destination routing, focus probe, and service-worker decision boundary. Tests: +378/-48 (net +330).

ClawSweeper follow-up

The first review identified legacy Boolean writes; the second identified legacy Boolean reads. The final head keeps canonical modes internally, accepts Boolean writes from old clients, negotiates Boolean reads when the mode capability is absent, and adds Gateway/UI boundary proof for both generations. All listed rank-up moves are applied; none were skipped.

Worked on by

@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
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.

@roboclaw-bot
roboclaw-bot marked this pull request as ready for review August 30, 2026 16:46
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

@clawsweeper review

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: L maintainer Maintainer-authored PR labels Aug 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
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 merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. 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 30, 2026
@clawsweeper

clawsweeper Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge.

What this changes

Adds account and per-device browser notification delivery modes, preserves Boolean RPC clients, and suppresses notifications when the service worker considers their destination focused.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) Useful controls and repaired RPC compatibility are outweighed by unresolved browser delivery defects and incomplete runtime and stored-state proof.
Proof confidence 🦪 silver shellfish (2/6) Real behavior proof is not required for maintainer- or bot-authored pull requests.
Patch quality 🦐 gold shrimp (3/6) 5 actionable review findings remain.

Regression provenance

Possible regression — suspected (reviewed change). No predecessor PR is attributed.

Merge readiness

⛔ Blocked before merge - 9 items remain

The feature remains distinct from current main and the related merged work. Boolean RPC compatibility is repaired, but the five previously reported findings remain on the unchanged head, including a browser-contract violation that can disable subsequent notifications. The protected maintainer label also excludes cleanup closure.

Priority: P2
Reviewed head: 4b630039216d295a50f5331d4c1077430af8e83c

Before merge

  • Preserve the browser's visible-push contract (P1) - When a focused destination matches, this resolves the push event without displaying a notification. Production subscriptions use userVisibleOnly: true; WebKit requires a visible notification and can revoke subscriptions for violations. Enabling this mode can therefore disable later background alerts, including approvals. Avoid unwanted pushes before dispatch or use a supported browser design. This previously reported blocker remains unchanged.
  • Restrict destination-less suppression to the OpenClaw scope (P2) - matchAll({ includeUncontrolled: true }) includes every same-origin window. This branch suppresses an untargeted notification when a different application or another Gateway PWA under a sibling base path is focused, without verifying scope or obtaining a valid OpenClaw probe response. Filter and validate the owning OpenClaw client before suppressing. The previous finding remains unresolved.
  • Compare resolved sessions instead of exact notification URLs (P2) - The new producer uses exactKey: true, while ordinary UI navigation builds shortened UUID or slug paths for the same session. Consequently a user viewing /chat/main/12345678 still receives the push targeting its full session-key path; unrelated query parameters also defeat equality. Report the committed session identity and compare that identity rather than pathname/search bytes. The previous finding remains unresolved.
  • Include the active Gateway in destination matching (P2) - The documented shared-PWA setup can connect one browser scope to multiple Gateways whose session or approval paths coincide. Notifications carry the originating gatewayUrl, but this comparison ignores it and the probe reports only a URL whose startup fragment has already been removed. A focused page connected to Gateway B can therefore suppress Gateway A's alert. Include the currently connected Gateway in the probe and matching contract. The previous finding remains unresolved.
  • Document delivery-mode semantics (P3) - The new 'Only when unfocused' control has no accompanying user documentation explaining destination-specific focus, destination-less behavior, device inheritance, or fail-open behavior. Update Notifications to describe the final supported semantics so operators can predict which alerts remain enabled. This previously reported documentation gap is still present.
  • Resolve merge risk - The stored Boolean-to-mode conversion lacks real existing-database upgrade and reopen proof; older readers reject mode strings as category values and can fall back to defaults or inheritance.
  • Resolve merge risk - The branch currently conflicts with main and needs a refreshed candidate against the newer notification and preference-worker owners before integration behavior can be assessed.
  • Complete next step - Resolve the five retained findings, refresh the conflicting candidate against current main, and supply real-browser and existing-state compatibility evidence before merge.
  • Add data-model compatibility proof - The review found that existing stored data may not work after upgrade. Show that existing data still loads and works with this change.

Findings

  • [P1] Preserve the browser's visible-push contract — ui/public/sw.js:257-262
  • [P2] Restrict destination-less suppression to the OpenClaw scope — ui/public/sw.js:84-88
  • [P2] Compare resolved sessions instead of exact notification URLs — ui/public/sw.js:113-116
Agent review details

How this fits together

The Gateway selects authorized browser subscriptions and sends approval or attention events through Web Push. The Control UI stores notification preferences and its service worker decides whether to display each received push.

flowchart TD
  A[Approval and attention events] --> B[Gateway recipient checks]
  C[Account and device preferences] --> B
  B --> D[Browser push service]
  D --> E[Service worker focus decision]
  F[Focused browser windows] --> E
  E --> G[Display or suppress notification]
Loading

Technical review

Best possible solution:

Implement device-specific focus avoidance through a browser-supported delivery boundary, using committed session and active Gateway identity, while preserving existing preferences and documenting the resulting semantics.

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

Yes, the patch defects have concrete source-backed triggers: a focused destination omits showNotification, an unrelated same-origin window suppresses untargeted pushes, and route/Gateway mismatches produce incorrect decisions. No browser reproduction was executed in this read-only review.

Is this the best way to solve the issue?

No. Suppressing an already-received Web Push violates the supported WebKit contract; focus avoidance must happen through a supported delivery design, with session and Gateway identity rather than raw URL equality.

Full review comments:

  • [P1] Preserve the browser's visible-push contract — ui/public/sw.js:257-262
    When a focused destination matches, this resolves the push event without displaying a notification. Production subscriptions use userVisibleOnly: true; WebKit requires a visible notification and can revoke subscriptions for violations. Enabling this mode can therefore disable later background alerts, including approvals. Avoid unwanted pushes before dispatch or use a supported browser design. This previously reported blocker remains unchanged.
    Confidence: 0.99
  • [P2] Restrict destination-less suppression to the OpenClaw scope — ui/public/sw.js:84-88
    matchAll({ includeUncontrolled: true }) includes every same-origin window. This branch suppresses an untargeted notification when a different application or another Gateway PWA under a sibling base path is focused, without verifying scope or obtaining a valid OpenClaw probe response. Filter and validate the owning OpenClaw client before suppressing. The previous finding remains unresolved.
    Confidence: 0.99
  • [P2] Compare resolved sessions instead of exact notification URLs — ui/public/sw.js:113-116
    The new producer uses exactKey: true, while ordinary UI navigation builds shortened UUID or slug paths for the same session. Consequently a user viewing /chat/main/12345678 still receives the push targeting its full session-key path; unrelated query parameters also defeat equality. Report the committed session identity and compare that identity rather than pathname/search bytes. The previous finding remains unresolved.
    Confidence: 0.98
  • [P2] Include the active Gateway in destination matching — ui/public/sw.js:113-116
    The documented shared-PWA setup can connect one browser scope to multiple Gateways whose session or approval paths coincide. Notifications carry the originating gatewayUrl, but this comparison ignores it and the probe reports only a URL whose startup fragment has already been removed. A focused page connected to Gateway B can therefore suppress Gateway A's alert. Include the currently connected Gateway in the probe and matching contract. The previous finding remains unresolved.
    Confidence: 0.99
  • [P3] Document delivery-mode semantics — ui/src/pages/config/notifications-section.ts:84-86
    The new 'Only when unfocused' control has no accompanying user documentation explaining destination-specific focus, destination-less behavior, device inheritance, or fail-open behavior. Update Notifications to describe the final supported semantics so operators can predict which alerts remain enabled. This previously reported documentation gap is still present.
    Confidence: 0.97

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Merge-risk options

Maintainer options:

  1. Repair delivery and prove upgrade behavior (recommended)
    Replace silent received-push suppression with a supported delivery design and verify existing account/device preferences through upgrade, reopen, and the applicable older-reader path.
  2. Retain binary delivery while redesigning focus awareness
    Keep current notification delivery intact and narrow the branch if a supported device-local suppression design cannot be established.

Security

None.

Evidence

What I checked:

  • Pinned introduction and review continuity: Inspected the introduced production and test hunks from the verified merge base to the exact original head. Comparing the September reviewed SHA with HEAD produced no changes in the implicated worker, entrypoint, event producer, or settings controls; the previous findings therefore remain applicable. (ui/public/sw.js:257, 4b630039216d)
  • Browser dependency signal: The changed worker consumes Push API events and conditionally omits showNotification. Its production subscription caller explicitly uses userVisibleOnly: true, establishing the browser contract as an authoritative dependency. No changed behavior depends on Codex runtime or protocol. (ui/src/app/web-push.runtime.ts:309, 4b630039216d)
  • Authoritative browser contracts: WebKit documents that each received push must display a notification and that violating userVisibleOnly can revoke the subscription: https://webkit.org/blog/12945/meet-web-push/. MDN confirms includeUncontrolled returns all same-origin clients rather than only the registration's controlled windows: https://developer.mozilla.org/en-US/docs/Web/API/Clients/matchAll.
  • Focus matching owner boundary: The worker's destination-less branch checks any focused same-origin window without a scope check or successful probe. Destination matching compares pathname and search only. The event producer builds exact-key paths, while the existing UI session URL builder supports shortened UUID paths and display-name slugs. (ui/public/sw.js:87, 4b630039216d)
  • Gateway identity is absent from the focus probe: The notification producer encodes gatewayUrl in the fragment, but main.ts reports only window.location.href and startup-settings.ts removes that fragment after consuming it. The documented shared-PWA workflow can therefore display the same route for different remote Gateways. (src/gateway/event-web-push.ts:138, 4b630039216d)
  • Earlier compatibility repairs verified: The write schemas accept Boolean values and canonical modes; preference reads negotiate Boolean responses unless deliveryModes is supplied. Gateway handler regressions cover both client generations, and the UI advertises the capability. These earlier findings should not be raised again. (src/gateway/server-methods/push.ts:327, 4b630039216d)

PR surface

Source +232, Tests +330. Total +562 across 19 files.

View PR surface stats
Area Files Added Removed Net
Source 11 312 80 +232
Tests 8 378 48 +330
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 19 690 128 +562

Review metrics

Metric Value Why it matters
Production versus tests production +312/-80, net +232; tests +378/-48, net +330 Production growth implements a new delivery capability and negotiated protocol contract rather than a bug-fix guard.
Preference contract 5 category values changed; 1 read capability added; defaults preserved The same modes affect account defaults, device overrides, RPC responses, and durable preference values.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #133392
Summary: This PR is the explicit implementation candidate for the linked focus-aware notification request; related merged work has different goals.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Labels

Label changes:

No label changes.

Label justifications:

  • P2: This optional notification improvement has bounded scope, although its proposed delivery mechanism has blocking defects.
  • merge-risk: 🚨 compatibility: Category values change in persisted account and device settings, and real existing-state compatibility remains unverified.
  • merge-risk: 🚨 message-delivery: Silent push handling can revoke subscriptions, and incorrect focus matching can suppress unrelated alerts.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rank-up moves

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

  • Replace silent received-push suppression with a supported design and demonstrate real-browser delivery, including a subsequent background alert.
  • Use scoped committed-session and active-Gateway identity, covering alternate session URLs and unrelated same-origin windows.
  • Refresh the conflicting branch onto current owners, document the modes, and prove existing preference upgrade/reopen compatibility.

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.

History

Review history (4 earlier review cycles)
  • reviewed 2026-08-30T16:51:34.500Z sha d0bab96781a8c3a078e26bf3337559ae7fc0c020 :: found issues before merge. :: [P1] Preserve Boolean preference payload compatibility
  • reviewed 2026-08-30T17:12:43.903Z sha 9179fbc6eb2996423564530a39058b531a052092 :: found issues before merge. :: [P1] Preserve reads for an already-open binary UI
  • reviewed 2026-08-30T17:36:36.892Z sha 4b63003 :: found issues before merge. :: [P3] Document delivery-mode semantics
  • reviewed 2026-09-22T17:52:01.131Z sha 4b63003 :: blocked before merge. :: [P1] Preserve the browser's visible-push contract | [P2] Restrict destination-less suppression to the OpenClaw scope | [P2] Compare resolved sessions instead of exact notification URLs | [P2] Include the active Gateway in destination matching | [P3] Document delivery-mode semantics

Reviewed October 7, 2026, 8:00 AM ET / 12:00 UTC (Revision 5).

@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Addressed ClawSweeper's P1 compatibility finding in 9179fbc6eb2996423564530a39058b531a052092.

The preference write schema now accepts either legacy booleans or delivery modes, while the read schema and stored representation remain canonical modes. push.web.preferences.set normalizes both account and device payloads immediately. Added a handler-boundary regression covering an already-open pre-upgrade Control UI client for both scopes.

Validation after the repair:

  • focused Gateway handler: 24 tests passed
  • complete focused suite: 169 tests passed across four shards
  • node scripts/check-changed.mjs: passed
  • complete-candidate autoreview at the pinned merge base: scoped clean

The listed rank-up move is applied; no move was skipped.

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. and removed P2 Normal backlog priority with limited blast radius. labels Aug 30, 2026
Add Never, Only when unfocused, and Always modes to every browser push
category, with destination-aware suppression in the Control UI service worker.
Preserve existing boolean preferences during the transition.

Co-authored-by: Takhoffman <[email protected]>
Worked on by:
- @Takhoffman
@roboclaw-bot
roboclaw-bot force-pushed the roboclaw/turn-notification-focus-policy branch from 9179fbc to 4b63003 Compare August 30, 2026 17:26
@roboclaw-bot

Copy link
Copy Markdown
Collaborator Author

Addressed ClawSweeper's second P1 rolling-upgrade finding in 4b630039216d295a50f5331d4c1077430af8e83c.

push.web.preferences.get now negotiates its response shape: a pre-upgrade UI omits deliveryModes and receives booleans, while the current UI sends deliveryModes: true and receives canonical mode strings. Boolean writes remain accepted and normalize immediately, so an already-open checkbox UI has a coherent get-after-set path without changing the mode-only durable representation.

Added boundary proof for both response generations and an assertion that current UI reads always advertise the capability. Final local validation: 170 focused tests passed, node scripts/check-changed.mjs passed, and complete-candidate autoreview is scoped clean.

Both listed compatibility rank-up moves are applied; none were skipped. Real PWA suppression proof remains a known optional proof gap; the destination/focus decision is covered by the service-worker harness and the UI controls by inspected Chromium screenshots.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed P1 High-priority user-facing bug, regression, or broken workflow. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Aug 30, 2026
@clawsweeper clawsweeper Bot added proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 22, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Sep 22, 2026
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. proof: 📸 screenshot Contributor real behavior proof includes screenshot evidence. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Oct 7, 2026

This branch has not been deployed

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

Labels

app: web-ui App: web-ui gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Focus-aware browser push notification modes

1 participant