From 14829186c32d86c867d8f0b2d50048a0306edebc Mon Sep 17 00:00:00 2001 From: OAra Labs Date: Thu, 12 Nov 2026 10:37:01 -0500 Subject: [PATCH 1/4] test(push): red: an approval push reaches owner devices only Co-Authored-By: Claude Opus 5.5 --- tests/test_approval_push_owner_only.py | 101 +++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 tests/test_approval_push_owner_only.py diff --git a/tests/test_approval_push_owner_only.py b/tests/test_approval_push_owner_only.py new file mode 100644 index 00000000..89b05be3 --- /dev/null +++ b/tests/test_approval_push_owner_only.py @@ -0,0 +1,101 @@ +"""An approval push goes to owner devices only. + +An approval push carries the tool name and the first line of the request's description, and it used to go to +every registered device. A scoped device sees only its own sessions everywhere else (``GET /api/approvals``, the +``approval_pending`` frame), and it cannot approve anything but a desktop prompt, so a push to it about another +session's request told it something no other surface would, and offered it a button it could not use. + +Held here: + + * the ordinary approval push reaches owner devices and nothing else: not a scoped device, not one marked for + computer use, not a revoked owner; + * a desktop prompt's push (no content at all: no tool, no description) reaches owner devices and the devices + marked for computer use, because those are the ones that may answer it; + * a store that cannot say which devices are owners sends no approval push at all (fail closed), and the other + pushes are unchanged. +""" + +from __future__ import annotations + +import asyncio +import types + +from prometheus.config.device_store import DeviceStore +from prometheus.push.apns import SendResult +from prometheus.push.dispatcher import PushDispatcher + + +class _Sender: + def __init__(self) -> None: + self.sent: list[dict] = [] + + async def send(self, **kwargs): + self.sent.append(kwargs) + return SendResult(outcome="ok", status=200) + + +def _signal(kind: str, payload: dict): + return types.SimpleNamespace(kind=kind, payload=payload, source="test") + + +def _world(tmp_path): + store = DeviceStore(tmp_path / "devices.db") + owner = store.mint_owner("owner phone", "ios", by="test") + scoped = store.mint("scoped phone", "ios") + marked = store.mint("marked tablet", "ios") + gone = store.mint_owner("old owner phone", "ios", by="test") + for d, tok in ((owner, "tok-owner"), (scoped, "tok-scoped"), (marked, "tok-marked"), (gone, "tok-gone")): + assert store.set_push(d["id"], tok, "sandbox", "ai.test.beacon") + assert store.set_computer(marked["id"], True, by="test") + store.revoke(gone["id"]) + return store + + +def _approval(**extra) -> dict: + return {"request_id": "r1", "tool_name": "bash", "description": "rm -rf build", "expires_at": 1.0, **extra} + + +def _tokens(sender: _Sender) -> list[str]: + return sorted(s["apns_token"] for s in sender.sent) + + +def test_an_approval_push_reaches_owner_devices_only(tmp_path): + sender = _Sender() + asyncio.run(PushDispatcher(_world(tmp_path), sender, bridge=None).on_signal( + _signal("approval_pending", _approval()))) + assert _tokens(sender) == ["tok-owner"] + + +def test_a_desktop_prompt_reaches_owners_and_devices_marked_for_computer_use(tmp_path): + sender = _Sender() + asyncio.run(PushDispatcher(_world(tmp_path), sender, bridge=None).on_signal( + _signal("approval_pending", _approval(task_id="t1")))) + assert _tokens(sender) == ["tok-marked", "tok-owner"] + for s in sender.sent: + assert "tool_name" not in s["payload"] and "rm -rf" not in str(s["payload"]) + + +def test_the_quiet_pushes_are_unchanged(tmp_path): + sender = _Sender() + asyncio.run(PushDispatcher(_world(tmp_path), sender, bridge=None).on_signal( + _signal("turn_completed", {"session_id": "web:s1"}))) + assert _tokens(sender) == ["tok-marked", "tok-owner", "tok-scoped"] + + +def test_a_store_that_cannot_name_its_owners_sends_no_approval_push(): + class _OldStore: + def push_targets(self): + return [types.SimpleNamespace(id="d1", apns_token="tok", environment="sandbox", bundle_id="", + push_failures=0)] + + sender = _Sender() + asyncio.run(PushDispatcher(_OldStore(), sender, bridge=None).on_signal(_signal("approval_pending", _approval()))) + assert sender.sent == [] + + +def test_the_store_query_answers_owner_and_marked_devices(tmp_path): + store = _world(tmp_path) + names = {t.apns_token for t in store.approval_push_targets(desktop=False)} + assert names == {"tok-owner"} + names = {t.apns_token for t in store.approval_push_targets(desktop=True)} + assert names == {"tok-owner", "tok-marked"} From f746116629b7aa184089e29299d04f10798d71be Mon Sep 17 00:00:00 2001 From: OAra Labs Date: Thu, 12 Nov 2026 10:37:41 -0500 Subject: [PATCH 2/4] fix(push): an approval push reaches owner devices only A desktop prompt's content-free push also reaches devices marked for computer use. A store that cannot name owners sends no approval push. Three tests that used ordinary devices or fakes without the new store method updated on purpose. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + src/prometheus/config/device_store.py | 10 ++++++++++ src/prometheus/push/dispatcher.py | 14 ++++++++++++-- tests/test_approval_push_fanout.py | 3 +++ tests/test_computer_livestream.py | 3 +++ tests/test_push_dispatch.py | 6 +++--- 6 files changed, 32 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2b3ff1b..5c230555 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ Notable changes in each release, newest first. Releases before 0.9.7 are describ ## Unreleased +- Push: an approval push now reaches owner devices only, and, for a desktop prompt (whose push carries no content), also the devices marked for computer use, which are the ones that may answer it. It went to every registered device with a push registration, scoped devices included, which see only their own sessions everywhere else and cannot approve. A device store that cannot name owner devices sends no approval push. Other pushes are unchanged. - Docs: `docs/reference/pairing-join-requests.md` is the reference for how a new device asks to join and how the owner lets it in: the routes and who may call them, every request and response field, the statuses, the expiry and rate limits, the sealed token, the operator's WebSocket frames and the owner code (the explicit, single-use grant that makes an owner device). It is written from the code and pinned to it by `tests/test_pairing_reference.py`. No behaviour changes. - Approvals: Prometheus now says when nothing can answer an approval prompt. `security.approval_queue.enabled` ships `false`, and the queue is only built together with the Telegram gateway; without it every call that needs an approval (a third-party MCP tool, a write or a shell command in `cautious` or `strict` mode, a network or install command in a background turn) is refused within seconds as "Permission denied" and none is ever listed to approve, so `cautious` read as "asks the owner" and behaved as "refuses everything". The daemon logs a warning at start and `oara doctor` has an "Approval prompts" row, both naming the keys to set. Nothing is switched on for you. - Approvals: the grants in `security.grants` are now loaded when the daemon starts. A remembered approval (`/approve always`) was written to the file and then ignored at every restart, so the prompt it silenced came back each time, and a `kind: tool` row written by hand (for one third-party MCP tool) never took effect. After this, a grant lasts until you `/revoke` it. **On upgrade, grants saved by earlier versions take effect again at the first start:** the startup log lists each one by id, kind and tool, `/grants` shows them in full, and `/revoke` removes one. The daemon and `SecurityGate.from_config` now read the key in one place. diff --git a/src/prometheus/config/device_store.py b/src/prometheus/config/device_store.py index a23743ee..471af199 100644 --- a/src/prometheus/config/device_store.py +++ b/src/prometheus/config/device_store.py @@ -328,6 +328,16 @@ def push_targets(self) -> list[PushTarget]: push_failures=int(r["push_failures"] or 0)) for r in rows] + def approval_push_targets(self, *, desktop: bool) -> list[PushTarget]: + """The push targets an APPROVAL push may reach: live owner devices, and, for a desktop prompt (whose push + carries no content at all), also the live devices marked for computer use, which are the ones that may + answer it. A scoped device sees only its own sessions everywhere else and approves nothing but a desktop + prompt, so a push naming another session's tool and action must not reach it.""" + allowed = set(self.owner_device_ids()) + if desktop: + allowed |= {t.id for t in self.push_targets() if self.computer_allowed(t.id)} + return [t for t in self.push_targets() if t.id in allowed] + # ------------------------------------------------------------------ # Live Activity tokens (GRAFT Piece 2) # ------------------------------------------------------------------ diff --git a/src/prometheus/push/dispatcher.py b/src/prometheus/push/dispatcher.py index fca6cd84..25f32a0c 100644 --- a/src/prometheus/push/dispatcher.py +++ b/src/prometheus/push/dispatcher.py @@ -113,7 +113,7 @@ async def _push_approval(self, payload: dict) -> None: "request_id": payload.get("request_id"), "expires_at": payload.get("expires_at"), } - for target in self._store.push_targets(): + for target in self._approval_targets(desktop=True): await self._deliver(target, desk) return body = { @@ -134,9 +134,19 @@ async def _push_approval(self, payload: dict) -> None: "tool_name": payload.get("tool_name"), "expires_at": payload.get("expires_at"), } - for target in self._store.push_targets(): + for target in self._approval_targets(desktop=False): await self._deliver(target, body) + def _approval_targets(self, *, desktop: bool) -> list: + """Owner devices (plus, for a content-free desktop prompt, devices marked for computer use): see + ``DeviceStore.approval_push_targets``. A store that cannot say which devices are owners gets no approval + push at all, rather than one to every device.""" + pick = getattr(self._store, "approval_push_targets", None) + if pick is None: + logger.warning("push: this device store cannot name owner devices; no approval push sent") + return [] + return list(pick(desktop=desktop)) + async def _push_quiet(self, kind: str, payload: dict) -> None: live = self._live_device_ids() category = _QUIET_KINDS[kind] diff --git a/tests/test_approval_push_fanout.py b/tests/test_approval_push_fanout.py index 7207a84d..8c59b431 100644 --- a/tests/test_approval_push_fanout.py +++ b/tests/test_approval_push_fanout.py @@ -58,6 +58,9 @@ def __init__(self) -> None: def push_targets(self): return ["device-1", "device-2"] + def approval_push_targets(self, *, desktop): # owner devices only (test_approval_push_owner_only.py) + return self.push_targets() + class _Sender: pass diff --git a/tests/test_computer_livestream.py b/tests/test_computer_livestream.py index 55103f07..3c0c6344 100644 --- a/tests/test_computer_livestream.py +++ b/tests/test_computer_livestream.py @@ -422,6 +422,9 @@ class _Store: def push_targets(self): return ["d1"] + def approval_push_targets(self, *, desktop): # owner and marked devices (test_approval_push_owner_only) + return self.push_targets() + d = PushDispatcher(_Store(), object(), bridge=None) async def _deliver(target, body): diff --git a/tests/test_push_dispatch.py b/tests/test_push_dispatch.py index 6b919e49..fde0006a 100644 --- a/tests/test_push_dispatch.py +++ b/tests/test_push_dispatch.py @@ -61,8 +61,8 @@ def _store(tmp_path) -> DeviceStore: return DeviceStore(tmp_path / "devices.db") -def _device(store, name="phone", push_token=None): - minted = store.mint(name, "ios") +def _device(store, name="phone", push_token=None, owner=False): + minted = store.mint_owner(name, "ios", by="test") if owner else store.mint(name, "ios") if push_token: assert store.set_push(minted["id"], push_token, "sandbox", "com.oaralabs.beacon") return minted @@ -113,7 +113,7 @@ def test_revoked_device_cannot_register_push_and_drops_from_targets(tmp_path): def test_approval_pushes_even_with_a_live_socket(tmp_path): store = _store(tmp_path) - d = _device(store, push_token="tok-a") + d = _device(store, push_token="tok-a", owner=True) # approval pushes reach owner devices only sender = _FakeSender() dispatcher = PushDispatcher(store, sender, _FakeBridge(live_ids=[d["id"]])) From 202167374970db56ba012386c9c2d0e3bc41b579 Mon Sep 17 00:00:00 2001 From: OAra Labs Date: Thu, 12 Nov 2026 10:54:01 -0500 Subject: [PATCH 3/4] perf(push): approval push targets in three queries, not one per device Co-Authored-By: Claude Opus 5.5 --- src/prometheus/config/device_store.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/prometheus/config/device_store.py b/src/prometheus/config/device_store.py index 471af199..d2a42632 100644 --- a/src/prometheus/config/device_store.py +++ b/src/prometheus/config/device_store.py @@ -335,7 +335,7 @@ def approval_push_targets(self, *, desktop: bool) -> list[PushTarget]: prompt, so a push naming another session's tool and action must not reach it.""" allowed = set(self.owner_device_ids()) if desktop: - allowed |= {t.id for t in self.push_targets() if self.computer_allowed(t.id)} + allowed |= self.computer_device_ids() return [t for t in self.push_targets() if t.id in allowed] # ------------------------------------------------------------------ From 2aeeea59c3be24e559b35d4f04349c203872e709 Mon Sep 17 00:00:00 2001 From: OAra Labs Date: Fri, 13 Nov 2026 12:44:04 -0500 Subject: [PATCH 4/4] fix(push): approval-push wording says only what it does; tests for a revoked marked device and a raising store From the second review of this PR. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 2 +- src/prometheus/config/device_store.py | 4 ++-- tests/test_approval_push_owner_only.py | 25 ++++++++++++++++++++++++- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5c230555..d99fffd9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Notable changes in each release, newest first. Releases before 0.9.7 are describ ## Unreleased -- Push: an approval push now reaches owner devices only, and, for a desktop prompt (whose push carries no content), also the devices marked for computer use, which are the ones that may answer it. It went to every registered device with a push registration, scoped devices included, which see only their own sessions everywhere else and cannot approve. A device store that cannot name owner devices sends no approval push. Other pushes are unchanged. +- Push: an approval push now reaches owner devices only, and, for a desktop prompt (whose push carries no content), also the devices marked for computer use, which are the ones that may answer it. A device store that cannot name owner devices sends no approval push. - Docs: `docs/reference/pairing-join-requests.md` is the reference for how a new device asks to join and how the owner lets it in: the routes and who may call them, every request and response field, the statuses, the expiry and rate limits, the sealed token, the operator's WebSocket frames and the owner code (the explicit, single-use grant that makes an owner device). It is written from the code and pinned to it by `tests/test_pairing_reference.py`. No behaviour changes. - Approvals: Prometheus now says when nothing can answer an approval prompt. `security.approval_queue.enabled` ships `false`, and the queue is only built together with the Telegram gateway; without it every call that needs an approval (a third-party MCP tool, a write or a shell command in `cautious` or `strict` mode, a network or install command in a background turn) is refused within seconds as "Permission denied" and none is ever listed to approve, so `cautious` read as "asks the owner" and behaved as "refuses everything". The daemon logs a warning at start and `oara doctor` has an "Approval prompts" row, both naming the keys to set. Nothing is switched on for you. - Approvals: the grants in `security.grants` are now loaded when the daemon starts. A remembered approval (`/approve always`) was written to the file and then ignored at every restart, so the prompt it silenced came back each time, and a `kind: tool` row written by hand (for one third-party MCP tool) never took effect. After this, a grant lasts until you `/revoke` it. **On upgrade, grants saved by earlier versions take effect again at the first start:** the startup log lists each one by id, kind and tool, `/grants` shows them in full, and `/revoke` removes one. The daemon and `SecurityGate.from_config` now read the key in one place. diff --git a/src/prometheus/config/device_store.py b/src/prometheus/config/device_store.py index d2a42632..92e5f517 100644 --- a/src/prometheus/config/device_store.py +++ b/src/prometheus/config/device_store.py @@ -331,8 +331,8 @@ def push_targets(self) -> list[PushTarget]: def approval_push_targets(self, *, desktop: bool) -> list[PushTarget]: """The push targets an APPROVAL push may reach: live owner devices, and, for a desktop prompt (whose push carries no content at all), also the live devices marked for computer use, which are the ones that may - answer it. A scoped device sees only its own sessions everywhere else and approves nothing but a desktop - prompt, so a push naming another session's tool and action must not reach it.""" + answer it. A scoped device approves nothing but a desktop prompt, so a push naming another session's tool + and action must not reach it.""" allowed = set(self.owner_device_ids()) if desktop: allowed |= self.computer_device_ids() diff --git a/tests/test_approval_push_owner_only.py b/tests/test_approval_push_owner_only.py index 89b05be3..79984457 100644 --- a/tests/test_approval_push_owner_only.py +++ b/tests/test_approval_push_owner_only.py @@ -1,7 +1,7 @@ """An approval push goes to owner devices only. An approval push carries the tool name and the first line of the request's description, and it used to go to -every registered device. A scoped device sees only its own sessions everywhere else (``GET /api/approvals``, the +every registered device. A scoped device sees only its own sessions' requests (``GET /api/approvals``, the ``approval_pending`` frame), and it cannot approve anything but a desktop prompt, so a push to it about another session's request told it something no other surface would, and offered it a button it could not use. @@ -99,3 +99,26 @@ def test_the_store_query_answers_owner_and_marked_devices(tmp_path): assert names == {"tok-owner"} names = {t.apns_token for t in store.approval_push_targets(desktop=True)} assert names == {"tok-owner", "tok-marked"} + + +def test_a_revoked_marked_device_gets_no_desktop_push(tmp_path): + store = _world(tmp_path) + marked = [d for d in store.list_devices() if d.name == "marked tablet"][0] + store.revoke(marked.id) + sender = _Sender() + asyncio.run(PushDispatcher(store, sender, bridge=None).on_signal( + _signal("approval_pending", _approval(task_id="t1")))) + assert _tokens(sender) == ["tok-owner"] + + +def test_a_store_that_raises_sends_no_approval_push_and_the_bus_survives(): + class _Raising: + def push_targets(self): + return [] + + def approval_push_targets(self, *, desktop): + raise RuntimeError("database is locked") + + sender = _Sender() + asyncio.run(PushDispatcher(_Raising(), sender, bridge=None).on_signal(_signal("approval_pending", _approval()))) + assert sender.sent == []