Skip to content

TokenUsageTask returns early if info is present - #408

Closed
didierofrivia wants to merge 1 commit into
mainfrom
check-stored-tokens-first
Closed

TokenUsageTask returns early if info is present#408
didierofrivia wants to merge 1 commit into
mainfrom
check-stored-tokens-first

Conversation

@didierofrivia

@didierofrivia didierofrivia commented Jul 30, 2026

Copy link
Copy Markdown
Member

This PR introduces an early check for fields present in order to avoid doing the hard work. It's also useful when external proceses can inject these type of fields and the wasm-shim can be alleviated from doing the body parsing.

Summary by CodeRabbit

  • Bug Fixes

    • Response processing now completes immediately when all expected response fields are already available.
    • Prevents unnecessary extraction and waiting for additional response data in these cases.
  • Performance

    • Reduces processing overhead and improves response handling efficiency when required fields have already been captured.

@didierofrivia didierofrivia self-assigned this Jul 30, 2026
@didierofrivia didierofrivia moved this to Ready For Review in Kuadrant Jul 30, 2026
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@didierofrivia, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 30 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 1a541441-3461-4368-9bac-d89714aef956

📥 Commits

Reviewing files that changed from the base of the PR and between 8ccf948 and ab50334.

📒 Files selected for processing (1)
  • crates/kuadrant-filter/src/kuadrant/pipeline/tasks/token_usage.rs
📝 Walkthrough

Walkthrough

TokenUsageTask::apply now exits with TaskOutcome::Done when all expected response fields are already present, avoiding unnecessary extraction and response-stream handling.

Changes

Token usage processing

Layer / File(s) Summary
Existing response field completion
crates/kuadrant-filter/src/kuadrant/pipeline/tasks/token_usage.rs
Checks whether every expected response field exists before selecting an extraction strategy or waiting for response data.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Suggested reviewers: adam-cattermole, eguzki

Poem

A rabbit checks the fields in a row,
Finds them all ready, and says “off we go!”
No bytes to buffer, no stream left to chase,
The task hops away at a brisker pace.

🚥 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: TokenUsageTask now exits early when the needed information is already present.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch check-stored-tokens-first

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
crates/kuadrant-filter/src/kuadrant/pipeline/tasks/token_usage.rs (1)

47-54: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression coverage for the early-exit path.

Pre-populate all expected response fields and assert TaskOutcome::Done; also cover the partial-field case to verify extraction still proceeds.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/kuadrant-filter/src/kuadrant/pipeline/tasks/token_usage.rs` around
lines 47 - 54, Add regression tests for the early return in the token-usage
task: pre-populate every field listed in expected_response_fields and assert
execution returns TaskOutcome::Done, then add a partial-field case that confirms
extraction continues rather than exiting early.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@crates/kuadrant-filter/src/kuadrant/pipeline/tasks/token_usage.rs`:
- Around line 47-54: Add regression tests for the early return in the
token-usage task: pre-populate every field listed in expected_response_fields
and assert execution returns TaskOutcome::Done, then add a partial-field case
that confirms extraction continues rather than exiting early.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: d62d4e3c-d6cd-490b-b133-674c1bc46aa8

📥 Commits

Reviewing files that changed from the base of the PR and between f86c2ba and 8ccf948.

📒 Files selected for processing (1)
  • crates/kuadrant-filter/src/kuadrant/pipeline/tasks/token_usage.rs

@@ -44,6 +44,16 @@ impl Task for TokenUsageTask {
fn apply(self: Box<Self>, ctx: &mut ReqRespCtx) -> TaskOutcome {

@adam-cattermole adam-cattermole Jul 30, 2026

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.

It's worth noting this task is legacy and (very) soon to be removed in favour of the StoreTask

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

nice! yup, I reckon this would be just for a PoC I'm working on... Do you reckon that the resulting config from a TokenRateLimit Policy will change the configuration that will result building the Pipeline with the StoreTask or would it be the same?

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.

Yeah, so all the bits will be extracted from the responseBodyJson vars and added to a StoreTask. So any task leveraging them will wait Pending until the StoreTask resolves for them

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.

See #412

* If response body fields are present.
* Avoids doing the work twice.

Signed-off-by: dd <4183971+didierofrivia@users.noreply.github.com>
@didierofrivia
didierofrivia force-pushed the check-stored-tokens-first branch from 8ccf948 to ab50334 Compare July 30, 2026 08:48
@didierofrivia

Copy link
Copy Markdown
Member Author

Closing this since task will be deprecated soon

@github-project-automation github-project-automation Bot moved this from Ready For Review to Done in Kuadrant Aug 3, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Aug 7, 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.

3 participants