fix: streaming guardrail bugs in realtime proxy #13
All Vouch review confidence checks passed
Residual risk 0.16 = Change Risk (0.40) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.40 · 276 lines diff across 3 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.336
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #13"
general
weight: 0.35
jbohanon
Summary
This PR fixes three bugs in the WebSocket realtime guardrail path. Rebased onto
keithmattix:streaming-guardrailstip (b00c0107). Out-of-band (concurrent) response support is tracked separately in agentgateway/agentgateway#2213.Writer tasks dropped before flushing
Writer tasks were included as arms of
tokio::select!. When either reader exited, the select exited immediately, dropping queued frames in the mpsc channels. Spawning the writers as independenttokio::spawntasks lets them drain concurrently with readers; the readers' select is followed bytokio::join!on the writer handles to wait for remaining frames.Empty
HeaderMappassed to guardrailbegin_streaming_response_guardreceivedHeaderMap::new()instead of the actual request headers. This is a silent failure for any webhook response guard configured withforwardHeaderMatches: the webhook would be called without the matched headers (e.g. an auth token or tenant ID), producing auth failures or incorrect evaluations at the external guardrail service.Fixed by adding
req_headerstoRealtimeGuardContextand threading it throughhandle_upgradetoguarded_realtime_proxy. The headers are used byget_webhook_forward_headerswhen building the outbound webhook request; regex and Bedrock guards ignore them.Double metric emission on FailOpen
apply_webhookrecordedGuardrailAction::FailOpeninternally then returnedGuardrailOutcome::None, causing callers to also recordGuardrailAction::Allow. Added aFailOpenvariant toGuardrailOutcomeso recording happens exactly once at the call site. Also changedapply_webhook_responseto returnGuardrailOutcomedirectly, fixing the same double-recording for the response webhook path (Mask/Reject/Pass were also double-recorded throughapply_single_response_guard).Tests
llm::policy::tests::webhook_fail_open_emits_single_metric— double metric emission on FailOpenThis test fails against
keithmattix:streaming-guardrailswithout this patch. Full suite: 1304 tests, 0 failures.Test plan
cargo test -p agentgateway --lib -- webhook_fail_open_emits_single_metriccargo test -p agentgateway