fix: upload failure logs to PR when agent tool fails without sessionId#1288
Merged
fix: upload failure logs to PR when agent tool fails without sessionId#1288
Conversation
Adding CLAUDE.md with task information for AI processing. This file will be removed when the task is complete. Issue: #1287
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>
--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 commandThis reverts commit 8aa6a65.
Contributor
Author
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost estimation:
Now working session is ended, feel free to review and add any feedback on the solution draft. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1287 - When
--tool agentfails (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.mjsrequiredsessionIdto be truthy:However, when the agent fails early (e.g., rate limits before any work is done), no
sessionIdis assigned, causing failure logs to never be uploaded to the PR.Changes
1. Fix log upload condition (
src/solve.mjs)sessionIdrequirement from the failure log upload conditionhandleFailure()fromsolve.error-handlers.lib.mjs--attach-logsis enabled and a PR exists2. Add FreeUsageLimitError detection (
src/usage-limit.lib.mjs)freeusagelimiterrorpattern to detect Agent/OpenCode Zen rate limit errors3. Improve rate limit detection (
src/agent.lib.mjs)lastMessage(the last chunk of output)errorMatch(the extracted error message from JSON output)fullOutput(complete output - fallback)4. Add case study documentation (
docs/case-studies/issue-1287/)5. Add tests (
tests/test-usage-limit.mjs)FreeUsageLimitErrordetectionTest Plan
--tool agent --attach-logson a rate-limited scenarioEvidence
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: nullcaused the log upload to be skipped even though--attach-logswas enabled.🤖 Generated with Claude Code