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
@@ -733,6 +733,29 @@ export function normalizeAgentRecord(
|
||||
if (data.isCompactSummary) return null
|
||||
if (!isClaudeChatVisibleMessage({ type: data.type, subtype: data.subtype })) return null
|
||||
|
||||
// Claude Code reports a failed API call ("Prompt is too long", usage
|
||||
// limits, logged out) as a synthetic assistant message with a top-level
|
||||
// `error`. Render it as an error, and keep its all-zero usage out of
|
||||
// the context gauge.
|
||||
if (data.type === 'assistant' && typeof data.error === 'string') {
|
||||
const message = isObject(data.message) ? data.message : null
|
||||
const text = Array.isArray(message?.content)
|
||||
? message.content
|
||||
.flatMap((block) => isObject(block) && typeof block.text === 'string' ? [block.text] : [])
|
||||
.join('\n')
|
||||
: asString(message?.content)
|
||||
return {
|
||||
id: messageId,
|
||||
localId,
|
||||
createdAt,
|
||||
role: 'event',
|
||||
content: { type: 'error', message: text?.trim() || data.error },
|
||||
isSidechain: Boolean(data.isSidechain),
|
||||
parentToolUseId: asString(data.parentToolUseId) ?? null,
|
||||
meta
|
||||
}
|
||||
}
|
||||
|
||||
if (data.type === 'assistant') {
|
||||
return normalizeAssistantOutput(messageId, localId, createdAt, data, meta)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user