fix: guard TaskPlanPanel against missing tasks/events arrays - #556
Merged
Merged
Conversation
Restored subtask_execution history messages may omit the tasks or events arrays when the backend's buffered delegation plan could not be matched to its response (e.g. delegate_tasks invoked via execute_tool wrapper). The omitempty JSON tag causes the field to be absent entirely. Before this fix, TaskPlanPanel's useMemo iterated data.tasks with for...of, which throws 'TypeError: tasks is not iterable' on undefined, crashing the entire chat render to a blank screen. Guard both iterations with Array.isArray() fallback to []. Add regression test that reproduces the exact crash condition.
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.
Problem
Opening a chat session that contains a
delegate_tasksdelegation (invoked via theexecute_toolwrapper) causes a blank screen with:Root Cause
When Studio reconstructs session history,
buildSubTaskExecutionMessageinchat_utils.gomay produce asubtask_executionmessage whereTasksis nil — this happens when the buffered delegation plan cannot be matched to its response (e.g.delegate_tasksinvoked through theexecute_toolcatalog wrapper, or the response carries no per-task results).The
StudioMessage.Tasksfield hasjson:"tasks,omitempty", so a nil slice is omitted entirely from the JSON. On the client,TaskPlanPanel.tsxiteratesdata.taskswithfor...ofinside auseMemo—for...of undefinedthrowsTypeError: tasks is not iterable, and since it happens during render, React unmounts the whole tree → blank screen.Fix
Guard both
data.tasksanddata.eventsiterations inTaskPlanPanelwithArray.isArray()fallback to[]. A malformed or incomplete history message now renders as an empty task panel instead of crashing the entire chat.Files Changed
web/src/components/chat/TaskPlanPanel.tsx— defensive guard ondata.tasksanddata.eventsweb/src/components/chat/__tests__/TaskPlanPanel.test.tsx— regression test that reproduces the exactTypeError: data.tasks is not iterablecrashTesting
The new test fails against the pre-fix code with the identical error from the bug report and passes with the guard applied.