Skip to content

fix(cli): preserve compressed history after session rotation in run_conversation (issue #29926) - #4

Open
zombi3butt wants to merge 4 commits into
mainfrom
fix/discord-no-reply-bot-loops
Open

fix(cli): preserve compressed history after session rotation in run_conversation (issue #29926)#4
zombi3butt wants to merge 4 commits into
mainfrom
fix/discord-no-reply-bot-loops

Conversation

@zombi3butt

Copy link
Copy Markdown
Owner

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 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.

This is the CLI counterpart of the gateway-side issue addressed in PR NousResearch#29505.

zombi3butt 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant