Framework: mastra (2025-12)
Issue: maxOutputTokens quits agentic loop if max output tokens reached at a particular step
Notes: paper:fr; UPGRADED from SKIPPED in v22-batch-26 revision per codebook section 10. Original triage skipped as S5 (user-found-existing-feature) but new evidence-deepening (Discord-source verbatim quotes, trace evidence, primitive-exists-but-only-via-callback-closure sub-mechanism framing) recharacterizes as fr-shape M-budget-primitive-missing case. CLOSED Dec 31 2025 by Member @roaminro as completed -- via stopWhen-callback workaround NOT first-class config field. Filed Dec 19 2025 by @daneatmastra (Mastra Contributor, Discord-sync-bot mirroring user post). REPORTER ORIGINAL DISCORD-SOURCED QUOTE (verbatim from @arielweinberger Dec 18 Discord post 1451303997465166167): "We have an agentic loop with maxSteps 20. We also have agent.stream(..., { modelSettings: { maxOutputTokens: 5000 } }... we see in our traces that one of the steps reached its output token limit... my understanding is that this setting is at the LLM request level (stop). we have found no way to limit the total output tokens for the entire agentic loop, is there one? That would be our preferred option over setting it at the modelSettings level." CONCRETE TRACE EVIDENCE: stepIndex 3 hit outputTokens 5000 with finishReason: length AND inputTokens: 1 (only 1 input token in iter 3 means this is mid-loop continuation). MAINTAINER WORKAROUND VIA STOPWHEN-CALLBACK NOT FIRST-CLASS CONFIG: @roaminro (Member) Dec 19 (via Discord, mirrored Dec 20 to issue) provided stopWhen callback closure -- "For a loop level limiter, you could maybe use stopWhen, something like this: stopWhen: ({ steps }) => { const totalOutputTokens = steps.reduce((sum, step) => sum + (step.usage.outputTokens || 0), 0); return totalOutputTokens >= 100000; }". Reporter @arielweinberger Dec 19 acknowledgement: "okay, we have not tried that. that seems like the solution." MULTI-USER INTEREST: @suhas_deshpande Dec 18 Discord: "Also curious about this." DISCORD-AS-SOURCE-OF-TRUTH PATTERN: All technical exchange happened on Discord (channel 1309558646228779139); issue is Discord-mirror via daneatmastra automated sync. Documents Mastra primary support venue (Discord) being where actual problem-solving happens, with issues serving as artifact-only mirrors. POST-CLOSURE 7-WEEK-LATER FOLLOW-UP COMMIT: @mathemusician Feb 23 2026 commit e2f8649 "Increase maxOutputTokens to 8000 to fix truncation issue" -- separate-but-related (default cap too low for many use cases). NEW SUB-MECHANISM within M-budget-primitive-missing: primitive-exists-but-only-via-callback-closure (Mastra has stopWhen primitive that CAN do aggregate-budget-enforcement via user-written reduce + threshold-check, but no declarative maxTotalOutputTokens config field at agent.stream() level -- requires user to write closure correctly each time, error-prone vs first-class field). Distinct from SMAG-005 primitive-doesnt-exist, MAST-004 primitive-only-runs-at-memory-retrieval, CRAI-011 primitive-exists-but-broken-via-silent-regression. REVISION TRANSPARENCY NOTE: original S5 skip was correct on narrow reading; updated retention reflects evidence-deepening. Methodology trail preserved.