fix: 22 bug fixes for non-Anthropic provider compatibility and compression reliability#523
Open
ranxianglei wants to merge 2 commits intoOpencode-DCP:masterfrom
Open
fix: 22 bug fixes for non-Anthropic provider compatibility and compression reliability#523ranxianglei wants to merge 2 commits intoOpencode-DCP:masterfrom
ranxianglei wants to merge 2 commits intoOpencode-DCP:masterfrom
Conversation
…ility Major fixes: - Bug 1: Persist messageIds across restarts (persistence.ts, state.ts) - Bug 2: resetOnCompaction preserves prune.messages (utils.ts) - Bug 3: syncCompressionBlocks ignores missing compressMessageId (sync.ts) - Bug 6: Fix silent summary drop when no user msg before anchor (prune.ts) - Bug 7: Assign mNNNN refs to synthetic summary messages (hooks.ts) - Bug 8: Fallback token estimation when API returns 0 (token-utils.ts) - Bug 9: Propagate save errors instead of swallowing (persistence.ts) - Bug 10: Persist block deactivations after sync (hooks.ts) - Bug 11: Recursive deactivatedByUser for decompress (decompress.ts) - Bug 12: Fix isMessageCompacted inconsistency at compaction boundary (utils.ts) - Bug 13: Fix duplicate activeBlockIds loading (utils.ts) - Bug 14: Guard against undefined modelID/providerID (reasoning-strip.ts) - Bug 17: Provider-aware token calculation heuristic (token-utils.ts) - Bug 18: Use raw context limit instead of inputBudget (hooks.ts) - Bug 19: Secondary anchor check against persisted byMessageId (sync.ts) - Bug 20: Cooldown period after compress to prevent repeated warnings (utils.ts) - Bug 21: Strengthen compress prompt against stale ID usage (compress-range.ts) All fixes marked with [FIX Bug N] or [PATCH Bug N] in source.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
DCP Plugin: Comprehensive Bug Fix — Persistence, Token Heuristics, and Compression Stability
This PR fixes 18 bugs across the Dynamic Context Pruning plugin that collectively rendered DCP unreliable in production. The issues span three failure domains: persistence (compression state lost across restarts and compaction), token measurement (inflated counts causing false warnings on non-Anthropic providers), and compression block lifecycle (blocks deactivating spuriously, summaries silently dropped, re-compression impossible). Together, these fixes make DCP's compression behavior stable across long sessions, restarts, and multi-provider setups.
Key themes:
Test Environment
🔴 CRITICAL Fixes
🟠 HIGH Fixes
🟡 MEDIUM Fixes
🟢 LOW Fixes
Design Decisions
1. Provider-Aware Token Heuristic (Bug #17)
Different providers report token counts with different semantics:
The heuristic: if `cacheRead > input && input > 0`, the provider uses split reporting where `cacheRead` is the better proxy. Otherwise `input` already contains the full context. This is deliberately simple and observable.
2. Anchor Persistence Strategy (Bugs #1, #19)
DCP now maintains its own persisted `byMessageId` index, decoupling block validity from opencode's message windowing:
3. Compaction Coexistence (Bug #2)
`resetOnCompaction()` now preserves `prune.messages` (compression blocks) while resetting transient state. After compaction, DCP reassigns refs and re-syncs blocks — but compression summaries survive.
Files Changed
Notes for Reviewers
Reproduction Recipes (for QA)
Bug #1: Start session → compress messages → restart opencode → attempt compress → `startId not available`
Bug #3: Start session → compress → continue 20+ turns → observe blocks deactivating
Bug #6: Compress messages near conversation start (first 5 messages) → observe messages vanish with no summary
Bug #17: Use non-Anthropic provider → observe CRITICAL WARNING at low context usage
Bug #18: Use model with large output budget (204K context, 131K output) → observe 45% threshold firing at ~17%
Bug #20: Compress at high context → observe model immediately re-compressing