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): require submitted work for active status

Ruben Lütke2706d193df57
diff --git a/jarvis/agentic_ide/activity.py b/jarvis/agentic_ide/activity.py
index 4180807a4e..93a0d10327 100644
--- a/jarvis/agentic_ide/activity.py
+++ b/jarvis/agentic_ide/activity.py
@@ -11,12 +11,11 @@ had been finished for nineteen of them.
## The rule: read the TERMINAL, never the product
-**A pane is working while its screen keeps changing, and waiting once the
-screen has stood still.** That is the whole detector, and it is deliberately a
-property of the terminal rather than of whatever is running inside it. A
-workspace opens five different coding CLIs today and an unknown number
-tomorrow; a rule that knows what any of them prints is a rule that breaks on
-the next one, in the next release, or in the next language.
+**A pane is working while its screen keeps changing after the current process
+received an instruction, and waiting once the screen has stood still.** Both
+halves are required. Movement remains a property of the terminal rather than
+of whichever product is running inside it, while the submit stamp prevents a
+CLI's own background redraws from inventing work nobody requested.
Two earlier versions proved that the hard way:
@@ -73,12 +72,12 @@ There is no ambiguous middle, so bytes answer the question on their own — whil
the screen fingerprint stays as the second signal, because it survives one
sweep longer than the byte stamp and holds the answer steady across the gap.
-The one thing this costs: a CLI that ticks at rest — a blinking cursor of its
-own, a clock in a status bar, a heartbeat — would read as permanently working.
-None of the four installed products does any of that (measured twice, above),
-and the failure would at least be VISIBLE rather than the silent one it
-replaces: a badge stuck on "working" gets reported, a badge wrongly saying
-"done" is believed.
+That measurement is useful but not a universal contract. Claude Code can emit
+background terminal traffic for an MCP authentication warning before anybody
+gives the pane a task. Movement therefore becomes ``working`` only after a
+submission to the current process; a CLI repainting its own idle state cannot
+invent work. The rule remains provider-neutral because the proof is input
+history, never wording on the screen.
## The two exclusions
@@ -288,7 +287,7 @@ def _resize_shadowed(term: Any, at: float | None) -> bool:
return 0 <= float(at) - float(resized_at) <= RESIZE_SHADOW_S
-def _moving(term: Any, moment: float, still_since: float | None) -> bool:
+def is_moving(term: Any, moment: float, still_since: float | None) -> bool:
"""Is anything happening in this pane right now?
Either signal is enough (see the module docstring): output that has just
@@ -305,6 +304,25 @@ def _moving(term: Any, moment: float, still_since: float | None) -> bool:
return _fresh(moment, still_since) and not _resize_shadowed(term, still_since)
+def _has_current_instruction(term: Any) -> bool:
+ """Did somebody submit work to the agent process that is live now?
+
+ Historical prompt counters, resumed conversations, and prior idle periods
+ prove that a pane has been used, but not that its replacement process is
+ currently working. The generation pair is stamped on manual, injected, and
+ Continue submissions and is reset by spawning a new process, so it is the
+ narrow proof required before movement may become a live ``working`` claim.
+ """
+ if not getattr(term, "last_submit_at", None):
+ return False
+ try:
+ return int(getattr(term, "submit_generation", -1)) == int(
+ getattr(term, "process_generation", 0)
+ )
+ except (TypeError, ValueError):
+ return False
+
+
def read_activity(
term: Any, *, now: float | None = None, still_since: float | None = None
) -> Activity:
@@ -327,7 +345,7 @@ def read_activity(
return "starting"
moment = time.time() if now is None else now
- if _moving(term, moment, still_since):
+ if _has_current_instruction(term) and is_moving(term, moment, still_since):
return "working"
if _contains(visible_rows(term), ASK_FRAGMENTS):
return "asking"
@@ -461,6 +479,7 @@ __all__ = [
"Activity",
"Reading",
"has_work_behind_it",
+ "is_moving",
"is_settled",
"observed",
"read_activity",
diff --git a/jarvis/agentic_ide/interrupted.py b/jarvis/agentic_ide/interrupted.py
index e0fbfb5c92..35dbfc7bfb 100644
--- a/jarvis/agentic_ide/interrupted.py
+++ b/jarvis/agentic_ide/interrupted.py
@@ -37,8 +37,9 @@ That matters, because the tempting heuristics are all wrong:
repaints its banner and its old transcript for several seconds before it
settles at a prompt; reading that as work retracted the offer for every
restored pane within two sweeps of it coming back, so the button reported
- zero for ever. Movement only counts once the pane has been SEEN standing
- still (:attr:`Terminal.idle_seen`).
+ zero for ever. Only a submission stamped for the current process proves
+ work; :attr:`Terminal.idle_seen` merely records that startup repainting has
+ settled.
## What the nudge is
diff --git a/jarvis/agentic_ide/notifications.py b/jarvis/agentic_ide/notifications.py
index 9d8681fb81..9c3e8bec47 100644
--- a/jarvis/agentic_ide/notifications.py
+++ b/jarvis/agentic_ide/notifications.py
@@ -94,7 +94,16 @@ from typing import TYPE_CHECKING, Any, Literal, NamedTuple
from loguru import logger
-from .activity import STILL_S, Activity, is_settled, read_activity, screen_digest, stamp
+from .activity import (
+ RESIZE_SHADOW_S,
+ STILL_S,
+ Activity,
+ is_moving,
+ is_settled,
+ read_activity,
+ screen_digest,
+ stamp,
+)
if TYPE_CHECKING: # pragma: no cover - typing only
from collections.abc import Iterable, Mapping
@@ -478,17 +487,25 @@ class ActivityWatcher:
if digest != watch.digest:
watch.digest = digest
- watch.changed_at = now
+ # A changed picture is movement — unless it is the redraw a resize
+ # just caused. The shadow on the pane is judged against the moment
+ # the redraw ARRIVED, but this comparison only sees it at sweep
+ # time, up to a full interval later — so the observation window is
+ # the shadow plus one sweep, or a repaint landing between two
+ # sweeps escapes whenever the next sweep runs late.
+ resized_at = float(getattr(term, "last_resize_at", 0.0) or 0.0)
+ if not (0 <= now - resized_at <= RESIZE_SHADOW_S + SWEEP_INTERVAL_S):
+ watch.changed_at = now
if not watch.tasked and _tasked(term):
watch.tasked = True
# ``now`` travels into the read as well, so a test can place a pane on
# its own timeline instead of racing the wall clock.
activity = read_activity(term, now=now, still_since=watch.changed_at)
- if is_settled(activity):
+ if is_settled(activity) and not is_moving(term, now, watch.changed_at):
# An OBSERVED still screen — two looks at the same picture, never
- # the assumption the first-sight branch above has to make. From here
- # on, movement in this pane is an agent working rather than its CLI
- # drawing itself back onto the screen (see `Terminal.idle_seen`).
+ # the assumption the first-sight branch above has to make. This
+ # proves only that restore/startup repainting has settled; a matching
+ # current-process submission remains the proof of actual work.
term.idle_seen = True
if activity != watch.activity:
@@ -551,17 +568,8 @@ class ActivityWatcher:
preserved while it waits at its prompt.
"""
if activity == "working":
- instructed_here = getattr(term, "submit_generation", -1) == getattr(
- term, "process_generation", 0
- )
- if not getattr(term, "idle_seen", False) and not instructed_here:
- # This is the pane's CLI painting itself back onto the screen
- # after a restart. Preserve both resume flags until this
- # process has genuinely stood still once or receives a real
- # instruction of its own.
- return
- # It stood still and then moved again, so somebody put this pane
- # back to work and the offer to continue it is spent.
+ # `read_activity` reaches this state only after a submission stamped
+ # for the live process. The offer to continue is therefore spent.
term.continuation_pending = False
self._set_resume_needed(term, watch, True)
return
@@ -675,6 +683,23 @@ def enabled() -> bool:
return value
+async def _enabled_off_loop() -> bool:
+ """The same switch, with the TOML parse kept off the event loop.
+
+ ``enabled()`` answers from its cache almost always; the miss parses
+ ``jarvis.toml``, which is file IO plus a TOML parse on the loop that also
+ carries the wake microphone — the freeze class this repo keeps re-finding
+ (AP-9/AP-26). A late sweep is not only slow, it is WRONG: stamps age past
+ ``STAMP_FRESH_S`` and every reader falls back to a one-look answer that
+ cannot see movement. So the sweep asks through here: cache hits stay
+ synchronous, and only the rare miss pays for a thread hop.
+ """
+ cached_at, value = _switch
+ if time.monotonic() - cached_at < SWITCH_TTL_S:
+ return value
+ return await asyncio.to_thread(enabled)
+
+
def reset_switch_cache() -> None:
"""Forget the cached switch — for tests, and for a live config change."""
global _switch
@@ -731,7 +756,7 @@ async def _run(registry: Registry) -> None:
# Resume evidence is independent of the optional bell. Even
# with notifications disabled, restored panes must not be
# offered a blind Continue merely because history exists.
- _WATCHER.poll(registry, emit=enabled())
+ _WATCHER.poll(registry, emit=await _enabled_off_loop())
if _WATCHER.take_resume_dirty():
await registry.persist_resume_activity()
except Exception as exc: # noqa: BLE001 - one bad pane must not end the sweep
diff --git a/jarvis/agentic_ide/session.py b/jarvis/agentic_ide/session.py
index 10d097f443..8c8c90a92f 100644
--- a/jarvis/agentic_ide/session.py
+++ b/jarvis/agentic_ide/session.py
@@ -945,24 +945,12 @@ class Terminal:
# Has this pane's screen been observed STANDING STILL since its current
# process started?
#
- # The line between "the agent carried on by itself" and "its CLI is drawing
- # itself back onto the screen". Both are movement, and movement is the only
- # thing the activity detector reads (see `.activity`) — so a resumed pane
- # repainting its banner and its old transcript reads exactly like an agent
- # at work, for the several seconds that takes.
- #
- # **The bug this fixes.** Both readers of that signal got it wrong in the
- # same window: the notification sweep retracted `continuation_pending`
- # ("it is already working, it needs no nudge") and the scan filtered the
- # pane out — so every restored pane lost its offer to continue within two
- # sweeps of coming back, and the button reported zero for ever. Reported as
- # "the Continue feature does not work".
- #
- # A start-up burst always ends at a prompt, so "has stood still at least
- # once" separates the two without knowing anything about what any CLI
- # draws. Raised by the notification sweep on an observed still screen (two
- # looks, never a single one), cleared on every spawn. Never persisted — it
- # describes the process now running in the pane.
+ # This says only that restore/startup repainting has settled. It never proves
+ # work: that requires a submission stamped with this process generation.
+ # Keeping the claims separate prevents both startup replay and later MCP or
+ # status redraws from retracting a valid Continue offer. Raised by the
+ # notification sweep on an observed still screen (two looks, never one),
+ # cleared on every spawn, and never persisted.
idle_seen: bool = False
# What this pane is DOING, as the activity sweep last observed it: working,
# waiting, asking, starting, exited, failed (see `.activity`). Empty until
diff --git a/tests/unit/agentic_ide/test_interrupted.py b/tests/unit/agentic_ide/test_interrupted.py
index 9c1e8ac22e..249ced54b5 100644
--- a/tests/unit/agentic_ide/test_interrupted.py
+++ b/tests/unit/agentic_ide/test_interrupted.py
@@ -131,39 +131,30 @@ async def test_a_finished_conversation_is_not_called_interrupted(
assert interrupted.scan(registry) == []
-async def test_a_resumed_pane_already_working_is_not_offered_continue(
+async def test_delayed_output_does_not_hide_a_resumed_pane_from_continue(
registry: Registry, tmp_path: Path, existing_conversation: Any
) -> None:
- """Active work needs no nudge.
-
- "Working" is a moving screen, not a phrase — `activity` deliberately stopped
- reading what the CLI prints, so this drives the property it does read. Faking
- it with a status line here would test a rule the product no longer has, and
- would keep passing after that rule broke.
-
- The pane has stood still once already (`idle_seen`), which is what makes the
- movement work rather than a CLI painting itself — see the test below.
- """
+ """A settled restore still needs Continue until this process gets a task."""
_session, term = await _restarted_pane(registry, tmp_path, existing_conversation)
term.idle_seen = True
term.last_output_at = time.time()
- assert interrupted.scan(registry) == []
+ found = interrupted.scan(registry)
+
+ assert [pane.name for pane in found] == [term.name]
+ assert term.reading().activity == "waiting"
+ assert term.continuation_pending is True
-async def test_a_resumed_pane_still_painting_itself_is_still_offered(
+async def test_resumed_startup_output_without_a_submission_is_still_offered(
registry: Registry, tmp_path: Path, existing_conversation: Any
) -> None:
- """The regression this whole flag exists for.
+ """Startup repainting has no current-process submission, so it is not work.
A restored CLI redraws its banner and its old transcript for several seconds
- before it settles at a prompt, and that movement is indistinguishable from
- work to a detector that only reads movement. Treating it as work filtered
- every restored pane out of this list in exactly the seconds somebody presses
- the button — reported as "the Continue feature does not work".
-
- A pane that has never been seen standing still since its process started is
- therefore still offered, however busy its screen looks.
+ before it settles at a prompt. Treating that movement as work filtered every
+ restored pane out of this list in exactly the seconds somebody pressed the
+ button. The absent generation-stamped submission keeps the offer intact.
"""
_session, term = await _restarted_pane(registry, tmp_path, existing_conversation)
assert term.idle_seen is False, "a freshly spawned process has settled nothing"
diff --git a/tests/unit/agentic_ide/test_pane_activity_status.py b/tests/unit/agentic_ide/test_pane_activity_status.py
index 1f858c9cf8..40295d3d80 100644
--- a/tests/unit/agentic_ide/test_pane_activity_status.py
+++ b/tests/unit/agentic_ide/test_pane_activity_status.py
@@ -75,6 +75,12 @@ def _sweep(registry: Registry, at: float) -> None:
notifications.watcher().poll(registry, now=at, emit=False)
+def _instruct(term: Any, at: float) -> None:
+ """Prove the current process received the work represented by a test."""
+ term.last_submit_at = at
+ term.submit_generation = term.process_generation
+
+
def _watched(registry: Registry, term: Any, *, moves: bool) -> None:
"""Two sweeps on the REAL clock — one look cannot see movement.
@@ -112,6 +118,7 @@ async def test_a_moving_pane_is_reported_as_working_whatever_it_runs(
) -> None:
"""And one whose picture keeps changing is still on the job."""
_session, term = await _pane(registry, tmp_path, agent=agent, name="Px")
+ _instruct(term, time.time() - 1)
term.transcript.feed(screen)
_watched(registry, term, moves=True)
@@ -132,6 +139,7 @@ async def test_output_outside_the_fingerprint_still_counts_as_working(
nothing for between 19 and 69 seconds.
"""
_session, term = await _pane(registry, tmp_path)
+ _instruct(term, time.time() - 1)
term.transcript.feed(REST_SCREENS["claude"])
now = time.time()
_sweep(registry, now - notifications.SWEEP_INTERVAL_S)
@@ -197,6 +205,7 @@ async def test_output_after_the_resize_shadow_still_counts_as_working(
otherwise a resize would hide real work instead of a repaint.
"""
_session, term = await _pane(registry, tmp_path)
+ _instruct(term, time.time() - 1)
term.transcript.feed(REST_SCREENS["claude"])
now = time.time()
_sweep(registry, now - notifications.SWEEP_INTERVAL_S)
@@ -230,6 +239,7 @@ async def test_the_state_carries_what_the_sweep_saw(registry: Registry, tmp_path
single look.
"""
_session, term = await _pane(registry, tmp_path)
+ _instruct(term, 499.0)
term.transcript.feed("\r\n· Scurrying… (2m 4s)\r\n")
_sweep(registry, 500.0)
term.transcript.clear()
@@ -361,6 +371,7 @@ async def test_the_caption_never_contradicts_the_badge(registry: Registry, tmp_p
async def test_the_caption_says_working_when_it_is(registry: Registry, tmp_path: Path) -> None:
"""And the other way round, or the wording would just be pessimistic."""
_session, term = await _pane(registry, tmp_path)
+ _instruct(term, time.time() - 1)
term.transcript.feed(REST_SCREENS["claude"])
_watched(registry, term, moves=True)
diff --git a/tests/unit/agentic_ide/test_pane_notifications.py b/tests/unit/agentic_ide/test_pane_notifications.py
index 7d18f76b33..70b052c706 100644
--- a/tests/unit/agentic_ide/test_pane_notifications.py
+++ b/tests/unit/agentic_ide/test_pane_notifications.py
@@ -217,11 +217,42 @@ async def test_a_moving_screen_is_a_working_pane(
) -> None:
"""And every CLI while its screen moves, whatever it happens to be drawing."""
_session, term = await _pane(registry, tmp_path, agent=agent, name="Px")
+ term.last_submit_at = 999.0
+ term.submit_generation = term.process_generation
_draw(term, screen)
assert read_activity(term, now=1000.5, still_since=1000.0) == "working"
+async def test_background_output_without_an_instruction_never_reads_as_working(
+ registry: Registry, tmp_path: Path
+) -> None:
+ """An idle MCP warning may repaint, but nobody asked the agent to work."""
+ _session, term = await _pane(registry, tmp_path)
+ term.transcript.feed("\r\n1 MCP server needs authentication\r\n")
+ term.last_output_at = 1000.4
+
+ assert term.last_submit_at is None
+ assert read_activity(term, now=1000.5, still_since=1000.0) == "waiting"
+
+
+async def test_a_previous_process_submission_cannot_arm_replacement_output(
+ registry: Registry, tmp_path: Path
+) -> None:
+ """Only a submission to the live process can turn movement into work."""
+ _session, term = await _pane(registry, tmp_path)
+ term.last_submit_at = 999.0
+ term.submit_generation = term.process_generation
+ term.process_generation += 1
+ term.last_output_at = 1000.4
+
+ assert read_activity(term, now=1000.5, still_since=1000.0) == "waiting"
+
+ term.last_submit_at = 1000.45
+ term.submit_generation = term.process_generation
+ assert read_activity(term, now=1000.5, still_since=1000.0) == "working"
+
+
async def test_movement_is_the_only_thing_that_counts(registry: Registry, tmp_path: Path) -> None:
"""The rows this build draws while WORKING are not treated as special.
@@ -242,6 +273,8 @@ async def test_a_pane_whose_screen_keeps_changing_is_working(
"""Through the watcher, which is what actually tracks the movement."""
watcher = notifications.watcher()
_session, term = await _pane(registry, tmp_path)
+ term.last_submit_at = 99.0
+ term.submit_generation = term.process_generation
_draw(term, REAL_WORKING)
watcher.poll(registry, now=100.0)
@@ -293,6 +326,8 @@ async def test_movement_after_the_typing_stopped_is_work(
_session, term = await _pane(registry, tmp_path)
_draw(term, IDLE_SCREEN)
term.last_input_at = 1000.0
+ term.last_submit_at = 1005.0
+ term.submit_generation = term.process_generation
assert read_activity(term, now=1010.2, still_since=1010.0) == "working"
@@ -304,6 +339,7 @@ async def test_a_real_pane_finishing_files_one_entry(registry: Registry, tmp_pat
_draw(term, REAL_WORKING)
term.last_submit_at = 999.0
+ term.submit_generation = term.process_generation
term.last_output_at = 1000.0
assert watcher.poll(registry, now=1000.5) == []
@@ -476,15 +512,10 @@ async def test_a_new_process_for_the_same_pane_discards_the_old_screen_observati
assert term.resume_continuation_needed is False
-async def test_movement_after_the_pane_settled_does_retract_the_offer(
+async def test_a_new_submission_after_settle_retracts_the_offer(
registry: Registry, tmp_path: Path
) -> None:
- """The other edge, and why the flag is "settled once" rather than a timer.
-
- Once a pane has stood at its prompt, anything that moves it again is work
- somebody asked for — so continuing it would put a second instruction behind
- the one already running.
- """
+ """A generation-stamped task, not prior stillness, proves resumed work."""
watcher = notifications.watcher()
_session, term = await _pane(registry, tmp_path)
term.continuation_pending = True
@@ -623,13 +654,11 @@ async def test_a_question_is_reported_even_though_it_never_worked(
_draw(term, IDLE_SCREEN)
watcher.poll(registry, now=100.0)
- # The question APPEARING is itself a screen change, so it settles like any
- # other before it is believed.
+ # The question APPEARING is not work, so its own settle window starts now.
term.transcript.clear()
_draw(term, QUESTION_SCREEN)
watcher.poll(registry, now=101.0)
- assert watcher.poll(registry, now=101.0 + STILL_S + 1) == []
- filed = watcher.poll(registry, now=101.0 + STILL_S + notifications.SETTLE_S + 2)
+ filed = watcher.poll(registry, now=101.0 + STILL_S + 1)
assert [entry.kind for entry in filed] == ["needs_input"]