feat: add ContextLimit helper to modelinfo#2982
Merged
Merged
Conversation
Add ContextLimit to centralize model context-window logic, sourcing from models.dev with a fallback. Also update LoadCaps to accept context.Context for proper timeout handling.
docker-agent
reviewed
Jun 3, 2026
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
The ContextLimit helper is implemented correctly. The nil-store early-return, bounded context.WithTimeout, and <= 0 fallback guard all work as intended. The DefaultAnthropicContextLimit constant migration is type-safe (untyped integer constant implicitly converts to int64). All five provider convertDocument call-sites are updated consistently. The LoadCaps context threading is correct. Tests cover the happy path, unknown model, and nil-store cases.
No high or medium severity bugs were found in the changed code.
trungutt
approved these changes
Jun 3, 2026
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.
Model context-window handling was scattered across providers. Each provider either hardcoded a limit (Anthropic had
anthropicContextLimitembedded in its package) or lacked a fallback when the models.dev store was unavailable, risking silent failures or degraded behavior in production environments.This change centralizes context-window logic into a new
ContextLimit(ctx, store, id, fallback)helper inpkg/modelinfo. It first attempts to source the window from the models.dev store with a bounded timeout, then falls back to a provided default. A newDefaultAnthropicContextLimitconstant (200000) replaces Anthropic's hardcoded function, and all five provider packages now usemodelinfo.ContextLimitconsistently.Additionally,
LoadCapsnow accepts acontext.Contextas its first parameter so callers can implement proper timeout behavior. This is wrapped internally withloadCapsTimeoutto bound the underlying models.dev load operation, though callers should understand that the timeout does not cover contention from the shared store lock.