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(trace): keep tool results readable and long enough to narrate
rubenluetke10-beep6ca4c3bb2834
diff --git a/jarvis/core/redact.py b/jarvis/core/redact.pyindex 10c7608ab6..8a682c16af 100644--- a/jarvis/core/redact.py+++ b/jarvis/core/redact.py@@ -20,7 +20,9 @@ import upward into ``jarvis.memory``. The two differ in intent: ``secret_guard``"""from __future__ import annotations+import jsonimport re+from collections.abc import Mappingfrom typing import Any# Default cap for a persisted preview. Big enough to be useful when scrolling@@ -107,6 +109,22 @@ def redact_secrets(text: str) -> str:return out+def _stringify(value: Any) -> str:+ """Text of a preview value; structured data becomes JSON, not a Python repr.++ A tool that returns a dict used to land in the trace as+ ``{'actions': [{'action_id': ...`` — readable to nobody and unparseable+ by the UI that turns results into sentences. JSON keeps the same content+ in the shape every reader (the trace narrative, a person) understands;+ a value JSON cannot encode falls back to ``str`` per item.+ """+ if isinstance(value, str):+ return value+ if isinstance(value, Mapping | list | tuple):+ return json.dumps(value, ensure_ascii=False, default=str)+ return str(value)++def safe_preview(value: Any, *, max_chars: int = DEFAULT_PREVIEW_CHARS) -> str:"""Stringify ``value`` -> mask credential shapes -> cap to ``max_chars``.@@ -118,7 +136,7 @@ def safe_preview(value: Any, *, max_chars: int = DEFAULT_PREVIEW_CHARS) -> str:if value is None:return ""try:- text = value if isinstance(value, str) else str(value)+ text = _stringify(value)except Exception: # noqa: BLE001 — a preview must never crash the callerreturn f"<{type(value).__name__}>"text = redact_secrets(text)diff --git a/jarvis/state/turn_trace.py b/jarvis/state/turn_trace.pyindex c4295d7eed..f3b056b911 100644--- a/jarvis/state/turn_trace.py+++ b/jarvis/state/turn_trace.py@@ -82,6 +82,19 @@ _PAYLOAD_KEYS: dict[str, tuple[str, ...]] = {#: Free-text caps: long enough to read, short enough for a row in a file._TEXT_MAX = 240_ARG_MAX = 160+#: Per-key caps for the text a person reads as the trace's prose: what a tool+#: returned, why it failed or was refused, the sentence the model wrote next to+#: a call. At 240 characters a JSON result was cut inside its first object and+#: the trace could say nothing about it; these keep enough for the narrative+#: to name the outcome while a stored turn still stays a few KB.+_PROSE_MAX: dict[str, int] = {+ "output_preview": 1200,+ "error": 600,+ "reason": 400,+ "rationale": 600,+ "utterance": 400,+}+_REASONING_TEXT_MAX = 4000_ARGS_MAX_KEYS = 8#: How many events the ring keeps. A turn rarely exceeds a few dozen; the#: ring spans the last several turns so a slow reply still finds its slice.@@ -118,7 +131,12 @@ def trace_payload_for(name: str, event: Any) -> dict[str, Any]:args[str(k)] = _scalar(v, max_chars=_ARG_MAX)out[key] = argscontinue- maximum = 4000 if name == "ReasoningSummaryUpdated" and key == "text" else _TEXT_MAX+ if name == "ReasoningSummaryUpdated" and key == "text":+ maximum = _REASONING_TEXT_MAX+ elif name == "AnnouncementRequested" and key == "text":+ maximum = _PROSE_MAX["rationale"]+ else:+ maximum = _PROSE_MAX.get(key, _TEXT_MAX)out[key] = _scalar(value, max_chars=maximum)return outdiff --git a/tests/unit/core/test_redact.py b/tests/unit/core/test_redact.pyindex 6bee94cd41..0c8fd23d16 100644--- a/tests/unit/core/test_redact.py+++ b/tests/unit/core/test_redact.py@@ -77,7 +77,7 @@ def test_custom_cap_is_respected() -> None:def test_none_and_non_string_values_are_stringified() -> None:assert safe_preview(None) == ""- assert safe_preview({"projects": 3}) == "{'projects': 3}"+ assert safe_preview({"projects": 3}) == '{"projects": 3}'assert safe_preview(42) == "42"@@ -102,3 +102,12 @@ def test_redacts_credentials_embedded_in_http_request_urls() -> None:assert telegram_token not in redactedassert "?key=<redacted:query_secret>&page=1" in redactedassert "bot<redacted:telegram_bot_token>/getUpdates" in redacted+++def test_structured_values_preview_as_json_not_python_repr() -> None:+ # The reasoning trace turns a result into a sentence; it can read JSON,+ # not ``{'computers': []}``.+ assert safe_preview({"computers": [], "ok": True}) == '{"computers": [], "ok": true}'+ assert safe_preview(["café", 2]) == '["café", 2]'+ # Anything JSON cannot encode still previews instead of raising.+ assert safe_preview({"at": object()}).startswith('{"at": "<object object')diff --git a/tests/unit/state/test_turn_trace.py b/tests/unit/state/test_turn_trace.pyindex 8fa2d03f26..9f3507527d 100644--- a/tests/unit/state/test_turn_trace.py+++ b/tests/unit/state/test_turn_trace.py@@ -90,13 +90,15 @@ def test_payload_is_redacted_and_capped() -> None:"long": "x" * 500,**{f"k{i}": i for i in range(20)},},- rationale="r" * 1000,+ rationale="why " * 250,),)assert secret not in payload["args"]["command"]assert len(payload["args"]["long"]) < 200assert len(payload["args"]) <= 8- assert len(payload["rationale"]) < 300+ # The model's own sentence is prose the trace reads out: kept longer than+ # an argument, still capped.+ assert 500 < len(payload["rationale"]) < 700# Numbers stay numbers, so the UI can format durations.done = trace_payload_for("ActionExecuted", ActionExecuted(tool_name="x", success=False, duration_ms=42)@@ -104,6 +106,19 @@ def test_payload_is_redacted_and_capped() -> None:assert done["duration_ms"] == 42 and done["success"] is False+def test_a_result_keeps_enough_text_for_the_narrative() -> None:+ """A JSON result survives past its first object, still capped."""+ result = '{"computers": [], "note": "' + "seen " * 600 + '"}'+ payload = trace_payload_for(+ "ActionExecuted",+ ActionExecuted(tool_name="list", success=True, duration_ms=4, output_preview=result),+ )+ assert payload["output_preview"].startswith('{"computers": [], "note": "seen seen')+ assert 1000 < len(payload["output_preview"]) < 1300+ denied = trace_payload_for("ActionDenied", {"tool_name": "x", "reason": "no " * 300})+ assert 300 < len(denied["reason"]) < 500++def test_trace_from_recorded_voice_rows_matches_collector_shape() -> None:rows = [{"kind": "TranscriptFinal", "ts_ms": 100, "payload": {}},