fix(interactive): treat missing thinking/text payloads as empty instead of crashing - #734
Open
groovyplanet wants to merge 1 commit into
Open
Conversation
…ad of crashing
Provider extensions can emit assistant content blocks in the wrong shape
(e.g. { type: "thinking", text: ... } instead of { type: "thinking",
thinking: ... }, or a bare block with no payload). The smooth streaming
reveal read block.thinking.length / block.text.length off undefined and
the transcript renderer called .trim() on the missing payload, crashing
the whole TUI process with an uncaught
TypeError: Cannot read properties of undefined (reading 'length').
Normalize missing payloads to empty strings in countVisibleUnits,
buildDisplayMessage, and createAssistantRenderDescriptors, and add a
regression test that fails with the exact production TypeError when the
fix is reverted.
Author
Remaining unguarded read in the same crash path — follow-up suggestionThis PR hardens the two interactive render paths (
Two options for a follow-up:
Note: Happy to open a separate PR for either approach. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Provider extensions can emit assistant content blocks in the wrong shape
(e.g.
{ type: "thinking", text: ... }instead of{ type: "thinking", thinking: ... },or a bare block with no payload). The interactive TUI crashed with an uncaught
during smooth streaming reveal (
block.thinking.length), and transcriptrendering could also crash on already-stored messages (
content.thinking.trim()).This hardens the core renderer so malformed blocks degrade to empty content
instead of terminating the whole TUI process.
Changes
streaming-reveal-content.ts:countVisibleUnits/buildDisplayMessagetreat a missing
text/thinkingpayload as""before counting, slicing,and
.lengthchecks.assistant-render-descriptors.ts:isVisibleContentand descriptorextraction use
(content.text ?? "").trim()/(content.thinking ?? "").trim().test/streaming-reveal-content.test.ts: regression test for malformedthinking/text blocks; fails with the exact production
TypeErrorwhen thefix is reverted.
changes.md: records the fork-visible behavior change.Test plan
TypeErrorwhen thefix is reverted.
tsc --noEmit,biome check --error-on-warnings, and the repo'spre-commit gate (biome + pinned-deps + ts-imports + shrinkwrap + browser
smoke) all pass.
Summary by cubic
Fixes a crash in the interactive TUI when provider extensions emit malformed assistant blocks. Missing
text/thinkingpayloads are treated as empty strings so streaming reveal and transcript rendering don’t throw.text/thinkingto""in streaming reveal and render descriptor paths to avoid.length/.trim()onundefined.Written for commit 2432d02. Summary will update on new commits.