Skip to content

Subagent spend is missing from the parent session's cost #203

Description

@unrelentingfox

Problem

Subagents run in their own AgentSession. Their LLM spend never reaches the parent session's cost accounting. Every surface that reads parent session cost under-reports total spend. This includes pi core's getUsageCostBreakdown, /session, and statusline extensions such as pi-starship and pi-powerline-footer. In a test on pi 0.83.0, two one-turn subagent runs spent $0.066 and none of it reached the parent session's cost accounting.

Proposal

Pi provides a canonical channel for tool spend: ToolResultMessage.usage. Pi core aggregates that field into its "Tools/summaries" cost bucket, and statusline extensions sum the same field. The extension already accumulates per-agent token usage from message_end events. It does not track cost and does not attach anything to the tool results it returns.

I propose three changes:

  1. Extend the lifetime usage accumulator with cacheRead and cost.
  2. Attach the not-yet-reported usage slice to tool results at terminal points: foreground Agent return, resume return, and terminal get_subagent_result.
  3. Advance a per-record watermark on each report so resumes and repeated result fetches never report the same spend twice.

I implemented and tested this in #202.

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