fix(cli): preserve compressed history after session rotation in run_conversation (issue #29926) - #4
Open
zombi3butt wants to merge 4 commits into
Open
fix(cli): preserve compressed history after session rotation in run_conversation (issue #29926)#4zombi3butt wants to merge 4 commits into
zombi3butt wants to merge 4 commits into
Conversation
added 4 commits
May 22, 2026 00:29
When provider hooks silently strip the role="system" message (known with some Ollama Cloud variants), re-inject from original input so SOUL.md is never lost mid-flight. Adds defensive verification in _build_kwargs_from_profile.
…esearch#29920) Two-layer fix for `HTTP 400: invalid message content type: map[string]interface{}`. 1. `_tool_result_content_for_active_model` in run_agent.py — serializes non-string, non-list results (Python dicts/lists from MCP tools or memory helpers) as JSON before appending to messages. Falls back to repr() on serialization failure. 2. `sanitize_api_messages` in agent_runtime_helpers.py — coerces tool role `content` to JSON string as a safety-net before every API call. Catches any tool results that bypass the first layer (e.g. from session restore or manual message manipulation). Fixes the 'model provider failed after retries' loop caused by a single bad tool result poisoning the entire message history.
Three-layer fix for Discord bot-to-bot silence token handling: 1. Entry filter (_handle_message): Drop Discord bot messages with content exactly "NO_REPLY" before they enter the agent loop. When DISCORD_ALLOW_BOTS=mentions, other bots' NO_REPLY must be ignored. 2. Backfill exclusion (_fetch_channel_context): Exclude NO_REPLY sentinel messages from channel history backfill so they don't contaminate session context. 3. Delivery suppression (send): Suppress literal NO_REPLY responses from being sent to Discord channels — it's a control/silence token, not user-facing content. Fixes noisy bot-to-bot loops caused by agent silence being surfaced as empty-response retries.
…onversation (issue NousResearch#29926) When auto-compression rotates the session mid-run, result["messages"] contains the inflated post-turn list (compressed baseline + this turn's growth). The CLI was overwriting conversation_history with this inflated list, causing the next turn to start from 130K+ tokens instead of the compressed ~24K baseline — wasting VRAM and API time. Fix: detect session rotation via _cli_last_run_old_session_id (captured before run_conversation in the agent thread) and use agent._session_messages instead of result["messages"] when rotation occurred. Falls back to result["messages"] for normal (non-rotated) runs. Mirrors the gateway path fix in PR NousResearch#29505.
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.
Problem
When auto-compression rotates the session mid-run,
result["messages"]contains the inflated post-turn list (compressed baseline + this turn's growth). The CLI was overwritingconversation_historywith this inflated list, causing the next turn to start from 130K+ tokens instead of the compressed ~24K baseline — wasting VRAM and API time.This is the CLI counterpart of the gateway-side issue addressed in PR NousResearch#29505.