Skip to content

fix: consolidate model context-window tables (close eval gpt-5/gpt-4.1 gap)#3194

Merged
Leebana merged 2 commits into
mainfrom
claude/issue-3192-20260719-1715
Jul 20, 2026
Merged

fix: consolidate model context-window tables (close eval gpt-5/gpt-4.1 gap)#3194
Leebana merged 2 commits into
mainfrom
claude/issue-3192-20260719-1715

Conversation

@praisonai-triage-agent

@praisonai-triage-agent praisonai-triage-agent Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Fixes #3192

Summary

The core SDK maintained two independent "model → context-window" tables that had drifted: context/budgeter.MODEL_LIMITS knew the gpt-5 / gpt-4.1 (1M-context) families, but eval/tokens.DEFAULT_CONTEXT_LENGTHS did not — so eval token accounting silently fell back to the default context length for those models.

Change

eval/tokens.py now builds DEFAULT_CONTEXT_LENGTHS from the canonical context/budgeter.MODEL_LIMITS (single source of truth) plus a small _EVAL_EXTRA_LENGTHS table holding eval-only keys (dated Anthropic snapshots, o1 variants, Mistral/DeepSeek/Groq, gpt-4-32k, etc.):

from ..context.budgeter import MODEL_LIMITS as _CANONICAL_LIMITS
DEFAULT_CONTEXT_LENGTHS = {
    **{k: v for k, v in _CANONICAL_LIMITS.items() if k != "default"},
    **_EVAL_EXTRA_LENGTHS,
}

Behaviour

  • gpt-5 / gpt-4.1 (and mini/nano) now resolve to their real 1,047,576 window in the eval path.
  • Every model key previously present in either table is preserved (verified: 0 missing, 0 changed values).
  • Public helpers unchanged: get_model_limit(), get_context_length(), and the DEFAULT_CONTEXT_LENGTH fallback constant.
  • Pure consolidation of static reference data — no new params/exports/dependencies.

Validation

  • tests/unit/eval/test_tokens.py + tests/unit/context/test_tokens.py: 44 passed
  • tests/unit/test_token_budget.py: 29 passed
  • Verified union preserves all 37 original eval keys with identical values; gpt-5/gpt-4.1 now resolve to 1M.

Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Updated model context-window limits used during evaluation and token processing.
    • Improved consistency by using the latest canonical limits while retaining evaluation-specific model overrides.
    • Preserved existing fallback behavior for models without a recognized context length.

