Skip to content

fix(tui): include mode in turn metadata#2539

Draft
cyq1017 wants to merge 1 commit into
Hmbown:mainfrom
cyq1017:codex/2515-turn-meta-mode
Draft

fix(tui): include mode in turn metadata#2539
cyq1017 wants to merge 1 commit into
Hmbown:mainfrom
cyq1017:codex/2515-turn-meta-mode

Conversation

@cyq1017
Copy link
Copy Markdown
Contributor

@cyq1017 cyq1017 commented Jun 1, 2026

Problem

  • Mode changes are only reflected in the refreshed prompt/tool context, but the per-turn metadata sent with the next user message does not include the active mode.

Change

  • Add the current AppMode to <turn_meta> for user turns.
  • Keep the scope limited to request metadata; this does not add a get_mode tool or auto-retry behavior.

Verification

  • cargo test -p codewhale-tui turn_metadata_includes_current_mode --locked
  • cargo test -p codewhale-tui turn_metadata --locked
  • cargo fmt --all -- --check
  • git diff --check

Refs #2515

Greptile Summary

This PR adds the active AppMode to 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 new mode: AppMode parameter through turn_metadata_block and user_text_message_with_turn_metadata_for_route, and a dedicated test (turn_metadata_includes_current_mode) verifies the Yolo-mode path.

  • The main send path (handle_send_messageuser_text_message_with_turn_metadata_for_route) correctly receives and forwards the live mode value.
  • The no-route wrapper user_text_message_with_turn_metadata hardcodes AppMode::Agent; it is used for mid-turn steer messages, REPL feedback, goal-continuation messages, and LSP diagnostics — all of which will incorrectly report agent mode 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_metadata hardcodes AppMode::Agent and is called in seven places inside the turn loop for steer/REPL/continuation/LSP messages. In any non-Agent mode session those messages will carry Current mode: agent, which is the opposite of what this PR sets out to fix. The mode parameter is already present at every affected call-site in turn_loop.rs so 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_metadata wrapper and all its call-sites in turn_loop.rs and lsp_hooks.rs

Important Files Changed

Filename Overview
crates/tui/src/core/engine.rs Adds mode: AppMode to turn_metadata_block and user_text_message_with_turn_metadata_for_route; the main send path correctly passes the live mode, but the no-route wrapper hardcodes AppMode::Agent, leaving steer/REPL/LSP mid-turn messages with wrong mode metadata in Plan and Yolo sessions.
crates/tui/src/core/engine/tests.rs Adds turn_metadata_includes_current_mode test covering the Yolo mode path; correctly updates the existing turn_metadata_includes_auto_model_route test to supply the new mode argument.

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 sessions
Loading

Comments Outside Diff (1)

  1. crates/tui/src/core/engine.rs, line 962-971 (link)

    P1 Mid-turn injected messages always report agent mode

    user_text_message_with_turn_metadata (the no-_for_route variant) hardcodes AppMode::Agent. This method is used in seven places inside handle_deepseek_turn (steer messages, REPL feedback, goal-continuation messages) and in flush_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 carry Current mode: agent in 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.rs already receive mode: AppMode as a parameter, so the mode is available; it just isn't threaded through this helper.

    Fix in Codex Fix in Claude Code Fix in Cursor

Fix All in Codex Fix All in Claude Code Fix All in Cursor

Reviews (1): Last reviewed commit: "fix(tui): include mode in turn metadata" | Re-trigger Greptile

@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!

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.

1 participant