Skip to content

feat(m3a): spawn bridge — bubble child session costs to parent#171

Open
kenotron-ms wants to merge 6 commits intomainfrom
feat/resume-cost-bridge
Open

feat(m3a): spawn bridge — bubble child session costs to parent#171
kenotron-ms wants to merge 6 commits intomainfrom
feat/resume-cost-bridge

Conversation

@kenotron-ms
Copy link
Copy Markdown

@kenotron-ms kenotron-ms commented May 6, 2026

What

Adds spawn-boundary cost bridging to the app-cli session spawner as part of the M3 cost management milestone.

Background

M2 providers register a session.cost contributor in each session that tracks cumulative cost_usd across all LLM calls. Without bridging, child session costs stay isolated — the parent sees only its own direct LLM calls when collecting contributions.

How it works

Two helpers are added to session_spawner.py:

_sum_cost_usd(contributions) — Reduces the list returned by collect_contributions("session.cost") to a single Decimal total, or None when no cost data is present (e.g. self-hosted models). None propagates correctly rather than masking as zero.

_bridge_child_cost(child_coordinator, parent_coordinator, child_session_id) — Called after child_session.execute() returns and before child_session.cleanup() so the child coordinator is still alive. Collects the child's cost contributions, sums them, and registers the frozen total as a new contributor on the parent coordinator's session.cost channel, keyed as "delegate:{child_session_id}".

Coverage

Both spawn sites are patched:

  • spawn_sub_session() — new child sessions
  • resume_sub_session() — resumed sessions

After these changes, a parent session's collect_contributions("session.cost") includes costs from every child spawned in that session, enabling accurate session-total cost display in M3's turn footer.


Tracks: microsoft-amplifier/amplifier-support#225

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