fix(*): the 32,768 per-call output cap cuts large dispatch graphs
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Tech stack
- python
- Domain
- ai-infra-agents
Research direction
Start with the output ceiling and request flow in raven/providers/rates.py, raven/providers/base.py, and the loop paths in raven/agent/loop/organ_glue.py and raven/agent/loop/turn_path.py; read the linked design and its listed tests first. The work involves separating model ceilings from reply reservations, narrowing loop requests, and handling provider refusals. Done means the proposed cases pass and the deepseek-flash acceptance probe and dispatch replay validate the change; several open design decisions remain.
Written by the indexing model from the issue text.
Description
Summary
Every request Raven sends names max_tokens = min(declared or 64,000, window room, 32,768). The last term, MAX_OUTPUT_TOKENS_PER_ITERATION, was added for the prompt budget's reply reservation, but because one function serves both jobs it also caps what a single reply may emit. Models that declare far more (deepseek-flash declares 393,216) are cut at 32,768, and the calls that hit it are mostly large run_subagent_dag graphs.
Deferred on 2026-11-10: the cap stays for now, and the dispatch tool texts are being tuned first. This issue records the analysis and a design so the work can resume.
Code references are at 7110dffec.
Evidence
- Audit records, last 10 days, 38,385 calls: 25 ended at exactly 32,768. 24 were
run_subagent_dag(9% of 262 dispatch calls), 1 was a text reply. - A cut dispatch call is a refused tool call (
incomplete_hint), so the model has to re-plan the round. In a replay on deepseek-flash, a cut call took a median 115 s and paid for 32,768 output tokens before the refusal. - Replaying 9 large dispatch contexts (78-90-node rounds), 22 of 40 trials were cut. Tool-text changes alone brought that to 13 of 40.
Why the cap exists
e3bbe866a (2026-09-11) added it after two 400s. Both came from the prompt budget reserving the model's whole declared ceiling:
- glm-4.6: window 204,800, declares 131,000. The prompt was left 73,800, and a 73,878-token prompt plus the ceiling was refused.
- glm-5.3: window 1,048,576, declares 943,718. The prompt was left 104,858, it grew to 127,373, and the sum was refused.
Per-call narrowing (headroom.request_max_tokens, raven/context_engine/headroom.py:147, added in dacfc64c0) now sizes each loop request to the room its prompt leaves, so the request side no longer depends on the cap.
Why the cap cannot simply be deleted
The loop and the request body resolve the ceiling differently:
- The loop uses
allow_fetch=False:organ_glue._wire_output_ceiling(raven/agent/loop/organ_glue.py:151), feedingturn_path._reply_room(raven/agent/loop/turn_path.py:724). - The body uses
allow_fetch=True:send_max_tokens(raven/providers/base.py:232).
In a fresh process, declared_max_output_tokens("deepseek/deepseek-flash", allow_fetch=False) is None, so the loop side falls back to 64,000 while the body carries 393,216. With the 32,768 term both sides collapse to the same number. Without it, the narrowing check would compare against the wrong ceiling, and a prompt near the window would go out unnarrowed.
Proposed design
Three numbers, three names:
| number | definition | deepseek-flash |
|---|---|---|
| model ceiling | min(declared or 64,000, max(window - 16,384, window // 2)). The 32,768 term is dropped from resolve_max_output_tokens (raven/providers/rates.py:1032). |
393,216 |
| reply reservation | min(model ceiling, 32,768). Read by token_budget (raven/agent/harness/memory.py:119) and by learn_from_overflow (raven/context_engine/headroom.py:89). |
32,768 (unchanged) |
| request ceiling | What the body carries. A loop request gets min(room beside the prompt, model ceiling); an unsized request gets the reply reservation. |
up to 393,216 |
send_max_tokens: a pin is bounded by the model ceiling, so it may now exceed 32,768. With no pin, the request carries the reply reservation. The roughly 20 side call sites that name nomax_tokens(titles, memory consolidation, sentinel, playbook,dag_verdict) don't change.- The loop pins the room,
max(floor, window - int(prompt * 1.05)), on every call, andsend_max_tokenstakes the min with the model ceiling at request time. The room doesn't depend on the ceiling, which removes theallow_fetchdisagreement instead of syncing it.subagent/backends/raven_loop.pyruns its own model loop with no narrowing (threechat_with_retrycalls), so it gets the same pin. - Reservation readers switch by name. If
learn_from_overflowkept reading the model ceiling, an unnarrowed refusal would teachmin(declared, window // 2)as reply headroom, which is 524,288 on a 1M window. Once every loop request carries the room,_learn_from_overflowtreats them all asnarrowed.doctorprints both numbers. - A refused ceiling falls back to today's behaviour once. The LiteLLM path gets the clamp the Anthropic path already has (
clamp_to_model_limit,raven/providers/anthropic_messages_provider.py:470): on a 400 namingmax_tokens, retry at the limit the error names, or at 32,768 if it names none, and remember that per wire model id for the life of the process. This matters because catalogue figures would reach the wire for the first time. glm-5.3-flash, kimi-k3 and deepseek-v4.1-flash on OpenRouter declare 943,717-943,718, which is 0.9 of a 1,048,576 window, and_trustworthy_ceilingonly drops rows equal to the window.
Effect on some current models (window / declared / now / proposed): deepseek-flash 1,000,000 / 393,216 / 32,768 / 393,216; glm-5.3-flash 1,048,576 / 943,717 / 32,768 / 943,717; minimax-m3.1-flash 1,048,576 / 524,288 / 32,768 / 524,288; gpt-5.6-terra 1,050,000 / 128,000 / 32,768 / 128,000; claude-opus-5 200,000 / 64,000 / 32,768 / 64,000. Reservations stay at 32,768 on every row.
Risks
- Runaway replies. A reasoning loop that stops at 32,768 today would run to the model ceiling: about 25 min and $0.47 on deepseek-flash (267 tok/s measured, $1.20/M output). The 180 s stream idle timeout doesn't fire while tokens keep arriving, and the streaming path has no total-time limit. In the last 10 days, 1 non-dispatch call in 38,385 reached 32,768.
- Catalogue overstatement. Covered by item 4. The first request per model per process pays one refusal.
- More requests at the window edge. Narrowing now applies to every prompt above
window - declared, which is about 100K tokens on glm-5.3-flash. This is the same 5% slack and +8,192 overflow learning that already runs whenever the room drops below 32,768. - Up-front accounting. Some gateways may count the requested
max_tokensagainst rate limits or a credit check, and effort labels may map to a fraction ofmax_tokens. Neither is verified for the configured providers.
Tests and validation
- Twelve test files pin 32,768 or the constant.
- New tests:
- On a fresh process, before the catalogue is imported, a loop request carries
min(declared, room). - An unsized request still carries 32,768.
- A
raven_looprequest carries the room pin. - The clamp retries at most once and is remembered per wire id.
learn_from_overflownever learns more than the reservation.reserved_outputis unchanged.
- On a fresh process, before the catalogue is imported, a loop request carries
- Before merging:
- An acceptance probe on deepseek-flash naming
max_tokens = 393,216. - A replay of the 9 large dispatch contexts, expecting cut calls to go from 22/40 to about 0.
- An acceptance probe on deepseek-flash naming
Open decisions
- Scope. The loop plus
raven_loop(recommended), or every caller. - Runaway replies. Accept and measure for a week after merge, or add a separate guard.
- Config knob. Add an operator upper bound applied as
min(knob, model ceiling). Not recommended for now. - Constant name. Rename
MAX_OUTPUT_TOKENS_PER_ITERATIONtoREPLY_RESERVATION_TOKENS, since after this change it only means the reservation.
- Dominant language
- Python
- Stars
- 4.1k
- Forks
- 94
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 216
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from EverMind-AI/Raven
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
EverMind-AI/Raven#1413 ·
Maintainers usually reply within 1 day
-
feat: allow users to build ui-web and ui-tui with `bun`May be free again @0warning0error claimed this 8 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
EverMind-AI/Raven#1283 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
EverMind-AI/Raven#121 ·
Maintainers usually reply within 1 day
-
fix: Feishu channel status wrongly reports missing credentials and "not connected" while WebSocket is livePossibly taken @pcbeingused333 claimed this 1 day ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 18/100
EverMind-AI/Raven#1399 · 1 comment ·
Maintainers usually reply within 1 day
-
WebUI tab froze silently while gateway stayed healthy (heartbeat stopped 1h49m); reproducible /auth refresh dead-end fixed in #1392Possibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 4/5 3-5 days Newbie friendliness 22/100
EverMind-AI/Raven#1393 · 2 comments ·
Maintainers usually reply within 1 day
All issues in EverMind-AI/Raven
Similar issues
-
bug docs
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
ActivityWatch/docs#223 ·
-
[Bug]: OpenCode v2 skips an assistant message that gains text after an earlier capturePossibly taken @jianyx1 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
volcengine/OpenViking#8354 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ARTPARK-SAHAI-ORG/calibrate-frontend#842 ·
Maintainers usually reply within 1 day
-
comp/tools P2 tool/skills type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NousResearch/hermes-agent#159541 ·
Maintainers usually reply within 1 day