mirror of
https://github.com/wu736139669/hapi.git
synced 2026-11-07 01:21:37 +00:00
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:
co-authored by
Claude Opus 5.5
parent
6bf0a633bb
commit
d3473f9ed4
@@ -211,6 +211,41 @@ describe('sessionScanner', () => {
|
||||
expect(result.nextCursor).toBe(Buffer.byteLength(line1 + '\n' + line2))
|
||||
})
|
||||
|
||||
it('forwards a Claude API error record with null usage fields and keeps its error flags (#1857)', async () => {
|
||||
const filePath = join(testDir, 'api-error.jsonl')
|
||||
const line = JSON.stringify({
|
||||
type: 'assistant',
|
||||
uuid: 'a1',
|
||||
isSidechain: false,
|
||||
isApiErrorMessage: true,
|
||||
error: 'invalid_request',
|
||||
message: {
|
||||
model: '<synthetic>',
|
||||
role: 'assistant',
|
||||
content: [{ type: 'text', text: 'Prompt is too long' }],
|
||||
usage: {
|
||||
input_tokens: 0,
|
||||
output_tokens: 0,
|
||||
cache_creation_input_tokens: 0,
|
||||
cache_read_input_tokens: 0,
|
||||
service_tier: null,
|
||||
inference_geo: null,
|
||||
speed: null
|
||||
}
|
||||
}
|
||||
})
|
||||
await writeFile(filePath, line + '\n')
|
||||
|
||||
const result = await readSessionLog(filePath, 0)
|
||||
expect(result.events).toHaveLength(1)
|
||||
expect(result.events[0].event).toMatchObject({
|
||||
type: 'assistant',
|
||||
uuid: 'a1',
|
||||
isApiErrorMessage: true,
|
||||
error: 'invalid_request'
|
||||
})
|
||||
})
|
||||
|
||||
it('forwards a single complete record with no newline at all', async () => {
|
||||
const filePath = join(testDir, 'single-no-newline.jsonl')
|
||||
const only = JSON.stringify({ type: 'user', uuid: 'u1', message: { content: 'only' } })
|
||||
|
||||
Reference in New Issue
Block a user