fix(tui): include mode in turn metadata#2539
Draft
cyq1017 wants to merge 1 commit into
Draft
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
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.
Problem
Change
AppModeto<turn_meta>for user turns.get_modetool or auto-retry behavior.Verification
cargo test -p codewhale-tui turn_metadata_includes_current_mode --lockedcargo test -p codewhale-tui turn_metadata --lockedcargo fmt --all -- --checkgit diff --checkRefs #2515
Greptile Summary
This PR adds the active
AppModeto the<turn_meta>block sent with each user turn, so the model can see whether it is operating in agent, plan, or yolo mode on every request. The change threads a newmode: AppModeparameter throughturn_metadata_blockanduser_text_message_with_turn_metadata_for_route, and a dedicated test (turn_metadata_includes_current_mode) verifies the Yolo-mode path.handle_send_message→user_text_message_with_turn_metadata_for_route) correctly receives and forwards the live mode value.user_text_message_with_turn_metadatahardcodesAppMode::Agent; it is used for mid-turn steer messages, REPL feedback, goal-continuation messages, and LSP diagnostics — all of which will incorrectly reportagentmode during Plan or Yolo sessions.Confidence Score: 3/5
The main user-message path works correctly, but mid-turn injected messages (steers, REPL feedback, LSP diagnostics) will silently report the wrong mode in Plan and Yolo sessions.
The wrapper
user_text_message_with_turn_metadatahardcodesAppMode::Agentand is called in seven places inside the turn loop for steer/REPL/continuation/LSP messages. In any non-Agent mode session those messages will carryCurrent mode: agent, which is the opposite of what this PR sets out to fix. Themodeparameter is already present at every affected call-site inturn_loop.rsso the fix is straightforward, but the current code ships incorrect metadata on a high-frequency code path.crates/tui/src/core/engine.rs — the
user_text_message_with_turn_metadatawrapper and all its call-sites inturn_loop.rsandlsp_hooks.rsImportant Files Changed
mode: AppModetoturn_metadata_blockanduser_text_message_with_turn_metadata_for_route; the main send path correctly passes the live mode, but the no-route wrapper hardcodesAppMode::Agent, leaving steer/REPL/LSP mid-turn messages with wrong mode metadata in Plan and Yolo sessions.turn_metadata_includes_current_modetest covering the Yolo mode path; correctly updates the existingturn_metadata_includes_auto_model_routetest to supply the newmodeargument.Sequence Diagram
sequenceDiagram participant UI as TUI / User participant Engine as Engine participant TurnLoop as handle_deepseek_turn participant Meta as turn_metadata_block UI->>Engine: Op::SendMessage(content, mode) Engine->>Engine: user_text_message_with_turn_metadata_for_route(content, mode) Engine->>Meta: turn_metadata_block(mode, ...) Meta-->>Engine: "turn_meta Current mode: {mode}" Engine->>TurnLoop: handle_deepseek_turn(mode) note over TurnLoop: Mid-turn steer / REPL / LSP / continuation messages TurnLoop->>Engine: user_text_message_with_turn_metadata(steer) Engine->>Meta: turn_metadata_block(AppMode::Agent [hardcoded], ...) Meta-->>Engine: turn_meta Current mode: agent note over TurnLoop: Always agent even in Plan / Yolo sessionsComments Outside Diff (1)
crates/tui/src/core/engine.rs, line 962-971 (link)user_text_message_with_turn_metadata(the no-_for_routevariant) hardcodesAppMode::Agent. This method is used in seven places insidehandle_deepseek_turn(steer messages, REPL feedback, goal-continuation messages) and inflush_pending_lsp_diagnostics, all of which run while a turn is already in progress. In Plan or Yolo mode sessions those mid-turn messages will carryCurrent mode: agentin their metadata, giving the model a false picture of the active mode — exactly the problem this PR intends to fix.All call-sites in
turn_loop.rsalready receivemode: AppModeas a parameter, so the mode is available; it just isn't threaded through this helper.Reviews (1): Last reviewed commit: "fix(tui): include mode in turn metadata" | Re-trigger Greptile