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(permissions): ignore undecodable cache

Max799d5276186a
diff --git a/tests/test_permissions.py b/tests/test_permissions.py
index ebbeba58c..a3c4556ed 100644
--- a/tests/test_permissions.py
+++ b/tests/test_permissions.py
@@ -515,6 +515,24 @@ def test_permissions_live_read_survives_cache_write_failure(monkeypatch) -> None
assert result.projection["instance"]["id"] == "inst-123"
+def test_permissions_live_read_replaces_an_invalid_utf8_cache(monkeypatch) -> None:
+ cache_path = permissions._cache_path() # noqa: SLF001
+ cache_path.parent.mkdir(parents=True, exist_ok=True)
+ cache_path.write_bytes(b"\xff")
+ monkeypatch.setattr(
+ permissions.requests,
+ "request",
+ lambda *_args, **_kwargs: _Response(200, _projection()),
+ )
+
+ result = permissions.get_current_permissions(_config())
+ cached = permissions._read_cache("inst-123") # noqa: SLF001
+
+ assert result.source == "live"
+ assert cached is not None
+ assert cached.projection == result.projection
+
+
@pytest.mark.parametrize(
("status", "error"),
[
diff --git a/vibe/permissions.py b/vibe/permissions.py
index 0fc6a5b9c..e20cbf3d3 100644
--- a/vibe/permissions.py
+++ b/vibe/permissions.py
@@ -433,7 +433,7 @@ def _write_cache(instance_id: str, projection: dict[str, Any]) -> None:
def _read_cache(instance_id: str) -> PermissionsProjectionResult | None:
try:
envelope = json.loads(_cache_path().read_text(encoding="utf-8"))
- except (FileNotFoundError, OSError, json.JSONDecodeError):
+ except (FileNotFoundError, OSError, UnicodeDecodeError, json.JSONDecodeError):
return None
if not isinstance(envelope, dict):
return None