Repository navigation
fix: account for current context growth in token usage - #582
Open
bittylicious wants to merge 1 commit into
Open
bittylicious wants to merge 1 commit into
bittylicious wants to merge 1 commit into
Conversation
bittylicious
marked this pull request as ready for review
July 6, 2026 00:35
specializedken
pushed a commit
to specializedken/opencode-dynamic-context-pruning
that referenced
this pull request
Oct 23, 2026
…arquinen#627 61adf37) Cherry-picked from upstream PR Tarquinen#627, adapted to keep the tool named "compress" (the dcp_compress rename is not taken): - self-heal the compress tool into event.tools when the host drops it - refuse to overwrite a state file that exists but failed to load; unique temp paths for atomic writes - content-based token usage fallback when no assistant reports tokens, merged with Tarquinen#582's max(reported, estimate) and memoized per window, since Tarquinen#660 made counting async and it runs on every request Bun-only tests (V2 setup seam, TUI render) move to tests/bun and run via scripts/test-bun.mjs with bun or the OpenCode binary (BUN_BE_BUN=1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
specializedken
added a commit
to specializedken/opencode-dynamic-context-pruning
that referenced
this pull request
Oct 24, 2026
… text Seen live on OpenCode V2 with Mimo (1.05M context): three `read` results carried PNG screenshots as data URIs (808k chars). extractCompletedToolOutput JSON-stringified the V2 content array, so the base64 was tokenized as text: 566,152 phantom tokens (155 after this fix). With Tarquinen#582's max(reported, estimate) that pushed usage past the 262k min threshold at ~200k real tokens; DCP kept sending reminders and the model retried compress until the upstream timed out. Strip uri/url/data from non-text items before counting; the provider-reported usage still covers the real image cost. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Summary
Why
DCP currently decides whether to inject max-context compression nudges from the latest successful assistant response token report. If large tool output or user content is added after that report, the next assembled request can exceed the provider context window before the model ever sees the max-context nudge. Estimating the current transformed messages lets DCP detect that growth before the next request is sent.
Verification
node --import tsx --test tests/token-usage.test.tsnpm run typechecknpm run format:check -- lib/token-utils.ts tests/token-usage.test.tsnpm testnpm run build