Skip to content

fix(anthropic): record streaming latency before safety masking - #43

Merged
sayonfortify merged 1 commit into
fr-v0.52.6.xfrom
fix/anthropic-streaming-latency-before-safety
Jun 20, 2026
Merged

fix(anthropic): record streaming latency before safety masking#43
sayonfortify merged 1 commit into
fr-v0.52.6.xfrom
fix/anthropic-streaming-latency-before-safety

Conversation

@sayonfortify

Copy link
Copy Markdown

Summary

Fixes Anthropic TTFT/STTG span attributes when FortifyRoot streaming safety masks or buffers the first text token. The wrapper now detects the first streaming token before applying streaming-safety processing, then continues the existing safety/pending-item flow.

Why

Live dev telemetry showed Anthropic streaming usage events landing in RDS, but TTFT/STTG stayed NULL when a config profile was enabled. A local spy confirmed the latency attributes were skipped because safety processing could mutate the token event before _is_streaming_token_item(...) ran.

Validation

  • python -m py_compile on the Anthropic streaming wrapper and test file
  • python -m pytest tests/test_safety_unit.py -q -k "streaming_latency or latency_attrs_before_safety" -> 5 passed
  • Live demo rerun after vendored mirror: Anthropic TTFT/STTG strict backend validation passed for pv-demo-streaming-latency-anthropic

Notes

No provider API behavior changes; only span attribute timing changes. Histograms and safety masking behavior remain unchanged.

@sayonfortify
sayonfortify merged commit 0d03c3f into fr-v0.52.6.x Jun 20, 2026
10 checks passed
@sayonfortify
sayonfortify deleted the fix/anthropic-streaming-latency-before-safety branch June 20, 2026 18:03
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