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.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(model-hub): remove the engine's lock sidecar with a deleted OAuth grant (#2786)
Call White8ed5cbeafff2
diff --git a/tests/test_model_hub_runtime.py b/tests/test_model_hub_runtime.pyindex ab5a8d00a..34f765a1d 100644--- a/tests/test_model_hub_runtime.py+++ b/tests/test_model_hub_runtime.py@@ -2157,6 +2157,54 @@ def test_state_rejects_unsafe_inputs_and_auth_permissions(tmp_path: Path) -> Nonassert stat.S_IMODE(auth_file.stat().st_mode) == 0o600+def _codex_grant_with_engine_lock(store: EngineStateStore) -> tuple[Path, Path]:+ """A Codex grant and the ``<name>.lock`` CPA v8.0.28+ keeps beside it (0600, never removed)."""++ store.audit_auth_permissions()+ grant = store.auth_dir / "codex-synthetic.json"+ lock = store.auth_dir / "codex-synthetic.json.lock"+ for path in (grant, lock):+ path.write_text("{}" if path is grant else "", encoding="utf-8")+ path.chmod(0o600)+ return grant, lock+++def test_deleting_an_oauth_grant_removes_the_engine_lock_beside_it(tmp_path: Path) -> None:+ store = EngineStateStore(tmp_path / "state")+ grant, lock = _codex_grant_with_engine_lock(store)+ # The sidecar is a regular private file: every auth-dir consumer accepts it.+ store.audit_auth_permissions()++ store.delete_oauth_auth_file(grant.name)++ assert not grant.exists() and not lock.exists()+ assert list(store.auth_dir.iterdir()) == []+++def test_a_lock_the_engine_holds_never_fails_the_grants_removal(+ tmp_path: Path, monkeypatch: pytest.MonkeyPatch, caplog: pytest.LogCaptureFixture,+) -> None:+ """On Windows the engine may hold its lock during a refresh; the grant still goes."""++ store = EngineStateStore(tmp_path / "state")+ grant, lock = _codex_grant_with_engine_lock(store)+ remove = EngineStateStore._remove_private_file_if_present.__func__++ def held(cls, path: Path) -> bool:+ if path == lock:+ raise EngineStateError("unable to remove engine state file")+ return remove(cls, path)++ monkeypatch.setattr(EngineStateStore, "_remove_private_file_if_present", classmethod(held))++ store.delete_oauth_auth_file(grant.name)++ assert not grant.exists() and lock.exists()+ assert "Could not remove the engine lock" in caplog.text+ # A leftover sidecar keeps passing the audit every engine start runs.+ store.audit_auth_permissions()++def test_a_persisted_key_source_survives_a_repin_of_its_vendor(tmp_path: Path) -> None:"""A stored api-key Source is judged by its upstream, not by today's pin.diff --git a/tests/test_model_hub_state_private.py b/tests/test_model_hub_state_private.pyindex 6e7049938..5d2e14215 100644--- a/tests/test_model_hub_state_private.py+++ b/tests/test_model_hub_state_private.py@@ -42,12 +42,16 @@ def test_windows_engine_start_and_api_key_source_keep_secrets_private(root):reference = store.store_api_key("sk-synthetic-windows", base_url="https://example.invalid/v1")assert store.read_api_key(reference) == "sk-synthetic-windows"- # The engine writes its grants into the auth directory without asking for- # any access rule; they must pass the audit every engine start runs.+ # The engine writes its grants, and since CPA v8.0.28 a Codex grant's lock+ # sidecar, into the auth directory without asking for any access rule; they+ # must pass the audit every engine start runs.(store.auth_dir / "codex-synthetic.json").write_text("{}", encoding="utf-8")+ (store.auth_dir / "codex-synthetic.json.lock").write_text("", encoding="utf-8")store.audit_auth_permissions()for path in (store.root, instance_dir, instance_dir / "runtime-secrets.json", instance_dir / "logs", store.auth_dir):assert _private(path), path+ store.delete_oauth_auth_file("codex-synthetic.json")+ assert list(store.auth_dir.iterdir()) == []@windows_onlydiff --git a/vibe/model_hub_runtime/state.py b/vibe/model_hub_runtime/state.pyindex 5c4fd4e48..ad92da429 100644--- a/vibe/model_hub_runtime/state.py+++ b/vibe/model_hub_runtime/state.py@@ -1113,11 +1113,22 @@ class EngineStateStore:return matches[0] if matches else Nonedef delete_oauth_auth_file(self, auth_name: str) -> None:- """Delete one managed OAuth file without requiring a running engine."""+ """Delete one managed OAuth file without requiring a running engine.++ Its engine lock sidecar goes with it, best effort: since CPA v8.0.28 the+ engine locks a Codex grant through ``<name>.lock`` beside it and never+ removes that file. The engine may hold it during a refresh, which on+ Windows blocks the delete; a leftover sidecar locks nothing and passes+ the auth audit, so it is not worth failing the grant's removal over.+ """normalized = _validated_oauth_auth_name(auth_name)with self._lock:self.audit_auth_permissions(enforce=True)self._remove_private_file_if_present(self.auth_dir / normalized)+ try:+ self._remove_private_file_if_present(self.auth_dir / f"{normalized}.lock")+ except EngineStateError:+ logger.warning("Could not remove the engine lock beside a deleted OAuth grant", exc_info=True)def audit_auth_permissions(self, *, enforce: bool = False) -> None:self._ensure_private_dir(self.root)