Repository navigation
fix(guardian): Raise action review output budget to 8,000 tokens - #3297
Merged
Merged
Conversation
Reasoning tokens share the output budget with the assessment. Slow reviews hit the 2,000-token cap and failed with AI_NoObjectGeneratedError. Co-Authored-By: David Cramer <[email protected]>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
dcramer
marked this pull request as ready for review
November 12, 2026 18:50
dcramer
approved these changes
Nov 12, 2026
This comment has been minimized.
This comment has been minimized.
Contributor
|
10 screenshot changes — 10 changed · 0 added · 0 removed Review screenshots in Frameshift |
23 tasks done
MathurAditya724
added a commit
that referenced
this pull request
Nov 17, 2026
Briefs and memory calls keep failing with `ProviderError: AI provider error: invalid_response` because they run out of output tokens before the JSON is done. Each caller set its own `maxTokens`, and reasoning tokens count against that same limit. Now `completeObject` owns the limit. A caller says how big the object is. `completeObject` adds a fixed 6,000 tokens for reasoning and sends the sum as `maxOutputTokens`. If the model's own output limit is lower, it sends that limit instead. When parsing fails, the `gen_ai.chat` span now records the finish reason and token usage, including reasoning tokens. A `length` finish gets its own cause, `StructuredOutputLengthError`, so a spent budget no longer looks like a malformed object. Guardian goes back to sizing only its assessment: 2,000 + 6,000 keeps it at the same 8,000 it has today. A 10,000 limit made one Guardian eval fail on every run, so the allowance is 6,000 rather than 8,000. The Brief and memory callers need no change. Before: a large Brief stopped at 2,500 output tokens, reasoning included, and failed as `invalid_response` with no finish reason on the span. After: the same Brief gets 2,500 + 6,000 = 8,500 tokens. If it still runs out, the span shows `finish_reasons: ["length"]` and the usage, and the error cause is `StructuredOutputLengthError`. Sentry, last 14 days: - Successful `junior.brief_update` spans max out at exactly 2,500 output tokens, and memory spans at exactly 1,000. About 25% of Brief calls and 20–40% of memory calls fail. - Failed spans take as long as successful spans that used the full budget (Brief: about 23s vs 21s; memory: about 13s vs 12s). - Truncated Brief JSON stops at 2.8k to 7k characters, well short of 2,500 tokens of text. That fits reasoning taking part of the budget. Reasoning usage was not recorded until this PR, so that part is still inference. Issues: [JUNIOR-BN](https://sentry.sentry.io/issues/7777451977/), [JUNIOR-A8](https://sentry.sentry.io/issues/7761736970/), [JUNIOR-WQ](https://sentry.sentry.io/issues/7845631434/), [JUNIOR-A1](https://sentry.sentry.io/issues/7753627696/), [JUNIOR-WR](https://sentry.sentry.io/issues/7845636347/) Related: this replaces the Brief-only budget bump in #2554, and it overlaps the failed-span telemetry in #3299. It extends the Guardian one-off in #3297 to every caller. #3558 moves `completeObject` to `generateText` with `Output.object`. Whichever PR merges second has to move this PR's failure-span telemetry (finish reason and usage) to a new hook in that flow. The budget change carries over as is. Open question: `completeObject` accepts `thinkingLevel` but never passes it to the model. A fixed allowance is the simple fix for now. Wiring up `thinkingLevel` would let callers cap reasoning directly. <!-- junior-request-attribution:start --> via @MathurAditya724. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent%3A1d1f9a2435c5b179e98d246acf9c276b --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent%3A1d1f9a2435c5b179e98d246acf9c276b) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent%3A1d1f9a2435c5b179e98d246acf9c276b/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: Aditya Mathur <[email protected]>
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Guardian action reviews sometimes fail with
AI_NoObjectGeneratedError. When the retry fails too, the Turn aborts withToolActionReviewUnavailableError.What failed
Sentry
juniorproject, last 7 days,junior.guardian_action_reviewspans onopenai/gpt-6-luna:AI_NoObjectGeneratedErrorfailures. All were slow (15–27s) and had large request bodies (79–145KB).guardian.action_review.retryingwarnings. The retry sends the same request. 2 retries also failed and aborted the Turn (example trace36509e41692b4307ad7c812b12373ad8, 2026-11-12 18:34 UTC).Root cause (inference)
GUARDIAN_REVIEW_MAX_TOKENS(2,000) goes to the AI SDK asmaxOutputTokens. NothinkingLevelis set, so reasoning tokens share this budget. On large proposals the model uses the budget for reasoning and does not finish the object. Failed spans do not recordfinish_reason, so this is not confirmed. The successful max at exactly 2,000 and the slow, large failures fit this cause.Fix
Raise the budget to 8,000 tokens. Retry logic and model stay the same.
Remaining risk
Worst-case cost and latency per review go up. The 60s
GUARDIAN_REVIEW_TIMEOUT_MSstill bounds latency.via @dcramer.
--
View Session [Sentry]