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.
Python agent-orchestrationai-agentai-coding-assistantclaude-codecoding-agentcomputer-usedesktop-applocal-firstmcppersonal-jarvisvoice-assistantvoice-coding
fix(agentic-ide): a pane's chat reads its record from the head, so a long task still opens with its question
rubenluetke10-beep10617ebf6632
diff --git a/docs/BUGS.md b/docs/BUGS.mdindex 59ccf3b533..6981b4f1e4 100644--- a/docs/BUGS.md+++ b/docs/BUGS.md@@ -13841,3 +13841,41 @@ DOWN alone. When a badge and a bell answer the same question they mustshare the same debounce, or one of them is wrong by construction. And alist that only polls is a list that lies for a poll interval — the thingthat decides a state should say so.++## BUG-196: the Agentic IDE's chat view would not scroll to the top of a long session — the timeline began mid-answer and the prompt that opened it was nowhere (MEDIUM, FIXED 2026-08-27)++**Symptom.** A pane an hour into one task, opened in chat mode: the scrollbar+sits at the very top and the first thing drawn is "CODING AGENT · Thought for+1m 20s" — the agent's first thought, not the question it was answering. No+amount of scrolling reaches the prompt (maintainer screenshot 2026-08-27 11:49,+T15). It read as a scroll lock; nothing was locked. There was nothing above+the first row to scroll to.++**Root cause.** `agent_transcript` read the last 2 MB of the CLI's record+(`MAX_TAIL_BYTES`), and `_last_turns` cut "at a person's message" only when+there were MORE than `MAX_TURNS` of them — with fewer it returned every event,+including the torso of the turn the tail had landed in. A pane given one long+task has its question at the HEAD of the file and megabytes of tool output+after it: T15's record was 3.6 MB with one prompt in it, and the 2 MB tail held+zero user messages. The bound was justified as "paying disk for the first+thousand turns to render the last ten"; measured, a line-by-line pass over the+21 MB record — the largest on the box — takes 0.08 s, and decoding the 2 MB+tail as one block took 0.12 s. The bound cost more than it saved and cut the+one thing a reader scrolls up for.++**Fix.** The record is streamed from its head, one line at a time (`_lines` /+`_rows` are generators — never the file in one piece), so the turn on stage is+read from the question that opened it. `MAX_READ_BYTES` (64 MB) replaces the+tail: past it the read starts that far before the end, the fragment the seek+lands in is dropped whole, and the first turn shows from wherever that lands —+a runaway file still draws. The 60-turn window is unchanged. Regression:+`test_agent_transcript_events.py` ("one long task still opens with its+question" — 3 MB of tool result after the prompt; "a file past the read bound+is read from its tail"). Proof on the real files: both the 3.6 MB and the+21 MB session now open with `user_message`, in 0.017 s and 0.084 s. The live+backend has the old module loaded; a restart picks the fix up.++**Lesson.** A window on "the recent past" has to open on a turn boundary or it+opens on garbage — and a cut taken only when a limit is EXCEEDED protects+nothing when the input is short. Measure a bound before keeping it: this one+was defended by a cost that was never there.diff --git a/jarvis/agentic_ide/agent_transcript.py b/jarvis/agentic_ide/agent_transcript.pyindex 3ab4047ecc..29643dcb30 100644--- a/jarvis/agentic_ide/agent_transcript.py+++ b/jarvis/agentic_ide/agent_transcript.py@@ -27,12 +27,17 @@ same deal for free by registering an adapter.## Bounds-Two, both load-bearing. A long-running session's file reaches megabytes, so the-read starts from the END of the file and walks backwards only as far as it must-— a conversation view shows the last stretch, and paying disk for the first-thousand turns to render the last ten is how a chat surface becomes slower the-longer it is used. And each block of text is capped, because a tool result can-be a whole file and this is a conversation, not a file viewer.+Two, both load-bearing. A conversation view answers with the last+:data:`MAX_TURNS` exchanges, cut at a person's message and never inside one —+a turn is shown from what was asked, or not at all. The file is streamed from+its head, one line at a time, to find those turns: a pane given one long task+has its question at the HEAD of the file and megabytes of tool output after+it, and a read that started from the end and stopped short came back with the+answer's torso and no question (BUG-196). A line-by-line pass over a+20-megabyte record costs a tenth of a second, less than decoding a fixed tail+as one block did; :data:`MAX_READ_BYTES` only keeps a runaway file from being+walked whole on every poll. And each block of text is capped, because a tool+result can be a whole file and this is a conversation, not a file viewer.Cross-platform: paths come from :mod:`.agent_sessions`, everything is read asUTF-8 with replacement, and nothing here is OS-specific.@@ -42,7 +47,7 @@ from __future__ import annotationsimport jsonimport re-from collections.abc import Callable+from collections.abc import Callable, Iteratorfrom dataclasses import dataclass, fieldfrom datetime import datetimefrom pathlib import Path@@ -61,13 +66,15 @@ MAX_TURNS = 60#: what a person reads, and the pane behind it still holds the raw output.MAX_TEXT = 4000-#: How much of the file's tail may be read to find those turns. Generous enough-#: that MAX_TURNS is reached in one pass for any normal session, bounded so a-#: pathological file cannot pull megabytes into memory.-MAX_TAIL_BYTES = 2_000_000--#: Read granularity when walking backwards from the end of the file.-_CHUNK = 256 * 1024+#: How much of a file is walked to find those turns — from the head, so the+#: turn a pane is on is read from the question that opened it, however much+#: output came after (a 2 MB tail once cut a 3.6 MB session's one prompt off+#: and drew the answer without it, BUG-196). Far above any real session: the+#: largest on the maintainer's box is 21 MB and streams in a tenth of a+#: second. Past the bound the read starts this far before the end, and the+#: first turn shows from wherever that lands — a runaway file is still a+#: file, and a torso beats a blank stage.+MAX_READ_BYTES = 64_000_000@dataclass(frozen=True, slots=True)@@ -124,52 +131,53 @@ def _clip(text: str) -> str:return f"{value[:half]}\n\n[…]\n\n{value[-half:]}"-def _tail_lines(path: Path, *, max_bytes: int = MAX_TAIL_BYTES) -> list[str]:- """The last lines of ``path``, without reading what comes before them.+def _lines(path: Path, *, max_bytes: int = MAX_READ_BYTES) -> Iterator[str]:+ """The lines of ``path``, oldest first, streamed — never the file in one piece.- Walks backwards in chunks and stops at ``max_bytes``. The first line of the- result may be a fragment — the caller parses per line and a fragment simply- fails to parse, which is the correct outcome for half a JSON object.+ A file larger than ``max_bytes`` is read from that far before its end. The+ line the seek lands in is a fragment and is dropped whole, so a caller only+ ever sees lines that begin where the CLI began them; the last line may+ still be one the CLI is mid-way through writing, and fails to parse, which+ is the right outcome for half a JSON object — the next poll sees it whole."""try:size = path.stat().st_size- except OSError as exc:- logger.debug("Agent transcript: cannot stat {}: {}", path.name, exc)- return []- want = min(size, max_bytes)- try:with path.open("rb") as handle:- handle.seek(size - want)- blob = handle.read(want)+ skip = size - max_bytes+ if skip > 0:+ logger.debug(+ "Agent transcript: {} is {} bytes, reading the last {}",+ path.name,+ size,+ max_bytes,+ )+ handle.seek(skip)+ handle.readline()+ for raw in handle:+ yield raw.decode("utf-8", "replace")except OSError as exc:logger.warning("Agent transcript: cannot read {}: {}", path.name, exc)- return []- text = blob.decode("utf-8", "replace")- return text.splitlines()-def _rows(path: Path) -> list[dict[str, Any]]:- """Every JSON object in the tail of ``path``, oldest first.+def _rows(path: Path, *, max_bytes: int = MAX_READ_BYTES) -> Iterator[dict[str, Any]]:+ """Every JSON object in ``path``, oldest first, one at a time.A line that does not parse is skipped in silence, and that IS the handling:- the first line of a tail read is usually half an object, and a CLI writing- its file while this reads it will always produce one. Nothing is lost — the- next poll sees the complete line.+ a CLI writing its file while this reads it always leaves a half line at the+ end, and transcripts interleave plain text with JSONL. Nothing is lost —+ the next poll sees the complete line."""- out: list[dict[str, Any]] = []- for line in _tail_lines(path):+ for line in _lines(path, max_bytes=max_bytes):stripped = line.strip()if not stripped or not stripped.startswith("{"):continuetry:payload = json.loads(stripped)except (ValueError, TypeError):- # Not a JSON line — transcripts interleave plain text with JSONL,- # so skipping is the parse contract, not a swallowed failure.+ # Not a JSON line — the parse contract, not a swallowed failure.continueif isinstance(payload, dict):- out.append(payload)- return out+ yield payload#: Argument names worth showing as a step's headline, best first.diff --git a/tests/unit/agentic_ide/test_agent_transcript_events.py b/tests/unit/agentic_ide/test_agent_transcript_events.pyindex e9d9c4ba2a..c176198a8a 100644--- a/tests/unit/agentic_ide/test_agent_transcript_events.py+++ b/tests/unit/agentic_ide/test_agent_transcript_events.py@@ -250,6 +250,48 @@ class TestClaudeEvents:# The cut is at a question, so the first event is one — never half a turn.assert events[0]["kind"] == "user_message"+ def test_one_long_task_still_opens_with_its_question(self, tmp_path: Path) -> None:+ """BUG-196: megabytes of tool output after the prompt never cut the prompt off.++ A pane given one task writes its question at the head of the file and+ everything after it is the answer; a read that took a fixed tail came+ back with the answer's torso and the chat stage had nothing above it to+ scroll to. Three megabytes of tool result here — more than the tail+ that was read — and the first event is still what the person said.+ """+ haystack = "x" * 3_000_000+ _claude_session(+ tmp_path,+ "abc",+ [+ _user("fix the scroll", 0),+ _assistant({"type": "tool_use", "id": "c1", "name": "Read", "input": {}}, 1),+ _tool_result("c1", haystack, 2),+ _assistant({"type": "text", "text": "done"}, 3),+ ],+ )+ events = agent_transcript.read_events("claude", "abc", home=tmp_path)+ assert events is not None+ assert events[0]["kind"] == "user_message"+ assert events[0]["payload"]["text"] == "fix the scroll"+ texts = [ev["payload"]["text"] for ev in events if ev["kind"] == "assistant_text"]+ assert texts == ["done"]++ def test_a_file_past_the_read_bound_is_read_from_its_tail(self, tmp_path: Path) -> None:+ """The bound is the one thing that still cuts — and it cuts on a whole line.++ The seek lands mid-object; that fragment is dropped rather than parsed+ as garbage, and every line after it comes back intact.+ """+ rows = [_user(f"q{n}", n) for n in range(5)]+ _claude_session(tmp_path, "abc", rows)+ path = tmp_path / "projects" / "C--some--folder" / "abc.jsonl"+ one = len(json.dumps(rows[-1], ensure_ascii=False)) + 1+ kept = list(agent_transcript._rows(path, max_bytes=one * 2 + one // 2))+ assert [row["uuid"] for row in kept] == ["u-3", "u-4"]+ whole = list(agent_transcript._rows(path))+ assert [row["uuid"] for row in whole] == [f"u-{n}" for n in range(5)]+def test_no_file_is_none_not_an_error(self, tmp_path: Path) -> None:assert agent_transcript.read_events("claude", "nope", home=tmp_path) is Noneassert agent_transcript.read_events("shell", "abc", home=tmp_path) is None