Skip to content

fix(tui): display subagent todos and prevent HTTP 413 payload errors#290

Merged
echobt merged 1 commit intomasterfrom
fix/subagent-todo-display-and-payload-size
Jan 27, 2026
Merged

fix(tui): display subagent todos and prevent HTTP 413 payload errors#290
echobt merged 1 commit intomasterfrom
fix/subagent-todo-display-and-payload-size

Conversation

@echobt
Copy link
Contributor

@echobt echobt commented Jan 27, 2026

Summary

This PR addresses two issues when running tasks via the Task tool (subagent delegation):

Issue 1: Todo list not displaying during delegation

When a subagent is delegated a task, the user sees:

● Task research
  ⎿ Processing request...

✽ Delegation (1m 55s • Esc to interrupt)

But the subagent's todo list (with [pending], [in_progress], [completed] items) never appears.

Root cause: The subagent runs in a background task and executes tools directly via the registry. When it calls TodoWrite, the result is never sent back to the UI.

Fix: Detect TodoWrite calls in spawn_subagent, parse the todos from the arguments, and send a new ToolEvent::TodoUpdated event to the UI. The event handler then updates the SubagentTaskDisplay.todos field.

Issue 2: HTTP 413 Payload Too Large

After the subagent runs for a while, the user sees:

Backend error: HTTP 413 Payload Too Large from https://api.cortex.foundation: Failed to buffer the request body: length limit exceeded

Root cause: The subagent accumulates messages and tool results in its context. Large tool outputs (from Grep, Read, etc.) can cause the total payload to exceed backend limits.

Fix: Truncate tool outputs to 32KB maximum in the subagent's tool execution loop. A clear truncation message is appended so the model knows the output was truncated.

Changes

  • cortex-tui/src/events.rs: Add ToolEvent::TodoUpdated variant
  • cortex-tui/src/runner/event_loop.rs:
    • Detect TodoWrite calls and send TodoUpdated event
    • Truncate tool outputs > 32KB to prevent payload errors
    • Handle TodoUpdated event to update app_state

This commit addresses two issues when running tasks via the Task tool:

1. Todo list display: When a subagent calls TodoWrite, the todos are now
   parsed and forwarded to the UI via a new ToolEvent::TodoUpdated event.
   The SubagentTaskDisplay in the TUI is then updated to show the todos
   with their status (pending, in_progress, completed).

2. HTTP 413 Payload Too Large: Tool outputs from subagent tool calls are
   now truncated to 32KB to prevent the cumulative context from exceeding
   backend payload limits. This is especially important for tools like
   Grep or Read that can return large outputs.

Changes:
- Add ToolEvent::TodoUpdated variant to events.rs
- Detect TodoWrite calls in spawn_subagent and send todo updates to UI
- Truncate tool outputs > 32KB with a clear truncation message
- Handle TodoUpdated event in handle_tool_event to update app_state
@echobt echobt merged commit d6578f3 into master Jan 27, 2026
2 of 3 checks passed
@echobt echobt deleted the fix/subagent-todo-display-and-payload-size branch January 27, 2026 14:52
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.

2 participants