Skip to content

feat(observability): /trace should walk parent_agent_id chain #31

@justrach

Description

@justrach

Background

The `/trace [N|all]` slash command (added in #28) calls `API::list_trajectory(conversation_id)`, which queries:

```sql
SELECT * FROM trajectory_events
WHERE conversation_id = ? AND agent_id = <active_agent>
ORDER BY seq;
```

So `/trace` shows only the active agent's trajectory. When the active agent is the root and it spawned subagents (under different `agent_id`s), those subagent rows are invisible. To inspect them today you'd have to know each child's agent_id and run a separate query.

Proposed fix

Two pieces:

  1. Repo: walk children. Add `TrajectoryRepo::list_with_children(conv, root_agent) -> Vec` that recursively pulls everything where `parent_agent_id` chains back to `root_agent`. Already supported by the `(conversation_id, agent_id, seq)` index — one query per level.

  2. Renderer: indent by depth. Update the /trace renderer in `crates/forge_main/src/ui.rs::on_trace` to indent child events under their parent's row, so a tree like:

```
1 call Task call_id=t1
12 call read call_id=c1 (child agent A, indented)
13 result read duration=4ms
2 result Task duration=120ms
```

… makes the parent → child structure visible.

Acceptance

  • `/trace` of a conversation with subagents shows parent + child events in one view
  • Indentation makes the parent_agent_id relationship clear at a glance
  • `/trace all` still works on conversations with no subagents (no regression)

Depends on

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions