agentd persistent JSONL events can lag due stdout buffering

t-817·WorkTask·
·
·
Created14 hours ago·Updated14 hours ago·pipeline runs →

Dependencies

Description

Edit

Persistent agent stdout appears block-buffered, so session JSONL events can lag behind actual execution. Repro from omni-coder:

1) agentd send omni-coder --mode persistent "Run exactly one command with run_bash: echo health-check-ok..." 2) Checkpoint (~/.local/state/agentd-agents/checkpoints/omni-coder/session-latest.json) updates immediately and shows tool output. 3) agentd logs omni-coder --mode persistent --last N may show older events for minutes, and current turn may only appear as a trailing agent_start line.

Evidence suggests event writes are not flushed line-by-line from agent (JSONL writer uses BL.putStr + newline without hFlush), so data remains in process buffer when running under systemd/pipe/tee.

Impact:

  • Users think persistent agent is stuck.
  • agentd logs/watch/top appear stale even when turns completed.

Proposed fix:

  • Force flush after each JSON event + result in Omni/Agent.hs (emitTraceEvent + emitRunResult), or make stdout line-buffered explicitly for JSON mode.
  • Keep JSONL reader robustness fix (t-816) for valid trailing line parsing.

Git Commits

70daf843fix(agentd): realtime persistent logs and trailing-line parse
Coder Agent14 hours ago3 files

Timeline (4)

🔄[human]Open → InProgress14 hours ago
💬[human]14 hours ago

Fixed in commit 70daf843.

Changes:

  • Omni/Agentd/SessionLog.hs
  • splitCompleteJsonlLines now keeps a trailing line when it is valid JSON even if file lacks final newline.
  • prevents agentd logs --last ... from hiding freshest valid event at EOF.
  • Omni/Agentd/Daemon.hs tests
  • added regression tests:
  • splitter keeps trailing valid JSON without newline
  • tail reader keeps trailing valid JSON without newline
  • Omni/Agent.hs
  • flush stdout (hFlush) after each JSON trace event and JSON result line.
  • removes long buffering lag in persistent session JSONL writes under systemd/tee.

Verification:

  • lint Omni/Agent.hs Omni/Agentd/SessionLog.hs Omni/Agentd/Daemon.hs
  • typecheck.sh Omni/Agent.hs
  • typecheck.sh Omni/Agentd/Daemon.hs
  • bild --test Omni/Agentd/Daemon.hs
  • bild Omni/Agent.hs
  • bild Omni/Agentd.hs

Runtime smoke on omni-coder:

  • Restarted persistent agent to pick up new binaries/runtime assets.
  • Sent probe: echo after-flush-fix via agentd send ...
  • agentd logs omni-coder --mode persistent --last 10 now immediately showed infer/tool/result events and completion.
🔄[human]InProgress → Review14 hours ago