fix(agent): guard against non-positive context_length poisoning the cache - #85507
Merged
Conversation
Reapply the non-positive context-length guards onto the post-history-replacement mainline without carrying any stale branch history. save_context_length() now refuses to persist length <= 0 (keeping upstream's normalized _context_cache_key), and get_model_context_length() drops non-positive cache hits at the head of the invalidation chain (Codex/Kimi/MiniMax/Grok branches become elif) so a poisoned entry re-resolves instead of short-circuiting to 0. Refresh of PR #25812; original head d62ed5eb92f057d8c707ba937b44f168f2df0677.
Follow-up to the salvaged #25812 — the original PR shipped without tests.
Contributor
૮ >ﻌ< ა ci reviewran on 064d23f — test: regression coverage for the non-positive context-cache
|
2 tasks
This was referenced Aug 13, 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.
Summary
A cached
context_lengthof 0 (corrupted cache, failed probe, manual edit) poisoned the whole resolution chain:0 is not Noneshort-circuits step 1, so the compressor and every downstream display got context_length=0 forever. This refuses to persist non-positive values and drops any pre-existing non-positive entry so it re-resolves.Salvages #25812 by @OmarB97 (cherry-picked, authorship preserved). The original shipped without tests; we added sabotage-verified regression coverage on top.
Changes
agent/model_metadata.py(@OmarB97):save_context_length()refuseslength <= 0; step-1 dropscached <= 0entries and re-resolves.tests/agent/test_model_metadata.py(ours): never-persisted + dropped-and-re-resolved regression tests.Validation
test_model_metadata.pyInfographic