Skip to content

Commit 20a6147

Browse files
roboclaw-botTakhoffmansteipete
authored
feat: add secure PWA approval notifications and preferences (#129348)
* feat: notify PWAs about approval requests * feat: add configurable Web Push notifications * fix: harden web push lifecycle * fix: close web push review findings Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * fix(plugins): preserve install failure cause Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * perf(ui): trim notification startup copy Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * test: align notification metadata contracts Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * fix: complete web push recovery lifecycle Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * test(codex): stabilize persistent startup retry Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * chore: drop superseded plugin lint workaround Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * test(android): await replacement connection readiness Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * test(ui): await Workboard picker expansion Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * fix: sanitize web push display labels Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * test(codex): stabilize persistent startup retry under load Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * fix(web-push): repair subscription recovery and scoped delivery Keep mismatched browser subscriptions explicitly recoverable in Settings, and share registration validation between manual enablement and reconnects. Use the canonical display sanitizer for notification labels while retaining raw IDs for authorization and filtering. Honor implied admin scopes for question notifications through the shared target resolver. Consolidate duplicate state and display helpers, expand boundary regression coverage, and document reset and re-enablement. Co-authored-by: roboclaw-bot <[email protected]> Co-authored-by: Tak Hoffman <[email protected]> * fix(web-push): complete explicit recovery state and label normalization Share one subscription state contract across the capability and Settings, keep stale browser subscriptions resettable, and consolidate key validation. Provide the canonical label normalizer used by delivery and preferences, with raw agent identifiers preserved for authorization and allowlists. Document the reset flow and cover reconnect, manual enable, first-send, native notifications, and stale Gateway transitions. Co-authored-by: roboclaw-bot <[email protected]> Co-authored-by: Tak Hoffman <[email protected]> * fix: preserve aggregate failure causes Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * fix(ui): fence web push actions to current gateway Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * fix(web-push): enforce subscription ownership through recovery Share device/profile authorization across preferences and unsubscribe, atomically fence deletion, and require existing subscription keys for ownership transfers. Co-authored-by: roboclaw-bot <[email protected]> Co-authored-by: Tak Hoffman <[email protected]> * fix(ui): settle passive push lookup without worker activation Use the current service worker registration for existing subscription reads and unsubscribe. Keep readiness waiting only for explicit enablement. Co-authored-by: Tak Hoffman <[email protected]> * test(ui): keep a bound unsubscribe mock assertion * fix(web-push): preserve implied scope authority Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * fix(web-push): close final review findings Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * fix(qa-lab): preserve aggregate causes portably Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman * fix(plugins): preserve install failure cause Co-authored-by: Tak Hoffman <[email protected]> Worked on by: - @Takhoffman --------- Co-authored-by: roboclaw-bot <[email protected]> Co-authored-by: Tak Hoffman <[email protected]> Co-authored-by: Peter Steinberger <[email protected]>
1 parent 27c9bbe commit 20a6147

72 files changed

Lines changed: 6086 additions & 303 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/android/app/src/main/java/ai/openclaw/app/gateway/GatewayProtocol.kt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,8 @@ enum class GatewayMethod(
679679
PushWebSubscribe("push.web.subscribe"),
680680
PushWebUnsubscribe("push.web.unsubscribe"),
681681
PushWebTest("push.web.test"),
682+
PushWebPreferencesGet("push.web.preferences.get"),
683+
PushWebPreferencesSet("push.web.preferences.set"),
682684
ConfigOpenFile("config.openFile"),
683685
Connect("connect"),
684686
ChatInject("chat.inject"),

‎apps/android/app/src/test/java/ai/openclaw/app/ui/chat/ChatFullMessageOwnershipLayoutTest.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1432,8 +1432,8 @@ class ChatFullMessageOwnershipLayoutTest {
14321432
}
14331433
}
14341434
assertTrue(gateway.operatorConnection.get() > oldConnection)
1435-
assertEquals("full-message-${gateway.operatorConnection.get()}", runtime.serverName.value)
14361435
awaitRuntimeReady(key)
1436+
assertEquals("full-message-${gateway.operatorConnection.get()}", runtime.serverName.value)
14371437
}
14381438

