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(agentic-ide): tell the truth about a pane whose agent refused to start

rubenluetke10-beep760a93da416c
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.py
index 56431adade..abceecc8ed 100644
--- a/jarvis/agentic_ide/session.py
+++ b/jarvis/agentic_ide/session.py
@@ -2886,17 +2886,32 @@ class Registry:
# per MCP server. The account gate is async so waiters do not occupy the
# shared executor while one thread owns the filesystem setup lock.
redirected_home = _redirected_home(term)
- if redirected_home is None:
- env = await asyncio.to_thread(self._prepare_spawn, term, session.folder)
- else:
- account_key = os.path.normcase(str(redirected_home))
- account_gate = self._account_prepare_locks.setdefault(
- account_key, asyncio.Lock()
- )
- async with account_gate:
- env = await asyncio.to_thread(
- self._prepare_spawn, term, session.folder
+ # Recorded ON THE PANE, not only raised. A refusal here is the SAME kind
+ # of "this cannot start" as a missing binary or a spawn that threw, and
+ # both of those mark the pane before they raise. Left unmarked, the pane
+ # stayed `pending` — and `pending` has a headline of its own that reads
+ # "waiting for terminal connection", which is a promise: it says the
+ # terminal is about to connect. Nothing was ever going to connect. The
+ # one refusal that reaches this path (an unconfigured launch profile —
+ # see `agent_spawn_overlay`) therefore showed the user a pane that
+ # claimed to be starting forever, with the actual reason living only in
+ # a socket frame the pane painted over a moment later.
+ try:
+ if redirected_home is None:
+ env = await asyncio.to_thread(self._prepare_spawn, term, session.folder)
+ else:
+ account_key = os.path.normcase(str(redirected_home))
+ account_gate = self._account_prepare_locks.setdefault(
+ account_key, asyncio.Lock()
)
+ async with account_gate:
+ env = await asyncio.to_thread(
+ self._prepare_spawn, term, session.folder
+ )
+ except SessionError as exc:
+ term.status = "error"
+ term.error = str(exc)
+ raise
# The provider/account gate is acquired BEFORE the machine-wide gate.
# A Codex pane waiting on shared state must never occupy a CPU slot that
diff --git a/jarvis/ui/web/agentic_ide_routes.py b/jarvis/ui/web/agentic_ide_routes.py
index e2544b8a6f..48bdae5e66 100644
--- a/jarvis/ui/web/agentic_ide_routes.py
+++ b/jarvis/ui/web/agentic_ide_routes.py
@@ -3699,7 +3699,16 @@ async def agentic_pty(ws: WebSocket, name: str) -> None:
exc,
)
await ws.send_json({"t": "error", "message": str(exc)})
- await ws.close(code=4404, reason="attach failed")
+ # 4500, not 4404. The pane EXISTS — its agent refused to start. 4404 is
+ # the client's code for "this pane is not in the open workspace", and it
+ # acts on that: it replaces whatever reason was just sent with its own
+ # "no longer part of the open workspace" line and asks the view to
+ # re-read the grid. So the honest diagnosis one frame earlier ("… is not
+ # configured yet — add its API key …") was painted over by a sentence
+ # that was not true, and the user was told to go looking for a missing
+ # pane instead of a missing key. A refusal has its own code now, and the
+ # client keeps the reason that came with it.
+ await ws.close(code=4500, reason="attach failed")
return
await ws.send_json(
diff --git a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
index 35dd3fc17d..043c89da8c 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
+++ b/jarvis/ui/web/frontend/src/components/agentic/AgenticTerminal.tsx
@@ -820,6 +820,13 @@ export function AgenticTerminal({
// a pane that keeps knocking every half minute would otherwise stamp a red
// line into the terminal twice a minute forever.
let troubleShown: "retrying" | "unreachable" | null = null;
+ // And at most one line per WORDING, which is a separate limit. A refused
+ // attach reaches this twice — once as the reason the server sent, then
+ // again as the verdict on the close that immediately follows it — and the
+ // two are now the same sentence, because the second one no longer invents
+ // its own. Printing it again in red under itself in yellow reads like two
+ // problems.
+ let troubleText = "";
/*
* Is anyone actually looking at this pane?
@@ -1354,6 +1361,7 @@ export function AgenticTerminal({
},
onReady: ({ resumed, reattached, lastPrompt }) => {
troubleShown = null;
+ troubleText = "";
// What this pane was told BEFORE this socket existed. A reload, a
// reconnect or a second window opened afterwards would otherwise
// show no receipt at all for a prompt that really was delivered —
@@ -1408,8 +1416,13 @@ export function AgenticTerminal({
// merely restarting.
report(retrying ? "connecting" : "error", message);
const kind = retrying ? "retrying" : "unreachable";
- if (troubleShown === kind) return;
+ const repeats = troubleShown === kind || message === troubleText;
troubleShown = kind;
+ // The status was reported either way — only the terminal write is
+ // skipped. The notice row keeps the sentence on screen (see
+ // `PaneNotice`), so nothing is lost by not repeating it.
+ if (repeats) return;
+ troubleText = message;
writeToPane(
`\r\n\x1b[${retrying ? "33" : "31"}m[${message}]\x1b[0m\r\n`,
);
diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneSocket.test.ts b/jarvis/ui/web/frontend/src/components/agentic/paneSocket.test.ts
index 9faa825598..dcb4a96393 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/paneSocket.test.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/paneSocket.test.ts
@@ -171,6 +171,31 @@ describe("openPaneSocket", () => {
socket.close();
});
+ it("keeps the server's reason when the agent refused to start", async () => {
+ const cb = handlers();
+ const socket = openPaneSocket({ name: "Tara", cols: 80, rows: 24 }, cb);
+ const first = MockWebSocket.last;
+ first!.fire("open");
+
+ // The pane IS in the workspace; its agent would not start. That answer
+ // carries the only sentence naming the fix, and it used to be discarded:
+ // sent under 4404, the pane replaced it with "no longer part of the open
+ // workspace" and sent the view off to re-read a grid that was never wrong.
+ const reason =
+ "GLM Coding Plan is not configured yet — add its API key on the API Keys page.";
+ const reread = vi.fn();
+ window.addEventListener("jarvis:agentic-ide-changed", reread);
+ first!.deliver({ t: "error", message: reason });
+ first!.dropped(4500);
+ await vi.advanceTimersByTimeAsync(60_000);
+ window.removeEventListener("jarvis:agentic-ide-changed", reread);
+
+ expect(MockWebSocket.opened).toHaveLength(1);
+ expect(cb.onTrouble).toHaveBeenLastCalledWith(reason, false);
+ expect(reread).not.toHaveBeenCalled();
+ socket.close();
+ });
+
it("re-joins a running agent after the connection drops", async () => {
const cb = handlers();
const socket = openPaneSocket({ name: "Mika", cols: 80, rows: 24 }, cb);
diff --git a/jarvis/ui/web/frontend/src/components/agentic/paneSocket.ts b/jarvis/ui/web/frontend/src/components/agentic/paneSocket.ts
index b67eb9ede3..bf028936b1 100644
--- a/jarvis/ui/web/frontend/src/components/agentic/paneSocket.ts
+++ b/jarvis/ui/web/frontend/src/components/agentic/paneSocket.ts
@@ -73,6 +73,18 @@ const CLOSE_NOT_READY = 4503;
* {@link WORKSPACE_CHANGED_EVENT} asks the view to do.
*/
const CLOSE_STALE_WORKSPACE = 4409;
+/**
+ * Server close code: the pane is here, but its agent refused to start.
+ *
+ * The fourth verdict, and the one 4404 used to be borrowed for. The distinction
+ * matters because the two ask for opposite things: "not here" means the grid on
+ * screen is stale and must be re-read, while this one means the grid is right
+ * and the AGENT has a problem the user can fix — almost always a launch profile
+ * with no key configured. Sharing a code meant the pane discarded the server's
+ * explanation, replaced it with "no longer part of the open workspace", and sent
+ * the view off to re-read a grid that was never wrong.
+ */
+const CLOSE_ATTACH_FAILED = 4500;
/**
* The window event the Agentic-IDE view re-fetches its whole state on.
@@ -257,6 +269,17 @@ export function openPaneSocket(
let waits = 0;
let ticketRetries = 0;
let pendingTicket: string | null = null;
+ /**
+ * The last reason the SERVER gave, kept for the close that follows it.
+ *
+ * An `error` frame is never the end of the story — the server sends it and
+ * closes in the same breath — so the close handler is where a pane decides
+ * what it believes, and until it could read this it had only the close code
+ * to go on. That is how a pane whose agent refused to start ("… is not
+ * configured yet — add its API key …") ended up telling the user it was no
+ * longer part of the workspace: a true sentence about the wrong problem.
+ */
+ let serverReason = "";
const schedule = (delay: number) => {
if (timer !== null || stopped) return;
@@ -339,6 +362,14 @@ export function openPaneSocket(
askForFreshState("stale-workspace");
return;
}
+ if (code === CLOSE_ATTACH_FAILED) {
+ // The pane is where it belongs and the grid is current — the agent would
+ // not start. Retrying cannot fix a missing key, so this ends the pane,
+ // and it ends it with the server's OWN sentence: that sentence names the
+ // problem and the page to fix it on, which no message written here could.
+ giveUp(serverReason || "This terminal could not be started.");
+ return;
+ }
if (code === CLOSE_NO_SUCH_PANE) {
// The server is not saying "not right now", it is saying "not here".
// No number of retries turns that into a terminal.
@@ -468,7 +499,10 @@ export function openPaneSocket(
handlers.onExit(msg.code ?? 0);
} else if (msg.t === "error") {
// The server refused the attach and is about to close; the close code
- // decides whether that is worth another attempt.
+ // decides whether that is worth another attempt. Kept as well as shown,
+ // because the close handler runs a moment later and would otherwise
+ // have nothing to say beyond what the bare code implies.
+ serverReason = msg.message ?? "";
handlers.onTrouble(msg.message ?? "The terminal could not be started.", true);
}
});
diff --git a/tests/unit/agentic_ide/test_new_cli_providers.py b/tests/unit/agentic_ide/test_new_cli_providers.py
index f4be243ffa..2bde693f41 100644
--- a/tests/unit/agentic_ide/test_new_cli_providers.py
+++ b/tests/unit/agentic_ide/test_new_cli_providers.py
@@ -416,6 +416,51 @@ def test_an_unconfigured_glm_pane_refuses_on_the_real_spawn_path(
registry._prepare_spawn(_stub_pane("glm"), str(tmp_path))
+async def test_a_refused_glm_pane_says_so_instead_of_claiming_to_be_starting(
+ monkeypatch: pytest.MonkeyPatch, tmp_path: Path
+) -> None:
+ """Refusing has to be VISIBLE on the pane, not only raised at the caller.
+
+ The refusal above is correct and was still invisible. A pane whose spawn is
+ refused never reaches the two places that mark a pane broken — a missing
+ binary and a spawn that threw — so it stayed ``pending``, and ``pending``
+ has a headline that reads "Not started — waiting for terminal connection".
+ That sentence is a promise about a connection nothing was ever going to
+ make: the user was left watching a pane that claimed to be starting, with
+ the one line naming the actual fix (the API key) living in a socket frame
+ that the pane painted over a second later.
+ """
+ from jarvis.agentic_ide import recap as ide_recap
+ from jarvis.agentic_ide import session as ide_session
+
+ # The borrowed binary need not be installed for this: what is under test is
+ # what happens AFTER argv resolves, and hard-coding an install would make the
+ # test pass or fail on the machine rather than on the code.
+ monkeypatch.setattr(ide_session, "agent_argv", lambda _agent: ("noop",))
+ monkeypatch.setattr("jarvis.core.config.get_secret", lambda *_a, **_k: None)
+
+ registry = ide_session.Registry()
+ session = await registry.start(str(tmp_path), [{"agent": "glm"}])
+ term = session.terminals[0]
+
+ async def sink(_text: str) -> None:
+ return None
+
+ async def gone(_code: int) -> None:
+ return None
+
+ with pytest.raises(ide_session.SessionError):
+ await registry.attach(term.key, 80, 24, sink, gone, workspace_id=session.id)
+
+ assert term.status == "error", "a pane that cannot start must not look pending"
+ assert "API key" in term.error, term.error
+ # And the recap the header renders quotes it rather than promising a
+ # connection.
+ headline = ide_recap.summarize(term).headline
+ assert "waiting for terminal connection" not in headline
+ assert "Not running" in headline
+
+
def test_the_glm_environment_factory_reports_not_configured_without_a_key(
monkeypatch: pytest.MonkeyPatch,
) -> None:
diff --git a/tests/unit/web/test_agentic_ide_pty_socket.py b/tests/unit/web/test_agentic_ide_pty_socket.py
index 15c2441b2e..c60f0030ec 100644
--- a/tests/unit/web/test_agentic_ide_pty_socket.py
+++ b/tests/unit/web/test_agentic_ide_pty_socket.py
@@ -125,6 +125,14 @@ async def test_failed_attach_is_recorded_with_pane_and_reason(
This is the terminal failure, not the "try again" one above: a spawn that
will not come back. It is the case where nobody is hovering over the red
badge, because it tends to hit every pane at once.
+
+ The code is 4500 and deliberately NOT 4404. 4404 means "this pane is not in
+ the open workspace", and the client acts on exactly that: it overwrites the
+ reason sent one frame earlier with its own "no longer part of the open
+ workspace" line and asks the view to re-read the grid. A pane whose agent
+ refused to start over a missing API key was then told to go looking for a
+ missing pane — the one sentence naming the actual fix having been painted
+ over by a sentence about a different problem entirely.
"""
monkeypatch.setattr(routes, "credentials_valid", lambda scope: True)
@@ -137,7 +145,7 @@ async def test_failed_attach_is_recorded_with_pane_and_reason(
with caplog.at_level(logging.WARNING, logger=routes.__name__):
await routes.agentic_pty(ws, "Mika")
- assert ws.closed == (4404, "attach failed")
+ assert ws.closed == (4500, "attach failed")
assert ws.sent and ws.sent[0]["t"] == "error"
logged = " ".join(record.getMessage() for record in caplog.records)
assert "Mika" in logged