Repository navigation
chore: 🥅 Surface deny invocations - #921
Conversation
Signed-off-by: Evaline Ju <[email protected]>
|
Warning Review limit reachedNext included review available in 43 minutes. View limit detailsLimit details: You’ve used the included review currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (3)
Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review. 📝 WalkthroughWalkthroughThe budget tracker now records a deny-phase invocation when a request exceeds the daily budget. The invocation includes spending, budget, and call-count details. Tests and documentation cover the denial event. ChangesBudget denial recording
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to Over-budget requests now appear in the session timeline with budget and call-count details while preserving the existing HTTP 429 response. The changed behavior is covered for denied and allowed requests, with no current merge-blocking risk identified. Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches 💡 1🛠️ Fix failing CI checks 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
mrsabath
left a comment
There was a problem hiding this comment.
The 429 budget-exceeded path denied the request but never recorded an Invocation, so phase:"denied" events never surfaced on the session timeline. This PR emits a deny record with a spend/call snapshot before returning the 429 — no change to the wire response.
Verified against the PR head on GitHub:
- API usage is correct — uses the documented two-step form (explicit
pctx.Record(Invocation{…Details})thenDenyStatus), which theDenyAndRecordgodoc explicitly recommends when attaching richerDetails.Recordauto-populatesPlugin/Phase/Path, so omitting them is right; the entry is taggedPhase=requestand will surface viaFilteredByPhase. Detailsconventions followed — snake_case keys, floats formatted with-1precision,total_callsstringified, matching theInvocation.Detailsgodoc.- Race-safe —
callsis snapshotted underp.mu.Lock()alongsidespend. - Tests exercise the real path —
TotalCallsis incremented only inaccumulate(response path); the deny test drives a realOnResponsefirst, sototal_calls: "1"is a genuine snapshot rather than a hardcoded stub. Both the deny-records and under-budget-records-nothing cases are covered.
Areas reviewed: Go (plugin + test), commit/PR conventions, security, tests
Commits: 1, signed-off: yes
CI: 23/23 passing (Spellcheck skipped)
No must-fix issues. LGTM.
huang195
left a comment
There was a problem hiding this comment.
Traced the fix end-to-end and the core claim holds: recordOutboundReject (and its inbound twin) both bail early on pctx.Extensions.Invocations == nil — "Skips when no Invocations were appended … a content-free SessionDenied event would be noise without attribution" (listener/forwardproxy/server.go:946-953, listener/extproc/server.go:314-320). So before this PR the 429 budget deny emitted no phase:"denied" event at all. The Record call is the right fix, it sits after p.mu.Unlock() so there's no deadlock risk, strconv was already imported, and this is the plugin's only DenyStatus — no sibling deny path was missed. As a bonus, recording right before Reject also makes markLastInvocationShadow work for this plugin under ErrorPolicyObserve.
No blocking issues. Two suggestions and a nit inline.
One more, on a file outside the diff so I can't anchor it: authbridge/docs/litellm-budgettrack-plugin.md has an ## Observability section that tables the cost-event fields (lines 156-172) and never mentions denials. This PR adds a second observability surface — a deny invocation carrying three detail keys — that isn't documented there. Worth a short table alongside the cost-event one.
Areas reviewed: Go (plugin + tests), security, docs, commit/PR conventions
Agent/IDE config (.claude/.vscode): none
Commits: 1 (803aa44), signed-off: yes
CI: all 22 checks passing (Spellcheck skipped); Trivy/CodeQL/Bandit clean
| ResponseHeaders: http.Header{responseCostHeader: {"0.002"}}, | ||
| }) | ||
|
|
||
| pctx := &pipeline.Context{} |
There was a problem hiding this comment.
suggestion — this passes, but it doesn't exercise the filter that actually gates the record into the session event.
&pipeline.Context{} leaves the framework-owned currentPhase empty, so Record stamps Phase: "". Both listeners snapshot via SnapshotInvocations(..., pipeline.InvocationPhaseRequest) → FilteredByPhase, which is a strict match and drops Phase == "" entries — its own doc comment calls an untagged entry "a plugin bug." Since the assertions read the raw pctx.Extensions.Invocations.Inbound slice, they'd still pass even if the invocation were filtered out on the way to the denied event, which is the outcome the test is named for.
Production is correct — Pipeline.Run stamps the phase through setCurrent before dispatching OnRequest — so this is test fidelity, not a bug. The house pattern across 9+ plugin tests (e.g. opa/plugin_test.go:1106) is:
pctx := &pipeline.Context{}
pctx.SetCurrentPlugin("litellm-budget-track", "request")
defer pctx.ClearCurrentPlugin()With that in place, asserting got.Phase == pipeline.InvocationPhaseRequest (and got.Plugin) would pin the behavior the listener depends on. Same applies to line 683.
Signed-off-by: Evaline Ju <[email protected]>
Signed-off-by: Evaline Ju <[email protected]>
Summary
The 429 budget-exceeded path denied the request but didn't record, so the cutoff never surfaced on the session timeline. The plugin now records a deny row on the session event before returning, no change to wire response
Assisted-By: Claude (Anthropic AI) [email protected]
Related issue(s)
Fixes #908
Summary by CodeRabbit
Bug Fixes
Documentation
Tests