Skip to content

fix(compaction): stabilize request-local reduction cache - #901

Open
codeg-dev wants to merge 2 commits into
code-yeongyu:mainfrom
codeg-dev:fix/context-reduction-cache-stability-pr
Open

fix(compaction): stabilize request-local reduction cache#901
codeg-dev wants to merge 2 commits into
code-yeongyu:mainfrom
codeg-dev:fix/context-reduction-cache-stability-pr

Conversation

@codeg-dev

@codeg-dev codeg-dev commented Aug 16, 2026

Copy link
Copy Markdown

Summary

  • Keep builtin request-local context reduction engaged after the 50% gate is crossed.
  • Reset the latch only after an accepted, persisted session_compact event.
  • Preserve the provider-native compaction bypass even while the latch is engaged.

The context hook rewrites only the outgoing request; it does not replace stored session history. With a stateless gate, reported usage moving from 501,000 to 499,000 tokens against a one-million-token window alternated reduced and unreduced payload shapes for the same stored history. This change keeps the request shape stable until compaction actually changes that history.

The stateful high/low watermark introduced for emergency pruning in #425 is the closest precedent. Here, an accepted compaction is the release condition because a narrow numeric release band cannot prove that stored history changed.

Fixes #900.

Tests

  • Stock v2026.8.14 characterization: the same history at 501,000 then 499,000 reported tokens produces different payload hashes.
  • Threshold-control regression: 507 request-local evaluations with 319 crossings verifies stable reduction without treating those counts as payload-scale evidence or attributing overhead to them.
  • Payload-scale lifecycle regression: 1,510 eligible tool results and more than one megabyte of serialized history verify that a rejected compaction does not reset the latch and an accepted compaction does.
  • Provider-native regression: the native path remains bypassed while the latch is engaged.
  • npm run check
  • Compaction and regression suite: 63 files, 421 tests passed.
  • npm run build
  • CLI mock loop with a tool: 4/4 checks passed.
  • CLI offline smoke: 8/8 checks passed.

Summary by cubic

Stabilizes request-local context reduction by latching once the 50% gate is crossed and releasing only after an accepted, persisted compaction or when session-tree navigation changes the active branch. Previously reduction flipped around 50%, producing alternating payload shapes; now requests keep one reduced shape until history actually changes.

  • Adds ContextReductionLatch with createContextReductionLatch and resetContextReductionLatch; shouldApplyContextReduction optionally accepts a latch. Stateless callers are unchanged; pass a latch to keep stable reduction across requests.
  • Resets the latch on accepted session_compact and on session_tree navigation; rejected compaction does not reset. Preserves provider-native compaction bypass while latched.
  • Primary touch points: packages/coding-agent/src/core/extensions/builtin/compaction/context-reduction.ts and packages/coding-agent/src/core/extensions/builtin/compaction/index.ts.
  • Adds targeted regressions for threshold-control stability and payload-scale lifecycle.

Written for commit 231d467. Summary will update on new commits.

Review in cubic

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f11d2061f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

Context reduction alternates payload shapes around the 50% gate

1 participant