feat(m3a): spawn bridge — bubble child session costs to parent#171
Open
kenotron-ms wants to merge 6 commits intomainfrom
Open
feat(m3a): spawn bridge — bubble child session costs to parent#171kenotron-ms wants to merge 6 commits intomainfrom
kenotron-ms wants to merge 6 commits intomainfrom
Conversation
…an implementation note
…ove stray artifact
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.costcontributor in each session that tracks cumulativecost_usdacross 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 bycollect_contributions("session.cost")to a singleDecimaltotal, orNonewhen no cost data is present (e.g. self-hosted models).Nonepropagates correctly rather than masking as zero._bridge_child_cost(child_coordinator, parent_coordinator, child_session_id)— Called afterchild_session.execute()returns and beforechild_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'ssession.costchannel, keyed as"delegate:{child_session_id}".Coverage
Both spawn sites are patched:
spawn_sub_session()— new child sessionsresume_sub_session()— resumed sessionsAfter 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