Skip to content

feat(runtime): lift the output cap to the model ceiling where reasoning shares it (RR8.3) - #200

Merged
lg2m merged 4 commits into
fix/eng-954-rr8-gateway-reasoningfrom
fix/eng-955-rr8-effort-aware-output-cap
Sep 28, 2026
Merged

lg2m merged 4 commits into
fix/eng-954-rr8-gateway-reasoningfrom
fix/eng-955-rr8-effort-aware-output-cap

Conversation

@lg2m

@lg2m lg2m commented Sep 26, 2026 •

Copy link
Copy Markdown
Collaborator

RR8.3: effort-aware output ceiling

Spec: docs/plans/run-reliability.md (RR8) Linear: ENG-955 Stack: 3/4, on ENG-954

What changed

  • resolved_model_for_snapshot: when a reasoning effort is set and the route's thinking is billed inside max_tokens (Anthropic Messages, or an Anthropic model behind an OpenAI-compatible gateway — recognised by catalog canonical id or the vendor segment of the gateway id such as us.anthropic.claude-…), the wire cap resolves to the catalog ceiling instead of the compiled 16 384 default.
  • An operator-set max_output_tokens (any non-Compiled provenance: config layer or runtime override) is honoured verbatim. Responses-wire models are unchanged. Run budgets still bound spend: the cap stops being a wire parameter that strangles reasoning and stays a cost ceiling.
  • Original RR8 item: a per-session persisted cap equal to a legacy default (LEGACY_DEFAULT_MAX_OUTPUT_TOKENS = [2 048, 4 096]) records the default of its day, not a choice, and is treated as unset at load; any other persisted value is kept. New rows never persist the compiled default (see review round). The lift is bounded by a managed policy.max_output_tokens, and reasoning_effort: none does not trigger it.

How verified

  • reasoning_effort_lifts_the_default_output_cap_where_thinking_shares_it: Anthropic wire → 128 000; gateway id → 128 000; no effort → default; override 4 096 / config 8 192 honoured; Responses wire → default; no catalog ceiling → default; none → default; managed policy 32 000 binds.
  • a_persisted_output_limit_below_the_default_is_treated_as_unset (2 048/4 096 → None; 123, 16 384, 32 768 kept).
  • a_new_session_pins_the_output_cap_only_when_it_was_chosen (compiled default → None; override 16 384 / 4 096 kept).

Docs

  • docs/design/architecture.md § resolved model.

Compatibility

  • Changes the wire max_tokens sent for effort-pinned Anthropic routes that relied on the compiled default. ResolvedModel.max_output_tokens records the effective value as before. No protocol/schema change.

Follow-ups

  • Live qualification on the LiteLLM route at effort: max (not run here).

Evidence

Operator store, read-only: two provider_output_truncated runs on litellm/us.anthropic.claude-fable-5-1 (2026-09-23, 2026-09-25). Every failing turn persisted assistant_content_json = [] with output_tokens = 16384; every continuation request had input_tokens = 2 uncached (byte-identical resend). Route-wide since 09-10: 3 935 turns, 49 truncated, 31 empty, ≈ 671 k output tokens and ≈ 2 h wall producing nothing.

Review round (Codex)

  • Fixed: the lifted cap is now clamped to a managed policy.max_output_tokens.
  • Fixed: reasoning_effort: none no longer triggers the lift.
  • Fixed (important, revised in round 2): the TUI/headless paths persisted the compiled default into every new session row, which the loader read as a Runtime override and refused to lift, so the feature did not apply to ordinary sessions. Round one filtered the value at load, which would have discarded an explicit --max-output-tokens 16384; that is withdrawn. Instead pickers, the configured default, the worker selection and the headless path materialise max_output_tokens into ModelSelection only when its provenance is not Compiled (chosen_max_output_tokens), so a row records a choice, never the default of its day. Legacy 2 048 / 4 096 rows are still treated as unset.
  • Fixed: Bedrock Converse removed from the predicate and docs; effort is rejected at load on that wire, so the branch could never run.
  • Fixed: the original commit referenced RR8.4's effort field one commit early and did not compile standalone; the hunk moved to feat(delegation): choose a sub-agent's reasoning effort from its roster role (RR8.4) #201.
  • Fixed (round 3, real): the lifted wire cap fed the 4 MiB storage backstop at 32 bytes/token; a 128 000 ceiling left 32 KiB for the prompt and would have rejected every effort-enabled session before its first request. The storage reserve is now capped at the default's 512 KiB (the enlarged cap holds hidden reasoning, never transcript). Test: a_lifted_wire_cap_does_not_consume_the_storage_backstop.
  • Fixed (round 3): max_output_tokens: Clear restores compiled provenance instead of reading as an operator pin. protocol.md notes the cap exception.
  • Declined (round 3): migrating pre-existing rows that recorded 16 384 (unchanged behaviour, not a regression); route_direct copying the fallback cap (opt-in Jev routing, out of scope); nested gateway/bedrock/anthropic.… ids (hypothetical).
  • Declined: clamping each request to the remaining run output budget (pre-existing after-the-turn meter semantics, out of scope).

Gates (run on the stack tip and on this branch's tip)

  • cargo fmt --all -- --check ✅
  • cargo clippy --workspace --all-targets --all-features -- -D warnings ✅ (every branch tip)
  • cargo test --workspace ✅ all passing at the stack tip; each intermediate tip compiles and passes qq/qq-core/qq-provider on its own.
  • cargo test -p qq-provider --no-default-features --features test-support ✅ 184 passed.
  • wasm32 qq-client build ✅

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-28T05:24:09.397171Z 53c470a New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@lg2m
lg2m added this pull request to stack #202 September 26, 2026 06:44

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 48637f0e89

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/runtime.rs Resolved
Comment thread src/runtime.rs Resolved
Comment thread src/runtime.rs Resolved
Comment thread docs/design/architecture.md Resolved
Comment thread src/runtime.rs Resolved
@lg2m
lg2m force-pushed the fix/eng-955-rr8-effort-aware-output-cap branch from 48637f0 to 8062cc6 Compare September 26, 2026 19:00

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8062cc6848

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/runtime.rs Resolved
@lg2m
lg2m force-pushed the fix/eng-955-rr8-effort-aware-output-cap branch from 8062cc6 to 2a4cdfb Compare September 26, 2026 19:36

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2a4cdfbc1a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/runtime.rs Resolved
Comment thread src/runtime.rs Resolved
Comment thread src/runtime.rs Resolved
Comment thread src/runtime.rs Resolved
Comment thread src/runtime.rs Resolved
Comment thread docs/design/architecture.md Resolved
@lg2m
lg2m force-pushed the fix/eng-955-rr8-effort-aware-output-cap branch from 2a4cdfb to d5a2eb7 Compare September 26, 2026 19:55

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d5a2eb72e5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/design/architecture.md Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e798b17fbe

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/runtime.rs Resolved
Comment thread crates/qq-core/src/sessions/context.rs Resolved
…ng shares it (RR8.3)

The compiled 16 384 default is sized for visible output. On Anthropic
Messages, Bedrock Converse, and Anthropic models behind an OpenAI-compatible
gateway, extended thinking is billed inside the same max_tokens, so a set
reasoning_effort spent the whole cap on hidden reasoning and the run saw an
empty truncation. With effort set on such a route, the wire cap now resolves
to the catalog ceiling unless the operator configured max_output_tokens
themselves (any non-compiled provenance). Run budgets still bound spend.

Also the original RR8 item: a per-session max_output_tokens persisted below
the current default (2 048 / 4 096 from older releases) is treated as unset.

Tests: reasoning_effort_lifts_the_default_output_cap_where_thinking_shares_it
(Anthropic wire, gateway id, no effort, explicit override/config, Responses
wire, no catalog ceiling),
a_persisted_output_limit_below_the_default_is_treated_as_unset.

Linear: ENG-955
…piled default session cap as unset (RR8.3 review)

Four review findings on the effort-aware output cap:

- A managed `policy.max_output_tokens` validated the configured value but the
  lift then replaced it with the catalog ceiling. The lifted cap is now
  clamped to the policy ceiling.
- `reasoning_effort: none` disables thinking; there is no hidden budget to
  make room for, so it no longer triggers the lift (like `Default`).
- The TUI and headless paths materialise the compiled default (16 384) into
  every new session's `ModelSelection`, which the loader then saw as a
  `Runtime` override and refused to lift. That value is treated as unset at
  load, exactly like the older 2 048 / 4 096 defaults, so the lift applies to
  ordinary sessions. Any other persisted value is still an operator's choice.
- Bedrock Converse is removed from the documented lift: effort is unsupported
  on that wire and rejected at load, so the branch could never run.

Linear: ENG-955
….3 review 2)

Treating a persisted 16 384 as unset discarded an explicit
`--max-output-tokens 16384` (and, via the legacy list, 4 096 / 2 048). The
value-based filter is withdrawn for the current default. Instead the source of
the problem is fixed: the TUI pickers, the configured-model default, the
legacy worker selection, and the headless path no longer materialise the
compiled default into `ModelSelection.max_output_tokens`. A new session row
pins the cap only when its provenance is not `Compiled`, so the row records a
choice, never the default of its day, and the reasoning-aware lift applies to
ordinary sessions. Legacy 2 048 / 4 096 rows are still treated as unset.

