fix(lsp): inject hover notes immediately before LLM call (#3595)#3596
Merged
fix(lsp): inject hover notes immediately before LLM call (#3595)#3596
Conversation
The previous implementation attempted to inject LSP notes at the top of each tool loop iteration, guarded by `!last_msg_has_tool_results()`. This guard correctly returned `true` on every iteration after the first because the previous iteration's `User(ToolResult)` message was always the last non-System message — blocking injection permanently. Move the injection block into `call_chat_with_tools`, after `run_before_chat_layers` and immediately before `provider.chat_with_tools`. At that point there is no pending ToolUse/ToolResult pair, so inserting a `Role::System` message is safe for all providers (OpenAI, Claude, Ollama). Remove the now-unused `last_msg_has_tool_results` function and its tests. Closes #3595
Add two tests covering the new call_chat_with_tools injection path: - lsp_notes_injected_before_llm_call_in_call_chat_with_tools: verifies that queued hover notes appear as a System message before the LLM call - lsp_notes_not_duplicated_on_retry: verifies that on ContextLengthExceeded retry the note is not re-injected (drain returns None, stale msg removed) Add #[cfg(test)] push_note helper to LspHookRunner for pre-queuing notes without an MCP connection. Fix formatting.
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
LspHookRunner::after_toolwere never reaching the LLM because the injection guard!last_msg_has_tool_results()always returnedfalseafter the first tool loop iterationprocess_single_native_turnintocall_chat_with_tools, immediately afterrun_before_chat_layersand beforeprovider.chat_with_tools— at that point no ToolUse/ToolResult pair is pending, so inserting aRole::Systemmessage is safe for all providerslast_msg_has_tool_resultsfunction and its 5 unit testsRoot cause
The original code placed LSP note injection at the top of each iteration of the tool loop. The guard prevented injection when the last non-System message was
User(ToolResult). However, after iteration N completes, the committed tool results from that iteration makelast_msg_has_tool_results()returntrueat the start of iteration N+1 — so notes were always discarded.Test plan
cargo build -p zeph-core— cleancargo clippy -p zeph-core -- -D warnings— zero warningscargo +nightly fmt --check— cleancargo nextest run --workspace --lib --bins— 8835 passed, 0 failedreadtool on a Rust file with LSP enabled, verify hover notes appear in the next LLM context (requires mcpls + LSP server)Closes #3595