Skip to content

fix(agent): respect deliberately small context windows - #6152

Merged
kovtcharov-amd merged 4 commits into
amd:mainfrom
huong8373tt-beep:fix/context-overflow-small-window-5284
Oct 30, 2026
Merged

kovtcharov-amd merged 4 commits into
amd:mainfrom
huong8373tt-beep:fix/context-overflow-small-window-5284

Conversation

@huong8373tt-beep

Copy link
Copy Markdown
Contributor

Summary

Fixes #5284. Context-overflow handling previously treated literal 4K/8K/16K text in the backend error as proof that the model was loaded with the wrong window. That breaks users who intentionally pin a smaller context window: the turn is re-raised for a reload instead of using the normal trim-and-retry path.

Changes

  • Compare the backend's loaded context with the requested effective context window.
  • Treat an exact ctx_size_override as the requested target when deciding whether a reload is needed.
  • Remove the brittle literal-size heuristic from both streaming and non-streaming paths.
  • Add regression coverage for intentional 8K/16K windows, genuine undersized loads, malformed values, and the reported llama.cpp error wording.

Tests

  • python -m pytest tests/unit/agents/test_context_window_overflow.py -q (5 passed)
  • python -m py_compile src/gaia/agents/base/agent.py tests/unit/agents/test_context_window_overflow.py
  • git diff --check

Generated with AI assistance.

@huong8373tt-beep

Copy link
Copy Markdown
Contributor Author

Fixed the only actionable CI failure in 4f17438b5 by applying the repository’s Black formatting to the two changed files.

Verification on the pushed head:

  • python -m pytest tests/unit/agents/test_context_window_overflow.py → 5 passed
  • uvx black --check src/gaia/agents/base/agent.py tests/unit/agents/test_context_window_overflow.py → passed
  • git diff --check → passed

The local pytest run emitted the pre-existing Windows temporary pytest-link cleanup warning only after the successful test result; it did not affect the exit status. CI has been re-triggered by the push.

Slai Agent Runtime assisted with investigation, implementation, and test execution. The account owner reviewed and authorized this contribution and is responsible for the submitted content.

The original tests checked only the comparison helper and grepped the
source, so they could not catch a regression in the agent loop. These drive
both the streaming and non-streaming overflow branches with 4K/8K/16K
llama.cpp errors and confirm they trim and retry, check that an undersized
load still re-raises for a reload, and exercise the health probe with an
exact client pin, malformed pins and no chat client.

Also drops the comment that still described the removed substring check.
@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Thanks @huong8373tt-beep — dropping the hard-coded 4K/8K/16K list is the right fix, and honouring an exact client pin in the health probe closes the second half of the same bug. I pushed two small things to your branch and merged in current main.

  • Tests now drive the agent loop itself. An overflow naming a 4K, 8K or 16K window now trims and retries on both the streaming and non-streaming paths, and an undersized load still re-raises for a reload. These fail on main and pass here.
  • The comments got shorter. One still described the substring check this PR removes, so it contradicted the code.
🔍 Technical details
  • tests/unit/agents/test_context_window_overflow.py replaces the source-grep test and the tautological error-string test with: helper boundaries (negative, float, zero, larger-than-requested), the probe with a client pin (matching pin, load below the pin, malformed pins True/0/-4096/"16384"/16384.0, no chat client), the overflow loop for both branches across six llama.cpp phrasings, the reload re-raise for both branches, and a check that a non-overflow error never consults the probe. 13 of them fail against main's agent loop.
  • Related suites pass: tests/unit/agents, error classification, turn metrics, llamacpp backend (4685 passed). The two local failures, test_registry_load_errors and test_denied_effects, fail the same way on bare main.
  • I also ran the flagship agent once end to end through a cloud model to confirm a normal tool-using turn is unaffected.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 30, 2026
Merged via the queue into amd:main with commit 642e614 Oct 30, 2026
31 checks passed
@kovtcharov-amd kovtcharov-amd mentioned this pull request Oct 30, 2026
6 of 12 tasks
akshat-lakhera pushed a commit to akshat-lakhera/gaia that referenced this pull request Oct 31, 2026
## Why this matters

v0.25.4 is cut for Arabic support: the Agent UI runs right to left in
Arabic, and people can ask about Arabic, English or mixed documents in
either language (amd#6165). It also adds a local-only mode that keeps every
AI request on the PC, image indexing, and email thread reading for the
GAIA agent. Among the fixes, chats no longer get stuck on "Waiting for
the GPU", and file paths resolve to the chat's folder and the real
Documents folder. 59 commits since v0.25.3; the notes are in
`docs/releases/v0.25.4.mdx` and credit 7 outside contributors.

This is a patch carrying 8 `feat` commits, approved as v0.25.4 for the
Arabic RC.

## Test plan

- [x] `python util/validate_release_notes.py docs/releases/v0.25.4.mdx
--tag v0.25.4` passes, and with `--tag v0.25.4-rc1`
- [x] `mintlify validate` (from `docs/`) passes
- [x] `python util/release_versions.py --check`, `python
util/check_doc_links.py --internal-only` and `python
util/check_doc_versions.py` pass
- [x] `python util/check_component_core_api.py --release-version 0.25.4`
passes
- [x] `pytest tests/unit/test_docs_json_release.py
tests/unit/test_check_component_core_api.py
tests/unit/test_release_tag.py tests/unit/test_hub_core_version_gate.py
tests/unit/test_release_versions.py
hub/agents/gaia/python/tests/test_npm_doc_min_version.py`: 230 passed
- [x] Re-run the above after amd#6165 merged and main was merged in
- [ ] CI green on the merge commit
- [ ] `release_train_dryrun.yml` passes on that commit before the RC tag

## Evals to re-run on the RC tag

LLM-affecting PRs merged without per-PR evals; run these on
`v0.25.4-rc1`:

- `rag_quality` and `real_world` (amd#6165, amd#6057)
- `gaia_rag` and `gaia_media` (amd#5651)
- `gaia_email` (amd#6124)
- `gaia_skills_tasks` and `gaia_skills_lifecycle` (amd#5450, amd#5454, amd#6080)
- `gaia_files` and `gaia_shell` (amd#6069, amd#6074, amd#6120)
- `gaia_code` (amd#6056)
- `gaia_core` and `context_retention` (amd#6152)
- `gaia_data` and `tool_selection` (amd#6053, amd#6130)
- `memory` and `gaia_memory` (amd#6127, amd#6081)
- `gaia_tool_selection` for tool confirmations (amd#5541)

## Release checklist

- [ ] Keep amd#6114 unmerged until v0.25.4 is tagged, so main stays on
0.25.4
- [ ] Freeze main, wait for green CI on the exact commit, pass
`release_train_dryrun.yml`, then push `v0.25.4-rc1` (the RC freezes its
own flagship; no agent release needed)
- [ ] Before the final: release the flagship from the release commit
(`agent-pkg-gaia-v<next>`), merge its pin-lock PR, and pass
`check_flagship_release.py`
- [ ] Extend the changelog if main gains commits before the tag
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(agent): an overflow on a deliberately small window (4K/8K/16K) is always treated as a bad load

2 participants