Skip to content

Large context windows (1M Opus) mishandled: wrong get_context_length + compaction hard-capped at 100K #3518

@akhil29

Description

@akhil29

Two related problems cause forge to under-utilize large context windows on Claude Opus 4.x (1M) models.

1. get_context_length() returns 200K for 1M-token Opus models

crates/forge_app/src/dto/anthropic/response.rs:96-101 matches the prefix claude-opus-4- and returns 200_000, incorrectly capturing claude-opus-4-6/4-7/4-8, which are 1M-token models per crates/forge_repo/src/provider/provider.json ("id": "claude-opus-4-8", "context_length": 1000000).

This affects the native Anthropic /models path (the vertex_ai_anthropic path is unaffected since it reads context_length from provider.json).

Suggested fix: return 1_000_000 for the claude-opus-4-6-/4-7-/4-8- prefixes before the generic 200K branch; update the test at response.rs:713-722.

2. Default compaction token_threshold (100K) ignores large windows

The effective compaction trigger is min(configured_token_threshold, context_window * token_threshold_percentage) (crates/forge_domain/src/agent.rs:255-271). The embedded default token_threshold = 100000 (crates/forge_config/.forge.toml) makes the trigger min(100K, 0.7 x 1M) = 100K on a 1M-token model — only ~10% of the window, firing compaction far too early and leaving ~900K tokens unused.

Suggestion: let the percentage cap drive the threshold on large windows (drop the hard 100K default, or make it window-relative).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions