Skip to content

Comments

fix: add default limit of 20 to sessions_history tool [AI-assisted]#12433

Closed
Baoxd123 wants to merge 1 commit intoopenclaw:mainfrom
Baoxd123:fix/sessions-history-default-limit
Closed

fix: add default limit of 20 to sessions_history tool [AI-assisted]#12433
Baoxd123 wants to merge 1 commit intoopenclaw:mainfrom
Baoxd123:fix/sessions-history-default-limit

Conversation

@Baoxd123
Copy link

@Baoxd123 Baoxd123 commented Feb 9, 2026

Summary

Adds a safe default limit of 20 messages to the sessions_history tool when the caller does not specify one.

Problem

When limit is not provided, sessions_history returns all messages from the target session. This can cause instant context overflow in the calling session, especially when querying sessions with large histories (many tool calls, long conversations).

Fix

One-line change in src/agents/tools/sessions-history-tool.ts (line 254):

- : undefined;
+ : 20;

Agents that need more history can explicitly pass a higher limit parameter.

Testing

  • Verified the tool schema already accepts limit as an optional number parameter
  • The change only affects the fallback when limit is not provided
  • No breaking changes — callers explicitly passing limit are unaffected
  • pnpm build && pnpm check && pnpm test (running locally)

AI Disclosure 🤖

  • AI-assisted: Code change identified and made with Claude Code (Opus 4.6), PR authored by OpenClaw agent (Teddy)
  • Testing level: Lightly tested (code review + schema verification, local test pending)
  • Understanding: The change sets a safe default of 20 for the limit parameter fallback in createSessionsHistoryTool(). When params.limit is not a finite number, instead of passing undefined (which fetches all messages), it now defaults to 20.

Fixes #12432

When the caller does not specify a limit, sessions_history returns all
messages from the target session, which can cause context overflow in
the calling session.

Set a safe default of 20 messages. Agents needing more can explicitly
pass a higher limit.

Fixes openclaw#12432
@openclaw-barnacle openclaw-barnacle bot added the agents Agent runtime and tooling label Feb 9, 2026
@Baoxd123 Baoxd123 changed the title fix: add default limit of 20 to sessions_history tool fix: add default limit of 20 to sessions_history tool [AI-assisted] Feb 9, 2026
@Takhoffman Takhoffman self-assigned this Feb 10, 2026
@Takhoffman
Copy link
Contributor

Fixed in #12988.

This will go out in the next OpenClaw release.

If you still see this after updating to the first release that includes #12988, please open a new issue with:

  • your OpenClaw version
  • channel (Telegram/Slack/etc)
  • the exact prompt/response that got rewritten
  • whether Web UI showed the full text vs the channel being rewritten
  • relevant logs around send/normalize (if available)

Link back here for context.

@Takhoffman
Copy link
Contributor

Closing as superseded/already fixed.

#10000 (merged) already addressed this bug class by hard-capping and truncating sessions_history payloads, which prevents context-overflow behavior without requiring this specific limit=20 fallback change.

If we want to enforce a default message-count policy as a product choice (separate from overflow safety), we can open a focused follow-up PR with tests for that behavior.

@Takhoffman Takhoffman closed this Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: 🚨sessions_history tool returns unbounded results when limit is not specified, causing context overflow

2 participants