docs(hook_streaming): correct why _sum_cost_usd is not foundation's sum_cost_usd - #156
Merged
Salil Das (sadlilas) merged 1 commit intoAug 26, 2026
Merged
Conversation
…um_cost_usd The docstring described this function as "replicated inline (not imported) ... to keep this hook free of foundation coupling." That is false: this package declares amplifier-foundation as a dependency and imports it in eleven places across src/, including elsewhere in this same bundle package. There is no boundary here to protect. The real reason is that this function differs from foundation's in two ways that a "de-duplicate this into the import" pass would silently regress: it returns a str (sessionCostTotal is a decimal string on the wire) and it skips non-finite values (foundation's has no such guard). Neither regression would fail a type check, because _emit takes dict[str, Any]. The docstring now says that, and points at the existing is_finite comment rather than restating it. Docstring only. No code change. Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
Salil Das (sadlilas)
force-pushed
the
docs/sum-cost-usd-divergence-rationale
branch
from
August 26, 2026 20:27
4961d8b to
73acf3a
Compare
Salil Das (sadlilas)
deleted the
docs/sum-cost-usd-divergence-rationale
branch
August 26, 2026 20:41
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.
Summary
_sum_cost_usdinhook_streaming.pycarried this rationale:That is false, and it invites a refactor that would introduce a real bug. Docstring only — no code change.
Coupling is not the reason
This package declares
amplifier-foundationas a dependency inpyproject.tomland imports it in eleven places acrosssrc/, including elsewhere in this same bundle package. There is no boundary here to protect.The actual reason: two differences a de-duplication pass would erase
str, not aDecimal.sessionCostTotalis a decimal string on the wire (docs/spec/wire-protocol.md).Decimal("NaN")andDecimal("Infinity")are validDecimals that do not raiseInvalidOperation, andx + NaNisNaN. Foundation's helper has no such guard. That reasoning is already recorded in the comment on theis_finitecheck itself, so the docstring points there rather than restating it.Neither regression would fail a type check:
_emittakesdict[str, Any], so aDecimalwould reach the wire unchecked, and there are no unit tests over this function.Verification
Zero executable lines changed.
🤖 Generated with Amplifier