Skip to content

armgit / avibe

Public Imported from GitHub
0

Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.

fix(auth): expire private show event streams

Maxvint3a2011ac7621
diff --git a/tests/test_ui_show_pages.py b/tests/test_ui_show_pages.py
index d4b48ba99..2d4b44afc 100644
--- a/tests/test_ui_show_pages.py
+++ b/tests/test_ui_show_pages.py
@@ -2488,6 +2488,31 @@ def test_show_events_stream_forwards_live_dispatch_events(monkeypatch, tmp_path)
assert '"show_event_id": "show_evt_1"' in body
+def test_private_show_events_stream_ends_at_authorization_refresh_deadline(monkeypatch, tmp_path):
+ from vibe.ui_server import _show_events_stream
+
+ monkeypatch.setenv("AVIBE_HOME", str(tmp_path))
+ _save_config(tmp_path)
+ _create_agent_session("ses123")
+ _create_show_page("ses123", "private")
+
+ async def _collect_until_expired() -> list[str | bytes]:
+ response = await _show_events_stream(
+ "ses123",
+ authorization_refresh_at=ui_server.time.time(),
+ )
+ iterator = response.body_iterator.__aiter__()
+ try:
+ chunks = [await iterator.__anext__()]
+ with pytest.raises(StopAsyncIteration):
+ await asyncio.wait_for(iterator.__anext__(), timeout=1)
+ finally:
+ await iterator.aclose()
+ return chunks
+
+ assert len(asyncio.run(_collect_until_expired())) == 1
+
+
def test_public_show_events_stream_redacts_nested_dispatch_ids(monkeypatch, tmp_path):
from vibe.sse_broker import broker
from vibe.ui_server import _show_events_stream
diff --git a/vibe/ui_server.py b/vibe/ui_server.py
index 3cc3ce99a..14326fbe9 100644
--- a/vibe/ui_server.py
+++ b/vibe/ui_server.py
@@ -9466,6 +9466,7 @@ async def _show_events_stream(
after_id: str | None = None,
public: bool = False,
public_share_id: str | None = None,
+ authorization_refresh_at: float | None = None,
):
import asyncio
@@ -9485,11 +9486,15 @@ async def _show_events_stream(
cursor = after_id
yield ": show events connected\n\n"
while True:
+ if authorization_refresh_at is not None and time.time() >= authorization_refresh_at:
+ return
batch = store.list(session_id, after_id=cursor, limit=500)
events = batch["events"]
if not events:
break
for event_payload in events:
+ if authorization_refresh_at is not None and time.time() >= authorization_refresh_at:
+ return
if isinstance(event_payload.get("id"), str):
replayed_ids.add(event_payload["id"])
yield _sse_frame(
@@ -9507,8 +9512,14 @@ async def _show_events_stream(
store.close()
while True:
+ wait_timeout = 15.0
+ if authorization_refresh_at is not None:
+ remaining = authorization_refresh_at - time.time()
+ if remaining <= 0:
+ return
+ wait_timeout = min(wait_timeout, remaining)
try:
- event_type, payload = await asyncio.wait_for(queue.get(), timeout=15.0)
+ event_type, payload = await asyncio.wait_for(queue.get(), timeout=wait_timeout)
decoded = json.loads(payload)
event_payload = decoded.get("data") if isinstance(decoded, dict) else None
if event_type == "show.event" and isinstance(event_payload, dict) and _event_visible(event_payload):
@@ -9528,6 +9539,8 @@ async def _show_events_stream(
elif event_type == "show.dispatch" and isinstance(event_payload, dict) and _event_visible(event_payload):
yield _sse_frame("show.dispatch", _show_dispatch_response_payload(event_payload, public=public))
except asyncio.TimeoutError:
+ if authorization_refresh_at is not None and time.time() >= authorization_refresh_at:
+ return
yield ": ping\n\n"
except asyncio.CancelledError:
raise
@@ -9559,6 +9572,9 @@ async def _show_events_response(
after_id=request.args.get("after_id") or _last_event_id_from_request(),
public=public,
public_share_id=public_share_id,
+ authorization_refresh_at=(
+ None if public else getattr(g, "remote_authorization_refresh_at", None)
+ ),
)
store = _show_session_event_store()
try: