Skip to content

fix(memory): turn thinking off for memory's short JSON side calls - #4687

Merged
kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/side-requests-thinking
Oct 4, 2026
Merged

kovtcharov-amd merged 2 commits into
amd:mainfrom
kovtcharov:kalin/side-requests-thinking

Conversation

@kovtcharov

@kovtcharov kovtcharov commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

On Qwen3.6-35B-A3B (the local default wherever a GPU holds it), every memory extraction after a turn reasoned until its 4096-token cap and wrote no answer — so memory learned nothing, and each call held the GPU for 2–3 minutes after the user's turn had ended. The agent abandons the call at 60s but Lemonade keeps generating, so calls pile up: on the v0.25 RC a /model switch waited ~12 minutes for six of them to drain. Memory's short JSON side calls (extraction, consolidation, reconciliation, skill distillation) now turn thinking off for local models that have a thinking switch; the main turn is unchanged.

Eval required before merge — this changes what Qwen3.6 is asked to do for memory extraction (an LLM-affecting path). A gaia eval agent run on the gaia_memory category is pending.

🔍 Technical details
  • RC evidence: lemond.log shows six non-streaming requests at out=4096 (prompts 404–1142 tokens), each fired ~100 ms after a turn's Streaming completed; the same call on Gemma produces 179–215 tokens. The TUI's agent log is ERROR-only in user mode, which is why the "extraction abandoned" WARNING never appeared.
  • Root cause: ModelRequirement.thinking=True for Qwen3.6 makes chat_completions send enable_thinking: true on every request unless the caller overrides it, and no memory side call did. Consolidation (1024) and reconciliation (256) had the same flaw with even smaller budgets.
  • New no_thinking_kwargs(model) in lemonade_client.py mirrors the auto-title helper's gate: it returns {} for cloud models and for models without a registered switch.
  • An extraction that still ends on finish_reason=length with no text now logs an ERROR naming the model.
  • Rebases cleanly onto perf(llm): local chat model keeps the conversation cached across side requests #4543: its id_slot=SIDE_SLOT sits on different lines of the same call.

Test plan

  • pytest tests/unit/test_lemonade_cloud_models.py tests/unit/test_memory_mixin.py tests/unit/test_skill_synthesis_incremental.py tests/unit/test_skill_synthesis.py: 489 passed
  • The new call-site tests fail on unfixed main (5 fail on the Qwen3.6 path; the Gemma and cloud "send nothing" cases pass either way)
  • Wire test: a side call to Qwen3.6 reaches Lemonade with enable_thinking: false and the card's non-thinking sampling, streaming and non-streaming
  • python util/lint.py --black --isort
  • gaia eval agent --category gaia_memory on Qwen3.6-35B-A3B (scores the flagship)
  • On a Qwen3.6 TUI session, grep "out=4096" lemond.log stays empty across several turns, and a /model switch loads at once

With Qwen3.6-35B-A3B as the local default, every memory extraction after a
turn reasoned until its 4096-token cap and returned no answer. Each call held
the GPU for 2-3 minutes, outlived the agent's 60s abandon, and queued behind
the next one, so a /model switch waited ~12 minutes for the backlog to drain.

GAIA sends enable_thinking=true on every Qwen3.6 request, side calls
included. Extraction, consolidation, reconciliation and skill distillation
now pass no_thinking_kwargs(model), which turns it off for local models with
a thinking switch and sends nothing for cloud models or models without one.
An extraction that still spends its whole budget on reasoning now logs an
ERROR instead of a WARNING the TUI's user-mode log drops.
@github-actions github-actions Bot added documentation Documentation changes llm LLM backend changes tests Test changes performance Performance-critical changes agents labels Oct 4, 2026
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Verdict: Approve with suggestions. Merge once the gaia_memory eval is back.

On Qwen3.6, memory's background JSON calls spent their whole token budget reasoning, so they returned nothing and held the GPU for minutes after each turn. This PR turns thinking off for those side calls only, and only for local models GAIA has a thinking switch for. The main chat turn, Gemma, and cloud models are unaffected. The fix is narrow and correct, and the tests check what actually goes out over the wire.

  • The eval is still pending. The PR changes what an LLM is asked to do on a memory path, so the project rules require gaia eval agent --category gaia_memory before merge. The PR already lists it as unchecked. Please post the scorecard comparison against the flagship baseline (PASS→FAIL and FAIL→PASS listed separately).

Real-world evidence

N/A: no evidence bundle was produced for this run. The changed surface is an internal LLM side call that needs real Qwen3.6 inference, so it is deferred to the strix-halo lane. The PR's own test plan names the right on-hardware check (grep "out=4096" lemond.log stays empty, and /model switches load at once). Until that and the eval come back, this verdict rests on static review and the unit and wire tests.