14391439
private fun assertRetiredDisclosureCannotLoad(

‎config/assertion-safety-baseline.txt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3900,7 +3900,7 @@ ui/src/app/theme.ts 4
39003900
ui/src/app/update-schedule-dto.ts 2
39013901
ui/src/app/update-success-notice.ts 1
39023902
ui/src/app/user-profile.ts 2
3903-
ui/src/app/web-push.runtime.ts 3
3903+
ui/src/app/web-push.runtime.ts 2
39043904
ui/src/components/agent-select.ts 3
39053905
ui/src/components/app-sidebar-agent-menu.ts 2
39063906
ui/src/components/app-sidebar-nav-menus.ts 6

‎docs/refactor/database-first.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,8 @@ plugin_state_entries(plugin_id, namespace, entry_key, value_json, created_at, ex
15101510
plugin_blob_entries(plugin_id, namespace, entry_key, metadata_json, blob, created_at, expires_at)
15111511
skill_uploads(upload_id, kind, slug, force, size_bytes, sha256, actual_sha256, received_bytes, archive_blob, created_at, expires_at, committed, committed_at, idempotency_key_hash)
15121512
skill_upload_chunks(upload_id, byte_offset, size_bytes, chunk_blob)
1513-
web_push_subscriptions(endpoint_hash, subscription_id, endpoint, p256dh, auth, created_at_ms, updated_at_ms)
1513+
web_push_subscriptions(endpoint_hash, subscription_id, endpoint, p256dh, auth, device_id, user_profile_id, preferences_json, created_at_ms, updated_at_ms)
1514+
web_push_approval_deliveries(approval_id, subscription_id, device_id, user_profile_id, prepared_at_ms)
15141515
apns_registrations(node_id, transport, token, relay_handle, send_grant, installation_id, relay_origin, topic, environment, distribution, token_debug_suffix, updated_at_ms)
15151516
apns_registration_tombstones(node_id, deleted_at_ms)
15161517
device_identities(identity_key, device_id, public_key_pem, private_key_pem, created_at_ms, updated_at_ms)

‎docs/reference/database-schemas.md‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ column in state schema 9. Operator-role assignment lazily ensures the column on
7171
first use. Older readers ignore the column and can reopen the same database
7272
safely.
7373

74+
Web Push subscription ownership uses the same rule for nullable bare
75+
`web_push_subscriptions.device_id TEXT`, `user_profile_id TEXT`, and
76+
`preferences_json TEXT` columns. Web Push lazily ensures all three columns on
77+
first use. Existing rows remain unbound and test-only until the browser
78+
reconnects; older readers ignore the columns and continue reading or updating
79+
the endpoint and key fields safely.
80+
81+
Approval-notification cleanup uses the same-version additive
82+
`web_push_approval_deliveries` table. It records the approval/subscription
83+
identifiers plus the request-time device/profile binding for notifications that
84+
may have reached a browser. A terminal or restarted Gateway sends only when the
85+
current subscription still has that binding. The table is lazily created on
86+
first use, rows cascade away with their approval or subscription, and older
87+
readers ignore it safely.
88+
7489
Installing OpenClaw manually through npm bypasses the updater guard. Database open checks still refuse an incompatible build.
7590

7691
Structured [Goal controls](/tools/goal#gateway-requests-and-retries) use a lazy

‎docs/web/control-ui.md‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -691,12 +691,12 @@ See [Notifications](/web/notifications) for the browser and macOS setup steps.
691691

692692
If the page shows **Protocol mismatch** right after an OpenClaw update, first reopen the dashboard with `openclaw dashboard` and hard-refresh. If it still fails, clear site data for the dashboard origin or test in a private browser window; an old tab or browser service-worker cache can keep running a pre-update Control UI bundle against the newer Gateway.
693693

694-
| Surface | What it does |
695-
| ---------------------------------------------------------------------- | ---------------------------------------------------------------------------- |
696-
| `ui/public/manifest.webmanifest` | PWA manifest. Browsers offer "Install app" once it is reachable. |
697-
| `ui/public/sw.js` | Service worker that handles `push` events and notification clicks. |
698-
| `state/openclaw.sqlite` → `config_machine_state` (`webPush.vapidKeys`) | Auto-generated VAPID keypair used to sign Web Push payloads. |
699-
| `state/openclaw.sqlite` → `web_push_subscriptions` | Persisted browser subscription endpoints, keys, and registration timestamps. |
694+
| Surface | What it does |
695+
| ---------------------------------------------------------------------- | --------------------------------------------------------------------------- |
696+
| `ui/public/manifest.webmanifest` | PWA manifest. Browsers offer "Install app" once it is reachable. |
697+
| `ui/public/sw.js` | Service worker that handles `push` events and notification clicks. |
698+
| `state/openclaw.sqlite` → `config_machine_state` (`webPush.vapidKeys`) | Auto-generated VAPID keypair used to sign Web Push payloads. |
699+
| `state/openclaw.sqlite` → `web_push_subscriptions` | Persisted browser endpoints, keys, device/profile bindings, and timestamps. |
700700

701701
Upgrades from the retired `push/vapid-keys.json` and `push/web-push-subscriptions.json` stores are imported by `openclaw doctor --fix`. Stop the Gateway before running that repair so an older process cannot recreate retired state during import. Run the repair before using Web Push after an upgrade; registration, delivery, deletion, and key resolution refuse to proceed while either retired source or an interrupted Doctor claim remains. The Gateway runtime reads and writes SQLite only.
702702

@@ -706,13 +706,17 @@ Override the VAPID keypair through env vars on the Gateway process when you want
706706
- `OPENCLAW_VAPID_PRIVATE_KEY`
707707
- `OPENCLAW_VAPID_SUBJECT` (defaults to `https://openclaw.ai`)
708708

709+
One service-worker registration scope has one browser push subscription and therefore one application-server key. If one installed PWA switches among multiple logical Gateways, configure the same public/private VAPID pair on every Gateway and set each Gateway's `gateway.publicOrigin`; otherwise registration fails closed with a VAPID-identity mismatch. Sharing the private VAPID key and browser endpoint creates one push-signing trust domain, so do this only among mutually trusted Gateways. PWAs installed from separate HTTPS origins or base-path scopes have separate registrations and do not need to share keys.
710+
709711
The Control UI uses these scope-gated Gateway methods to register and test browser subscriptions:
710712

711713
- `push.web.vapidPublicKey` fetches the active VAPID public key.
712-
- `push.web.subscribe` registers an `endpoint` plus `keys.p256dh`/`keys.auth`.
714+
- `push.web.subscribe` registers an `endpoint` plus `keys.p256dh`/`keys.auth`; the Gateway binds it to the authenticated browser device and current user profile.
713715
- `push.web.unsubscribe` removes a registered endpoint.
714716
- `push.web.test` sends a test notification to registered browser subscriptions.
715717

718+
Pending exec and plugin approvals also trigger Web Push. Approval delivery is narrower than `push.web.test`: the Gateway targets only bound subscriptions whose paired device, current operator token, profile role, and approval visibility still authorize the request. Legacy unbound subscriptions stay test-only until the Control UI reconnects and reconciles them. Push payloads contain generic text and an authenticated `/approve/<approvalId>` link, not approval details.
719+
716720
<Note>
717721
Web Push is independent of the iOS APNS relay path (see [Configuration](/gateway/configuration) for relay-backed push) and the `push.test` method, which targets native mobile pairing.
718722
</Note>

‎docs/web/notifications.md‎

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ read_when:
77
- Comparing Control UI notifications with mobile push
88
---
99

10-
OpenClaw can ping you when something needs your attention — in the browser that runs the Control UI, or through native macOS notifications when you use the OpenClaw macOS app. Your first chat send may request permission automatically; **Settings → Notifications** remains the place to enable or repair the current device, check its status, and send yourself a test.
10+
OpenClaw can ping you when something needs your attention — including an exec or plugin approval request — in the browser that runs the Control UI, or through native macOS notifications when you use the OpenClaw macOS app. Your first chat send may request permission automatically; **Settings → Notifications** remains the place to enable or repair the current device, check its status, and send yourself a test.
1111

1212
This page covers those two surfaces. It does not control channel reaction notifications, Android notification forwarding, or iOS background push — the mobile apps register for push through their own node paths; see [iOS](/platforms/ios) and [Nodes](/nodes).
1313

1414
## Which surface you get
1515

1616
What the Notifications page controls depends on where you opened it:
1717

18-
| Where Settings is open | Transport | What you can do |
19-
| ------------------------------------------------- | -------------------------------------------------- | ----------------------------------------------------------------------------- |
20-
| Supported web browser or installed Control UI PWA | Browser Push API via the Control UI service worker | Grant permission, subscribe or unsubscribe this browser, send a test |
21-
| OpenClaw macOS app | Native macOS notifications | Grant app permission, jump to System Settings when blocked, send a local test |
22-
| Browser without Push API support | None | Status only; enable and test stay unavailable |
18+
| Where Settings is open | Transport | What you can do |
19+
| ------------------------------------------------- | -------------------------------------------------- | ------------------------------------------------------------------------------ |
20+
| Supported web browser or installed Control UI PWA | Browser Push API via the Control UI service worker | Receive approval requests, manage this browser's subscription, and send a test |
21+
| OpenClaw macOS app | Native macOS notifications | Grant app permission, jump to System Settings when blocked, send a local test |
22+
| Browser without Push API support | None | Status only; enable and test stay unavailable |
2323

2424
The macOS app deliberately uses the native permission flow instead of browser push — that is the notification system your Mac already respects.
2525

@@ -33,9 +33,42 @@ The Control UI asks for notification permission automatically the first time you
3333
4. Allow notifications when the browser asks.
3434
5. Select **Send test** — a test notification should arrive within a few seconds.
3535

36-
Behind the scenes, enabling creates a push subscription in this browser and registers its endpoint and keys with the Gateway. The Gateway keeps browser subscriptions and its VAPID signing key in `state/openclaw.sqlite` — there is no `openclaw.json` key to edit. When the Control UI reconnects, existing subscriptions are reconciled with the Gateway automatically.
36+
Behind the scenes, enabling creates a push subscription in this browser and registers its endpoint and keys with the Gateway. The Gateway binds the subscription to the browser's paired device and, when operator roles are enabled, its authenticated user profile. The Gateway keeps browser subscriptions and its VAPID signing key in `state/openclaw.sqlite` — there is no `openclaw.json` key to edit. When the Control UI reconnects, existing subscriptions are reconciled with the Gateway automatically.
3737

38-
**Send test** asks the Gateway to push a test message to every registered browser subscription. **Unsubscribe** removes the current browser's endpoint from the Gateway, then unsubscribes locally.
38+
Approval notifications use generic lock-screen text; command, working-directory, prompt, and plugin details stay out of the push payload. Selecting the notification opens the authenticated `/approve/<approvalId>` page. Before each send, the Gateway rechecks the paired device's current approval scopes, operator role, user profile, and approval visibility. A revoked or downgraded browser stops receiving approval pushes without needing to unsubscribe first.
39+
40+
### Choose what reaches each device
41+
42+
After subscribing, **Settings → Notifications** exposes two preference layers:
43+
44+
- **Account defaults** follow a durable authenticated user profile across devices. They control approval requests and updates, agent completion, agent questions, scheduled-task failures, background-task failures, lock-screen detail, quiet hours, timezone, and an optional agent allowlist.
45+
- **This browser or app** can mute one browser profile or installed Home Screen app, add a source label, or override individual categories without changing the account defaults. Native OpenClaw app notifications are configured separately.
46+
47+
Owner-style Gateways without a durable user profile keep the same controls, but store them only with the current browser subscription. Preferences never grant access: every delivery still rechecks the paired device, current role and scopes, authenticated profile, and session visibility. Multi-user events without an authoritative session owner are suppressed instead of being broadcast to every operator.
48+
49+
The default preserves the original behavior: approval request and resolution notifications are enabled, while newly added attention categories are opt-in. Quiet hours suppress matching sends rather than queueing stale alerts for later delivery.
50+
51+
The detail levels are:
52+
53+
- **Private** — generic attention text only.
54+
- **Names only** — may include a sanitized device, agent, task, or automation label.
55+
- **Detailed** — currently uses the same bounded, sanitized producer-owned labels; raw prompts, command arguments, output, environment values, and errors never enter the push payload.
56+
57+
On iPhone and iPad, Web Push is available only after installing the Control UI with **Share → Add to Home Screen** and opening that installed app. A normal Safari tab remains usable for the Control UI, but the Notifications page reports the install requirement and does not attempt to dereference an unavailable `PushManager`.
58+
59+
**Send test** asks the Gateway to push a test message to every registered browser subscription. Tests intentionally verify transport only; approval requests are targeted to authorized device bindings. **Unsubscribe** removes the current browser's endpoint from the Gateway only when its paired device and user profile still own the subscription, then unsubscribes locally. Reconnecting under another profile can transfer the browser subscription only with its existing subscription keys; knowing an endpoint alone cannot change its owner or remove it.
60+
61+
The Gateway sends Web Push directly to the browser vendor's push service. This works with a self-hosted Gateway and does not use the OpenClaw-hosted iOS relay.
62+
63+
### Use more than one Gateway on one phone
64+
65+
The recommended self-hosted setup is one Control UI service-worker scope per Gateway. Open or install each Gateway's PWA from its own HTTPS origin or base path, enable notifications there, and reconnect once after upgrades. Each scope then owns an independent browser subscription, and approval links return to the Gateway that created them.
66+
67+
A single installed PWA can also switch among remote Gateways, but every Gateway behind that PWA must use the same VAPID keypair and set `gateway.publicOrigin` to its browser-reachable HTTPS origin. Reconnect the PWA to each Gateway once so each one registers the shared browser subscription and current device/profile binding. Approval notification links stay inside the installed PWA's scope and carry the owning Gateway URL in their fragment; the Control UI removes the fragment before authentication and uses the normal remote-Gateway handoff.
68+
69+
The browser Push API permits only one application-server key per service-worker registration. If a PWA subscription belongs to a different VAPID key, OpenClaw removes the unusable row from the current Gateway and shows **Unavailable** and **Not subscribed**, with an error explaining the mismatch. To switch that PWA scope to the current Gateway, select **Unsubscribe**, then **Enable notifications** and **Send test**. Unsubscribing deactivates the shared browser subscription for every Gateway registered through that scope; after re-enabling, reconnect to each Gateway once.
70+
71+
Sharing a private VAPID key and browser endpoint makes those Gateways one push-signing trust domain. Use that layout only for Gateways you trust equally. Configure VAPID values through each Gateway process's secure environment or secret manager; do not place private keys in URLs or command arguments.
3972

4073
## Enable notifications in the macOS app
4174

@@ -66,6 +99,12 @@ The Control UI waits up to 10 seconds for its service worker. If that times out
6699

67100
Run `openclaw doctor --fix` with the Gateway stopped. Web Push refuses to use the retired JSON stores until Doctor imports them into SQLite.
68101

102+
### Tests arrive but approval requests do not
103+
104+
Reconnect or reload the Control UI once so an older subscription is bound to the current paired device. The device must still have `operator.approvals` and `operator.read`; when Gateway roles are enabled, the current user profile's role must allow those scopes too. Approval visibility and session-sharing rules can intentionally exclude a request that the same Gateway sends to another operator.
105+
106+
For a single PWA that switches among Gateways, also verify that every Gateway uses the same VAPID keypair and has a browser-reachable `gateway.publicOrigin`. Separate PWA origins or base-path scopes do not need to share VAPID keys.
107+
69108
## Related
70109

71110
- [Control UI PWA and Web Push](/web/control-ui#pwa-install-and-web-push)

‎docs/web/urls.md‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,11 @@ These Gateway-served documents sit outside the application route table:
278278
- `/?onboarding=1` opens the first-run onboarding presentation.
279279
- `/approve/<approvalId>` opens a standalone approval document. With a base
280280
path, use `<basePath>/approve/<approvalId>`. The id identifies an approval but
281-
never authorizes it; normal Gateway authentication still applies.
281+
never authorizes it; normal Gateway authentication still applies. An approval
282+
notification uses a scope-relative approval path and may add
283+
`#gatewayUrl=<encoded-ws-url>` when the owning Gateway has
284+
`gateway.publicOrigin`. The Control UI strips that fragment before
285+
authentication and applies the normal remote-Gateway handoff below.
282286

283287
Registered exact and prefix plugin HTTP routes can own `/focus` and
284288
`/focus/*`. After plugin authentication and dispatch decline a request, the

0 commit comments

Comments
 (0)