Skip to content

fix: upload failure logs to PR when agent tool fails without sessionId#1288

Merged
konard merged 3 commits intomainfrom
issue-1287-42929adbc77d
Feb 13, 2026
Merged

fix: upload failure logs to PR when agent tool fails without sessionId#1288
konard merged 3 commits intomainfrom
issue-1287-42929adbc77d

Conversation

@konard
Copy link
Contributor

@konard konard commented Feb 13, 2026

Summary

Fixes #1287 - When --tool agent fails (e.g., due to rate limit), the solve command should upload failure logs to the PR even if no sessionId was established.

Root Cause

The log upload condition in solve.mjs required sessionId to be truthy:

if (shouldAttachLogs && sessionId && global.createdPR && global.createdPR.number) {

However, when the agent fails early (e.g., rate limits before any work is done), no sessionId is assigned, causing failure logs to never be uploaded to the PR.

Changes

1. Fix log upload condition (src/solve.mjs)

  • Remove sessionId requirement from the failure log upload condition
  • Now aligns with the pattern in handleFailure() from solve.error-handlers.lib.mjs
  • Logs will be uploaded when --attach-logs is enabled and a PR exists

2. Add FreeUsageLimitError detection (src/usage-limit.lib.mjs)

  • Add freeusagelimiterror pattern to detect Agent/OpenCode Zen rate limit errors
  • This enables proper usage limit detection for the agent tool

3. Improve rate limit detection (src/agent.lib.mjs)

  • Check multiple sources for usage limit detection:
    1. lastMessage (the last chunk of output)
    2. errorMatch (the extracted error message from JSON output)
    3. fullOutput (complete output - fallback)
  • This ensures rate limits are detected regardless of where they appear in the output

4. Add case study documentation (docs/case-studies/issue-1287/)

  • Detailed timeline of events from the original failure
  • Root cause analysis
  • Error details in JSON format
  • Full log file from the issue

5. Add tests (tests/test-usage-limit.mjs)

  • Test for FreeUsageLimitError detection
  • Test for agent rate limit error message detection

Test Plan

  • All existing tests pass (65/65)
  • ESLint passes
  • New tests for FreeUsageLimitError detection pass
  • Manual test with --tool agent --attach-logs on a rate-limited scenario

Evidence

From the original log file, the agent returned:

{
  "type": "error",
  "exitCode": 0,
  "errorDetectedInOutput": true,
  "errorType": "AgentError",
  "errorMatch": "Failed after 3 attempts. Last error: Rate limit exceeded. Please try again later.",
  "sessionId": null,
  "limitReached": false,
  "limitResetTime": null
}

The sessionId: null caused the log upload to be skipped even though --attach-logs was enabled.


🤖 Generated with Claude Code

Adding CLAUDE.md with task information for AI processing.
This file will be removed when the task is complete.

Issue: #1287
@konard konard self-assigned this Feb 13, 2026
Issue #1287: When `--tool agent` fails (e.g., rate limit), the solve command
should upload failure logs to the PR even if no sessionId was established.

Root cause: The log upload condition in solve.mjs required sessionId to be
truthy, but agent failures (like rate limits) often occur before a session
is established, causing logs to never be uploaded.

Changes:
- Remove sessionId requirement from failure log upload condition in solve.mjs
- Add FreeUsageLimitError pattern to usage-limit.lib.mjs for Agent/OpenCode Zen
- Improve rate limit detection in agent.lib.mjs by checking multiple sources
- Add case study documentation in docs/case-studies/issue-1287/
- Add tests for FreeUsageLimitError detection

The fix aligns with the pattern in handleFailure() from solve.error-handlers.lib.mjs
which does not require sessionId for log attachment.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@konard konard changed the title [WIP] On error of --tool agent we should actually fail and upload log at comment, where it is clearly marked that agent command is failed like we do with claude command fix: upload failure logs to PR when agent tool fails without sessionId Feb 13, 2026
@konard konard marked this pull request as ready for review February 13, 2026 23:07
@konard
Copy link
Contributor Author

konard commented Feb 13, 2026

🤖 Solution Draft Log

This log file contains the complete execution trace of the AI solution draft process.

💰 Cost estimation:

  • Public pricing estimate: $5.784912
  • Calculated by Anthropic: $3.899087 USD
  • Difference: $-1.885825 (-32.60%)
    📎 Log file uploaded as Gist (1031KB)
    🔗 View complete solution draft log

Now working session is ended, feel free to review and add any feedback on the solution draft.

@konard konard merged commit 8ab00c6 into main Feb 13, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant