From 73acf3a60c48bf5e33db379d05c4b9cbe2471df8 Mon Sep 17 00:00:00 2001 From: sadlilas <11658960+sadlilas@users.noreply.github.com> Date: Wed, 26 Aug 2026 13:17:26 -0700 Subject: [PATCH] docs(hook_streaming): correct why _sum_cost_usd is not foundation's sum_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> --- src/amplifier_agent_lib/bundle/hook_streaming.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/amplifier_agent_lib/bundle/hook_streaming.py b/src/amplifier_agent_lib/bundle/hook_streaming.py index a5a3dbaa..4b5f0871 100644 --- a/src/amplifier_agent_lib/bundle/hook_streaming.py +++ b/src/amplifier_agent_lib/bundle/hook_streaming.py @@ -63,11 +63,15 @@ def _parse_agent_name(session_id: str) -> str | None: def _sum_cost_usd(results: list[dict[str, Any]]) -> str | None: """Sum ``cost_usd`` contributions, preserving Decimal precision. - Replicated inline (not imported) from - ``amplifier_foundation.bundle._prepared.sum_cost_usd`` to keep this hook - free of foundation coupling. Contributions carry cost as a string (the - kernel's Decimal-as-string convention). Returns the total as a string, or - ``None`` when no contributor reported a cost. + Contributions carry cost as a string (the kernel's Decimal-as-string + convention). Returns the total as a string, or ``None`` when no contributor + reported a cost. + + Deliberately not ``amplifier_foundation.bundle._prepared.sum_cost_usd``, and + not safe to "de-duplicate" into that import: foundation's returns ``Decimal`` + where the wire needs a string, and does not skip non-finite values (see the + ``is_finite`` comment below). Neither regression would fail a type check -- + ``_emit`` takes ``dict[str, Any]``. """ total: Decimal | None = None for entry in results: