Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/lemon-impalas-yawn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"layne": patch
---

fix: claude prompt mode now signals an error when the API response is truncated by max_tokens instead of silently returning empty findings
21 changes: 21 additions & 0 deletions src/__tests__/adapters/claude.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,27 @@ describe('runClaude()', () => {
expect(findings).toEqual([]);
});

it('logs an error when stop_reason is max_tokens instead of silently dropping findings', async () => {
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
mockReadFile.mockResolvedValueOnce(DUMMY_CONTENT);
mockCreate.mockResolvedValueOnce({
stop_reason: 'max_tokens',
content: [],
});

await runClaude({
workspacePath: WORKSPACE,
changedFiles: CHANGED_FILES,
toolConfig: ENABLED_CONFIG,
});

expect(consoleSpy).toHaveBeenCalledWith(
expect.stringContaining('max_tokens'),
);
consoleSpy.mockRestore();
});


it('passes the configured model to the API', async () => {
mockReadFile.mockResolvedValueOnce(DUMMY_CONTENT);
mockCreate.mockResolvedValueOnce(cleanResponse());
Expand Down
5 changes: 5 additions & 0 deletions src/adapters/claude.ts
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ async function scanBatchWithPrompt(
tool_choice: { type: 'any' },
});

if (response.stop_reason === 'max_tokens') {
console.error('[claude] API error during scan batch (prompt mode): response truncated — max_tokens reached, findings may be incomplete');
return { error: true };
}

return extractFindings(response.content);
} catch (err) {
console.error('[claude] API error during scan batch (prompt mode):', (err as Error).message ?? err);
Expand Down
Loading