Skip to content

chore: 🥅 Surface deny invocations - #921

Merged
evaline-ju merged 3 commits into
rossoctl:mainfrom
evaline-ju:deny-path
Sep 9, 2026
Merged

evaline-ju merged 3 commits into
rossoctl:mainfrom
evaline-ju:deny-path

Conversation

@evaline-ju

@evaline-ju evaline-ju commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

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

    • Budget-exceeded requests now record a denial event with spending totals, budget limits, and call counts before returning a 429 response.
    • Requests within the daily budget continue without recording a denial event.
  • Documentation

    • Added guidance on denial events and the information included when a request is rejected.
  • Tests

    • Added coverage for budget-exceeded and under-budget request behavior.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

Warning

Review limit reached

Next included review available in 43 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 7f9f33ca-94d1-44f1-8077-011cb39d0959

📥 Commits

Reviewing files that changed from the base of the PR and between 4f226a5 and e7fd7fa.

📒 Files selected for processing (3)
  • authbridge/authlib/plugins/litellm_budgettrack/plugin.go
  • authbridge/authlib/plugins/litellm_budgettrack/plugin_test.go
  • authbridge/docs/litellm-budgettrack-plugin.md

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 16edd3c9-99fa-4c67-8c68-29fcef8c8e6b

📥 Commits

Reviewing files that changed from the base of the PR and between 803aa44 and 4f226a5.

📒 Files selected for processing (3)
  • authbridge/authlib/plugins/litellm_budgettrack/plugin.go
  • authbridge/authlib/plugins/litellm_budgettrack/plugin_test.go
  • authbridge/docs/litellm-budgettrack-plugin.md

Included review availability: Your plan provides up to 1 included review per hour; 0 remain after this review.


📝 Walkthrough

Walkthrough

The 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.

Changes

Budget denial recording

Layer / File(s) Summary
Record budget-exceeded denials
authbridge/authlib/plugins/litellm_budgettrack/plugin.go, authbridge/authlib/plugins/litellm_budgettrack/plugin_test.go, authbridge/docs/litellm-budgettrack-plugin.md
OnRequest records a budget.exceeded deny invocation with formatted daily spending, daily limit, and total call count before returning HTTP 429. Tests verify over-budget and under-budget behavior. Documentation describes the emitted denial event.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 4f226

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: aslom, ibrahim2595

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: exposing deny invocations for budget-exceeded requests. The conventional prefix and emoji do not obscure the scope.
Linked Issues check ✅ Passed The PR satisfies issue #908. The budget-exceeded path records a deny-phase Invocation with the required budget and call-count details before returning DenyStatus. Tests verify both denial recording an…
Out of Scope Changes check ✅ Passed The code, tests, and documentation changes directly support the linked issue. No unrelated changes are identified.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 2 files. (1 skipped: 1 …
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mrsabath mrsabath left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}) then DenyStatus), which the DenyAndRecord godoc explicitly recommends when attaching richer Details. Record auto-populates Plugin/Phase/Path, so omitting them is right; the entry is tagged Phase=request and will surface via FilteredByPhase.
  • Details conventions followed — snake_case keys, floats formatted with -1 precision, total_calls stringified, matching the Invocation.Details godoc.
  • Race-safe — calls is snapshotted under p.mu.Lock() alongside spend.
  • Tests exercise the real path — TotalCalls is incremented only in accumulate (response path); the deny test drives a real OnResponse first, so total_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 huang195 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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{}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@evaline-ju
evaline-ju merged commit 68abe41 into rossoctl:main Sep 9, 2026
23 checks passed
@github-project-automation github-project-automation Bot moved this from New/ToDo to Done in Rossoctl Issue Prioritization Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Record an Invocation on the litellm-budget track budget-exceeded deny path

3 participants