feat(deepseek): prefix cache stability primitives (#145 follow-up)#295
Merged
Conversation
Gap close: upstream PR 1jehuang#194 (open) added a prefix_cache_stable module + agent integration. Our master had neither. Earlier verify-close was wrong — upstream itself never merged that PR. This PR ports the **detection + preflight primitives** as a clean standalone module. Agent integration (turn loop history folding, tool-result truncation hooks) is a separate follow-up that needs dedicated test coverage. API: use jcode::prefix_cache_stable as pcs; if pcs::is_prefix_cache_stable_mode() { let cap = pcs::recommended_tool_result_cap_tokens() .unwrap_or(usize::MAX); // truncate large tool results to <cap> tokens } let ctx_max = pcs::context_tokens_for_model(model); let decision = pcs::preflight_check_simple(estimate, ctx_max); if decision.needs_action { // user_warn or kick off compaction } Detection signals (any one is enough, case-insensitive): JCODE_OPENROUTER_CACHE_NAMESPACE=deepseek JCODE_RUNTIME_PROVIDER=deepseek JCODE_NAMED_PROVIDER_PROFILE=deepseek Constants exported: DEEPSEEK_V4_CONTEXT_TOKENS=1_000_000 DEFAULT_CONTEXT_TOKENS=128_000 HISTORY_FOLD_THRESHOLD/AGGRESSIVE_THRESHOLD/FORCE_SUMMARY_THRESHOLD PREFLIGHT_EMERGENCY_THRESHOLD=0.95 TURN_END_RESULT_CAP_TOKENS=3000 Tests: 12 unit tests covering detection (5) + context resolution (2) + preflight thresholds (3) + recommended cap toggle (2). Refs upstream PR 1jehuang#194, fork #145.
1 task
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.
Gap close on #145
Upstream PR 1jehuang/jcode#194 (open, not merged) added a
prefix_cache_stablemodule + agent integration. Our master had neither — earlier verify-close was inaccurate.This PR ports the detection + preflight primitives as a standalone module. Agent integration (turn loop history folding, tool-result truncation) is a separate follow-up that needs dedicated test coverage.
Detection signals (any one, case-insensitive)
Tests
Refs upstream PR 1jehuang/jcode#194, fork #145.