AI Agents SDE Task Viewer
      • Context
      • Plan
      • Prd
  1. Home
  2. AgentSDE
  3. agent-core
  4. gh-496
  5. plan
  6. plan.md
plan.md(3.0 KB)· Apr 14, 2026· 2 min read
  • Summary
  • Files
  • Steps
  • Verification
  • Risks

Plan: Restore agent-runner.log in agent-worker InvocationProcessor#

Summary#

Port the human-readable agent-runner.log writing logic into InvocationProcessor in the agent-worker repo. The processor currently pipes stdout/stderr directly to file descriptors; it must switch to 'pipe' mode, parse stream-json chunks for log formatting, and write timestamped entries to meta/agent-runner.log alongside existing outputs.

Files#

FileActionDescription
agent-worker/src/invocation/invocation.processor.tsmodifyAdd log stream creation, switch stdio to pipe, parse JSON lines, write formatted log entries
agent-worker/src/invocation/invocation.processor.spec.tscreateUnit tests for agent-runner.log creation, format, logEnded guard, and error paths

Steps#

  1. Add cetTs() helper — Add a private cetTs() method or module-level function returning new Date().toLocaleString('sv-SE', { timeZone: 'Europe/Berlin' }) for CET/CEST timestamps.
  2. Create log WriteStream — Open {metaDir}/agent-runner.log with flags: 'a' and write a start header: {ts} - {phase} - Starting Claude invocation.
  3. Switch stdio from fd to pipe — Change stdio from ['ignore', stdoutFd, stderrFd] to ['ignore', 'pipe', 'pipe'] so stdout/stderr are available as streams.
  4. Pipe stdout to both output file and log — Attach child.stdout.on('data') handler: write raw chunks to the output file WriteStream, parse JSON lines to extract type (tool_use → [tool:ToolName], text → [text]), and write formatted entries to the log stream.
  5. Pipe stderr to both stderr file and log — Attach child.stderr.on('data') handler: write raw chunks to the stderr file WriteStream, write {ts} - {phase} - stderr: {chunk} to the log stream.
  6. Add logEnded guard — Introduce a logEnded boolean flag; set it true on stream close/error; check before every logStream.write() call.
  7. Write completion footer — In the close handler, write {ts} - {phase} - Completed with exit code {code} to the log, then close the log stream.
  8. Handle error path — In the error handler, write an error entry and close the log stream with the logEnded guard.
  9. Write unit tests — Test: log file created with correct header/footer, JSON line parsing produces correct [tool:X]/[text] prefixes, logEnded prevents write-after-end, missing taskDir handled gracefully.

Verification#

  • Run npm run lint and npm run test in agent-worker — all pass
  • After an invocation, meta/agent-runner.log exists with timestamped start header, per-chunk entries, and completion footer
  • Viewer no longer returns 404 for the log

Risks#

  • Stream backpressure — Switching from fd to pipe adds buffering; mitigate by keeping log writes synchronous and non-blocking (WriteStream handles this)
  • JSON parse errors — Malformed stdout lines from Claude; mitigate by wrapping JSON.parse in try/catch and falling back to raw line logging
ContextPrd