🔍 Technical details

Issues

🟡 Eval gate not yet met. This is an LLM-affecting change: the request sent to Lemonade for memory extraction, consolidation, reconciliation and distillation is different now. Per CLAUDE.md, run gaia eval agent --category gaia_memory on the Strix Halo pool (dispatch eval_flagship.yml) and compare it to tests/fixtures/eval_baselines/gaia-flagship/scorecard_gaia_memory.json.

🟢 Duplicate empty-reply warning (memory.py:1789). AgentSDK._warn_if_budget_exhausted (chat/sdk.py:150) already logs a WARNING for finish_reason == "length" with empty text. A reasoning-only extraction will now log a WARNING and then an ERROR. That is harmless, and the ERROR adds the memory context. Just be aware the two messages overlap.

🟢 Coverage is limited to models GAIA registers. no_thinking_kwargs returns {} for any model without a ModelRequirement.thinking entry. A user-chosen thinking model whose template thinks by default (e.g. a Qwen3 hybrid loaded via gaia config set default_model) would still reason to the cap on these calls. The new ERROR log now surfaces that case, which seems like the right trade-off over guessing. Noting it so it's a deliberate choice.

Checked and fine

  • requested_thinking respects an explicit enable_thinking, so the caller's False wins over Qwen3.6's default True. The parametrized wire test confirms the body and the non-thinking sampling profile for both streaming and non-streaming.
  • effective_model returns the Claude model id under use_claude. That id matches no MODELS entry, so no llama.cpp template kwargs leak to Anthropic.
  • AgentResponse.finish_reason is populated by send_messages (chat/sdk.py:507-517), so the new finish_reason == "length" check fires on real responses, not just in mocks.
  • Wrapping send_messages in functools.partial for distill_cluster keeps the distiller's call signature unchanged.

Strengths

  • The helper reuses the auto-title gate (cloud → {}, no switch → {}) instead of adding a second rule for which models think.
  • The tests cover every call site (extraction, consolidation, reconciliation, distillation) plus the negative Gemma and cloud cases. The PR also notes the Qwen3.6 tests fail on unfixed main.
  • Replacing a silent empty extraction with a named ERROR follows the fail-loudly rule.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 4, 2026
Merged via the queue into amd:main with commit c7a3fb0 Oct 4, 2026
@kovtcharov-amd
kovtcharov-amd deleted the kalin/side-requests-thinking branch October 4, 2026 23:35
kovtcharov-amd added a commit to aksh8b/gaia that referenced this pull request Oct 6, 2026
Asking GAIA to summarize a 46-minute meeting returned half a summary:
the `summarize_document` result stopped mid-bullet, before the second
half of the meeting, so the answer listed 3 action items with no owners
where the meeting had 9 with owners. Every summary request went out
under the RAG client's 1,024-token output limit, and a model that
reasons first (Gemma 4, and Qwen3.6, the new large default, which runs
with thinking on) spent most of that before writing. The cut-off reply
was returned as if it were complete. Summaries now get an 8,192-token
budget with thinking off where the model has a switch, a reply the limit
still cuts off is an error instead of a summary, and a section that
fails no longer drops silently out of a multi-section summary.

## Test plan
- [x] Reproduced on a real 46-min meeting recording (Gemma-4-E4B, local
Lemonade): the same summary request with the old budget ends with
`finish_reason: length`, 4,284 chars of reasoning and 755 chars of
summary.
- [x] Same recording end to end through `gaia chat -q "Transcribe …
summary … action items"` on this branch: the summary now covers the
whole meeting (message UUIDs, auth friction, native-binary plan from the
second half were missing before).
- [x] `pytest tests/unit/test_summarize_document_sections.py
tests/unit/test_rag_file_resolution.py tests/unit/test_audio_tools.py`
(60 passed), `pytest tests/unit/rag` (312 passed)
- [x] `python util/lint.py --black --isort --flake8`
- [ ] Eval: `rag_quality` and the meeting/audio scenarios on the CI
Strix Halo pool (summarize_document is a model-visible tool path)

<details>
<summary>🔍 Technical details</summary>

- `_summary_text()` in `rag_tools.py` sends with
`max_tokens=SUMMARY_MAX_TOKENS` and
`no_thinking_kwargs(effective_model)` (the helper amd#4687 added for
memory's side calls), and raises on `finish_reason == "length"`.
- The single-section path returns `status: error` with a hint to answer
from `query_documents`; the section loop now propagates a failure to the
tool's existing error handler instead of `continue`.
- Gemma 4 has no thinking switch (`requested_thinking` is None), so its
reasoning still comes out of the budget; 8,192 leaves room at its 64K
context.
</details>

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents documentation Documentation changes llm LLM backend changes performance Performance-critical changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants