Skip to content

fix(compaction): preserve usr txt query to prevent Jinja template crash#1704

Closed
krisclarkdev wants to merge 1 commit into
Hmbown:mainfrom
krisclarkdev:bugfix-jinja-no-user-query-after-autocompact
Closed

fix(compaction): preserve usr txt query to prevent Jinja template crash#1704
krisclarkdev wants to merge 1 commit into
Hmbown:mainfrom
krisclarkdev:bugfix-jinja-no-user-query-after-autocompact

Conversation

@krisclarkdev

Copy link
Copy Markdown

When auto compaction runs on a session where recent history is dominated by tool calls and results, all original user text queries could be dropped from the pinned context. This causes backend inference servers (e.g. vLLM/SGLang hosting DeepSeek V4) that rely on Jinja chat templates to throw a "No user query found in messages" exception.

This fix forces plan_compaction to scan backwards and pin at least one user text query if the recent pinned context lacks one.

Summary

Testing

  • cargo test --all-features
  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features

Checklist

  • Updated docs or comments as needed
  • Added or updated tests where relevant
  • Verified TUI behavior manually if UI changes

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the message compaction logic in crates/tui/src/compaction.rs to ensure that at least one user text query is always preserved, preventing potential crashes in backends like vLLM when a context consists solely of tool interactions. A new unit test was added to verify that the oldest user query is correctly pinned. The review feedback suggests refactoring the logic for identifying user text queries into a closure to eliminate code duplication and improve maintainability.

Comment thread crates/tui/src/compaction.rs Outdated
…rash

When auto compaction runs on a session where recent history is dominated by tool calls and results, all original user text queries could be dropped from the pinned context. This causes backend inference servers (e.g. vLLM/SGLang hosting DeepSeek V4) that rely on Jinja chat templates to throw a "No user query found in messages" exception.

This fix forces `plan_compaction` to scan backwards and pin at least one user text query if the recent pinned context lacks one.
@krisclarkdev krisclarkdev force-pushed the bugfix-jinja-no-user-query-after-autocompact branch from b075ece to 72310ba Compare May 16, 2026 03:03
@Hmbown Hmbown added this to the v0.8.39 milestone May 16, 2026
Hmbown added a commit that referenced this pull request May 17, 2026
Bump workspace, inter-crate, and npm package versions 0.8.38 -> 0.8.39.

Roll CHANGELOG [Unreleased] into [0.8.39] with all fixes:
- Revert v0.8.38 /model picker rework (back to instant curated picker)
- Restore approval grouping (lossy v0.8.37 logic for approvals, exact key for denials)
- Thinking-only turn surface fix (#1727)
- ACP server JSON-RPC id stringification (#1696)
- Chat client: reasoning_content for generic providers (#1673)
- Compaction: user text query preservation (#1704)
- Engine: system prompt override survival (#1688)
- Pager: G/End overshoot fix (#1706), mouse scroll (#1716)
- Composer: scroll with text (#1677), multiline arrows (#1721)
- macOS system theme detection (#1670)
- rlm_open blank source fields (#1712)
- Terminal resize paging fix (#1724)
- Docker first-run permission (#1684)
- README Rust 1.88+ requirement note (#1718)

Tests: 3149 passed, 0 failed (deepseek-tui crate)
clippy: clean on --all-targets --all-features
@Hmbown

Hmbown commented May 17, 2026

Copy link
Copy Markdown
Owner

Thanks, this was the right bug to catch. The compaction user-query preservation fix was harvested into v0.8.39 via #1734 and credited in the changelog, so I am closing this PR to keep the queue clean. Any remaining cache/compaction performance work is now tracked under the v0.8.40 milestone.

@Hmbown Hmbown closed this May 17, 2026
@krisclarkdev krisclarkdev deleted the bugfix-jinja-no-user-query-after-autocompact branch May 17, 2026 15:06
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.

2 participants