Skip to content

fix(agent): guard against non-positive context_length poisoning the cache - #85507

Merged
teknium1 merged 2 commits into
mainfrom
fix/context-cache-zero-guard
Aug 13, 2026
Merged

fix(agent): guard against non-positive context_length poisoning the cache#85507
teknium1 merged 2 commits into
mainfrom
fix/context-cache-zero-guard

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

A cached context_length of 0 (corrupted cache, failed probe, manual edit) poisoned the whole resolution chain: 0 is not None short-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() refuses length <= 0; step-1 drops cached <= 0 entries and re-resolves.
  • tests/agent/test_model_metadata.py (ours): never-persisted + dropped-and-re-resolved regression tests.

Validation

Result
test_model_metadata.py 76/76 pass
Sabotage run (guard disabled) both new tests fail as expected, restore → green

Infographic

Zero poisons the cache — non-positive context lengths rejected

Omar Baradei and others added 2 commits August 13, 2026 10:51
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.
@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

૮ >ﻌ< ა ci review

ran on 064d23f — test: regression coverage for the non-positive context-cache

⚠️ Warnings

OSV vulnerability scan · View job

5 known vulnerabilities found in pinned dependencies.

How to fix:

Review the findings in the Security tab. Update the affected dependencies if a patched version is available.


debug info

CI timings

CI timings · View report · View job

Wall time 6m20s vs 5m59s (+5.8%). 13 job(s) slower, 10 faster, 1 unchanged.

  • Python lints / Windows footguns (blocking): -33.0s
  • Python tests / Run tests slice 5/12: +29.0s
  • Python tests / Run tests slice 4/12: +27.0s
  • Python tests / Run tests slice 1/12: +25.0s
  • Python tests / Run tests slice 9/12: +17.0s

@teknium1
teknium1 merged commit d3a8be4 into main Aug 13, 2026
45 checks passed
@teknium1
teknium1 deleted the fix/context-cache-zero-guard branch August 13, 2026 18:05
@alt-glitch alt-glitch added type/bug Something isn't working comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists labels Aug 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint P2 Medium — degraded but workaround exists type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants