Skip to content

fix: pass MAX_MESSAGE_PAIRS_PER_AGENT to streaming conversation save#468

Open
octo-patch wants to merge 1 commit into
2FastLabs:mainfrom
octo-patch:fix/issue-365-streaming-max-message-pairs
Open

fix: pass MAX_MESSAGE_PAIRS_PER_AGENT to streaming conversation save#468
octo-patch wants to merge 1 commit into
2FastLabs:mainfrom
octo-patch:fix/issue-365-streaming-max-message-pairs

Conversation

@octo-patch

Copy link
Copy Markdown

Fixes #365

Problem

The processStreamInBackground method in orchestrator.ts was calling saveConversationExchange without the maxHistorySize parameter. Streaming responses ignored MAX_MESSAGE_PAIRS_PER_AGENT, causing unbounded conversation history growth.

Solution

Added the missing this.config.MAX_MESSAGE_PAIRS_PER_AGENT parameter to saveConversationExchange inside processStreamInBackground, matching the non-streaming code path.

Testing

The fix is a one-line addition aligning the streaming code path with the already-correct non-streaming path.

…ixes 2FastLabs#365)

The processStreamInBackground method was calling saveConversationExchange
without the maxHistorySize parameter, causing conversation history to grow
unbounded when using streaming responses regardless of MAX_MESSAGE_PAIRS_PER_AGENT
config. This aligns the streaming code path with the non-streaming path.
@cornelcroi

Copy link
Copy Markdown
Collaborator

@claude check this PR. You must check of the problem statement is real, then to analyze the implementation and see if it really fixes the issue.

@claude

claude Bot commented Jun 13, 2026

Copy link
Copy Markdown

Claude finished @cornelcroi's task in 1m 30s —— View job


PR Review: fix/issue-365-streaming-max-message-pairs

Todo List:

  • Gather context and understand the request
  • Verify the problem statement is real (check original code for the bug)
  • Analyze the implementation/fix
  • Check if the Python implementation has the same issue
  • Post final review findings

Problem Statement — Confirmed Real ✓

The bug is genuine. Looking at the diff:

-            agent.id
+            agent.id,
+            this.config.MAX_MESSAGE_PAIRS_PER_AGENT

The processStreamInBackground method in typescript/src/orchestrator.ts was calling saveConversationExchange with only 6 arguments, leaving the 7th (maxHistorySize) as undefined. The function signature at typescript/src/utils/chatUtils.ts:5-12 is:

export async function saveConversationExchange(
  userInput: string,
  agentResponse: string,
  storage: ChatStorage,
  userId: string,
  sessionId: string,
  agentId: string,
  maxHistorySize?: number  // ← was always undefined for streaming
)

Without maxHistorySize, the storage backend has no upper bound on how many messages it retains per agent session, causing unbounded history growth for any streaming agent.


Fix Analysis ✓

The fix is correct and minimal. The non-streaming path at orchestrator.ts:428-436 was already passing this.config.MAX_MESSAGE_PAIRS_PER_AGENT correctly. The streaming path inside processStreamInBackground (lines 533–541 after the fix) is now consistent with it.

The fire-and-forget nature of processStreamInBackground (it's not awaited at the call site on line 411) is intentional — it allows the AccumulatorTransform stream to be returned immediately. The fix correctly applies to the save call inside that background method.


Python Parity — Not Affected ✓

The Python implementation doesn't have this bug. Its save_message helper at python/src/agent_squad/orchestrator.py:350-359 always includes self.config.MAX_MESSAGE_PAIRS_PER_AGENT:

async def save_message(self, message, user_id, session_id, agent):
    if agent and agent.save_chat:
        return await self.storage.save_chat_message(
            user_id, session_id, agent.id, message,
            self.config.MAX_MESSAGE_PAIRS_PER_AGENT  # always passed
        )

The Python streaming path calls this helper at lines 189 and 208, so it was never vulnerable.


Minor Observation ⚠️

No tests were added for the streaming conversation-save code path. The fix is a correct alignment with the non-streaming path, but a test covering that MAX_MESSAGE_PAIRS_PER_AGENT is respected in the streaming path would prevent future regressions. This is a nice-to-have rather than a blocker.


Verdict: The problem statement is real, the fix is correct and complete for the TypeScript implementation, and no Python changes are needed. The PR is ready to merge.

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.

Streaming responses don't respect MAX_MESSAGE_PAIRS_PER_AGENT configuration

2 participants