Skip to content

fix: guard TaskPlanPanel against missing tasks/events arrays - #556

Merged
rschardosin merged 1 commit into
mainfrom
fix/task-panel-not-iterable
Sep 26, 2026
Merged

rschardosin merged 1 commit into
mainfrom
fix/task-panel-not-iterable

Conversation

@rschardosin

Copy link
Copy Markdown
Contributor

Problem

Opening a chat session that contains a delegate_tasks delegation (invoked via the execute_tool wrapper) causes a blank screen with:

Uncaught TypeError: e.tasks is not iterable
    at StudioChat-BGAUhzsD.js:7:26449 (useMemo in TaskPlanPanel)

Root Cause

When Studio reconstructs session history, buildSubTaskExecutionMessage in chat_utils.go may produce a subtask_execution message where Tasks is nil — this happens when the buffered delegation plan cannot be matched to its response (e.g. delegate_tasks invoked through the execute_tool catalog wrapper, or the response carries no per-task results).

The StudioMessage.Tasks field has json:"tasks,omitempty", so a nil slice is omitted entirely from the JSON. On the client, TaskPlanPanel.tsx iterates data.tasks with for...of inside a useMemo — for...of undefined throws TypeError: tasks is not iterable, and since it happens during render, React unmounts the whole tree → blank screen.

Fix

Guard both data.tasks and data.events iterations in TaskPlanPanel with Array.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 on data.tasks and data.events
  • web/src/components/chat/__tests__/TaskPlanPanel.test.tsx — regression test that reproduces the exact TypeError: data.tasks is not iterable crash

Testing

The new test fails against the pre-fix code with the identical error from the bug report and passes with the guard applied.

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.
@rschardosin
rschardosin merged commit c1bacaf into main Sep 26, 2026
7 checks passed
@rschardosin
rschardosin deleted the fix/task-panel-not-iterable branch September 26, 2026 19:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant