diff --git a/CHANGELOG.md b/CHANGELOG.md index 9c0e19fb..85344442 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Notable changes in each release, newest first. Releases before 0.9.7 are describ - Speech (groundwork): `prometheus.speech.phrases` cuts a streaming reply into phrases a voice can speak, by the rules in `docs/design/speech-route.md` section 5: sentence ends (not decimals, common abbreviations or list numbers), line breaks, tool calls, clause ends, a 200-character maximum, code blocks never read and never cut, markdown taken out, and at most 5,000 characters spoken per reply. Nothing uses it yet; the speech routes follow. - Docs: `docs/design/speech-route.md` is the design for reading a reply aloud through Prometheus: the speech routes, who may call them, the `speech` capability, how phrases are cut, how the voice box is configured and checked, and what an app is told when it is down. No behaviour changes. - Computer use: the `computer` extra now pins cua-driver 0.28.3, because 0.28.2 was removed from PyPI. The adapter follows 0.28.3's types: the observe input passes the new `max_image_dimension` empty (the driver's default), and an action result that carries an `error` is a failed action, and the failure reason (in the task's end frame, the status API and the model's tool result) carries the driver's code and hint; a stale element token is refused as a stale snapshot, and the adapter does not retry either. The lock also moves dnspython to 2.9.2 (CVE-2026-128089) and the OpenTelemetry packages to 1.45.2 together (CVE-2026-126360). +- 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. - CI: the parity replay job runs on `ubuntu-24.04`, pinned, instead of `ubuntu-latest`. When `ubuntu-latest` moved to 26.04, the longer OS line in the system prompt raised the compaction scenario's token estimate by one and failed it, with every model request still matching. No behaviour changes. - 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. diff --git a/src/prometheus/config/device_store.py b/src/prometheus/config/device_store.py index a23743ee..92e5f517 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 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() + 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_approval_push_owner_only.py b/tests/test_approval_push_owner_only.py new file mode 100644 index 00000000..79984457 --- /dev/null +++ b/tests/test_approval_push_owner_only.py @@ -0,0 +1,124 @@ +"""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' 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. + +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"} + + +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 == [] 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"]]))