Skip to content

fix(guardian): Raise action review output budget to 8,000 tokens - #3297

Merged
dcramer merged 1 commit into
mainfrom
fix/guardian-review-output-budget
Nov 12, 2026
Merged

dcramer merged 1 commit into
mainfrom
fix/guardian-review-output-budget

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Guardian action reviews sometimes fail with AI_NoObjectGeneratedError. When the retry fails too, the Turn aborts with ToolActionReviewUnavailableError.

What failed

Sentry junior project, last 7 days, junior.guardian_action_review spans on openai/gpt-6-luna:

  • 25 AI_NoObjectGeneratedError failures. All were slow (15–27s) and had large request bodies (79–145KB).
  • 23 guardian.action_review.retrying warnings. The retry sends the same request. 2 retries also failed and aborted the Turn (example trace 36509e41692b4307ad7c812b12373ad8, 2026-11-12 18:34 UTC).
  • About 21.8k successful reviews: avg 277 output tokens, p99 1,320, max exactly 2,000. Successful reviews that took more than 15s averaged 1,446 output tokens.

Root cause (inference)

GUARDIAN_REVIEW_MAX_TOKENS (2,000) goes to the AI SDK as maxOutputTokens. No thinkingLevel is 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 record finish_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_MS still bounds latency.

via @dcramer.

--

View Session [Sentry]

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]>
@vercel

vercel Bot commented Nov 12, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
junior-docs Ready Ready Preview Nov 12, 2026 6:48pm UTC

Request Review

@dcramer
dcramer marked this pull request as ready for review November 12, 2026 18:50
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 12, 2026
@blacksmith-sh

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

10 screenshot changes — 10 changed · 0 added · 0 removed

Review screenshots in Frameshift

Automations Runs Filters · Desktop
Automations Runs Filters · Desktop
Changed
Conversation Captured Memories Popover · Desktop
Conversation Captured Memories Popover · Desktop
Changed
Conversation Captured Memories Popover · Mobile
Conversation Captured Memories Popover · Mobile
Changed
Conversation Details Watched Linked Work · Desktop
Conversation Details Watched Linked Work · Desktop
Changed
Conversation Long Transcript Touch · Mobile
Conversation Long Transcript Touch · Mobile
Changed
Conversation Object Links · Desktop
Conversation Object Links · Desktop
Changed
Show 4 more changed screenshots
Conversation Question Stepper · Desktop
Conversation Question Stepper · Desktop
Changed
Conversation Question Stepper Light · Desktop
Conversation Question Stepper Light · Desktop
Changed
Push Notifications Tip · Desktop
Push Notifications Tip · Desktop
Changed
Settings Mcp · Desktop
Settings Mcp · Desktop
Changed

@dcramer
dcramer merged commit acaa420 into main Nov 12, 2026
63 of 66 checks passed
@dcramer
dcramer deleted the fix/guardian-review-output-budget branch November 12, 2026 19:13
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

1 active deployment
Preview – junior-docs — b60e7699 Deployed Nov 12, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant