Skip to content

[codex] Add context compaction controls and background cleanup - #564

Open
aj47 wants to merge 2 commits into
mainfrom
codex/context-compaction-settings
Open

[codex] Add context compaction controls and background cleanup#564
aj47 wants to merge 2 commits into
mainfrom
codex/context-compaction-settings

Conversation

@aj47

@aj47 aj47 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds Settings > Agent Settings controls for context compaction thresholds.
  • Uses the active model context target as the default saved-conversation token compaction budget, with an optional absolute token override.
  • Moves saved-conversation compaction off the live prompt path so follow-up prompts do not wait on old-history summarization.
  • Schedules delayed, deduped background compaction after agent completion and skips stale compaction if the conversation changes mid-summary.

Root Cause

The live agent follow-up path loaded conversation history through a method that could synchronously compact old history. For long conversations, that could trigger serial LLM summarization calls before the new prompt was handled, making the UI sit on “thinking” for tens of seconds.

Validation

  • CI=1 pnpm --filter @dotagents/desktop test -- conversation-service.lazy-load.test.ts
  • node --test apps/desktop/tests/settings-general-context-compaction.test.mjs
  • CI=1 pnpm --filter @dotagents/desktop typecheck
  • CI=1 pnpm typecheck

Notes

  • PR is ready for review.
  • Left unrelated local changes out of this PR: apps/mobile/src/store/sessions.ts, apps/mobile/src/store/sessions.storage.test.ts, and apps/desktop/heroic.

@aj47
aj47 marked this pull request as ready for review June 23, 2026 20:04
@aj47

aj47 commented Jun 23, 2026

Copy link
Copy Markdown
Owner Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@augment-app-staging augment-app-staging 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.

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

if (messageCount <= COMPACTION_MESSAGE_THRESHOLD) {
const messageThreshold = getConfiguredConversationCompactionMessageThreshold()
const tokenThreshold = await getConversationCompactionTokenThreshold()
const tokenCount = tokenThreshold

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.

The tokenThreshold ? … : 0 and !tokenThreshold checks treat 0/NaN as “unset”, so an invalid mcpContextTargetRatio could silently bypass token-based compaction. Since getActiveContextTargetTokens() derives from config, this can make compaction behavior hard to predict for user-edited configs.

Severity: low

🤖 Was this useful? React with 👍 or 👎

</div>
</div>
<Slider
value={[

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.

If cfg.mcpContextTargetRatio is outside the allowed 10–95% range, the numeric draft can show an out-of-range value while the slider falls back to MCP_CONTEXT_TARGET_RATIO_PERCENT_DEFAULT, so the two controls can disagree.

Severity: low

🤖 Was this useful? React with 👍 or 👎

<Control
label={
<ControlLabel
label="Context Compaction"

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.

This adds new compaction controls to the desktop settings UI; per the renderer cross-platform reminder, is there a corresponding mobile remote-settings surface that should expose these for paired-desktop configuration as well?

Severity: low

🤖 Was this useful? React with 👍 or 👎

@aj47 aj47 changed the title [codex] Add context compaction settings [codex] Add context compaction controls and background cleanup Jun 23, 2026
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