Skip to content

feat(engine): context-limit handoff replaces routine compaction (closes #664)#667

Closed
merchloubna70-dot wants to merge 6 commits into
Hmbown:mainfrom
merchloubna70-dot:feat/context-handoff-664
Closed

feat(engine): context-limit handoff replaces routine compaction (closes #664)#667
merchloubna70-dot wants to merge 6 commits into
Hmbown:mainfrom
merchloubna70-dot:feat/context-handoff-664

Conversation

@merchloubna70-dot

Copy link
Copy Markdown

Three-stage awareness 70/80/90%. Closes #664

macworkers and others added 3 commits May 4, 2026 12:39
All system prompts were English-only, causing DeepSeek V4 to reason
and respond in English even when users wrote in Chinese or other
languages.

Add a Language Mirror section to base.md and base.txt that instructs
the model to detect the user's primary language and use it for both
reasoning (thinking tokens) and the final reply.
base.txt is not referenced via include_str! in prompts.rs.
Only base.md is loaded (BASE_PROMPT). Remove the redundant change
to base.txt as noted by Gemini Code Assist review.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@Hmbown

Hmbown commented May 5, 2026

Copy link
Copy Markdown
Owner

Review notes from v0.8.12 integration

Thanks for this PR. I've reviewed the code as part of merging it into the v0.8.12 branch. One finding:

prefer_handoff is dead code

The prefer_handoff: Option<bool> field was added to CompactionConfig, but zero code paths read it. There's no handoff-writing function, no trigger in should_compact or the engine turn loop, nothing that consults this field. Setting prefer_handoff = true in config would have no effect.

The idea itself is solid — when context pressure builds, write a .deepseek/handoff.md instead of paying for an LLM compaction call. That preserves the V4 prefix cache and avoids the compaction cost. But the plumbing behind the config knob was never built.

Recommendation: Either implement the handoff path (file writer + trigger in the compaction flow + context-clear mechanism) in a follow-up PR, or remove the field until that work is done. Shipping a config key that does nothing is misleading to users.

The rest of the PR (the auto_floor_tokensprefer_handoff coexistence in the struct) merged cleanly.

@Hmbown

Hmbown commented May 5, 2026

Copy link
Copy Markdown
Owner

v0.8.12: removed dead prefer_handoff field

Per the earlier review finding, the prefer_handoff field has been removed from CompactionConfig. The field was defined but zero code paths consulted it — it was a config knob wired to nothing.

The handoff idea itself (write .deepseek/handoff.md on context pressure instead of paying for LLM compaction) is a good one. When the implementation exists, the field can be re-added with the plumbing behind it.

Commit: c0e27485a

…follow-up)

`prefer_handoff: Option<bool>` was added to CompactionConfig but never
read — setting it had no effect. When `Some(true)`, skip automatic LLM
compaction so the handoff threshold system in handoff.rs can instruct
the model to write `.deepseek/handoff.md` instead.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@merchloubna70-dot

Copy link
Copy Markdown
Author

Fixed — should_compact now returns false when prefer_handoff == Some(true), directing context pressure to the handoff threshold system (handoff.rs) instead of triggering LLM compaction.

Updated per Hunter's v0.8.12 review: `prefer_handoff: Option<bool>`
was removed from CompactionConfig rather than being partially wired.
A half-wired field that prevents LLM compaction without writing a
handoff file is worse than no compaction — context would accumulate
unchecked. The field can be re-introduced once the full handoff
implementation (file writer + context-clear) is ready.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@merchloubna70-dot

Copy link
Copy Markdown
Author

Updated to align with your v0.8.12 approach — removed prefer_handoff from CompactionConfig entirely rather than wiring it into should_compact. Agreed that a half-wired knob (skip LLM compaction but write no handoff file) is worse than no knob. The field can come back once the full implementation (file writer + context-clear) is ready.

Hmbown added a commit that referenced this pull request May 5, 2026
The match guard at tui/ui.rs:1603 used `&& let Some(...) = ...` inside an
`if` guard, which requires the `if_let_guard` nightly feature on Rust
< 1.94. Reported by an external user attempting `cargo install
deepseek-tui` on stable rustc — it failed with E0658.

Rewrite as a plain match guard with a nested `if let` inside the arm
body so the language-picker hotkeys compile on every supported rustc.

Workspace also now declares `rust-version = "1.88"` to match the
codebase's actual reliance on `let_chains` in if/while conditions, so
users on too-old toolchains see a clear cargo error instead of a
confusing rustc one.

`AGENTS.md` and `CLAUDE.md` gain a "stable Rust only" section
documenting the trap and how to rewrite around it.

Also annotate the deferred `TuiPrefs` (#657) and `handoff::THRESHOLDS`
(#667) APIs with `#[allow(dead_code)]` so CI's `-D warnings` flag stays
green while the call sites are staged for v0.8.13.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Hmbown added a commit that referenced this pull request May 5, 2026
47 fmt drifts had accumulated from the squash-merged community PRs on
this branch (#653, #654, #655, #645, #658, #668, #659, #661, #660,
#667, #656). Pure formatting — no behavioural changes — applied via
`cargo fmt --all` to satisfy CI's `cargo fmt --all -- --check` gate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…mbown#664)

THRESHOLDS and threshold_message() are reserved for the planned
context-ratio tracking + system-prompt injection. Add #[allow(dead_code)]
and doc comments so the compiler does not warn and reviewers understand
these are future-wiring, not stale leftovers.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@merchloubna70-dot

Copy link
Copy Markdown
Author

Added #[allow(dead_code)] with doc comments to THRESHOLDS and threshold_message() in handoff.rs — these are reserved for the planned context-ratio tracking + injection, not stale leftovers.

kibuniverse pushed a commit to kibuniverse/DeepSeek-TUI that referenced this pull request May 5, 2026
kibuniverse pushed a commit to kibuniverse/DeepSeek-TUI that referenced this pull request May 5, 2026
…terminal_colors (Hmbown#671)

Neither field had any code path that read it. Shipping config knobs
that do nothing trains users to mistrust config. Remove until the
implementation exists.
MMMarcinho pushed a commit to MMMarcinho/DeepSeek-TUI that referenced this pull request May 6, 2026
MMMarcinho pushed a commit to MMMarcinho/DeepSeek-TUI that referenced this pull request May 6, 2026
…terminal_colors (Hmbown#671)

Neither field had any code path that read it. Shipping config knobs
that do nothing trains users to mistrust config. Remove until the
implementation exists.
MMMarcinho pushed a commit to MMMarcinho/DeepSeek-TUI that referenced this pull request May 6, 2026
The match guard at tui/ui.rs:1603 used `&& let Some(...) = ...` inside an
`if` guard, which requires the `if_let_guard` nightly feature on Rust
< 1.94. Reported by an external user attempting `cargo install
deepseek-tui` on stable rustc — it failed with E0658.

Rewrite as a plain match guard with a nested `if let` inside the arm
body so the language-picker hotkeys compile on every supported rustc.

Workspace also now declares `rust-version = "1.88"` to match the
codebase's actual reliance on `let_chains` in if/while conditions, so
users on too-old toolchains see a clear cargo error instead of a
confusing rustc one.

`AGENTS.md` and `CLAUDE.md` gain a "stable Rust only" section
documenting the trap and how to rewrite around it.

Also annotate the deferred `TuiPrefs` (Hmbown#657) and `handoff::THRESHOLDS`
(Hmbown#667) APIs with `#[allow(dead_code)]` so CI's `-D warnings` flag stays
green while the call sites are staged for v0.8.13.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
MMMarcinho pushed a commit to MMMarcinho/DeepSeek-TUI that referenced this pull request May 6, 2026
47 fmt drifts had accumulated from the squash-merged community PRs on
this branch (Hmbown#653, Hmbown#654, Hmbown#655, Hmbown#645, Hmbown#658, Hmbown#668, Hmbown#659, Hmbown#661, Hmbown#660,
Hmbown#667, Hmbown#656). Pure formatting — no behavioural changes — applied via
`cargo fmt --all` to satisfy CI's `cargo fmt --all -- --check` gate.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@Hmbown

Hmbown commented May 7, 2026

Copy link
Copy Markdown
Owner

Shipped on main in 2cdf4a256 (feat(engine): context-limit handoff replaces routine compaction, #667), with cleanup follow-up c0e27485a removing the unused prefer_handoff config field. Auto-close didn't fire — closing manually.

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-limit handoff as a default replacement for routine compaction

2 participants