Skip to content

fix(hyperagent): default 1M context for fable/opus/sonnet - #8496

Merged
diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.49from
artickc:fix/hyperagent-1m-context
Jul 26, 2026
Merged

diegosouzapw merged 2 commits into
diegosouzapw:release/v3.8.49from
artickc:fix/hyperagent-1m-context

Conversation

@artickc

@artickc artickc commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Follow-up related to HyperAgent (#7994 / sticky tool-loop work).

getTokenLimit('hyperagent', 'fable-latest') was falling through to the generic 128k default. Real agentic tool-loop prompts (catalog + history) easily exceed that and fail with:

Input exceeds the context window for hyperagent/fable: estimated 137042 input tokens, limit 128000

Claude-family agents on HyperAgent (Fable / Opus / Sonnet) should use a 1M context window by default.

Changes

  • hyperagent registry: defaultContextLength: 1_000_000 + per-model contextLength
  • hyperagentModels.ts: HYPERAGENT_DEFAULT_CONTEXT_LENGTH = 1_000_000 on catalog models
  • contextManager.ts: resolve hyperagent/ha (and fable/opus wire ids) to 1M before models.dev DB / generic default

Tests

node --import tsx -e "import { getTokenLimit } from './open-sse/services/contextManager.ts'; console.log(getTokenLimit('hyperagent','fable-latest'))"
# → 1000000

node --import tsx --test tests/unit/context-manager.test.ts tests/unit/service-context-manager.test.ts
# 30/30 PASS

Risk

Low — only raises the pre-flight token budget for HyperAgent; does not change chat protocol. Env override CONTEXT_LENGTH_HYPERAGENT still wins if set.

HyperAgent Claude-family models (fable, opus, sonnet) were falling through
getTokenLimit to the generic 128k default. Agentic tool-loop prompts with
large catalogs then failed with context_length_exceeded (~137k tokens).

- defaultContextLength + per-model contextLength = 1_000_000 on hyperagent registry
- DEFAULT_LIMITS.hyperagent / ha = 1M
- Resolve hyperagent/ha (and fable/opus wire ids) before models.dev DB fallback

Verified: getTokenLimit('hyperagent','fable-latest') === 1000000; context-manager tests 30/30.
@artickc
artickc requested a review from diegosouzapw as a code owner July 24, 2026 23:28
@diegosouzapw

Copy link
Copy Markdown
Owner

Thanks for chasing this down — getTokenLimit('hyperagent', 'fable-latest') really was falling through to the generic 128k default, and the registry-based fix (defaultContextLength on the provider entry + per-model contextLength in hyperagentModels.ts) is exactly the right pattern; it matches how dozens of other providers (windsurf, devin, github, etc.) already declare per-model context windows.

One thing we need adjusted before merge: the new block added at the top of resolveTokenLimit in contextManager.ts checks model.toLowerCase().includes(...) for strings like claude-opus-4, claude-fable, sonnet-latest, claude-sonnet-5 — but that check isn't scoped to the hyperagent provider, so it also fires for any other provider whose model id happens to contain those substrings (we verified this hits windsurf, anthropic, github, ghe-copilot, bedrock and more). Since it runs before the existing models.dev/registry per-model lookup, it silently overrides those providers' correctly-configured (smaller) context windows with 1M.

We tested and confirmed that the registry-only part of your change (hyperagent/index.ts + hyperagentModels.ts) is actually sufficient on its own to fix getTokenLimit for both hyperagent and its ha alias — no changes to contextManager.ts are needed at all. Could you drop the new p === "hyperagent" || p === "ha" / model-substring block from contextManager.ts (or, if you'd like to keep an explicit short-circuit there for clarity, scope it strictly to the provider check and drop the substring matching), and add a small regression test asserting getTokenLimit('hyperagent'|'ha', 'fable-latest') === 1_000_000? Happy to help iterate on this in your branch.

…ped model-name match

The step-1b branch in resolveTokenLimit() matched fable/opus/sonnet model
name substrings for ANY provider, before the models.dev DB lookup. That
collided with anthropic/claude, kiro, windsurf and bluesminds registries,
which serve the same Claude model ids (e.g. claude-opus-4.7-max,
claude-sonnet-5) with their own accurate per-model contextLength — those
were being clobbered to 1M instead of their real (often 200k) limit.

The registry-level defaultContextLength added on the hyperagent provider
entry already fixes the reported bug (getTokenLimit('hyperagent', ...) ===
1_000_000) on its own, scoped correctly by provider. Remove the redundant,
unscoped substring branch and add regression coverage for every hyperagent
fallback model id plus the cross-provider collision.

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
@diegosouzapw
diegosouzapw merged commit 2d48bb6 into diegosouzapw:release/v3.8.49 Jul 26, 2026
5 checks passed
@diegosouzapw

Copy link
Copy Markdown
Owner

Thanks @artickc — merged into release/v3.8.49 via the local merge-train (validated as one combined tree: full test:unit + test:vitest 274/274 on the 32-core box, tip d4b9ce6016). Your commit keeps its authorship. 🚀

@diegosouzapw diegosouzapw mentioned this pull request Jul 28, 2026
HouMinXi pushed a commit to HouMinXi/OmniRoute that referenced this pull request Aug 2, 2026
…pw#8496)

* fix(hyperagent): default 1M context for fable/opus/sonnet

HyperAgent Claude-family models (fable, opus, sonnet) were falling through
getTokenLimit to the generic 128k default. Agentic tool-loop prompts with
large catalogs then failed with context_length_exceeded (~137k tokens).

- defaultContextLength + per-model contextLength = 1_000_000 on hyperagent registry
- DEFAULT_LIMITS.hyperagent / ha = 1M
- Resolve hyperagent/ha (and fable/opus wire ids) before models.dev DB fallback

Verified: getTokenLimit('hyperagent','fable-latest') === 1000000; context-manager tests 30/30.

* fix(sse): scope hyperagent 1M context fix to the registry, drop unscoped model-name match

The step-1b branch in resolveTokenLimit() matched fable/opus/sonnet model
name substrings for ANY provider, before the models.dev DB lookup. That
collided with anthropic/claude, kiro, windsurf and bluesminds registries,
which serve the same Claude model ids (e.g. claude-opus-4.7-max,
claude-sonnet-5) with their own accurate per-model contextLength — those
were being clobbered to 1M instead of their real (often 200k) limit.

The registry-level defaultContextLength added on the hyperagent provider
entry already fixes the reported bug (getTokenLimit('hyperagent', ...) ===
1_000_000) on its own, scoped correctly by provider. Remove the redundant,
unscoped substring branch and add regression coverage for every hyperagent
fallback model id plus the cross-provider collision.

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

---------

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
muhamadgalihsaputra pushed a commit to niyatna/NiyatnaRoute that referenced this pull request Sep 27, 2026
…pw#8496)

* fix(hyperagent): default 1M context for fable/opus/sonnet

HyperAgent Claude-family models (fable, opus, sonnet) were falling through
getTokenLimit to the generic 128k default. Agentic tool-loop prompts with
large catalogs then failed with context_length_exceeded (~137k tokens).

- defaultContextLength + per-model contextLength = 1_000_000 on hyperagent registry
- DEFAULT_LIMITS.hyperagent / ha = 1M
- Resolve hyperagent/ha (and fable/opus wire ids) before models.dev DB fallback

Verified: getTokenLimit('hyperagent','fable-latest') === 1000000; context-manager tests 30/30.

* fix(sse): scope hyperagent 1M context fix to the registry, drop unscoped model-name match

The step-1b branch in resolveTokenLimit() matched fable/opus/sonnet model
name substrings for ANY provider, before the models.dev DB lookup. That
collided with anthropic/claude, kiro, windsurf and bluesminds registries,
which serve the same Claude model ids (e.g. claude-opus-4.7-max,
claude-sonnet-5) with their own accurate per-model contextLength — those
were being clobbered to 1M instead of their real (often 200k) limit.

The registry-level defaultContextLength added on the hyperagent provider
entry already fixes the reported bug (getTokenLimit('hyperagent', ...) ===
1_000_000) on its own, scoped correctly by provider. Remove the redundant,
unscoped substring branch and add regression coverage for every hyperagent
fallback model id plus the cross-provider collision.

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>

---------

Co-authored-by: diegosouzapw <8016841+diegosouzapw@users.noreply.github.com>
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.

2 participants