Skip to content

remote-session: show agent output in attach (STU-1696)#3366

Merged
epeicher merged 2 commits into
trunkfrom
show-agent-output-in-attach
May 6, 2026
Merged

remote-session: show agent output in attach (STU-1696)#3366
epeicher merged 2 commits into
trunkfrom
show-agent-output-in-attach

Conversation

@epeicher
Copy link
Copy Markdown
Contributor

@epeicher epeicher commented May 6, 2026

Related issues

How AI was used in this PR

Implementation, tests, and commit messages drafted with Claude Code. I drove the design (what to log, log shape, where the fallback goes), reproduced the empty-SDK-result bug live against the daemon to confirm the diagnosis, and reviewed each diff before committing. Reviewers should focus on the persisted-event log shape (logger.ts), the diagnostic fields on Turn outcome, and the empty-result workaround in turn-runner.ts.

Proposed Changes

1. Show agent output on studio code remote-session attach (commit 1)

RemoteSessionLogger.event() now persists conversation events (progress, info, error, replies, questions) to the daemon log file in addition to the existing stdout-mirror path. formatLogLineForStdout() recognizes the new { t, event, content } shape and renders it as [time] kind content. Result: when you attach to a running daemon, the conversation flow is visible alongside the polling logs.

2. Diagnostics for "no response" turns (commit 2)

Each non-result message event emits one agent.step line per content block (text snippet, tool_use with input preview, tool_result, thinking) so you can see exactly what the agent did. The Turn outcome info log gained event_counts, result_event_seen, result_event_empty_reply, turn_completed_seen, non_json_stdout_lines, plus subtype / stop_reason / num_turns on the new Result event had empty reply warn. The poll loop logs No reply produced; posting fallback before sending the user-facing fallback so the cause is captured in the log file.

3. Workaround for empty SDK result (commit 2)

While testing the new attach output, reproduced an issue where the agent finishes cleanly (status: success, stop_reason: end_turn, num_turns: 1) but the SDK result event arrives with result: "", even though an assistant text block was streamed earlier in the turn. The remote-session loop was posting "⚠️ Local agent did not return a result." to Telegram even though the agent did answer. Root cause is in the pi runtime (it hardcodes the result text to '' on agent_end). As a guard, the turn runner now captures the last assistant text seen during the turn and uses it as the reply when the result event has empty replyText and no error. The proper fix at the runtime source will follow.

Testing Instructions

Automated:

  • npm test -- apps/cli/remote-session — 111 tests pass (110 existing + 1 new for the empty-result fallback).
  • npm run typecheck — clean.

Manual:

  1. npm run cli:build && node apps/cli/dist/cli/main.mjs code remote-session start --detach (with a configured bot/chat).
  2. In a second terminal: node apps/cli/dist/cli/main.mjs code remote-session attach.
  3. Send a message from Telegram. You should see: Polled message, then a stream of progress / agent.step / reply event lines, then Turn outcome and Posting reply.
  4. To exercise the workaround, send a single-tool one-turn question like "How many local sites are currently running?". The reply should land in Telegram (previously it sometimes posted "⚠️ Local agent did not return a result."). The Turn outcome line will show result_event_empty_reply: true and used_assistant_text_fallback: true.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

epeicher added 2 commits May 6, 2026 20:04
Persist conversation events (progress, info, error, replies, questions)
to the daemon log file so `studio code remote-session attach` replays
them alongside the existing daemon polling logs. Previously these only
reached stdout in foreground mode.

Adds an `event` shape to the persisted log lines and teaches the stdout
formatter to render them as `[time] kind content`.
Adds per-message `agent.step` event lines (text snippets, tool_use with
input preview, tool_result, thinking) so the full agent reasoning shows
on attach.

Adds diagnostic fields to the `Turn outcome` info log
(`event_counts`, `result_event_seen`, `result_event_empty_reply`,
`turn_completed_seen`, `non_json_stdout_lines`) and surfaces
`subtype` / `stop_reason` / `num_turns` when the SDK result event has
an empty reply. Adds a warn line in the poll loop when the fallback
"did not return a result" message is about to be posted, so the cause
is visible in the log file.

Workaround: when the SDK result arrives with an empty `result` field
on a successful turn but an assistant text block was streamed earlier,
post that captured text as the reply instead of the user-facing
"did not return a result" fallback. The pi runtime hardcodes the
result text to '' on agent_end; once that is fixed at the source the
workaround can be removed.
@epeicher epeicher requested a review from gcsecsey May 6, 2026 18:10
@epeicher epeicher enabled auto-merge (squash) May 6, 2026 18:10
@wpmobilebot
Copy link
Copy Markdown
Collaborator

📊 Performance Test Results

Comparing 8ee3159 vs trunk

app-size

Metric trunk 8ee3159 Diff Change
App Size (Mac) 1409.57 MB 1409.57 MB +0.00 MB ⚪ 0.0%

site-editor

Metric trunk 8ee3159 Diff Change
load 1528 ms 1497 ms 31 ms ⚪ 0.0%

site-startup

Metric trunk 8ee3159 Diff Change
siteCreation 8089 ms 8080 ms 9 ms ⚪ 0.0%
siteStartup 4934 ms 4951 ms +17 ms ⚪ 0.0%

Results are median values from multiple test runs.

Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff)

Copy link
Copy Markdown
Contributor

@gcsecsey gcsecsey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @epeicher for improving the output here and for fixing the "no output" bug, I also ran into that a couple of times. 🙌

Changes LGTM and test well. 👍

telegram logs
Image Image

@epeicher epeicher merged commit 734c11d into trunk May 6, 2026
11 checks passed
@epeicher epeicher deleted the show-agent-output-in-attach branch May 6, 2026 21:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants