Skip to content

fix(work): surface captured output on a headless agent timeout instead of discarding it - #398

Merged
getappz merged 3 commits into
masterfrom
fix/work-timeout-diagnostics
Aug 7, 2026
Merged

fix(work): surface captured output on a headless agent timeout instead of discarding it#398
getappz merged 3 commits into
masterfrom
fix/work-timeout-diagnostics

Conversation

@getappz

@getappz getappz commented Aug 7, 2026

Copy link
Copy Markdown
Owner

Summary

  • run_headless's timeout branch (src/agent_launch.rs) discarded the child's already-captured stdout/stderr and reported only "<agent> timed out after Ns" — even though run_captured retains whatever the process wrote before being killed.
  • Found live: an agentflare work <item> --agent opencode run completed all of its actual work (4 commits, pushed to a branch) and then hung on something afterward; the timeout failure comment posted to the item said only "timed out", with nothing distinguishing it from a run that made zero progress. Had to manually dig through git branches to discover real work existed.
  • Fix: on timeout, include a tail (last 2000 chars, UTF-8-safe) of captured stdout (or stderr if stdout is empty) in the Failed message, so the item comment/CLI output actually shows what the agent was doing when it was killed.

Test plan

  • run_captured_keeps_output_written_before_a_timeout_kill — proves output written before a kill survives in Captured, which the fix depends on
  • tail_str unit tests, including a UTF-8 multi-byte boundary case
  • diagnostic_suffix unit tests: empty-output case, stdout-preferred case, stderr-fallback case
  • Full existing agent_launch:: suite still passes (20/20)

Summary by CodeRabbit

  • Bug Fixes
    • Improved timeout failure messages with captured diagnostic output.
    • Diagnostics now prefer standard output, fall back to error output, and clearly indicate when no output is available.
    • Long diagnostics are safely limited to the final 2,000 characters without breaking multibyte text.
    • Timeout diagnostics now provide more actionable details for troubleshooting failed launches.

…d of discarding it

run_headless's timeout branch reported only "<agent> timed out after Ns" and
threw away the child's already-captured stdout/stderr, even though
run_captured keeps whatever the process wrote before being killed. Every
timeout was a black box with no way to tell a genuinely stuck agent apart
from one that finished real work and hung afterward (observed live: an
opencode run completed and pushed 4 commits, then hung — the failure
comment posted to the item said only 'timed out', giving no hint that work
had actually happened).
@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Headless timeout failures now include captured stdout or stderr diagnostics. Output is limited to the final 2,000 UTF-8-safe characters. Tests cover capture, truncation, multibyte text, and source selection.

Changes

Headless timeout diagnostics

Layer / File(s) Summary
Diagnostic capture and validation
src/agent_launch.rs
Timed-out headless runs prefer stdout, fall back to stderr, and report when no output exists. Diagnostics use UTF-8-safe tail truncation at 2,000 characters. Tests verify capture after process termination, truncation, multibyte boundaries, and source selection.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: rust

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: exposing captured output when a headless agent times out.
Description check ✅ Passed The description includes a detailed summary and test plan, but it omits the optional Notes for reviewers section.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/work-timeout-diagnostics

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/agent_launch.rs`:
- Around line 312-325: Update diagnostic_suffix to select stdout whenever
captured.stdout is non-empty, without calling trim on either stream; otherwise
select stderr when non-empty, preserve the no-output fallback, and pass the
selected original stream directly to tail_str.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 9b840f4d-5e3f-401b-9333-62a6060baaa8

📥 Commits

Reviewing files that changed from the base of the PR and between c20aa47 and b2e188f.

📒 Files selected for processing (1)
  • src/agent_launch.rs

Comment thread src/agent_launch.rs
shiva added 2 commits August 7, 2026 19:56
…ead of trimming it

trim() dropped whitespace-only stdout to empty (wrongly falling back to
stderr) and shaved real trailing content off before the tail_str slice.
Select on emptiness of the untrimmed stream and pass the original stream
to tail_str.

Addresses CodeRabbit review comment on PR #398.
@getappz
getappz merged commit e3fea95 into master Aug 7, 2026
16 checks passed
@getappz
getappz deleted the fix/work-timeout-diagnostics branch August 7, 2026 14:42
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.

1 participant