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(society): let the open desktop Stop button still end the chat

rubenluetke10-beep96902ad63660
diff --git a/jarvis/ui/web/society_browser_routes.py b/jarvis/ui/web/society_browser_routes.py
index 2ead610a2b..aa32e99609 100644
--- a/jarvis/ui/web/society_browser_routes.py
+++ b/jarvis/ui/web/society_browser_routes.py
@@ -108,12 +108,18 @@ async def cancel_agent_browser(agent_id: str, request: Request) -> dict[str, Any
if session is None or session.closed:
return {"cancelled": False}
running = session.run_lock.locked()
- # The viewer Stop button sends this header and ends the planner too.
- # A bare POST only releases the browser. The agent calls that bare URL
- # when a tool client has already given up; ending the chat there is the
- # turn dying in the middle of the task.
+ # The viewer Stop button ends the planner too. A bare POST only releases
+ # the browser: the agent calls that URL when a tool client has already
+ # given up, and ending the chat there is the turn dying mid-task.
+ # The desktop fetch sets Sec-Fetch-Site; a shell call does not.
headers = getattr(request, "headers", None)
- stop_chat = bool(headers and headers.get("x-jarvis-stop-chat") == "1")
+ stop_chat = bool(
+ headers
+ and (
+ headers.get("x-jarvis-stop-chat") == "1"
+ or str(headers.get("sec-fetch-site") or "").lower() == "same-origin"
+ )
+ )
await rt.browser.live.cancel(session, end_turn=stop_chat)
chat = getattr(request.app.state, "agent_chat", None)
if running and stop_chat and chat is not None:
diff --git a/tests/contract/test_browser_contract.py b/tests/contract/test_browser_contract.py
index 12ba4748b6..d6da3493df 100644
--- a/tests/contract/test_browser_contract.py
+++ b/tests/contract/test_browser_contract.py
@@ -179,7 +179,7 @@ async def test_agent_cancel_releases_the_browser_without_stopping_the_chat(monke
)
request = SimpleNamespace(
- headers={},
+ headers={"origin": "http://127.0.0.1:47821"},
app=SimpleNamespace(state=SimpleNamespace(agent_chat=SimpleNamespace(cancel=cancel_chat))),
)
monkeypatch.setattr(routes, "_runtime", runtime)
@@ -187,6 +187,42 @@ async def test_agent_cancel_releases_the_browser_without_stopping_the_chat(monke
assert seen == [False]
+async def test_desktop_fetch_stop_still_ends_the_chat(monkeypatch):
+ import asyncio
+
+ from jarvis.ui.web import society_browser_routes as routes
+
+ seen = []
+ lock = asyncio.Lock()
+ await lock.acquire()
+ session = SimpleNamespace(closed=False, run_lock=lock, active_chat="society:test-bot")
+
+ async def cancel_browser(value, *, end_turn=True):
+ seen.append(end_turn)
+
+ async def cancel_chat(value):
+ seen.append(value)
+
+ async def resolve(_):
+ return SimpleNamespace(agent_id="test-bot")
+
+ async def runtime(_):
+ return SimpleNamespace(
+ roster=SimpleNamespace(resolve=resolve),
+ browser=SimpleNamespace(
+ live=SimpleNamespace(sessions={"test-bot": session}, cancel=cancel_browser)
+ ),
+ )
+
+ request = SimpleNamespace(
+ headers={"origin": "http://127.0.0.1:47821", "sec-fetch-site": "same-origin"},
+ app=SimpleNamespace(state=SimpleNamespace(agent_chat=SimpleNamespace(cancel=cancel_chat))),
+ )
+ monkeypatch.setattr(routes, "_runtime", runtime)
+ assert await routes.cancel_agent_browser("test-bot", request) == {"cancelled": True}
+ assert seen == [True, "society:test-bot"]
+
+
async def test_same_chat_replaces_an_abandoned_browser_run():
import asyncio