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(ide): make sure a new agent's first prompt is actually submitted

rubenluetke10-beep4c73ad1aab7d
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.py
index 7f77017360..d29786f9f1 100644
--- a/jarvis/agentic_ide/session.py
+++ b/jarvis/agentic_ide/session.py
@@ -335,6 +335,12 @@ MAX_WORKSPACES: int | None = None
# 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
+# After an unconfirmed send, how long to watch for the text surfacing late in
+# the box (a loading CLI that buffered it and dropped the Enter).
+_LATE_ARRIVAL_WINDOW_S = 8.0
+# How long a process's FIRST prompt waits for the composer to paint on a CLI
+# that otherwise skips the typing wait; past it the prompt goes out anyway.
+_FIRST_PROMPT_COMPOSER_WAIT_S = 20.0
Status = str # "pending" | "live" | "exited" | "error"
@@ -6717,6 +6723,15 @@ class Registry:
process_id = term.pty_id
generation = term.process_generation
+ if term.submit_generation != generation or term.last_submit_at is None:
+ # The FIRST prompt of a process lets the composer paint even on a
+ # CLI that opts out of the typing wait. Typed early, Claude Code
+ # buffers the text but drops the Enter, so the task sat unsent in a
+ # new agent's box (live 2026-10-01: briefed 3 s after spawn). Soft:
+ # an unrecognised composer still gets the opt-out fast path below.
+ await fleet_actions.wait_for_input_line(
+ owner, [wanted], timeout_s=_FIRST_PROMPT_COMPOSER_WAIT_S
+ )
ready = await fleet_actions.wait_for_prompt_ready(
owner,
[wanted],
@@ -6980,6 +6995,20 @@ class Registry:
manager.write(term.pty_id or "", "\r")
left_the_box = await self._confirm_submitted(term, payload, manager)
+ if not arrived and left_the_box and await self._await_arrival(
+ term, payload, window_s=_LATE_ARRIVAL_WINDOW_S
+ ):
+ # The text surfaced in the box only after the Enter went out: the
+ # pane buffered it while loading and dropped that early Enter. It
+ # is provably sitting there now, so one more Enter is safe and is
+ # the difference between a briefed agent and an idle one.
+ logger.warning(
+ "Agentic IDE: the prompt reached {} only after Enter — pressing Enter again",
+ term.name,
+ )
+ term.last_input_at = time.time()
+ manager.write(term.pty_id or "", "\r")
+ return 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
@@ -6997,7 +7026,9 @@ class Registry:
return None
return left_the_box
- async def _await_arrival(self, term: Terminal, payload: str) -> bool:
+ async def _await_arrival(
+ self, term: Terminal, payload: str, *, window_s: float | None = None
+ ) -> 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
@@ -7005,7 +7036,8 @@ class Registry:
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
+ window = _ARRIVAL_WINDOW_S if window_s is None else window_s
+ deadline = max(1, int(window / _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):
diff --git a/tests/conftest.py b/tests/conftest.py
index 998687c840..9bed26a6cc 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -232,6 +232,19 @@ def _provider_health_ledger_in_tmp(tmp_path_factory): # noqa: ANN001
ledger.set_ledger(ledger.ProviderHealthLedger(None))
[email protected](autouse=True)
+def _short_pane_delivery_waits(monkeypatch): # noqa: ANN001
+ """Fake panes never paint a composer, so the real first-prompt and
+ late-arrival windows (tens of seconds) would only slow every send test.
+ Tests that exercise those windows set their own values."""
+ import sys
+
+ session = sys.modules.get("jarvis.agentic_ide.session")
+ if session is not None:
+ monkeypatch.setattr(session, "_FIRST_PROMPT_COMPOSER_WAIT_S", 0.05, raising=False)
+ monkeypatch.setattr(session, "_LATE_ARRIVAL_WINDOW_S", 0.05, raising=False)
+
+
@pytest.fixture(autouse=True)
def _reset_bus():
"""Reset the global default bus before and after each test."""
diff --git a/tests/unit/agentic_ide/test_prompt_submit.py b/tests/unit/agentic_ide/test_prompt_submit.py
index bcdf7b7874..f7e7c0f487 100644
--- a/tests/unit/agentic_ide/test_prompt_submit.py
+++ b/tests/unit/agentic_ide/test_prompt_submit.py
@@ -131,6 +131,7 @@ def registry(fake_pty: FakePtyManager, monkeypatch: pytest.MonkeyPatch) -> Regis
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)
+ monkeypatch.setattr(session_mod, "_LATE_ARRIVAL_WINDOW_S", 0.04)
monkeypatch.setattr(fleet_actions, "READY_POLL_S", 0.01)
monkeypatch.setattr(fleet_actions, "READY_TIMEOUT_S", 0.08)
return Registry(pty_manager=fake_pty)
@@ -423,6 +424,58 @@ async def test_a_prompt_never_seen_to_arrive_is_reported_as_unconfirmed(
assert term.submitted is None, "never seen to arrive is not a success claim"
+async def test_a_new_claude_pane_is_briefed_once_its_composer_paints(
+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path, monkeypatch
+) -> None:
+ """Live 2026-10-01: a voice-created agent got its task 3 s after spawn and
+ the text sat unsent in the box. The first prompt waits for the composer."""
+ monkeypatch.setattr(session_mod, "_FIRST_PROMPT_COMPOSER_WAIT_S", 1.0)
+ fake_pty.tui_echo = True
+ term = await _live(registry, tmp_path)
+ await fake_pty.emit(term.pty_id, "\x1b[2J\x1b[H Claude Code v2 loading\r\n")
+
+ sending = asyncio.create_task(registry.send_prompt("Alex", "audit the codebase"))
+ await asyncio.sleep(0.03)
+ assert fake_pty.typed == [], "nothing is typed before the composer exists"
+
+ await fake_pty.emit(term.pty_id, "\x1b[2J\x1b[H❯ \r\n")
+ delivered = await sending
+ assert fake_pty.typed[:2] == ["audit the codebase", "\r"]
+ assert delivered.submitted is True
+
+
+async def test_a_prompt_that_surfaces_after_enter_gets_one_more_enter(
+ registry: Registry, fake_pty: FakePtyManager, tmp_path: Path, monkeypatch
+) -> None:
+ """A loading CLI buffers the text and drops the Enter; once the text shows
+ in the box, one guarded Enter sends it instead of leaving it there."""
+ monkeypatch.setattr(session_mod, "_LATE_ARRIVAL_WINDOW_S", 0.5)
+ term = await _live(registry, tmp_path)
+ on_output = fake_pty.spawns[-1]["on_output"]
+ await on_output("pty", "\x1b[2J\x1b[H❯ \r\n")
+
+ async def enters_typed(count: int) -> None:
+ for _ in range(400):
+ if sum(d == "\r" for d in fake_pty.typed) >= count:
+ return
+ await asyncio.sleep(0.005)
+
+ async def late_paint() -> None:
+ await enters_typed(1)
+ await asyncio.sleep(0.1)
+ await on_output("pty", "\x1b[2J\x1b[H❯ audit the codebase\r\n")
+ await enters_typed(2)
+ await on_output("pty", "\x1b[2J\x1b[H❯ \r\n")
+
+ painter = asyncio.create_task(late_paint())
+ await registry.send_prompt("Alex", "audit the codebase")
+ await painter
+ bodies = [d for d in fake_pty.typed if "audit the codebase" in d]
+ assert len(bodies) == 1, "the text is never typed twice"
+ assert [d for d in fake_pty.typed if d == "\r"] == ["\r", "\r"]
+ assert term.submitted is True
+
+
async def test_a_prompt_that_lands_reports_submitted(
registry: Registry, fake_pty: FakePtyManager, tmp_path: Path
) -> None: