Skip to content

feat: File Bob subagents and subtasks in the root session #1803

Closed

Description

@huang195

Problem

Bob's subagents and subtasks do not show in the session that started them. Each child task gets a session row of its own. The messages view and the timeline of the parent session show nothing between the parent's spawn_subagent (or start_subtask) call and the result. The child's cost is not in the parent's cost.

Cause: Cortex uses X-Task-Id as Bob's session id (core/session/idheader.go). Each child task sends a new X-Task-Id. Subagent support reads only Claude Code's headers (core/pipeline/subagent.go), so the subagent field is empty on every Bob row.

What Bob sends

Source: the code of bob-shell 2.1.0 and Bob IDE 2.2.3, and two live runs through the laptop proxy on 2026-11-11.

  • Every chat request sends X-Task-Id: <task id>.
  • A child task also sends X-Parent-Task-Id: <id>. The web_search tool sends the same pair.
  • Bob has two kinds of child task:
Kind Started by Where Runs Seen on the wire
Subagent spawn_subagent bob-shell and Bob IDE In parallel when there are several calls in one turn. It cannot start another child. Yes, both clients
Subtask start_subtask Bob IDE only (bob-shell 2.1.0 has no tool for it) One at a time. The parent sends nothing until end_subtask. No nested subtasks. Yes, Bob IDE
  • Every child names the root task. In the Bob IDE run, subagents that the subtask started sent X-Parent-Task-Id = the root, not the subtask. So the wire shows a tree with one level.
  • Bob treats both kinds as part of the parent. Its task list shows only root tasks (parentId: null, taskType: "normal"). It merges a child's messages into the parent's tool message, and it adds the child's spend to the parent. Bob IDE shows a subtask in the parent's breadcrumbs.
  • A subtask and a subagent send the same headers. The tool list is the difference. A subtask is offered end_subtask, and is not offered start_subtask. A subagent is offered neither.
  • Bob sends no subagent marker in the body. agentRole is empty. X-Parent-Task-Id is the only signal.
  • The router and security calls send no task id. Client affinity files them in the Bob session that Cortex saw last. In the live runs, one router call of a parallel spawn went to a subagent's session.

Live evidence (laptop session API):

Run Root Children (each one its own session today)
bob-shell 2.1.0 4430cc6e… 4 subagents, 2 of them in parallel. All name the root.
Bob IDE 2.2.3 f40f1df7… 1 subtask, 2 parallel subagents started by the subtask, 1 subagent started by the root. All name the root.

Rules

Apply these in this order. Each rule acts only on a header that Bob sent. No rule guesses.

  1. Session id. When the session id comes from X-Task-Id, and the request also sends a valid X-Parent-Task-Id, the session id is the X-Parent-Task-Id value. Check the parent id with validHeaderSessionID, as for every id header. An invalid parent id changes nothing: the request keeps its own X-Task-Id session, as today.
  2. Subagent id. For such a request, Context.Subagent() returns its X-Task-Id. ParentSubagent() returns "". The parent is the session, as for a Claude Code subagent that the main conversation started. Use validSubagentID on the value.
  3. Kind. Record the child's kind on the event: subtask when the request's tool list has end_subtask, otherwise subagent. A field or value name is decided in the plan.
  4. Header-less calls. No change. After rules 1–2, the Bob session that Cortex saw last is the root. Client affinity then files router and security calls in the root. They get no subagent id, because nothing on the wire names their child.
  5. Messages view (agentop). A Bob subagent is a collapsible block, as for Claude Code (feature: ability to distinguish Claude Code subagent traffic within abctl #1047). A subtask is a labeled section of the main conversation, at its place in time, because the parent waits for it.
  6. Timeline. A Bob child is an agent row under its subagent id, through agentOf (core/session/timeline/agents.go). A subtask row is labeled as a subtask.
  7. Cost. No new code. A child's rows are in the root session, so the root's cost includes them. This is what Bob does too.

Unchanged

  • Claude Code attribution, and every other client.
  • Bob root tasks: the session id stays X-Task-Id.
  • session.id_headers: X-Parent-Task-Id is not added to it. Rule 1 applies only when X-Task-Id gave the id.
  • Trust: X-Parent-Task-Id is client-asserted and unauthenticated, as X-Task-Id is. It is a grouping key, never a principal.

Not covered

  • Children of a subtask are not shown inside the subtask's section. The wire names the root, not the subtask. A match by time would be a guess.
  • A deeper tree. bob-shell's code sets a subagent's parent to the task that started it. That gives subtask → subagent only in bob-shell, and bob-shell cannot start a subtask. If a later Bob version names a subtask as a parent, rule 1 files that subagent in the subtask's id. Fix that when it is seen on the wire.
  • Archived child sessions stay as separate sessions. The archive is not re-filed.
  • resume_id. A resumed subagent sends its old task id again and the same parent, so rules 1–2 file it in the same block. Not seen on the wire.

Files

  • core/session/idheader.go: rule 1. Probably a BobParentTaskHeader const beside BobSessionHeader.
  • core/pipeline/subagent.go: rule 2.
  • Inference parse or event model: rule 3.
  • cmd/agentop: rule 5.
  • core/session/timeline/agents.go: rule 6.
  • Docs: docs/session-api.md (subagent for Bob, the kind) and docs/agents/bob.md (what Cortex shows for subagents and subtasks).

Required artifact: a doc for Bob

Update docs/agents/bob.md in the same PR. This issue does not close on code alone.

Tests

  • X-Task-Id + valid X-Parent-Task-Id → parent's session, subagent = own task id.
  • Invalid X-Parent-Task-Id → own session, no subagent id.
  • X-Parent-Task-Id without X-Task-Id, and on a Claude Code request → no effect.
  • Tool list with end_subtask → kind subtask. Without it → subagent.
  • A fixture from the Bob IDE run: root, a subtask, 2 parallel subagents and a header-less router call, interleaved. All rows land in the root. Two blocks and one subtask section render.
  • Live check: repeat both runs on the laptop proxy.

Size

One PR, about 400–600 lines with tests and docs.

Assisted-By: Claude (Anthropic AI) [email protected]

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions