Repository navigation
fix(context): calibrate the chars/4 guard estimate with provider-reported prompt_tokens - #15054
Merged
diegosouzapw merged 137 commits intoOct 6, 2026
Conversation
This was referenced Sep 29, 2026
diegosouzapw
changed the base branch from
release/v3.8.51
to
release/v3.8.52
September 29, 2026 11:17
Owner
|
Re-homed to |
added 2 commits
October 7, 2026 02:30
…rted prompt_tokens Refs diegosouzapw#14931. Part 2 of a 3-part series on the context-guard false kill: - Part 1: sibling-side limit resolution (combo limits) - Part 2 (this PR): estimator calibration - Part 3: proactive-compression log basis labels The issue stays open until all three land. The flat chars/4 estimator prices tool-schema JSON at prose density. True density is tokenizer-dependent (o200k ~4.7 chars/token, Qwen-family ~25), so a static ratio cannot cover both — cross-checked with js-tiktoken in the diegosouzapw#14931 thread. Instead, learn it: every completed request already carries usage.prompt_tokens from the provider; an EMA of actual/estimated is kept per (provider, model) bucket, split by tools presence (agent traffic is ~90% tool schema, chat traffic ~0%). The next estimate for the same shape is scaled by that factor. Safety: cold start is factor 1.0 (byte-identical legacy behavior); factor clamped to [0.15, 2.0]; wild ratios (<0.05, >20) and tiny estimates rejected; multi-leg tool-loop usage sums skipped (they re-count resent history); in-memory only (a restart re-learns, never worse than status quo); OMNIROUTE_ESTIMATOR_CALIBRATION=off disables everything. Wiring lives in handlers/chatCore/contextEstimation.ts (next to the raw estimate it scales, and outside the frozen chatCore.ts budget): the calibrated estimate feeds the last-resort compaction and enforceOutputTokenBudget through the same factor so the basis stays consistent, and the streaming + non-streaming completion paths both record observations. Tool-loop aggregates are marked and skipped — their prompt_tokens re-counts history sent on each leg.
…llow the house format
skygunner
force-pushed
the
fix/14931-estimator-usage-calibration
branch
from
October 6, 2026 16:35
35fefc5 to
2b8d76b
Compare
…locales (diegosouzapw#15666) * docs(i18n): refresh QUALITY_GATES mirrors across 66 locales * docs(i18n): re-adopt target hashes after pre-commit formatting * docs(i18n): refresh CONTRIBUTING mirrors across 66 locales * docs(i18n): re-adopt target hashes after pre-commit formatting
…gosouzapw#15202) (diegosouzapw#15213) Validated in a local merge-train on a clean-install host (FAST gates green: static + changed tests + vitest on the combined tree; audit.test.ts verified passing on base and PR tree when the machine is idle).⚠️ base-red inherited: diegosouzapw#15306
…iegosouzapw#14725) Validated in a local merge-train on a clean-install host (FAST gates green: static + changed tests + vitest on the combined tree; audit.test.ts verified passing on base and PR tree when the machine is idle).⚠️ base-red inherited: diegosouzapw#15306
…ion successes (diegosouzapw#14805) Validated in a combined board on the current release tip: 165 focused tests (0 failures), typecheck:core, open-sse typecheck, gate-manifest, mutation-test-coverage, file-size, changelog-integrity, complexity, env-doc-sync, test-discovery, vitest-exclusions, error-helper, test-masking, cli-i18n and the i18n gates green. Thank you for the contribution.
diegosouzapw#15449) Validated in a combined board on the current release tip: 165 focused tests (0 failures), typecheck:core, open-sse typecheck, gate-manifest, mutation-test-coverage, file-size, changelog-integrity, complexity, env-doc-sync, test-discovery, vitest-exclusions, error-helper, test-masking, cli-i18n and the i18n gates green. Thank you for the contribution.
…iegosouzapw#15451) Validated in a combined board on the current release tip: 165 focused tests (0 failures), typecheck:core, open-sse typecheck, gate-manifest, mutation-test-coverage, file-size, changelog-integrity, complexity, env-doc-sync, test-discovery, vitest-exclusions, error-helper, test-masking, cli-i18n and the i18n gates green. Thank you for the contribution.
… backend (diegosouzapw#15462) Validated in a combined board on the current release tip: 165 focused tests (0 failures), typecheck:core, open-sse typecheck, gate-manifest, mutation-test-coverage, file-size, changelog-integrity, complexity, env-doc-sync, test-discovery, vitest-exclusions, error-helper, test-masking, cli-i18n and the i18n gates green. Thank you for the contribution.
…rd stays off (diegosouzapw#15455) Brought the tip into the branch and revalidated: focused tests, typecheck:core, open-sse typecheck, file-size, changelog-integrity, complexity and mutation-test-coverage green. Thank you for the contribution.
…uses only that model for 5 minutes (diegosouzapw#15474) Brought the tip into the branch and revalidated: focused tests, typecheck:core, open-sse typecheck, file-size, changelog-integrity, complexity and mutation-test-coverage green. Thank you for the contribution.
…egosouzapw#15482) Brought the tip into the branch and revalidated: focused tests, typecheck:core, open-sse typecheck, file-size, changelog-integrity, complexity and mutation-test-coverage green. Thank you for the contribution.
… copies (diegosouzapw#15316) Brought the tip into the branch and revalidated: focused tests, typecheck:core, open-sse typecheck, file-size, changelog-integrity, complexity and mutation-test-coverage green. Thank you for the contribution.
…15383) Brought the tip into the branch and revalidated: focused tests, typecheck:core, open-sse typecheck, file-size, changelog-integrity, complexity and mutation-test-coverage green. Thank you for the contribution.
…iegosouzapw#15475) Brought the tip into the branch and revalidated: focused tests, typecheck:core, open-sse typecheck, file-size, changelog-integrity, complexity and mutation-test-coverage green. Thank you for the contribution.
…egosouzapw#15562) Brought the tip into the branch and revalidated: focused tests, typecheck:core, open-sse typecheck, file-size, changelog-integrity, complexity and mutation-test-coverage green. Thank you for the contribution.
… request (diegosouzapw#15484) Brought the tip into the branch and revalidated: focused tests, typecheck:core, open-sse typecheck, file-size, changelog-integrity, complexity and mutation-test-coverage green. Thank you for the contribution.
…aded (diegosouzapw#15159 B-03) (diegosouzapw#15384) Onda 1 (jonlwheat2-gif) validada num único board em `.claude/worktrees/batch-w1` sobre `origin/release/v3.8.52` (`2eee95e1`). Evidência do board: 93 testes focados passaram (sanitização de áudio, Kie, import degradado, literais das 8 rotas de auth, hop MCP, freetheai, check-error-helper). `typecheck:core` limpo. changelog-integrity, complexity e cognitive-complexity dentro do baseline. O arquivo `src/shared/constants/providers/apikey/gateways.ts` cresce 1544→1547 por causa do diegosouzapw#15520; o rebaseline entra no follow-up desta onda.⚠️ base-red inherited: diegosouzapw#15306 (timeouts de suíte no tip, não neste diff). Obrigado, @jonlwheat2-gif.
…afe (diegosouzapw#15159) (diegosouzapw#15394) Onda 1 (jonlwheat2-gif) validada num único board em `.claude/worktrees/batch-w1` sobre `origin/release/v3.8.52` (`2eee95e1`). Evidência do board: 93 testes focados passaram (sanitização de áudio, Kie, import degradado, literais das 8 rotas de auth, hop MCP, freetheai, check-error-helper). `typecheck:core` limpo. changelog-integrity, complexity e cognitive-complexity dentro do baseline. O arquivo `src/shared/constants/providers/apikey/gateways.ts` cresce 1544→1547 por causa do diegosouzapw#15520; o rebaseline entra no follow-up desta onda.⚠️ base-red inherited: diegosouzapw#15306 (timeouts de suíte no tip, não neste diff). Obrigado, @jonlwheat2-gif.
…gosouzapw#15310) Onda 5. Este squash entra com o crédito de @fidelix (fix(sse): reject premature upstream EOF in Responses translation). O board único validou os 28 PRs juntos: file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity 2976/3218, cognitive 1358/1437. Testes focados: 545 passaram, 0 falharam, 3 skip em 52 arquivos. Cinco timeouts de resilience-http-e2e eram carga e passaram isolados. O rebaseline de file-size e o adopt de i18n ficam num follow-up, fora deste squash.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @fidelix.
…15337) Onda 5. Este squash entra com o crédito de @zebrajaeger (fix(sse): preserve Copilot discovered endpoint routing). O board único validou os 28 PRs juntos: file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity 2976/3218, cognitive 1358/1437. Testes focados: 545 passaram, 0 falharam, 3 skip em 52 arquivos. Cinco timeouts de resilience-http-e2e eram carga e passaram isolados. O rebaseline de file-size e o adopt de i18n ficam num follow-up, fora deste squash.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @zebrajaeger.
Onda 5. Este squash entra com o crédito de @Kizuno18 (feat(proxy): add an operator HTTP/2 opt-out). O board único validou os 28 PRs juntos: file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity 2976/3218, cognitive 1358/1437. Testes focados: 545 passaram, 0 falharam, 3 skip em 52 arquivos. Cinco timeouts de resilience-http-e2e eram carga e passaram isolados. O rebaseline de file-size e o adopt de i18n ficam num follow-up, fora deste squash.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @Kizuno18.
…ken-plan (diegosouzapw#15308) Onda 5. Este squash entra com o crédito de @LazyGatto (fix(providers): live model discovery for xiaomi-mimo / xiaomi-mimo-token-plan (diegosouzapw#15307)). O board único validou os 28 PRs juntos: file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity 2976/3218, cognitive 1358/1437. Testes focados: 545 passaram, 0 falharam, 3 skip em 52 arquivos. Cinco timeouts de resilience-http-e2e eram carga e passaram isolados. O rebaseline de file-size e o adopt de i18n ficam num follow-up, fora deste squash.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @LazyGatto.
…souzapw#15301) Onda 5. Este squash entra com o crédito de @VihaanR (fix(cli): expose built-in auto combos to Claude Code discovery). O board único validou os 28 PRs juntos: file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity 2976/3218, cognitive 1358/1437. Testes focados: 545 passaram, 0 falharam, 3 skip em 52 arquivos. Cinco timeouts de resilience-http-e2e eram carga e passaram isolados. O rebaseline de file-size e o adopt de i18n ficam num follow-up, fora deste squash.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @VihaanR.
…souzapw#15573) Onda 5. Este squash entra com o crédito de @qirh (feat(providers): add Perplexity integration attribution header). O board único validou os 28 PRs juntos: file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity 2976/3218, cognitive 1358/1437. Testes focados: 545 passaram, 0 falharam, 3 skip em 52 arquivos. Cinco timeouts de resilience-http-e2e eram carga e passaram isolados. O rebaseline de file-size e o adopt de i18n ficam num follow-up, fora deste squash.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @qirh.
…egosouzapw#15559) Onda 5. Este squash entra com o crédito de @christianmahardhika (fix(qoder): make PAT validation and transient CLI failures robust). O board único validou os 28 PRs juntos: file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity 2976/3218, cognitive 1358/1437. Testes focados: 545 passaram, 0 falharam, 3 skip em 52 arquivos. Cinco timeouts de resilience-http-e2e eram carga e passaram isolados. O rebaseline de file-size e o adopt de i18n ficam num follow-up, fora deste squash.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @christianmahardhika.
…egosouzapw#15582) (diegosouzapw#15631) Onda 5. Este squash entra com o crédito de @alltomatos (fix(antigravity): strip stream field from Google request envelope (diegosouzapw#15582)). O board único validou os 28 PRs juntos: file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity 2976/3218, cognitive 1358/1437. Testes focados: 545 passaram, 0 falharam, 3 skip em 52 arquivos. Cinco timeouts de resilience-http-e2e eram carga e passaram isolados. O rebaseline de file-size e o adopt de i18n ficam num follow-up, fora deste squash.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @alltomatos.
…gosouzapw#15357) Onda 5. Este squash entra com o crédito de @kalpakprod (fix: prevent proxied stream crashes and normalize Groq reasoning). O board único validou os 28 PRs juntos: file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity 2976/3218, cognitive 1358/1437. Testes focados: 545 passaram, 0 falharam, 3 skip em 52 arquivos. Cinco timeouts de resilience-http-e2e eram carga e passaram isolados. O rebaseline de file-size e o adopt de i18n ficam num follow-up, fora deste squash.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @kalpakprod.
) Onda 5. O diegosouzapw#15548 conflitava com o tip porque a release já tinha removido o import de efeito colateral do quota batch (diegosouzapw#15643). A resolução mantém o import nomeado e a chamada explícita depois que os outros imports resolvem. Teste focado `quota-trackers-batch-init`: 3 passaram, 0 falharam. O head no fork foi avançado em fast-forward para `fce0875f`. O board da onda 5: file-size, changelog, i18n, typecheck:core, complexity 2976/3218, cognitive 1358/1437. Testes focados do lote: 545 passaram, 0 falharam, 3 skip.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @wedreamer.
…#15692) Follow-up da onda 5. Os squashes individuais não carregam o rebaseline de file-size nem o adopt de i18n. Teto novo: `providers.ts` 1240, `usageHistory.ts` 1227, `auth.ts` 3666, `openai-responses.ts` 1547, `stream.ts` 3325, `proxyFetch.ts` 1406. Hashes adotados só para `RESILIENCE_GUIDE.md`, `ENVIRONMENT.md` e `AUTO-COMBO.md`. Gates neste branch: file-size OK, i18n drift OK.⚠️ base-red inherited: diegosouzapw#15306
…w#15480) Onda 6. Este squash entra com o crédito de @lorenzozanee (fix(combo): include monthly quota in reset-aware scoring). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @lorenzozanee.
…osouzapw#15479) Onda 6. Este squash entra com o crédito de @lorenzozanee (fix(api): route provider-model handlers through management auth). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @lorenzozanee.
…5542) Onda 6. Este squash entra com o crédito de @lorenzozanee (fix(sse): make streaming fetch-start cap configurable). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @lorenzozanee.
…uzapw#15543) Onda 6. Este squash entra com o crédito de @lorenzozanee (fix(providers): route Command Code Claude models to Messages). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @lorenzozanee.
…15541) Onda 6. Este squash entra com o crédito de @lorenzozanee (docs: clarify npm 11 allow-scripts setup for global installation). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @lorenzozanee.
…iegosouzapw#15413) Onda 6. Este squash entra com o crédito de @QuangBlue (fix(kiro): stop discovery from stamping a fake 200k context window). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @QuangBlue.
…souzapw#15332) Onda 6. Este squash entra com o crédito de @QuangBlue (fix(api): keep Next's upgrade listener off the run-next server). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @QuangBlue.
… runs (diegosouzapw#15331) Onda 6. Este squash entra com o crédito de @QuangBlue (fix(api): standalone server owns SIGTERM so graceful-shutdown cleanup runs). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @QuangBlue.
…pw#15597) Onda 6. Este squash entra com o crédito de @insoln (fix(sse): scope type-only context errors in combo streams). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @insoln.
…ate (diegosouzapw#15598) Onda 6. Este squash entra com o crédito de @insoln (fix(sse): accept first-party Claude empty end_turn in combo quality gate). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @insoln.
…uzapw#12797) (diegosouzapw#15557) Onda 6. Este squash entra com o crédito de @insoln (fix(sse): stabilize standalone compression worker resolution (diegosouzapw#12797)). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @insoln.
…s-platform (diegosouzapw#15572) Onda 6. Este squash entra com o crédito de @Junior-HJ (test(compression): make worker-specifier and RTK TOML assertions cross-platform). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @Junior-HJ.
…namespaced root (diegosouzapw#15452) Onda 6. Este squash entra com o crédito de @yourspraveen (fix(api): stop restricted-key /v1/models leaking aggregator rows via namespaced root). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @yourspraveen.
… Go (diegosouzapw#15453) Onda 6. Este squash entra com o crédito de @yourspraveen (fix(providers): keep a third-party agent's own User-Agent on OpenCode Go). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @yourspraveen.
…fig auto table (diegosouzapw#15467) Onda 6. Este squash entra com o crédito de @yourspraveen (docs(readme): list auto/subscription and auto/thrifty in the zero-config auto table). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @yourspraveen.
…iegosouzapw#15458) Onda 6. Este squash entra com o crédito de @skygunner (fix(combo): keep declared priority order ahead of session stickiness). O board único validou os 19 PRs (sem o diegosouzapw#15412): file-size OK, changelog OK, i18n drift OK, typecheck:core OK, complexity e cognitive dentro do baseline. Testes focados: 390 passaram, 1 skip. O teste novo de GHE Copilot Sonnet 5.5 falhou no head original e foi corrigido no board; esse ajuste entra com o diegosouzapw#15478, fora deste squash. O rebaseline de file-size e o adopt de i18n ficam num follow-up.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @skygunner.
…iegosouzapw#15478) Onda 6. Este squash entra com o crédito de @lorenzozanee (fix(providers): declare Claude target format for GHE Copilot models). O board único validou o conjunto. O teste novo exige `targetFormat: "claude"` em todo modelo GHE Copilot cujo id começa com `claude-`. O catálogo da release já lista `claude-sonnet-5-5` sem esse campo; a linha foi acrescentada no fork para o teste passar, no mesmo formato das outras linhas Claude. O rebaseline de file-size e o adopt de i18n ficam num follow-up, depois dos três PRs restantes da onda.⚠️ base-red inherited: diegosouzapw#15306 Obrigado, @lorenzozanee.
Apply the diegosouzapw#14931 calibration to context estimation and to the streaming and non-streaming tails. The pre-split chatCore patch does not match the release layout.
diegosouzapw
merged commit Oct 6, 2026
d6aa440
into
diegosouzapw:release/v3.8.52
7 of 9 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR (plain language)
The guard estimates input size as "count characters, divide by 4". That is right for prose, but tool-schema JSON's true density depends on the provider's tokenizer: o200k packs it at ~4.7 chars/token while Qwen-family tokenizers reach ~25 — the js-tiktoken cross-check in #14931 showed no single static ratio can cover both (a discount tuned for Qwen would under-estimate for OpenAI-family providers and let genuinely oversized requests through).
So this PR doesn't guess a ratio — it learns one. Every completed request already carries the provider's own
usage.prompt_tokens. An exponential moving average ofactual / estimatedis kept per(provider, model), split into a tools-present and a tools-absent bucket (agent traffic is ~90% tool schema, chat traffic ~0%). The next estimate for the same shape is multiplied by that factor. Cold start is factor 1.0 — byte-identical to today's behavior — and the guard gets more accurate with every request.Safety properties
[0.15, 2.0]— the guard never loses its teeth, and the fix(backend): Context guard rejects Codex CLI at ~50k real tokens: chars/4 estimator over-counts ~1MB of tool schemas 5-6x, checked against a generic 128k fallback limit (model catalog miss → combo-min) #14931 incident ratio (~0.19) sits above the floor.[0.05, 20], estimates under 1,000 tokens, and usage objects without a token count never enter the EMA.prompt_tokensre-counts resent history and would poison the factor.OMNIROUTE_ESTIMATOR_CALIBRATION=off|0|falsedisables recording and application entirely.Wiring
Everything lives in the new
open-sse/services/estimatorCalibration.ts(164 lines). The chatCore integration sits inhandlers/chatCore/contextEstimation.ts— next to the raw estimate it scales, and outside the frozenchatCore.tssize budget (handleChatCoreInnergrows by 8 physical lines):enforceOutputTokenBudget(all re-computations go through the same factor, so the basis stays consistent);(guard-acted estimate, provider prompt_tokens)pairs.Claude-native
input_tokensis accepted alongsideprompt_tokens.Evidence
tests/unit/estimator-calibration.test.ts(10 cases): cold-start identity, bucket isolation, clamping, dirty-ratio rejection, EMA outlier absorption, tool-loop skip,input_tokensacceptance, env off-switch.tests/unit/chatcore-estimator-calibration-14931.test.ts, end-to-end throughhandleChatCore: three requests whose stub upstream reportsprompt_tokensat 1/4 of the chars/4 estimate teach the bucket; a fourth request whose raw estimate (25,000) exceeds the context limit (20,000) then passes the guard — and the same request with calibration disabled is still rejected atlimit 20000(counterfactual control).Relationship to #14931
Combined with Part 1, the incident is closed end-to-end: the limit stops being a baseless 128,000, and the estimate stops pretending 1 MB of Qwen-tokenized tool schemas is prose.
qwen3.8-27bdeployments can then retire theDISABLE_CONTEXT_WINDOW_CHECKSworkaround.