Skip to content

Review agent metrics zeroed when agent process exits with error after writing valid output #6806

Open

Description

@fullsend-ai-retro

What happened

The second review run on PR #6769 (run 33317698843) produced a valid agent-result.json with 5 findings and the review was successfully posted. However, the run's metrics.json reports num_turns: 0 and total_cost_usd: 0, and the telemetry span records exit_code: -1 and finish_reason: "error". The job step itself completed as success. This means the agent process terminated abnormally after writing its output but before metrics were flushed, making cost tracking unreliable for this run.

What could go better

Cost and usage metrics should be reliable for every run that produces valid output. When the agent crashes after writing results, the metrics file should still reflect the actual work performed. The zeroed metrics mean this run's cost does not appear in aggregate reporting, understating actual spend. Confidence is moderate — the root cause could be a crash in a post-output verification step (the agent ran fullsend-check-output or a subsequent Bash call that failed), or the metrics flush could depend on a clean exit that the error path bypasses. Related but distinct from #3548, which describes a Failure status despite valid output (inverse symptom — there the status was wrong; here the status was correct but metrics were lost).

Proposed change

Investigate the review agent runner's metrics collection path in the fullsend CLI. The metrics flush should happen before or atomically with the output write, not after a post-validation step that can fail. If fullsend-check-output or any post-output step fails, the error should be logged but should not prevent metrics from being persisted. The telemetry span should capture actual token counts from the API responses regardless of the agent's exit code. Look at the metrics collection in the harness runner (likely internal/harnessdispatch/ or the runner entrypoint) to ensure metrics are flushed before any post-output validation.

Validation criteria

Review agent runs that produce valid agent-result.json output should report non-zero num_turns and total_cost_usd in metrics.json, even when the agent process exits with a non-zero exit code. Verify by checking the next 10 review runs that complete with exit_code=-1 — all should have populated metrics.


Generated by retro agent from #6769

Activity

  1. added
    ready-for-triage
    on Aug 31, 2026
  2. fullsend-ai-triage commented on Aug 31, 2026

    @fullsend-ai-triage

    🤖 Finished Triage · ✅ Success · Started 3:38 PM UTC · Completed 3:43 PM UTC

    Commit: 32ad401 · View workflow run →

    Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $0.67

  3. added
    type/bug
    agent/review
    component/runner
    priority/medium
    ready-to-code
    on Aug 31, 2026
  4. fullsend-ai-triage commented on Aug 31, 2026

    @fullsend-ai-triage

    Re-checked relevance as requested: this remains a valid, distinct gap and should stay open for human prioritization rather than being auto-implemented right now.

    Since this issue was filed, PR #6908 (closing #6905) and PR #6938 (closing #6936) landed and fixed the closely related cancellation-metrics problem: InputTokens/OutputTokens/cache counters are now captured incrementally via a TokensEvent handler so they survive a run that never reaches Claude's terminal result event, and the agent-iteration loop now finalizes metrics/spans before extraction when a run is cancelled.

    However, both of those PRs explicitly leave NumTurns and TotalCostUSD sourced only from that terminal ResultEvent -- confirmed by reading internal/runtime/claude.go on current main. That is precisely the symptom this issue reports (num_turns: 0, total_cost_usd: 0, exit_code: -1) for a run whose process ended abnormally for reasons other than a GitHub Actions cancellation, after valid output had already been produced. So the underlying problem is narrower than when filed, but not resolved.

    One correction to the prior triage pass: the relevant code lives in internal/runtime/claude.go and the iteration loop in internal/cli/run.go, not internal/harnessdispatch/.

    Note: this triage run intentionally withholds a recommendation to auto-implement, per the request to leave this for human prioritization. This repository's current auto-code configuration promotes bug-category issues mechanically regardless of that preference, so please double check the issue's labels after this triage completes and manually hold it back if it gets auto-promoted.


    Next steps:

    • /fs-code — agent creates a PR to implement this issue
    • /fs-code <your instruction> — agent implements with your specific guidance
    Previous run

    Severity: medium — cost tracking reliability is impacted but agent output and reviews are unaffected.

    Related issues

    Investigation pointers

    The metrics collection likely lives in the harness runner entrypoint — start with internal/harnessdispatch/ and trace how metrics.json is written relative to the agent process lifecycle. Key question: does the runner write metrics in a defer block (which would survive panics) or in a sequential step after post-output validation (which wouldn't)?

    Proposed test

    Scenario: metrics survive post-output failure
      Given the agent runner completes API calls (non-zero tokens)
      And valid agent-result.json is written
      When a post-output step (e.g., fullsend-check-output) fails with exit code -1
      Then metrics.json should report actual num_turns > 0
      And metrics.json should report actual total_cost_usd > 0
    

    Labels: Review agent metrics bug affecting the harness runner component, medium priority since it impacts cost reporting but not agent functionality.


    Next steps:

    • /fs-code — agent creates a PR to implement this issue
    • /fs-code <your instruction> — agent implements with your specific guidance
  5. fullsend-ai-coder commented on Aug 31, 2026

    @fullsend-ai-coder
    Contributor

    🤖 Finished Code · ✅ Success · Started 3:44 PM UTC · Completed 4:04 PM UTC

    Commit: 32ad401 · View workflow run →

    Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $5.52

  6. ralphbean commented on Sep 24, 2026

    @ralphbean
    Member

    /fs-triage lots of things have changed between when this was originally filed and now across both the https://github.com/fullsend-ai/fullsend and https://github.com/fullsend-ai/agents repos. Is this still relevant? This is a stale-issue review, not an implementation request: even if the issue is still a valid bug and has sufficient information, do not recommend or trigger ready-to-code yet. Leave it for human prioritization after confirming whether it remains relevant. Do not close a still-relevant bug merely to avoid coding it.

  7. fullsend-ai-triage commented on Sep 24, 2026

    @fullsend-ai-triage

    🤖 Finished Triage · ✅ Success · Started 6:38 PM UTC · Completed 6:45 PM UTC

    Commit: fbf65c8 · View workflow run →

    Runtime: claude · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $0.64

  8. added
    ready-to-code
    and removed
    ready-to-code
    on Sep 24, 2026
  9. fullsend-ai-coder commented on Sep 24, 2026

    @fullsend-ai-coder
    Contributor

    🤖 Finished Code · ✅ Success · Started 6:47 PM UTC · Completed 7:11 PM UTC

    Commit: fbf65c8 · View workflow run →

    Runtime: pi · Model: xai/grok-4.6 · Effort: high · Cost: $12.38

  10. added a commit that references this issue on Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/reviewbugcomponent/runnerpriority/mediumready-for-triageready-to-codetype/bug

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions