fix(*): the 32,768 per-call output cap cuts large dispatch graphs

Open
#1,233 0 comments 0 reactions 0 assignees View on GitHub

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

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), feeding turn_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
  1. 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 no max_tokens (titles, memory consolidation, sentinel, playbook, dag_verdict) don't change.
  2. The loop pins the room, max(floor, window - int(prompt * 1.05)), on every call, and send_max_tokens takes the min with the model ceiling at request time. The room doesn't depend on the ceiling, which removes the allow_fetch disagreement instead of syncing it. subagent/backends/raven_loop.py runs its own model loop with no narrowing (three chat_with_retry calls), so it gets the same pin.
  3. Reservation readers switch by name. If learn_from_overflow kept reading the model ceiling, an unnarrowed refusal would teach min(declared, window // 2) as reply headroom, which is 524,288 on a 1M window. Once every loop request carries the room, _learn_from_overflow treats them all as narrowed. doctor prints both numbers.
  4. 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 naming max_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_ceiling only 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_tokens against rate limits or a credit check, and effort labels may map to a fraction of max_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_loop request carries the room pin.
    • The clamp retries at most once and is remembered per wire id.
    • learn_from_overflow never learns more than the reservation.
    • reserved_output is unchanged.
  • 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.

Open decisions

  1. Scope. The loop plus raven_loop (recommended), or every caller.
  2. Runaway replies. Accept and measure for a week after merge, or add a separate guard.
  3. Config knob. Add an operator upper bound applied as min(knob, model ceiling). Not recommended for now.
  4. Constant name. Rename MAX_OUTPUT_TOKENS_PER_ITERATION to REPLY_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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from EverMind-AI/Raven

All issues in EverMind-AI/Raven

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.