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(self-build): file only the pane prompts this app announced (#881)

Ruben Lütke3ae964be523c
diff --git a/docs/self-build.md b/docs/self-build.md
index c21faf0ffa..e7c7786516 100644
--- a/docs/self-build.md
+++ b/docs/self-build.md
@@ -125,7 +125,10 @@ files `typed` (the person's sentence) when the prompt was a brief written
around it, else the prompt itself; a row whose text is only dropped files'
contents is skipped. The route tells the loop when such a prompt was stored,
and each pass reads a history file from where the last one stopped, so a
-prompt is filed once; the maintenance pass catches a missed notice. While the
+prompt is filed once. Only rows the running app announced this way count: the
+maintenance pass and the start only move the read position past the others,
+because a row no notice announced was written by another process (a test run,
+another instance) and is not the person's. While the
loop is paused or off the read position still moves, so nothing typed then is
filed later.
diff --git a/dodaios/self_build/loop.py b/dodaios/self_build/loop.py
index 45fb061b72..3997d05a82 100644
--- a/dodaios/self_build/loop.py
+++ b/dodaios/self_build/loop.py
@@ -191,7 +191,8 @@ class SelfBuildLoop:
):
bus.subscribe(event_type, handler)
self._subscriptions.append((event_type, handler))
- # Pane prompts written while the loop was not running.
+ # Rows written while the loop was not running are not filed: only the
+ # prompts this app announces are (``pane_prompt_recorded``).
self._spawn(self.ingest_pane_prompts(), "pane-prompts")
async def stop(self) -> None:
@@ -698,17 +699,23 @@ class SelfBuildLoop:
self._spawn(self.ingest_pane_prompts([path]), "pane-prompts")
async def ingest_pane_prompts(self, paths: list[Any] | None = None) -> int:
- """File the person's new pane prompts as turns; ``paths`` ``None`` reads every pane.
-
- Each history file is read from where the last pass stopped (an offset
- in the signal store), so a prompt is filed once. Only rows marked
- ``origin: person`` count, in the person's own words (``typed`` when the
- prompt was a brief around them). While the loop is paused or off the
- offsets still move: what was typed then is never filed later.
+ """File the person's new pane prompts as turns.
+
+ ``paths`` are the history files the IDE just stored a person's prompt
+ in (:meth:`pane_prompt_recorded`, in this process). Each is read from
+ where the last pass stopped (an offset in the signal store), so a
+ prompt is filed once. Only rows marked ``origin: person`` count, in the
+ person's own words (``typed`` when the prompt was a brief around them).
+
+ ``paths`` ``None`` scans every pane but only moves the offsets: a row
+ nobody in this app announced was written by another process (a test
+ run, another instance), and is not the person's evidence. While the
+ loop is paused or off the offsets still move: what was typed then is
+ never filed later.
"""
async with self._pane_lock:
found = await asyncio.to_thread(self._read_pane_prompts, paths)
- if not found or not self._active():
+ if paths is None or not found or not self._active():
return 0
for obs in sorted(found, key=lambda o: o.ts_ms):
await self.observe(obs)
@@ -987,7 +994,7 @@ class SelfBuildLoop:
await asyncio.to_thread(self.store.prune, now=stamp)
# Turns filed while no zone could be named get their clock now.
await asyncio.to_thread(self.store.fill_clocks)
- # Pane prompts whose notice was missed (the app was busy or restarting).
+ # Move the offsets past rows no notice announced (written elsewhere).
await self.ingest_pane_prompts()
await self.ingest_typed_prompts()
# Offsets of pane files that are gone or too old to count: the IDE
diff --git a/tests/unit/self_build/test_self_build_inputs.py b/tests/unit/self_build/test_self_build_inputs.py
index 67b5da4661..838f4436fa 100644
--- a/tests/unit/self_build/test_self_build_inputs.py
+++ b/tests/unit/self_build/test_self_build_inputs.py
@@ -82,14 +82,14 @@ async def test_a_pane_prompt_typed_on_three_days_becomes_one_proposal(
world: Any, panes: Path
) -> None:
world.brain.answers = [PANE_ANSWER]
- _write_history(
+ path = _write_history(
panes,
"pane-a",
[{"text": PROMPT, "at": _days_ago(d, 10) / 1000} for d in (6, 4, 2)],
)
- assert await world.loop.ingest_pane_prompts() == 3
+ assert await world.loop.ingest_pane_prompts([path]) == 3
# Read once: a second pass files nothing again.
- assert await world.loop.ingest_pane_prompts() == 0
+ assert await world.loop.ingest_pane_prompts([path]) == 0
turns = world.loop.store.recent_turns(since_ms=0)
assert {t.channel for t in turns} == {"pane"} and len(turns) == 3
opened = await world.loop.run_queue()
@@ -112,15 +112,15 @@ async def test_prompts_the_brain_or_an_agent_sent_are_not_evidence(world: Any, p
"attachments": [{"name": "notes.txt"}],
}
)
- _write_history(panes, "pane-b", rows)
- assert await world.loop.ingest_pane_prompts() == 0
+ path = _write_history(panes, "pane-b", rows)
+ assert await world.loop.ingest_pane_prompts([path]) == 0
assert world.loop.store.recent_turns(since_ms=0) == []
async def test_the_persons_words_are_filed_not_the_brief_around_them(
world: Any, panes: Path
) -> None:
- _write_history(
+ path = _write_history(
panes,
"pane-c",
[
@@ -131,7 +131,7 @@ async def test_the_persons_words_are_filed_not_the_brief_around_them(
}
],
)
- await world.loop.ingest_pane_prompts()
+ await world.loop.ingest_pane_prompts([path])
(turn,) = world.loop.store.recent_turns(since_ms=0)
assert turn.text == PROMPT and not turn.correction
@@ -145,12 +145,25 @@ async def test_the_ide_hook_reads_only_the_pane_it_names(world: Any, panes: Path
assert [t.text for t in world.loop.store.recent_turns(since_ms=0)] == [PROMPT]
+async def test_rows_no_notice_announced_are_never_filed(world: Any, panes: Path) -> None:
+ """A row in a history file this app did not announce was written by another
+ process: a test run once left six "typed by the person" rows in the live
+ folder, and the scan filed them as a need."""
+ path = _write_history(panes, "pane-g", [{"text": PROMPT, "at": _days_ago(1, 10) / 1000}])
+ assert await world.loop.ingest_pane_prompts() == 0 # the scan
+ await world.loop.maintain()
+ assert world.loop.store.recent_turns(since_ms=0) == []
+ # The scan moved past it: a later notice for that pane files only new rows.
+ _write_history(panes, "pane-g", [{"text": "open the release notes draft", "at": time.time()}])
+ assert await world.loop.ingest_pane_prompts([path]) == 1
+
+
async def test_pane_prompts_typed_while_paused_are_never_filed(world: Any, panes: Path) -> None:
- _write_history(panes, "pane-f", [{"text": PROMPT, "at": _days_ago(1, 10) / 1000}])
+ path = _write_history(panes, "pane-f", [{"text": PROMPT, "at": _days_ago(1, 10) / 1000}])
world.service.set_paused(True)
- assert await world.loop.ingest_pane_prompts() == 0
+ assert await world.loop.ingest_pane_prompts([path]) == 0
world.service.set_paused(False)
- assert await world.loop.ingest_pane_prompts() == 0
+ assert await world.loop.ingest_pane_prompts([path]) == 0
assert world.loop.store.recent_turns(since_ms=0) == []