Skip to content

perf(chat): trim sub-agent tool noise from wire payload#425

Merged
ArgaFairuz merged 1 commit into
mainfrom
perf/trim-subagent-wire-payload
Jul 16, 2026
Merged

perf(chat): trim sub-agent tool noise from wire payload#425
ArgaFairuz merged 1 commit into
mainfrom
perf/trim-subagent-wire-payload

Conversation

@ArgaFairuz

Copy link
Copy Markdown
Collaborator

Sessions with heavy sub-agent (Task) use loaded slowly and consumed a lot of bandwidth when opening the Chat panel. The bulk of the payload was sub-agent internal tool_result content (file dumps, command output) and large tool_use inputs (Write/Edit bodies) that the collapsed Agent view never renders — pure dead weight on the wire.

Add trimSubAgentForWire: for messages nested under a Task (parent.toolUseId set), empty tool_result content and reduce tool_use input to the single displayed brief field. Apply it at every egress to the frontend — message reads (getBySessionId), the live stream broadcast, and the reconnect catch-up buffer. The DB copy is never touched, so resume, branching/undo, interrupt detection, and the navigation rail/virtual-scroll windowing are all unaffected.

Because the trim is display-only, the Debug modal now fetches the full untrimmed sub-agent messages straight from the DB (messages:get-subagents) and rebuilds the complete subActivities, so Debug Information still shows the real, complete data.

Trimming is engine-agnostic (keyed on the unified parent.toolUseId and camelCase brief fields). The brief-field whitelist must stay in sync with getToolBrief in the AgentTool variants.

Sessions with heavy sub-agent (Task) use loaded slowly and consumed a
lot of bandwidth when opening the Chat panel. The bulk of the payload
was sub-agent internal tool_result content (file dumps, command output)
and large tool_use inputs (Write/Edit bodies) that the collapsed Agent
view never renders — pure dead weight on the wire.

Add trimSubAgentForWire: for messages nested under a Task
(parent.toolUseId set), empty tool_result content and reduce tool_use
input to the single displayed brief field. Apply it at every egress to
the frontend — message reads (getBySessionId), the live stream
broadcast, and the reconnect catch-up buffer. The DB copy is never
touched, so resume, branching/undo, interrupt detection, and the
navigation rail/virtual-scroll windowing are all unaffected.

Because the trim is display-only, the Debug modal now fetches the full
untrimmed sub-agent messages straight from the DB (messages:get-subagents)
and rebuilds the complete subActivities, so Debug Information still shows
the real, complete data.

Trimming is engine-agnostic (keyed on the unified parent.toolUseId and
camelCase brief fields). The brief-field whitelist must stay in sync with
getToolBrief in the AgentTool variants.
@ArgaFairuz
ArgaFairuz merged commit 3a4df7a into main Jul 16, 2026
1 check passed
@ArgaFairuz
ArgaFairuz deleted the perf/trim-subagent-wire-payload branch July 16, 2026 00:45
ArgaFairuz added a commit that referenced this pull request Jul 17, 2026
main's opencode PR (#424) is the squash-merge of this branch's own 467ca9a,
so the five conflicting opencode files were resolved in favour of our version
(a strict superset). The new preview (#422) and subagent-trim (#425) work
merged cleanly.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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