Skip to content

Select messages for persistent summary based on tokens or user-message count#9

Merged
neozhu merged 1 commit into
masterfrom
codex/analyze-conversation-compression-triggers
May 12, 2026
Merged

Select messages for persistent summary based on tokens or user-message count#9
neozhu merged 1 commit into
masterfrom
codex/analyze-conversation-compression-triggers

Conversation

@neozhu
Copy link
Copy Markdown
Owner

@neozhu neozhu commented May 12, 2026

Motivation

  • Ensure persistent summarization triggers not only when unsummarized token counts exceed a threshold but also when the number of recent user messages reaches a threshold so long-running conversations are compacted appropriately.

Description

  • Change selectMessagesForPersistentSummary to accept and consult both compactAfterTotalTokens and compactAfterUserMessageCount from getChatContextConfig and compute shouldCompactByTotalTokens and shouldCompactByUserMessageCount.
  • Update the early-return logic so compaction is triggered when either threshold is met and otherwise returns an empty selection.
  • Keep the existing behavior of slicing messages up to the latest user message when compaction is required.
  • Add and adjust unit tests in lib/botchat/chat-context.test.mts to cover compaction by user-message count and the combined-threshold behavior.

Testing

  • Ran unit tests in lib/botchat/chat-context.test.mts including selectMessagesForPersistentSummary summarizes when unsummarized user messages reach the threshold, selectMessagesForPersistentSummary waits until both persistent thresholds are unmet, and selectMessagesForPersistentSummary uses env token threshold by default, and they all passed.

Codex Task

@neozhu neozhu merged commit 63b046f into master May 12, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant