Skip to content

Dodaios is an open-source agent OS for your desktop: it runs your coding agents, browser and apps by voice or chat, on your own machine. Formerly Personal Jarvis.

fix(brain): signing out of a subscription in the app ends background subscription mode

rubenluetke10-beepcea072cbc3a7
diff --git a/jarvis/brain/background_policy.py b/jarvis/brain/background_policy.py
index 249472fe36..37ce6ed751 100644
--- a/jarvis/brain/background_policy.py
+++ b/jarvis/brain/background_policy.py
@@ -128,6 +128,23 @@ def keyless_local(provider: str) -> bool:
return _billing(provider) == "local"
+def _registry_probe(provider: str) -> bool | None:
+ """Ask the provider class whether its subscription login is usable.
+
+ Module-level so the test suite can replace it once for every test: the
+ real probe shells out to the vendor CLI and reads the developer's login.
+ """
+ try:
+ from jarvis.brain.provider_registry import BrainProviderRegistry
+
+ provider_class = BrainProviderRegistry().get_class(provider)
+ probe = getattr(provider_class, "subscription_connected", None)
+ return bool(probe()) if callable(probe) else None
+ except Exception: # noqa: BLE001 - an unknown answer, not a broken caller
+ log.debug("background policy: login probe failed for %s", provider, exc_info=True)
+ return None
+
+
def login_state(provider: str) -> bool | None:
"""Memoised subscription-login probe: True, False, or None (unknown)."""
now = time.monotonic()
@@ -135,19 +152,8 @@ def login_state(provider: str) -> bool | None:
cached = _probe_cache.get(provider)
if cached is not None and now - cached[0] < _PROBE_TTL_S:
return cached[1]
- result: bool | None
- if _probe_override is not None:
- result = _probe_override(provider)
- else:
- try:
- from jarvis.brain.provider_registry import BrainProviderRegistry
-
- provider_class = BrainProviderRegistry().get_class(provider)
- probe = getattr(provider_class, "subscription_connected", None)
- result = bool(probe()) if callable(probe) else None
- except Exception: # noqa: BLE001 - an unknown answer, not a broken caller
- log.debug("background policy: login probe failed for %s", provider, exc_info=True)
- result = None
+ probe = _probe_override if _probe_override is not None else _registry_probe
+ result = probe(provider)
with _lock:
_probe_cache[provider] = (time.monotonic(), result)
if result is True:
diff --git a/jarvis/ui/web/antigravity_routes.py b/jarvis/ui/web/antigravity_routes.py
index 755b4dc788..09c43930c4 100644
--- a/jarvis/ui/web/antigravity_routes.py
+++ b/jarvis/ui/web/antigravity_routes.py
@@ -21,6 +21,7 @@ from typing import Any
from fastapi import APIRouter, HTTPException
+from jarvis.brain import background_policy
from jarvis.core.interactive_terminal import InteractiveTerminalUnavailable
from jarvis.google_cli.auth_service import (
GoogleCliAuthService,
@@ -107,4 +108,7 @@ async def antigravity_logout() -> dict[str, Any]:
ok, error = await asyncio.to_thread(service.logout_blocking)
if not ok:
raise HTTPException(status_code=500, detail=error or "Google logout failed")
+ # A deliberate sign-out ends subscription mode for background work now,
+ # not after the 30-day memory in background_policy.
+ await asyncio.to_thread(background_policy.forget, "antigravity")
return {"ok": True, "message": "Antigravity (Google) was disconnected"}
diff --git a/jarvis/ui/web/claude_routes.py b/jarvis/ui/web/claude_routes.py
index e911038fc4..d8b2f117c3 100644
--- a/jarvis/ui/web/claude_routes.py
+++ b/jarvis/ui/web/claude_routes.py
@@ -26,6 +26,7 @@ from typing import Any
from fastapi import APIRouter, HTTPException
+from jarvis.brain import background_policy
from jarvis.claude_auth import ClaudeAuthService, claude_install_command
from jarvis.core.interactive_terminal import InteractiveTerminalUnavailable
@@ -111,4 +112,7 @@ async def claude_logout() -> dict[str, Any]:
ok, error = await asyncio.to_thread(service.logout_blocking)
if not ok:
raise HTTPException(status_code=500, detail=error or "Claude logout failed")
+ # A deliberate sign-out ends subscription mode for background work now,
+ # not after the 30-day memory in background_policy.
+ await asyncio.to_thread(background_policy.forget, "claude-cli")
return {"ok": True, "message": "Claude was disconnected"}
diff --git a/jarvis/ui/web/grok_build_routes.py b/jarvis/ui/web/grok_build_routes.py
index fe18090f06..ef21f1a0de 100644
--- a/jarvis/ui/web/grok_build_routes.py
+++ b/jarvis/ui/web/grok_build_routes.py
@@ -15,6 +15,7 @@ from typing import Any
from fastapi import APIRouter, HTTPException
+from jarvis.brain import background_policy
from jarvis.core.interactive_terminal import InteractiveTerminalUnavailable
from jarvis.grok_build_auth import (
GrokBuildAuthService,
@@ -89,4 +90,7 @@ async def grok_build_logout() -> dict[str, Any]:
ok, error = await asyncio.to_thread(service.logout_blocking)
if not ok:
raise HTTPException(status_code=500, detail=error or "Grok Build logout failed")
+ # A deliberate sign-out ends subscription mode for background work now,
+ # not after the 30-day memory in background_policy.
+ await asyncio.to_thread(background_policy.forget, "grok-build")
return {"ok": True, "message": "Grok Build was disconnected"}
diff --git a/jarvis/ui/web/provider_routes.py b/jarvis/ui/web/provider_routes.py
index 205ce1eca6..0060e788f4 100644
--- a/jarvis/ui/web/provider_routes.py
+++ b/jarvis/ui/web/provider_routes.py
@@ -28,6 +28,7 @@ from typing import Any, Final, Literal, get_args
from fastapi import APIRouter, HTTPException, Request, Response
from pydantic import BaseModel, Field
+from jarvis.brain import background_policy
from jarvis.brain import provider_test as _provider_test
from jarvis.brain import section_health as _section_health
from jarvis.brain.model_catalog import ModelInfo, catalog_spec, classify_model
@@ -3986,6 +3987,9 @@ async def codex_logout(request: Request) -> dict[str, Any]:
ok, error = await asyncio.to_thread(service.logout_blocking)
if not ok:
raise HTTPException(status_code=500, detail=error or "Codex logout failed")
+ # A deliberate sign-out ends subscription mode for background work now,
+ # not after the 30-day memory in background_policy.
+ await asyncio.to_thread(background_policy.forget, "codex")
return {"ok": True, "message": "Codex was disconnected"}
diff --git a/tests/conftest.py b/tests/conftest.py
index 3860c87c8e..ba0be269c0 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -183,6 +183,26 @@ def _pricing_feed_in_tmp(tmp_path_factory, monkeypatch): # noqa: ANN001
yield
[email protected](autouse=True)
+def _background_policy_in_tmp(tmp_path_factory, monkeypatch): # noqa: ANN001
+ """Keep the background billing policy off the developer's real login state.
+
+ The policy remembers a connected subscription in the user-data directory
+ and probes vendor CLIs for their login. Unpinned, a suite run on a machine
+ with a signed-in CLI would flip tests into subscription mode, and a logout
+ route test would erase the developer's real marker. Tests that need a
+ login script it through ``_probe_override``.
+ """
+ from jarvis.brain import background_policy
+
+ root = tmp_path_factory.mktemp("background-policy")
+ monkeypatch.setattr(background_policy, "_marker_path", lambda: root / "subscription_seen.json")
+ monkeypatch.setattr(background_policy, "_registry_probe", lambda _provider: None)
+ background_policy.reset_for_tests()
+ yield
+ background_policy.reset_for_tests()
+
+
@pytest.fixture(autouse=True)
def _app_action_state_in_tmp(tmp_path_factory, monkeypatch): # noqa: ANN001
"""Every registry-command or app-action call records its outcome for the
diff --git a/tests/integration/test_antigravity_routes.py b/tests/integration/test_antigravity_routes.py
index 06cd109ed9..2aa10b4760 100644
--- a/tests/integration/test_antigravity_routes.py
+++ b/tests/integration/test_antigravity_routes.py
@@ -84,3 +84,14 @@ def test_logout_ok(monkeypatch):
resp = client.post("/api/antigravity/logout")
assert resp.status_code == 200
assert resp.json()["ok"] is True
+
+
+def test_logout_ends_subscription_mode_for_background_work(monkeypatch):
+ from jarvis.brain import background_policy
+
+ background_policy.note_connected("antigravity")
+ assert background_policy.subscription_mode()
+ st = GoogleCliAuthStatus(installed=True, connected=True)
+ client = _client(monkeypatch, status=st)
+ assert client.post("/api/antigravity/logout").status_code == 200
+ assert not background_policy.subscription_mode()