fix(cli): forward Claude API error records with null service_tier (#1857) (#2087)

Claude Code writes failed API calls ("Prompt is too long", usage limits,
logged out) as synthetic assistant records whose usage carries
`service_tier: null`. The schema only accepted undefined, so the local
session scanner dropped every one and the web session just looked stalled.

- Accept null for the usage fields the Messages API types as nullable.
- Keep the top-level `error`/`isApiErrorMessage` on assistant records in
  local mode, and `error` in the SDK converter for remote mode.
- Render assistant records carrying `error` as the existing error event,
  so the all-zero synthetic usage no longer resets the context gauge.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SSU-WEI HUANG
2026-10-26 10:00:23 +08:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 6bf0a633bb
commit d3473f9ed4
6 changed files with 123 additions and 4 deletions
@@ -159,6 +159,23 @@ describe('SDKToLogConverter', () => {
expect((logMessage as any).requestId).toBe('req_123')
})
it('keeps the top-level error on synthetic API error messages (#1857)', () => {
const sdkMessage: any = {
type: 'assistant',
message: {
model: '<synthetic>',
role: 'assistant',
content: [{ type: 'text', text: 'Prompt is too long' }]
},
error: 'invalid_request',
is_api_error_message: true
}
const logMessage = converter.convert(sdkMessage)
expect((logMessage as any).error).toBe('invalid_request')
})
})
describe('System messages', () => {