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): press Enter when the pane can take it, and never claim an unseen prompt went out

Ruben Lütke59a57534f0c8
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.py
index f8c6cd6d12..dc8af69756 100644
--- a/jarvis/agentic_ide/session.py
+++ b/jarvis/agentic_ide/session.py
@@ -110,10 +110,15 @@ MAX_PROMPT_CHARS = 6000
# accidental click from spawning them, and the number is what still fits in a
# row of tabs the user can read.
MAX_WORKSPACES = 6
-# Delay between the prompt text and the Enter keystroke. Agent TUIs debounce
-# fast bursts as a paste; ~120 ms is past every debounce window measured while
-# still feeling instant.
-ENTER_DELAY_S = 0.12
+# How long to wait for the pane to SHOW the prompt before pressing Enter, and
+# how finely to look. This replaced a fixed 120 ms delay: the wait is not really
+# about debouncing, it is about the pane having taken the text at all. A pane
+# that is still booting swallows a paste outright (measured on a real Codex
+# while its MCP servers were loading), and pressing Enter into that types into
+# nothing. Polling returns the moment the text is visible, so a healthy pane is
+# faster than the old fixed delay, and a busy one gets the time it needs.
+_ARRIVAL_POLL_S = 0.2
+_ARRIVAL_WINDOW_S = 3.0
Status = str # "pending" | "live" | "exited" | "error"
@@ -1727,35 +1732,35 @@ class Registry:
multiline = "\n" in payload
submitted = await self._write_and_confirm(term, payload, manager, multiline)
- if not submitted and multiline:
- # Re-typing is only ever right for a pane that never RECEIVED the
- # paste. When the text is demonstrably still in the input box, a
- # second copy would land BEHIND the first and the next Enter would
- # submit both — so a stuck prompt is answered with Enter alone.
- if _input_line_holds(term.transcript.tail(10), _submit_needle(payload)):
- logger.warning(
- "Agentic IDE: {} still has the prompt in its input box — "
- "leaving it there rather than typing a second copy",
- term.name,
- )
- else:
- logger.warning(
- "Agentic IDE: {} did not accept a multi-line prompt — "
- "re-sending it on one line",
- term.name,
- )
- payload = sanitize_prompt(payload)
- multiline = False
- submitted = await self._write_and_confirm(term, payload, manager, False)
+ if submitted is False:
+ # NOT a retry site. A hard False means the verification watched the
+ # text SIT in the input box for the whole window, which is proof the
+ # pane received it. Typing it again (the single-line fallback this
+ # used to do) appends a second copy behind the first, and the next
+ # Enter submits both — worse, a retry Enter landing mid-rewrite runs
+ # the prompt twice for real. Extra Enters belong in the verification
+ # loop, where each one is guarded by "the text is still there".
+ #
+ # Nothing is lost by stopping: the prompt sits in the pane in full,
+ # visible to the user, and the caller is told plainly it never went.
+ logger.warning(
+ "Agentic IDE: {} kept the prompt in its input box — it was typed "
+ "in full but never submitted",
+ term.name,
+ )
term.prompts_sent += 1
term.last_prompt = payload
term.submitted = submitted
- term.sent_multiline = multiline and submitted
+ term.sent_multiline = multiline and submitted is True
logger.info(
"Agentic IDE prompt -> {} ({}, {}): {}",
term.name,
- "submitted" if term.submitted else "STILL IN THE INPUT BOX",
+ "submitted"
+ if submitted is True
+ else "STILL IN THE INPUT BOX"
+ if submitted is False
+ else "UNCONFIRMED — never seen to arrive",
"multi-line" if term.sent_multiline else "one line",
payload[:120],
)
@@ -1767,8 +1772,19 @@ class Registry:
payload: str,
manager: PtyManager,
multiline: bool,
- ) -> bool:
- """Type ``payload``, press Enter, and report whether it was accepted."""
+ ) -> bool | None:
+ """Type ``payload``, press Enter, and report whether it was accepted.
+
+ Three answers, because there genuinely are three: it went out, it is
+ still sitting in the box, or the pane never visibly took it and no
+ honest claim can be made either way (``None``).
+
+ Enter is timed against the SCREEN, not against a stopwatch. A pane that
+ is still booting swallows a paste whole — measured on a real Codex —
+ and an input box that never received the text is indistinguishable from
+ one that submitted it, so a blind "type, wait 120 ms, press Enter" both
+ pressed into nothing and then reported success.
+ """
# The completion guard applies to the LAST line: that is the one the
# cursor sits on when Enter arrives.
last_line = payload.rsplit("\n", 1)[-1]
@@ -1777,9 +1793,42 @@ class Registry:
typed = f"{PASTE_START}{typed}{PASTE_END}"
if not manager.write(term.pty_id or "", typed):
raise SessionError(f"Could not write to {term.name}.")
- await asyncio.sleep(ENTER_DELAY_S)
+
+ arrived = await self._await_arrival(term, payload)
manager.write(term.pty_id or "", "\r")
- return await self._confirm_submitted(term, payload, manager)
+ left_the_box = await self._confirm_submitted(term, payload, manager)
+
+ if not arrived and left_the_box:
+ # The prompt was never SEEN in the box, and an empty box is exactly
+ # what a successful submit looks like — so "it went out" and "the
+ # pane swallowed it" are indistinguishable from here. Say so instead
+ # of picking the flattering one: a booting Codex really does drop a
+ # paste whole (measured 2026-07-26), and the old check called that
+ # success. Writing it again is NOT the answer — if the text is in
+ # fact sitting there unread, a second copy lands behind the first
+ # and the pane runs a doubled instruction.
+ logger.warning(
+ "Agentic IDE: never saw the prompt reach {} — it may have been "
+ "submitted or dropped; reporting it as unconfirmed",
+ term.name,
+ )
+ return None
+ return left_the_box
+
+ async def _await_arrival(self, term: Terminal, payload: str) -> bool:
+ """Wait until the pane visibly holds ``payload``, or give up.
+
+ Returns as soon as the text (or the TUI's collapsed stand-in for it) is
+ on the input line, which is also the moment Enter is worth pressing —
+ so on a healthy pane this costs a fraction of the old fixed delay.
+ """
+ needle = _submit_needle(payload)
+ deadline = max(1, int(_ARRIVAL_WINDOW_S / _ARRIVAL_POLL_S)) if _ARRIVAL_POLL_S else 1
+ for _ in range(deadline):
+ await asyncio.sleep(_ARRIVAL_POLL_S)
+ if _input_line_holds(term.transcript.tail(10), needle):
+ return True
+ return False
async def _confirm_submitted(self, term: Terminal, payload: str, manager: PtyManager) -> bool:
"""True once ``payload`` has left the terminal's input line.
@@ -1897,7 +1946,6 @@ def reset_registry() -> None:
__all__ = [
"AGENT_BINARIES",
"AGENT_DISPLAY",
- "ENTER_DELAY_S",
"MAX_PROMPT_CHARS",
"MAX_TERMINALS",
"MAX_WORKSPACES",
diff --git a/jarvis/ui/web/agentic_ide_routes.py b/jarvis/ui/web/agentic_ide_routes.py
index 449eaf8fdc..a4dfa729bb 100644
--- a/jarvis/ui/web/agentic_ide_routes.py
+++ b/jarvis/ui/web/agentic_ide_routes.py
@@ -1355,9 +1355,13 @@ async def terminal_prompt(name: str, req: PromptRequest) -> dict:
term = await registry.send_prompt(name, text)
except SessionError as exc:
raise HTTPException(status_code=409, detail=str(exc)) from exc
- # `submitted` is the honest part of this answer: the text was typed either
- # way, but only a True here means the agent actually accepted it and started.
- # A caller that reports "sent to Mika" on a False is lying to the user.
+ # `submitted` is the honest part of this answer, and it has THREE states:
+ # True the agent accepted the prompt and started, False the text is provably
+ # still in its input box, null the pane never visibly took it and no claim
+ # can be made either way. Collapsing null into False used to report "the
+ # text is sitting in its input box" about a pane where it demonstrably was
+ # not — a confident answer nobody had. A caller that reports "sent to Mika"
+ # on anything but True is lying to the user.
return {
"ok": True,
"terminal": term.name,
@@ -1366,14 +1370,20 @@ async def terminal_prompt(name: str, req: PromptRequest) -> dict:
"composed_by": composed_by,
"files": files,
"prompts_sent": term.prompts_sent,
- "submitted": bool(term.submitted),
+ "submitted": term.submitted,
"detail": (
""
- if term.submitted
+ if term.submitted is True
else (
f"{term.name} did not accept the prompt — the text is sitting in "
"its input box. Tell the user, and let them press Enter there."
)
+ if term.submitted is False
+ else (
+ f"{term.name} never showed the prompt arriving, so it may have "
+ "started or may have missed it entirely. Tell the user to check "
+ "that pane."
+ )
),
}
diff --git a/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts b/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts
index 6ac091077e..d8dab9a9eb 100644
--- a/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts
+++ b/jarvis/ui/web/frontend/src/lib/agenticIdeApi.ts
@@ -548,12 +548,14 @@ export interface PromptResult {
/** Repo-relative files referenced with `@` in the sent prompt. */
files: string[];
/**
- * Did the agent actually ACCEPT the prompt? The text is typed either way; a
- * false means it is still sitting in that terminal's input box (see the
- * backend's submit verification). Never report a send as done without it.
+ * Did the agent actually ACCEPT the prompt? Three answers, because there are
+ * three: `true` it started, `false` the text is provably still sitting in
+ * that terminal's input box, `null` the pane never visibly took it so nobody
+ * can say (a pane still booting can swallow a paste whole). Only `true` means
+ * the instruction is running — never report a send as done without it.
*/
- submitted: boolean;
- /** Plain-language explanation when `submitted` is false. */
+ submitted: boolean | null;
+ /** Plain-language explanation whenever `submitted` is not `true`. */
detail?: string;
}
diff --git a/tests/fakes/fake_pty_manager.py b/tests/fakes/fake_pty_manager.py
index 601177d3af..56ad54a090 100644
--- a/tests/fakes/fake_pty_manager.py
+++ b/tests/fakes/fake_pty_manager.py
@@ -10,9 +10,15 @@ signature.
"""
from __future__ import annotations
+import asyncio
from dataclasses import dataclass, field
from typing import Any
+# Bracketed-paste markers, spelled out rather than imported so the fake stays
+# independent of the module under test.
+_PASTE_START = "\x1b[200~"
+_PASTE_END = "\x1b[201~"
+
@dataclass(slots=True)
class FakePtySession:
@@ -31,7 +37,15 @@ class FakePtyManager:
closed: list[str] = field(default_factory=list)
# Set to make spawn fail the way a missing PTY backend would.
spawn_error: str | None = None
+ # When true the fake DRAWS like an agent TUI: text written to it appears on
+ # the input line, and Enter clears the line and echoes the prompt into the
+ # history. Anything asserting on the submit contract needs this — a screen
+ # that never changes is not a terminal any agent ever ran in, and code that
+ # reads the screen to decide whether a prompt landed cannot be tested
+ # against one.
+ tui_echo: bool = False
_live: set[str] = field(default_factory=set)
+ _box: dict[str, str] = field(default_factory=dict)
_counter: int = 0
# Callbacks per live terminal, so a test can make an agent SPEAK (see
# ``emit``) rather than only observe what was typed at it.
@@ -74,8 +88,32 @@ class FakePtyManager:
if terminal_id not in self._live:
return False
self.writes.append((terminal_id, data))
+ if self.tui_echo:
+ self._redraw(terminal_id, data)
return True
+ def _redraw(self, terminal_id: str, data: str) -> None:
+ """Repaint the way an agent TUI would after receiving ``data``."""
+ if data == "\r":
+ sent, self._box[terminal_id] = self._box.get(terminal_id, ""), ""
+ # A submitted prompt scrolls up into the history; the line is empty.
+ screen = f"\x1b[2J\x1b[H{sent}\r\n✽ Working…\r\n❯ \r\n"
+ else:
+ text = data.replace(_PASTE_START, "").replace(_PASTE_END, "")
+ # Only the first line is what the input line shows of a paste.
+ self._box[terminal_id] = self._box.get(terminal_id, "") + text
+ first = self._box[terminal_id].split("\n", 1)[0]
+ screen = f"\x1b[2J\x1b[H❯ {first}\r\n"
+ callbacks = self._callbacks.get(terminal_id)
+ if callbacks is None:
+ return
+ # The real reader thread delivers output asynchronously, so this does
+ # too — a test that polls the screen must see the same interleaving.
+ try:
+ asyncio.get_running_loop().create_task(callbacks[0](terminal_id, screen))
+ except RuntimeError: # no loop (sync test) — nothing is polling anyway
+ pass
+
def resize(self, terminal_id: str, cols: int, rows: int) -> bool:
if terminal_id not in self._live:
return False
diff --git a/tests/unit/agentic_ide/test_prompt_submit.py b/tests/unit/agentic_ide/test_prompt_submit.py
index 4b05eed240..f870d2893a 100644
--- a/tests/unit/agentic_ide/test_prompt_submit.py
+++ b/tests/unit/agentic_ide/test_prompt_submit.py
@@ -81,6 +81,37 @@ def test_an_echo_above_the_input_line_does_not_count_as_pending() -> None:
assert not _input_line_holds(["Review the pipeline", "✻ Cooked for 2s", "❯"], needle)
+ "input_line",
+ [
+ "› [Pasted Content 2497 chars]", # Codex
+ "❯ [Pasted text #1 +12 lines]", # Claude Code
+ "> [Pasted 40 lines]",
+ "› [pasted content 812 chars]",
+ "❯ [Image #1 pasted]",
+ ],
+)
+def test_every_paste_placeholder_wording_counts_as_still_pending(
+ input_line: str,
+) -> None:
+ """A collapsed paste is the prompt, still sitting in the box.
+
+ The TUI draws a summary instead of the text, so the text itself cannot be
+ compared against — but it has NOT been sent. Measured against a real Codex
+ (2026-07-26): a brief pasted into a fully booted pane renders as
+ ``[Pasted Content 2497 chars]`` and stays there, because Codex ignores an
+ Enter that arrives too soon after a paste. Recognising only Claude Code's
+ ``[Pasted text …]`` reported all of those as submitted, so no retry was ever
+ pressed and the user was told the prompt had gone out.
+
+ Wording is a TUI detail that changes between releases, so the check keys on
+ the shape — a bracketed summary containing "paste" — not on one vendor's
+ phrasing.
+ """
+ needle = _submit_needle("## Task\nReview the pipeline")
+ assert _input_line_holds([input_line], needle)
+
+
# ------------------------------------------------------------------ the path
@pytest.fixture
def fake_pty() -> FakePtyManager:
@@ -90,10 +121,14 @@ def fake_pty() -> FakePtyManager:
@pytest.fixture
def registry(fake_pty: FakePtyManager, monkeypatch: pytest.MonkeyPatch) -> Registry:
monkeypatch.setattr(session_mod, "agent_argv", lambda name: (f"/usr/bin/{name}",))
- # Keep the verification loop fast in tests.
- monkeypatch.setattr(session_mod, "_SUBMIT_POLL_S", 0.0)
- monkeypatch.setattr(session_mod, "_SUBMIT_WINDOW_S", 0.0)
- monkeypatch.setattr(session_mod, "_SUBMIT_RETRY_AFTER_S", 0.0)
+ # Keep the arrival wait and the verification loop fast — but not zero: the
+ # fake repaints through the event loop the way a real reader thread does,
+ # so a poll that never yields would never see the screen change.
+ monkeypatch.setattr(session_mod, "_SUBMIT_POLL_S", 0.01)
+ monkeypatch.setattr(session_mod, "_SUBMIT_WINDOW_S", 0.04)
+ monkeypatch.setattr(session_mod, "_SUBMIT_RETRY_AFTER_S", 0.02)
+ monkeypatch.setattr(session_mod, "_ARRIVAL_POLL_S", 0.01)
+ monkeypatch.setattr(session_mod, "_ARRIVAL_WINDOW_S", 0.04)
return Registry(pty_manager=fake_pty)
@@ -117,8 +152,8 @@ async def _live(registry: Registry, tmp_path: Path):
async def test_a_trailing_reference_gets_a_closing_space(
registry: Registry, fake_pty: FakePtyManager, tmp_path: Path
) -> None:
+ fake_pty.tui_echo = True # a pane that draws what it is given
term = await _live(registry, tmp_path)
- # Empty screen: the verification sees no pending input line -> submitted.
await registry.send_prompt("Alex", "review this. @jarvis/x.py")
assert fake_pty.typed[0] == "review this. @jarvis/x.py ", fake_pty.typed
assert fake_pty.typed[1] == "\r"
@@ -149,14 +184,84 @@ async def test_enter_is_pressed_again_while_the_prompt_sits_in_the_box(
assert term.submitted is False
-async def test_a_prompt_that_lands_reports_submitted(
+async def test_a_collapsed_paste_is_retried_and_reported_honestly(
+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path
+) -> None:
+ """Codex's collapsed-paste line must trigger the retry, not a success claim.
+
+ The live failure this guards (2026-07-26): two Codex panes were handed a
+ composed brief, both left it sitting in the input box as
+ ``[Pasted Content 2497 chars]``, and both were logged as "submitted" — so
+ neither the extra Enter nor the single-line fallback ever ran.
+ """
+ term = await _live(registry, tmp_path)
+ on_output = fake_pty.spawns[-1]["on_output"]
+ await on_output("pty", "\x1b[2J\x1b[H› [Pasted Content 2497 chars]\r\n")
+
+ await registry.send_prompt("Alex", "## Task\nReview the pipeline")
+
+ assert [d for d in fake_pty.typed if d == "\r"], "no Enter was ever pressed"
+ assert len([d for d in fake_pty.typed if d == "\r"]) >= 2, (
+ f"the prompt sat in the box — Enter must be pressed again: {fake_pty.typed}"
+ )
+ assert term.submitted is False, "a prompt still in the box is not submitted"
+
+
+async def test_a_prompt_stuck_in_the_box_is_never_typed_a_second_time(
registry: Registry, fake_pty: FakePtyManager, tmp_path: Path
) -> None:
+ """The single-line fallback must not append a duplicate of a stuck prompt.
+
+ The fallback exists for a pane that never RECEIVED the paste. When the text
+ is demonstrably still sitting in the input box, re-typing it puts a second
+ copy behind the first, and the next Enter submits both — so in that case the
+ only safe move is another Enter, never another paste.
+ """
term = await _live(registry, tmp_path)
on_output = fake_pty.spawns[-1]["on_output"]
- # Screen after a successful submit: the prompt is echoed in the history and
- # the input line is empty again.
- await on_output("pty", "\x1b[2J\x1b[Hreview the pipeline\r\n✽ Mulling…\r\n❯\r\n")
+ await on_output("pty", "\x1b[2J\x1b[H› [Pasted Content 2497 chars]\r\n")
+
+ await registry.send_prompt("Alex", "## Task\nReview the pipeline")
+
+ pastes = [d for d in fake_pty.typed if "Review the pipeline" in d]
+ assert len(pastes) == 1, f"the prompt was typed twice: {fake_pty.typed}"
+ assert term.submitted is False
+
+
+async def test_a_prompt_never_seen_to_arrive_is_reported_as_unconfirmed(
+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path
+) -> None:
+ """A pane that never displayed the text gets an honest "cannot say".
+
+ Measured against a real Codex (2026-07-26): a pane still booting swallows
+ the paste outright — the input box keeps showing its own idle hint and no
+ part of the prompt ever appears. An empty box is ALSO exactly what a
+ successful submit looks like, so the two cannot be told apart from here and
+ the old check simply picked the flattering reading and claimed success.
+
+ ``None`` is the truthful answer, and the fan-out already treats it as
+ "unknown" rather than overstating. Re-typing is deliberately NOT done: if
+ the text is in fact sitting there unread, a second copy lands behind the
+ first and the pane runs a doubled instruction.
+ """
+ term = await _live(registry, tmp_path)
+ on_output = fake_pty.spawns[-1]["on_output"]
+ # The pane shows its own idle hint — none of our prompt.
+ await on_output("pty", "\x1b[2J\x1b[H› Find and fix a bug in @filename\r\n")
+
+ await registry.send_prompt("Alex", "## Task\nReview the pipeline")
+
+ bodies = [d for d in fake_pty.typed if "Review the pipeline" in d]
+ assert len(bodies) == 1, f"the prompt must not be re-typed: {fake_pty.typed}"
+ assert term.submitted is None, "never seen to arrive is not a success claim"
+
+
+async def test_a_prompt_that_lands_reports_submitted(
+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path
+) -> None:
+ """The whole happy path: the pane shows the text, then Enter clears it."""
+ fake_pty.tui_echo = True
+ term = await _live(registry, tmp_path)
await registry.send_prompt("Alex", "review the pipeline")
assert term.submitted is True
@@ -164,8 +269,9 @@ async def test_a_prompt_that_lands_reports_submitted(
async def test_the_submitted_flag_is_reported(
- registry: Registry, tmp_path: Path
+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path
) -> None:
+ fake_pty.tui_echo = True
term = await _live(registry, tmp_path)
await registry.send_prompt("Alex", "review the pipeline")
assert term.to_dict()["submitted"] is True
@@ -227,6 +333,7 @@ def test_the_needle_uses_only_the_first_line() -> None:
async def test_a_multiline_prompt_is_sent_as_one_bracketed_paste(
registry: Registry, fake_pty: FakePtyManager, tmp_path: Path
) -> None:
+ fake_pty.tui_echo = True
term = await _live(registry, tmp_path)
await registry.send_prompt("Alex", _MARKDOWN)
@@ -259,16 +366,28 @@ def test_a_collapsed_paste_on_the_input_line_counts_as_pending() -> None:
assert _input_line_holds(["> [Pasted text +4 lines]", ""], needle)
-async def test_a_rejected_multiline_prompt_falls_back_to_one_line(
+async def test_a_stuck_multiline_prompt_is_left_in_the_box_not_retyped(
registry: Registry, fake_pty: FakePtyManager, tmp_path: Path
) -> None:
- """Worst case is the old behaviour, never a lost instruction."""
+ """A prompt the pane is still holding is never typed a second time.
+
+ This replaces an earlier single-line fallback. That fallback was written for
+ a pane that never RECEIVED the paste, but "not submitted" can only be
+ reached by watching the text sit in the input box — which is proof it DID
+ arrive. Re-typing then appends a second copy behind the first and the next
+ Enter submits both, so the pane runs a doubled instruction.
+
+ Nothing is lost by leaving it: the prompt sits in the pane in full, and
+ ``submitted`` reports plainly that it was typed but never accepted.
+ """
term = await _live(registry, tmp_path)
on_output = fake_pty.spawns[-1]["on_output"]
await on_output("pty", "\x1b[2J\x1b[H❯ [Pasted text #1 +4 lines]\r\n")
await registry.send_prompt("Alex", _MARKDOWN)
- assert any(d == _ONE_LINE for d in fake_pty.typed), fake_pty.typed
- assert term.sent_multiline is False
- assert term.last_prompt == _ONE_LINE
+ assert _ONE_LINE not in fake_pty.typed, f"prompt was re-typed: {fake_pty.typed}"
+ assert len([d for d in fake_pty.typed if "Review the ranking." in d]) == 1
+ assert term.submitted is False
+ assert term.sent_multiline is False, "an unsubmitted prompt did not go out"
+ assert term.last_prompt == _MARKDOWN, "what sits in the box is the markdown"