`ClientSnapshot::provenance` is exposed for the client catalog path. Test:
a_new_session_pins_the_output_cap_only_when_it_was_chosen.

Linear: ENG-955
…ap (RR8.3 review 3)

The lifted wire cap fed the session storage backstop, which reserves 32 bytes
per output token against a 4 MiB store: a 128 000-token ceiling reserved
4 161 568 bytes and left 32 KiB for the whole prompt, so every effort-enabled
Anthropic session would have been rejected as an irreducible storage overflow
before its first request. The reserve is now capped at what the 16 384 default
yields; the enlarged wire cap exists for hidden reasoning, which is never
persisted as transcript. Window arithmetic still sees the real cap. Test:
a_lifted_wire_cap_does_not_consume_the_storage_backstop.

Also: `max_output_tokens: Clear` restores the compiled default and now
restores compiled provenance too, instead of recording the clearing layer as
an operator's cap. Test: clearing_max_output_tokens_restores_compiled_provenance.

protocol.md's description of the resolved cap notes the exception.

Linear: ENG-955
@lg2m
lg2m force-pushed the fix/eng-955-rr8-effort-aware-output-cap branch from e798b17 to 53c470a Compare September 28, 2026 05:13
@lg2m
lg2m merged commit 6d8a9ba into main Sep 28, 2026
8 checks passed
@lg2m
lg2m deleted the fix/eng-955-rr8-effort-aware-output-cap branch September 28, 2026 05:16

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 53c470acab

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

let output_tokens = u64::from(input.max_output_tokens);
let storage_reserve_bytes = output_tokens
.saturating_mul(CONSERVATIVE_OUTPUT_BYTES_PER_TOKEN)
.min(MAX_OUTPUT_STORAGE_RESERVE_BYTES)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Reserve space for persisted Anthropic reasoning replay

When an effort-enabled Anthropic turn produces more than 512 KiB of hidden thinking replay after the prompt/history has consumed the remaining 4 MiB allowance, this clamp admits the request even though completed thinking is serialized into ProviderEvent::Replay, attached to the assistant message, and counted and persisted at turn commit. reserve_context_capacity can therefore fail only after the provider has completed and incurred cost, leaving the completed turn unpersisted. Fresh evidence beyond the earlier visible-output-reserve discussion is that this supposedly storage-free hidden reasoning is itself persisted as opaque continuation replay, so its storage must be represented in admission.

AGENTS.md reference: AGENTS.md:L79-L82

Useful? React with 👍 / 👎.

Field::Missing => {}
Field::Set(_) => self.provenance.max_output_tokens = Some(source.clone()),
Field::Clear => {
self.provenance.max_output_tokens = Some(SourceIdentity::virtual_source(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Retain the clearing layer in max-output provenance

When a project, inline, or managed layer uses max_output_tokens: Clear, replacing its source with a synthetic compiled source makes qq config explain max_output_tokens report compiled defaults instead of the layer that actually cleared the earlier cap. Fresh evidence beyond the earlier reasoning-lift fix is the user-facing diagnostic regression: the repository documents config explain as identifying which layer set a value, and other cleared fields explicitly retain the clearing source. Track set-versus-clear separately for lift decisions while preserving the real provenance here.

Useful? React with 👍 / 👎.

Comment thread src/runtime.rs
qq_provider::ReasoningEffort::Default | qq_provider::ReasoningEffort::None
)
}) && (api == ProviderApi::AnthropicMessages
|| anthropic_model_behind_a_gateway(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restrict gateway lifting to Chat Completions

When a custom or LiteLLM route uses OpenAiResponses with an Anthropic-looking ID such as us.anthropic.claude-…, this helper is evaluated without checking the resolved API and raises the compiled 16,384 cap to the catalog ceiling. That contradicts this change's explicit Responses-wire behavior—the new test says those routes retain the default—but the fixture uses test-model and therefore misses this branch. Require ProviderApi::OpenAiChatCompletions for gateway detection while retaining the direct AnthropicMessages case.

Useful? React with 👍 / 👎.

Comment thread src/runtime.rs
Comment on lines +1777 to +1780
(Some(model_limit), true) => snapshot
.policy()
.max_output_tokens()
.map_or(model_limit, |ceiling| model_limit.min(ceiling)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Carry the reasoning-aware allowance into compaction

When this branch lifts a high/max-effort Anthropic session, automatic, manual, and in-run compaction still begin summarizer requests at the fixed 8,192-token allowance while forwarding the same reasoning effort. The motivating provider behavior can consume even 16,384 tokens entirely on hidden reasoning: in-run summarization immediately fails on the empty truncation, while the other compaction path can only double once to 16,384 before failing. The session therefore becomes unable to compact once its history fills even though ordinary turns were repaired; carry the reasoning-aware allowance into summarization or suppress the effort there.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant