Skip to content

fix(discord): Apply historyLimit to channel/group sessions to prevent compaction bypass#11356

Merged
Takhoffman merged 3 commits into
openclaw:mainfrom
shadril238:fix/discord-channel-compaction-bypass
Feb 14, 2026
Merged

fix(discord): Apply historyLimit to channel/group sessions to prevent compaction bypass#11356
Takhoffman merged 3 commits into
openclaw:mainfrom
shadril238:fix/discord-channel-compaction-bypass

Conversation

@shadril238

@shadril238 shadril238 commented Feb 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #11224 - Discord channel sessions were bypassing compaction, leading to context overflow errors.

Problem

Discord channel sessions accumulated tokens indefinitely, ignoring the contextTokens limit and compaction settings. This resulted in context overflow errors when sessions exceeded the model's context window (e.g., 211k tokens > 200k limit).

Root Cause

The getDmHistoryLimitFromSessionKey function in history.ts explicitly skipped all non-DM sessions:

if (kind !== "dm") {
  return undefined;  // Channel sessions got no history limit!
}

<!-- greptile_comment -->

<h2>Greptile Overview</h2>

<h3>Greptile Summary</h3>

This change extends the session-key history-limit lookup so that Discord (and other providers) apply `historyLimit` to `channel`/`group` sessions (in addition to existing DM behavior), preventing long-running channel sessions from bypassing compaction and overflowing the model context window. It also introduces a new exported helper `getHistoryLimitFromSessionKey` while keeping `getDmHistoryLimitFromSessionKey` as a deprecated alias.

The only must-fix issue spotted in this PR is the addition of a brand-new `package-lock.json`, which is a large unrelated change and may alter dependency resolution; it should be removed unless the project explicitly wants to start tracking it in this PR.

<h3>Confidence Score: 4/5</h3>

- Mostly safe to merge once the lockfile change is resolved.
- Core logic change is narrow, covered by updated tests, and call sites already use the (aliased) helper for limiting history. The main risk is the new `package-lock.json` addition, which is large and unrelated to the stated fix and can change dependency resolution; removing or explicitly justifying it would reduce merge risk.
- package-lock.json

<!-- greptile_other_comments_section -->

<sub>(5/5) You can turn off certain types of comments like style [here](https://app.greptile.com/review/github)!</sub>

<!-- /greptile_comment -->

@openclaw-barnacle openclaw-barnacle Bot added the agents Agent runtime and tooling label Feb 7, 2026

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment thread package-lock.json Outdated
Comment on lines +1 to +3
{
"name": "openclaw",
"version": "2026.2.4",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected lockfile addition

This PR adds a new package-lock.json (~12k lines). If the repo isn’t already tracking an npm lockfile, this will introduce a large, unrelated change surface for a targeted Discord history-limit fix and can change dependency resolution for consumers. Please confirm this is intentional (and aligned with the repo’s package manager policy), otherwise drop it from the PR.

Prompt To Fix With AI
This is a comment left during a code review.
Path: package-lock.json
Line: 1:3

Comment:
**Unexpected lockfile addition**

This PR adds a new `package-lock.json` (~12k lines). If the repo isn’t already tracking an npm lockfile, this will introduce a large, unrelated change surface for a targeted Discord history-limit fix and can change dependency resolution for consumers. Please confirm this is intentional (and aligned with the repo’s package manager policy), otherwise drop it from the PR.

How can I resolve this? If you propose a fix, please make it concise.

@shadril238 shadril238 force-pushed the fix/discord-channel-compaction-bypass branch from d757bfc to 9d06864 Compare February 7, 2026 18:46
@Takhoffman Takhoffman self-assigned this Feb 14, 2026
shadril238 and others added 2 commits February 13, 2026 18:04
… compaction bypass

Extends getHistoryLimitFromSessionKey (renamed from getDmHistoryLimitFromSessionKey) to support
channel and group sessions using the existing historyLimit config property. Previously, the function
only applied limits to DM sessions, causing channel sessions to accumulate tokens indefinitely and
eventually hit context overflow errors.

Changes:
- Extended history.ts to resolve historyLimit for 'channel' and 'group' session kinds
- Added backward-compatible deprecated alias for getDmHistoryLimitFromSessionKey
- Added getHistoryLimitFromSessionKey export to pi-embedded-runner.ts
- Added comprehensive tests for channel/group session history limit resolution

Fixes openclaw#11224
@Takhoffman Takhoffman force-pushed the fix/discord-channel-compaction-bypass branch from 9d06864 to ca2a407 Compare February 14, 2026 00:10
@Takhoffman Takhoffman merged commit 5378583 into openclaw:main Feb 14, 2026
9 checks passed
@Takhoffman

Copy link
Copy Markdown
Contributor

Merged via squash.

  • Merge commit: 5378583
  • Verified: pnpm build, pnpm check, pnpm test (1 unrelated existing failure in models forward-compat), pnpm vitest src/agents/pi-embedded-runner.history-limit-from-session-key.test.ts
  • Changelog: CHANGELOG.md updated=true required=true opt_out=false

Thanks @shadril238!

GwonHyeok pushed a commit to learners-superpumped/openclaw that referenced this pull request Feb 15, 2026
… compaction bypass (openclaw#11356) thanks @shadril238

Verified:
- pnpm build
- pnpm check
- pnpm test (ran; one unrelated existing failure in models forward-compat test)
- pnpm vitest src/agents/pi-embedded-runner.history-limit-from-session-key.test.ts

Co-authored-by: shadril238 <63901551+shadril238@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
… compaction bypass (openclaw#11356) thanks @shadril238

Verified:
- pnpm build
- pnpm check
- pnpm test (ran; one unrelated existing failure in models forward-compat test)
- pnpm vitest src/agents/pi-embedded-runner.history-limit-from-session-key.test.ts

Co-authored-by: shadril238 <63901551+shadril238@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
… compaction bypass (openclaw#11356) thanks @shadril238

Verified:
- pnpm build
- pnpm check
- pnpm test (ran; one unrelated existing failure in models forward-compat test)
- pnpm vitest src/agents/pi-embedded-runner.history-limit-from-session-key.test.ts

Co-authored-by: shadril238 <63901551+shadril238@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
… compaction bypass (openclaw#11356) thanks @shadril238

Verified:
- pnpm build
- pnpm check
- pnpm test (ran; one unrelated existing failure in models forward-compat test)
- pnpm vitest src/agents/pi-embedded-runner.history-limit-from-session-key.test.ts

Co-authored-by: shadril238 <63901551+shadril238@users.noreply.github.com>
Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling size: S

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Discord channel sessions bypass compaction, causing context overflow

2 participants