Craft Anything: understand how any software works, and craft your own.
Rust
Refuse disabled backends when starting chat or compare (#1008)
Tomáš Doubek13fc7920baf3
diff --git a/crates/ai/src/lib.rs b/crates/ai/src/lib.rsindex 6bc6452b..b41475bd 100644--- a/crates/ai/src/lib.rs+++ b/crates/ai/src/lib.rs@@ -840,7 +840,7 @@ impl AiHub {})}- /// Start a conversation with the lead backend (or the named one).+ /// Start a conversation with the lead backend (or the named one, while it is enabled).pub fn start(&self, backend: Option<&str>, beginner: bool) -> Result<Box<dyn Conversation>, ToolError> {let cfg = self.config();let first = match backend {@@ -850,6 +850,10 @@ impl AiHub {.cloned().ok_or_else(|| ToolError::unavailable("No AI is set up yet.").with_remediation("Add one in Settings → AI."))?,};+ if !first.config.enabled {+ return Err(ToolError::new(ErrorCode::BadSettings, format!("{} is turned off.", first.config.name))+ .with_remediation("Turn it on in Settings → AI, or choose another backend for this conversation."));+ }if first.config.kind == BackendKind::AgentCli {return Ok(Box::new(cli_agents::SharedConversation::new(self.engine.clone(), first, beginner)?));}diff --git a/crates/ai/src/tests.rs b/crates/ai/src/tests.rsindex 343405f3..9234989c 100644--- a/crates/ai/src/tests.rs+++ b/crates/ai/src/tests.rs@@ -169,6 +169,56 @@ fn hub() -> (AiHub, tempfile::TempDir) {(h, dir)}+/// A named backend stays off for chat, including before API or agent setup can run.+#[test]+fn disabled_backends_are_refused_when_chat_starts() {+ let (h, _dir) = hub();+ for kind in [BackendKind::OpenaiCompatible, BackendKind::AgentCli] {+ // A malformed tunnel port fails before opening SSH if API setup is reached.+ let (base_url, ssh_host) =+ if kind == BackendKind::OpenaiCompatible { ("http://127.0.0.1:not-a-port/v1", Some("unused".into())) } else { ("http://127.0.0.1:0/v1", None) };+ h.add_backend(+ BackendConfig { name: "Off".into(), kind, model: "no-such-agent".into(), base_url: Some(base_url.into()), ssh_host, enabled: false },+ None,+ )+ .unwrap();+ let error = h.start(Some("Off"), false).err().expect("chat must refuse a disabled backend");+ assert_eq!(error.code, ErrorCode::BadSettings);+ assert!(error.message.contains("Off") && error.message.contains("turned off"), "{error:?}");+ assert!(error.remediation.as_deref().is_some_and(|s| s.contains("Settings → AI")), "{error:?}");+ }+}++/// Compare checks either position; enabled named and automatic chat choices still work.+#[test]+fn disabled_backends_are_refused_on_either_side_of_compare() {+ let (h, _dir) = hub();+ for (name, enabled) in [("Off", false), ("On", true), ("Other", true)] {+ h.add_backend(+ BackendConfig {+ name: name.into(),+ kind: BackendKind::OpenaiCompatible,+ model: "test-model".into(),+ base_url: Some("http://127.0.0.1:0/v1".into()),+ ssh_host: None,+ enabled,+ },+ None,+ )+ .unwrap();+ }+ for (left, right) in [("Off", "On"), ("On", "Off")] {+ let error = h.compare(left, right, true).err().expect("compare must refuse a disabled backend");+ assert_eq!(error.code, ErrorCode::BadSettings);+ assert!(error.message.contains("Off") && error.message.contains("turned off"), "{error:?}");+ }+ assert!(h.start(Some("On"), false).is_ok());+ assert!(h.start(None, false).is_ok());+ assert!(h.compare("On", "Other", false).is_ok());+ let unknown = h.start(Some("Missing"), false).err().unwrap();+ assert!(unknown.message.contains("No AI backend named"), "{unknown:?}");+}+/// A CLI stand-in checks saved selections, and an explicit one runs natively with our MCP server.#[cfg(unix)]#[test]diff --git a/docs/ROADMAP.md b/docs/ROADMAP.mdindex f1aa1c69..5a8b0809 100644--- a/docs/ROADMAP.md+++ b/docs/ROADMAP.md@@ -612,6 +612,8 @@ Owner: open · Status: in progressfix if the helper is missing. Verified: POSIX-shell regression test (`the_remote_line_runs_on_a_posix_shell`)and an SSH round-trip to localhost (probe, byte-exact write, mode, cleanup). Not run with a liveagent over SSH. — claimed: jelassiaymen94, branch feature/r2.2-opencode-remote-mcp+- [ ] Make `the_remote_line_runs_on_a_posix_shell` accept the shell's missing-command status:+ on macOS, `command -v` returns 1 rather than the asserted 127; the full AI suite fails.- [ ] Verify OpenCode model discovery and an explicit thinking selection on a live SSH host,and complete a live generation with the selected model and variant (local catalogue verified).@@ -811,8 +813,10 @@ Gaps found while using the app for real projects.- [x] A prompt brought back with Up keeps its pictures (their paths are absolute, so they don'tcome back after the project is moved)- [ ] Change a project's builder from its page (a tool, so the CLI and MCP can too) — in PR #245-- [ ] `chat --backend <a name that is turned off>` (and `compare`) still talks to it:- `AiHub::start` accepts a named backend without checking `enabled`, unlike a build+- [x] `chat --backend <a name that is turned off>` and `compare` refuse it before model or+ agent setup: `AiHub::start` checks `enabled` and says how to turn it on or choose another+ — PR #1008; claimed: Codex, branch bugfix/r2.9-disabled-chat-backend+ (the API regression uses invalid tunnel settings to detect setup before the guard)- [x] Ctrl+V (Shift+Insert, Cmd+V) in a prompt box that takes pictures pastes a copied image (savedas a PNG) or copied picture files; attachments show as square picture tiles, the wholepicture on hover, decoded on a workerdiff --git a/docs/STATUS.md b/docs/STATUS.mdindex 0846a0b3..67186871 100644--- a/docs/STATUS.md+++ b/docs/STATUS.md@@ -8,6 +8,7 @@ workspace clippy, layers, fmt and the secret scan of all history were clean. Chi| Area | State | Verified by ||---|---|---|+| Disabled chat backends | Naming a backend that is off refuses chat and either side of compare with a settings error and guidance, before API or coding-agent setup | Isolated hub regressions for disabled API and agent backends, both compare positions, and enabled/automatic controls. Invalid tunnel settings detect API setup before the guard. No live provider or agent was used || Runner-owned app windows | Runtime capture tries the launched process and its descendants; the captured window owner's PID is also used for the UI tree. Unrelated processes with matching names are excluded. Process discovery has a deadline, output cap and candidate limit | Hermetic regressions cover runner/child/grandchild ownership, unrelated windows, direct launches, cycles, malformed rows, caps and errors. A macOS process snapshot finds an owned child without opening a window. Windows and real Go GUI capture have not been run || New-project toolchains | New Python, Go, .NET, Maven, Gradle and Make projects use the same build catalogue as existing projects (`engine/src/toolchains.toml`). Shared launch recipes let screenshots, self-tests and Play start Python `main.py`, `app.py` or `__main__.py`, Go with a root `main.go`, and one root `.csproj`. Python uses a project-local virtual environment when present, resolves its executable to an absolute path even for relative project folders, and forces fresh syntax compilation; .NET passes app options after `--`. Manifest markers take priority over standalone Python files. Runtime window-capture requests normalize relative project and runner paths to absolute paths. Existing packaged programs, Rust, Electron and Godot keep launch priority. Multiple `.csproj` matches or a capped scan do not choose a project. Other layouts still need a packaged program or another launch recipe | Catalogue and launch regressions cover argv boundaries, ambiguous entrypoints, scan limits and Windows/local interpreter selection, including relative project folders and unchanged argument boundaries. Capture-request tests cover relative placements and PATH results, local interpreters and optional UI-tree output without opening a window. An owned interpreter stand-in runs the full new-project build/screenshot path, rejects failed builds, and verifies a failed screenshot cannot reuse an old PNG. An opt-in real Python 3.15.2 fixture on macOS passes build/screenshot checks, ignores invalid virtualenv code, and rejects a syntax error even when its mtime matches the cached version. Without `compileall -f` that same syntax-error probe incorrectly exits zero. Real Go/.NET/Maven/Gradle runs, Windows and GUI apps have not been verified for this change || macOS optional UI tree | `runtime_ui_read` with `accessibility: false` skips the tree and its permission check, returns empty nodes without truncation, and records the flag and skipped read in its evidence (#307). Walkthroughs still require Accessibility. Screenshot capture remains open (#248) | Engine regression on macOS compiles and runs the real Swift helper with zero and one node limits, without reading another app's UI. No granted-permission tree read or walkthrough was run for this change |