Skip to content

fix(query): preserve explicit model selection#31

Open
BunsDev wants to merge 1 commit into
mainfrom
codex/propose-fix-for-managed-agents-vulnerability
Open

fix(query): preserve explicit model selection#31
BunsDev wants to merge 1 commit into
mainfrom
codex/propose-fix-for-managed-agents-vulnerability

Conversation

@BunsDev
Copy link
Copy Markdown
Member

@BunsDev BunsDev commented Jun 3, 2026

Motivation

  • Prevent project managed_agents.manager_model from silently replacing an explicit caller-selected model/provider (e.g. --model) at query runtime, which could route private prompts to an unexpected provider.
  • Centralize model-selection logic so managed-agent overrides still apply by default but can be opt-out when the caller explicitly chose a model/provider.

Description

  • Add preserve_selected_model: bool to QueryConfig (default false) to record when a caller explicitly selected model/provider.
  • Introduce selected_model_for_query(cfg: &QueryConfig) -> String to centralize selection logic and return the manager model only when preserve_selected_model is false.
  • Replace the inline managed-agent override in run_query_loop with selected_model_for_query and make effective_model derived from it.
  • Set query_config.preserve_selected_model = cli.model.is_some() || cli.provider.is_some() in the CLI, and ensure sub-agent QueryConfig instances set it to false.
  • Add two unit tests covering the default override and explicit-selection preservation and update agent_tool and other call sites to initialize the new flag.

Testing

  • Ran cargo test --package claurst-query test_explicit_model_selection_blocks_managed_agent_override and it passed.
  • Ran cargo test --package claurst-query test_managed_agent_manager_model_overrides_by_default and it passed.
  • Ran cargo check --package claurst-query and it succeeded.
  • cargo check --workspace was attempted but blocked by a missing system dependency (alsa.pc / ALSA pkg-config) in the environment, so workspace-wide check could not complete here.

Codex Task

Copilot AI review requested due to automatic review settings June 3, 2026 11:49
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the query model-selection flow to ensure that when a caller explicitly selects a model/provider (e.g., via CLI flags), that choice is preserved and not silently overridden by managed_agents.manager_model at query runtime—reducing the risk of prompts being routed to an unexpected provider.

Changes:

  • Add preserve_selected_model: bool to QueryConfig (default false) to record explicit caller selection intent.
  • Centralize model selection in selected_model_for_query(&QueryConfig) -> String, applying managed_agents.manager_model only when preserve_selected_model == false.
  • Wire the flag from the CLI (--model/--provider) and update AgentTool / tests to initialize the new field.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src-rust/crates/query/src/lib.rs Adds the new config flag, centralizes model selection logic, and adds unit tests for override vs preservation behavior.
src-rust/crates/query/src/agent_tool.rs Updates QueryConfig construction to initialize preserve_selected_model for agent tool invocations.
src-rust/crates/cli/src/main.rs Sets preserve_selected_model when --model or --provider is explicitly provided.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants