Skip to content

Commit 8d62d48

Browse files
TomasPalssonclaude
andcommitted
🛡️ fix: Guard against null content parts in formatAgentMessages payload
Sanitize each message's content array with the existing filterMalformedContentParts helper before passing the payload to formatAgentMessages, which reads part.type without a null guard and crashes on corrupted history (e.g. content parts persisted from aborted/partial streams via an OpenAI-compatible proxy). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 566e20b commit 8d62d48

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

api/server/controllers/agents/client.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -886,13 +886,21 @@ class AgentClient extends BaseClient {
886886
(this.agentConfigs != null &&
887887
Array.from(this.agentConfigs.values()).some(hasDeepSeekAgent));
888888
const formatOptions = needsDeepSeekFormat ? { provider: Providers.DEEPSEEK } : undefined;
889+
/** Strip null/malformed content parts before formatting; `formatAgentMessages` reads
890+
* `part.type` without a null guard and crashes on corrupted history (e.g. content parts
891+
* persisted from aborted or partial streams via an OpenAI-compatible proxy). */
892+
const sanitizedPayload = payload.map((message) =>
893+
Array.isArray(message.content)
894+
? { ...message, content: filterMalformedContentParts(message.content) }
895+
: message,
896+
);
889897
let {
890898
messages: initialMessages,
891899
indexTokenCountMap,
892900
summary: initialSummary,
893901
boundaryTokenAdjustment,
894902
} = formatAgentMessages(
895-
payload,
903+
sanitizedPayload,
896904
this.indexTokenCountMap,
897905
toolSet,
898906
skillPrimeResult?.skills,

0 commit comments

Comments
 (0)