…4.1 gap (fixes #3192)

Build eval/tokens DEFAULT_CONTEXT_LENGTHS from the canonical
context/budgeter.MODEL_LIMITS plus eval-specific extras, so gpt-5 and
gpt-4.1 resolve to their real 1M window in the eval path. All prior eval
keys (dated snapshots, o1/mistral/deepseek/groq) are preserved.

Co-authored-by: MervinPraison <MervinPraison@users.noreply.github.com>
@MervinPraison

Copy link
Copy Markdown
Owner

@coderabbitai review

@MervinPraison

Copy link
Copy Markdown
Owner

/review

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@MervinPraison MervinPraison added pipeline/blocked:ci Blocked: CI not green on HEAD pipeline/blocked:manual-review Blocked: requires manual review pipeline/blocked:no-final Blocked: no FINAL @claude trigger yet pipeline/final-claude-pending Reviews done; waiting for FINAL @claude labels Jul 19, 2026
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b634b516-f31e-46cd-8c81-f683a5d12954

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

eval/tokens.py now derives model context lengths from the canonical budgeter limits and merges evaluation-specific model entries, preserving the existing fallback and token-processing behavior while adding canonical model coverage.

Changes

Context limit consolidation

Layer / File(s) Summary
Merge canonical and evaluation-specific limits
src/praisonai-agents/praisonaiagents/eval/tokens.py
Imports MODEL_LIMITS, defines _EVAL_EXTRA_LENGTHS, and constructs DEFAULT_CONTEXT_LENGTHS from both sources while excluding the canonical default entry.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly reflects the main change: consolidating model context-window tables and fixing the eval gpt-5/gpt-4.1 gap.
Linked Issues check ✅ Passed The change matches #3192 by using canonical MODEL_LIMITS, preserving eval-only keys, and resolving gpt-5/gpt-4.1 to 1M windows.
Out of Scope Changes check ✅ Passed No unrelated changes are indicated; the patch stays focused on context-window table consolidation and eval token lookup behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/issue-3192-20260719-1715

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/praisonai-agents/praisonaiagents/eval/tokens.py`:
- Around line 76-80: Update DEFAULT_CONTEXT_LENGTHS after merging the canonical
and evaluation limits so its entries are ordered by descending key length.
Preserve all existing values while ensuring get_context_length checks specific
model names such as “gpt-4-32k” before shorter prefixes such as “gpt-4”.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 035865e5-3ae1-4bc6-9e01-798002e16350

📥 Commits

Reviewing files that changed from the base of the PR and between 4bb3911 and a9cd7d9.

📒 Files selected for processing (1)
  • src/praisonai-agents/praisonaiagents/eval/tokens.py

Comment on lines +76 to +80
DEFAULT_CONTEXT_LENGTHS: Dict[str, int] = {
**{k: v for k, v in _CANONICAL_LIMITS.items() if k != "default"},
**_EVAL_EXTRA_LENGTHS,
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Sort the merged dictionary by key length to fix partial matching precedence.

Because _CANONICAL_LIMITS is unpacked first, general prefixes like "gpt-4" appear before specific models like "gpt-4-32k" (from _EVAL_EXTRA_LENGTHS) in the resulting dictionary. During partial matching in get_context_length, "gpt-4" in "gpt-4-32k-0314" will evaluate to True before the loop ever reaches "gpt-4-32k", incorrectly returning 8192 instead of 32768.

Sort the dictionary keys by length in descending order so that the longest, most specific model names are always checked first.

🐛 Proposed fix
-DEFAULT_CONTEXT_LENGTHS: Dict[str, int] = {
-    **{k: v for k, v in _CANONICAL_LIMITS.items() if k != "default"},
-    **_EVAL_EXTRA_LENGTHS,
-}
+DEFAULT_CONTEXT_LENGTHS: Dict[str, int] = dict(
+    sorted(
+        {
+            **{k: v for k, v in _CANONICAL_LIMITS.items() if k != "default"},
+            **_EVAL_EXTRA_LENGTHS,
+        }.items(),
+        key=lambda item: len(item[0]),
+        reverse=True,
+    )
+)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
DEFAULT_CONTEXT_LENGTHS: Dict[str, int] = {
**{k: v for k, v in _CANONICAL_LIMITS.items() if k != "default"},
**_EVAL_EXTRA_LENGTHS,
}
DEFAULT_CONTEXT_LENGTHS: Dict[str, int] = dict(
sorted(
{
**{k: v for k, v in _CANONICAL_LIMITS.items() if k != "default"},
**_EVAL_EXTRA_LENGTHS,
}.items(),
key=lambda item: len(item[0]),
reverse=True,
)
)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/praisonai-agents/praisonaiagents/eval/tokens.py` around lines 76 - 80,
Update DEFAULT_CONTEXT_LENGTHS after merging the canonical and evaluation limits
so its entries are ordered by descending key length. Preserve all existing
values while ensuring get_context_length checks specific model names such as
“gpt-4-32k” before shorter prefixes such as “gpt-4”.

@greptile-apps

greptile-apps Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a silent drift between two independent model→context-window lookup tables by making eval/tokens.DEFAULT_CONTEXT_LENGTHS derive from context/budgeter.MODEL_LIMITS as the single source of truth. An eval-only overlay (_EVAL_EXTRA_LENGTHS) covers dated Anthropic snapshots, o1 variants, and third-party providers not yet in the canonical table, with a module-load assertion that fails immediately if a key ever appears in both tables.

  • gpt-5 / gpt-4.1 (and mini/nano) now resolve to their correct 1 M-token context window in the eval path instead of silently falling back to the 128 k default.
  • The merged dict is sorted by descending key length so the partial-match loop in get_context_length prefers longer, more-specific keys (e.g. gpt-4-32k) over shorter prefixes (e.g. gpt-4), which is strictly more correct than the previous insertion-order iteration.

Confidence Score: 5/5

Safe to merge — the change is a pure reference-data consolidation with no new runtime logic, no new public API, and the only behavioural difference (gpt-5/gpt-4.1 now resolve to 1 M tokens) is the stated goal.

The merge is deterministic and fully unit-tested. The assertion guard fires at module import time (no deferred risk). Sorting by descending key length strictly improves partial-match precision over the previous insertion-order iteration. No circular imports are introduced, and the canonical table in budgeter.py is not modified, so all existing callers of that path are unaffected.

No files require special attention; the single changed file is self-contained.

Important Files Changed

Filename Overview
src/praisonai-agents/praisonaiagents/eval/tokens.py Consolidates DEFAULT_CONTEXT_LENGTHS by importing MODEL_LIMITS from context/budgeter.py, adds an overlap-guard assertion, and sorts the merged dict by descending key length to improve partial-match precision. No regressions found; the sort change actually makes partial matching more correct.

Reviews (2): Last reviewed commit: "fix: order eval context table by key len..." | Re-trigger Greptile

Comment thread src/praisonai-agents/praisonaiagents/eval/tokens.py Outdated
@MervinPraison

Copy link
Copy Markdown
Owner

@claude You are the FINAL architecture reviewer. If the branch is under MervinPraison/PraisonAI (not a fork), you are able to make modifications to this branch and push directly. SCOPE: Focus ONLY on Python packages (praisonaiagents, praisonai). Do NOT modify praisonai-rust or praisonai-ts. Read ALL comments above from Gemini, Qodo, CodeRabbit, and Copilot carefully before responding.

Phase 1: Review per AGENTS.md

  1. Protocol-driven: check heavy implementations vs core SDK
  2. Backward compatible: ensure zero feature regressions
  3. Performance: no hot-path regressions
  4. SDK value: review in depth whether the change genuinely adds value to the SDK — never add features for the sake of adding them. It must strengthen the SDK (simpler, more user-friendly, robust, world-class, secure). If it does not clearly add value, request changes or recommend rejecting/closing rather than merging scope creep
  5. Do not bloat the Agent class with additional params — only if absolutely required; we already support many params.
  6. Repo routing: agent-callable tools → PraisonAI-Tools; lifecycle plugins → PraisonAI-Plugins; optional sandbox backends → PraisonAI-Plugins (praisonai.sandbox entry point) — request changes if wrongly added to praisonaiagents/

Phase 2: FIX Valid Issues
7. For any VALID bugs or architectural flaws found by Gemini, CodeRabbit, Qodo, Copilot, or any other reviewer: implement the fix
8. Also independently identify and fix any gaps or issues you find in the changed code — do not rely only on prior reviewer feedback
9. Push all code fixes directly to THIS branch (do NOT create a new PR)
10. Comment a summary of exact files modified and what you skipped

Phase 3: Final Verdict
11. If all issues are resolved, approve the PR / close the Issue
12. If blocking issues remain, request changes / leave clear action items

@MervinPraison MervinPraison added pipeline/awaiting-merge-gate FINAL done; waiting for merge gate / CI pipeline/blocked:cooldown Blocked: post-push or @claude cooldown and removed pipeline/final-claude-pending Reviews done; waiting for FINAL @claude pipeline/blocked:no-final Blocked: no FINAL @claude trigger yet labels Jul 19, 2026
@praisonai-triage-agent

praisonai-triage-agent Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor Author

Claude finished @MervinPraison's task —— View job


Final Architecture Review — PR #3194

  • Read AGENTS.md + changed file
  • Verify CodeRabbit finding (partial-match precedence)
  • Verify Greptile finding (overlap assertion)
  • Implement valid fixes
  • Run tests (73 passed)
  • Push & final verdict

Phase 1 — Architecture Review (per AGENTS.md)

Check Verdict
Protocol-driven ✅ Pure static reference-data consolidation in core SDK. No heavy impl added.
Backward compatible ✅ Public API (get_context_length, needs_chunking, DEFAULT_CONTEXT_LENGTHS, DEFAULT_CONTEXT_LENGTH) unchanged. All canonical keys preserved (49 keys, 0 missing, 0 changed values).
Performance ✅ Merge/sort happens once at module import; hot path (get_context_length) unchanged. No new imports beyond the already-lightweight context/budgeter (pure dataclasses, no circular import).
SDK value ✅ Genuinely strengthens SDK: single source of truth eliminates table drift; gpt‑5 / gpt‑4.1 now resolve to their real 1M window in the eval path. No scope creep.
No Agent bloat ✅ No Agent params/exports/dependencies touched.
Repo routing ✅ Correctly scoped to praisonaiagents/eval + context. No misrouted tools/plugins.

Phase 2 — Fixes Implemented

Both reviewer findings were VALID and are now fixed — commit f378222a8, file src/praisonai-agents/praisonaiagents/eval/tokens.py:

  1. CodeRabbit (🟠 Major) — partial-match precedence. Confirmed via repro: because _CANONICAL_LIMITS is unpacked first, general prefix "gpt-4" (8192) preceded specific "gpt-4-32k" (32768). So get_context_length("gpt-4-32k-0314") returned 8192 (direct "gpt-4-32k" worked, but versioned variants fell into partial matching and were shadowed).

    • Fix: DEFAULT_CONTEXT_LENGTHS is now built ordered by descending key length, so specific names are matched before shorter prefixes.
    • Before → after: gpt-4-32k-0314 8192 → 32768
  2. Greptile (P2) — silent shadowing invariant. _EVAL_EXTRA_LENGTHS wins on overlap (last-wins dict unpacking); the "not in canonical table" constraint was only a comment.

    • Fix: Added a module-load assert that fails fast if any eval-only key overlaps canonical MODEL_LIMITS, making the single-source-of-truth invariant explicit.

Skipped: Nothing. Qodo review was paused (no actionable items). No independent issues found beyond the two above.

Validation

tests/unit/eval/test_tokens.py ....... 23 passed
tests/unit/context/test_tokens.py .... 21 passed
tests/unit/test_token_budget.py ...... 29 passed
= 73 passed in 0.63s =

Also verified: 49 keys total, 0 missing/changed canonical values, keys ordered descending by length.

Phase 3 — Verdict

Approve. All reviewer findings resolved; change is minimal, backward‑compatible, and adds clear SDK value. No blocking issues remain. (Note: I can't submit a formal GitHub approval for security reasons — this comment is the review.)

Job run · Branch claude/issue-3192-20260719-1715

Sort DEFAULT_CONTEXT_LENGTHS by descending key length so get_context_length's
partial matching checks specific model names (e.g. gpt-4-32k) before shorter
prefixes (e.g. gpt-4), fixing gpt-4-32k-0314 resolving to 8192 instead of 32768.
Add a module-load assertion so eval-only extras can never silently shadow
canonical MODEL_LIMITS entries.

Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
@MervinPraison MervinPraison added pipeline/blocked:stale-final Blocked: FINAL stale after new commits and removed pipeline/blocked:stale-final Blocked: FINAL stale after new commits labels Jul 19, 2026
@praisonai-triage-agent praisonai-triage-agent Bot removed the pipeline/blocked:cooldown Blocked: post-push or @claude cooldown label Jul 19, 2026
@Leebana
Leebana merged commit f5517eb into main Jul 20, 2026
36 of 37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pipeline/awaiting-merge-gate FINAL done; waiting for merge gate / CI pipeline/blocked:ci Blocked: CI not green on HEAD pipeline/blocked:manual-review Blocked: requires manual review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Core SDK: duplicate model context-window tables have drifted (eval/tokens missing gpt-5 / gpt-4.1)

2 participants