Skip to content

[Bug]: promoteThinkingTagsToBlocks crashes on malformed assistant content entries #35032

@bmendonca3

Description

@bmendonca3

Bug type

Crash (process/app exits or hangs)

Summary

promoteThinkingTagsToBlocks can throw when assistant content contains malformed non-object entries (e.g. null) because it reads block.type without a guard.

Steps to reproduce

  1. Construct an assistant message with content: [null, {"type":"text","text":"ok"}].
  2. Call promoteThinkingTagsToBlocks(message).
  3. Observe a throw: Cannot read properties of null (reading 'type').

Expected behavior

Malformed content entries should be passed through unchanged (or ignored), and thinking-tag promotion should not throw.

Actual behavior

Function throws before processing content.

Root cause

In src/agents/pi-embedded-utils.ts, message.content.some((block) => block.type === "thinking") and loop branches dereference block.type without validating block shape.

Proposed fix

Add object/type guards before reading block.type and keep existing behavior for well-formed blocks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions