Skip to content

fix(claude): log error and mark batch failed when stop_reason is max_tokens#78

Open
Valyrian-Code wants to merge 1 commit into
RocketChat:developfrom
Valyrian-Code:fix/claude-max-tokens
Open

fix(claude): log error and mark batch failed when stop_reason is max_tokens#78
Valyrian-Code wants to merge 1 commit into
RocketChat:developfrom
Valyrian-Code:fix/claude-max-tokens

Conversation

@Valyrian-Code
Copy link
Copy Markdown

Summary

  • In prompt mode, when the Anthropic API hits the max_tokens limit, stop_reason is 'max_tokens' and the response content is truncated. The adapter passed this truncated content to extractFindings, which returned { findings: [] } — identical to a clean scan with no findings.
  • Added a stop_reason check before calling extractFindings. When truncated, the batch returns { error: true } and logs an error, so the partial result is counted in the error tally instead of silently treated as clean.

Test plan

  • New test: console.error is called with a message containing max_tokens when the API returns stop_reason: 'max_tokens'
  • Full suite: npm test — 635 tests, 0 failures

scanBatchWithPrompt used max_tokens: 1024 but never checked
stop_reason on the response. When the API hit the token limit,
extractFindings found no tool_use block and returned { findings: [] }
— identical to a clean empty result. No error was logged, errorCount
stayed at zero, and findings were silently dropped.

Added stop_reason check before extractFindings: a max_tokens response
now returns { error: true } and logs an error, so the batch is counted
as failed and the caller knows findings may be incomplete.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

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.

2 participants