headroom/plugins
chopratejas 694589fec4 refactor(proxy): collapse 3 stream finalizers onto RequestOutcome.from_stream
Three streaming finalizers — ``_finalize_stream_response``,
``_stream_response_bedrock``, ``_stream_openai_via_backend`` — each
duplicated the same set of body- and config-derived fields when
constructing a ``RequestOutcome``:

  * ``attempted_input_tokens = optimized_tokens + tokens_saved``
  * ``num_messages = len(body.get("messages", []))``
  * ``request_messages`` conditional on ``config.log_full_messages``
  * ``transforms_applied`` list → tuple (frozen-dataclass contract)
  * ``tags or {}`` normalization
  * ``turn_id`` via ``compute_turn_id``

The last one was a real bug. Only the Bedrock site computed
``turn_id`` — sites 1 and 3 silently dropped it, breaking the
dashboard's multi-turn-session grouping for every Anthropic-SSE and
OpenAI-via-backend request. The new ``RequestOutcome.from_stream``
classmethod computes it uniformly so the three finalizers cannot
drift apart on derivation logic again.

Each call site now hands ``from_stream`` the body + provider-specific
cache/timing fields and gets a fully-constructed outcome back. The
funnel call after it stays identical (``await
self._record_request_outcome(outcome)``).
2026-05-14 22:34:23 -07:00
..
headroom-agent-hooks refactor(proxy): collapse 3 stream finalizers onto RequestOutcome.from_stream 2026-05-14 22:34:23 -07:00
openclaw chore(deps): bump the npm_and_yarn group across 3 directories with 4 updates 2026-04-24 22:15:53 +00:00