Skip to content

Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins

fix(host-core): keep tool-level failures for an unknown session

vastsab78ad234b918
diff --git a/crates/host-core/src/rpc/mod.rs b/crates/host-core/src/rpc/mod.rs
index 8e19185de..a7ef7e477 100644
--- a/crates/host-core/src/rpc/mod.rs
+++ b/crates/host-core/src/rpc/mod.rs
@@ -3727,7 +3727,9 @@ async fn handle_request(
let remote_workspace = {
let st = state.lock().await;
- remote_tools::session_remote_workspace(&st, &p.session_id)?
+ // A session the store does not have keeps the local tool path
+ // and its tool-level failure instead of becoming an RPC error.
+ remote_tools::session_remote_workspace_optional(&st, &p.session_id)?
};
let command_shell_id = if p.tool_name == "Bash" && remote_workspace.is_none() {
let catalog = {
diff --git a/crates/host-core/src/rpc/remote_tools.rs b/crates/host-core/src/rpc/remote_tools.rs
index b82e43a21..235ca70ff 100644
--- a/crates/host-core/src/rpc/remote_tools.rs
+++ b/crates/host-core/src/rpc/remote_tools.rs
@@ -3,13 +3,10 @@
use super::*;
use crate::db::{Database, RemoteWorkspace};
-pub(super) fn session_remote_workspace(
+fn remote_workspace_of(
state: &AppState,
- session_id: &str,
+ summary: &sessions::SessionSummary,
) -> Result<Option<RemoteWorkspace>, JsonRpcError> {
- let summary = sessions::session_summary(&state.db, session_id)
- .map_err(|e| rpc_err(1000, e.to_string(), "INTERNAL"))?
- .ok_or_else(|| rpc_err(1007, "session not found", "SESSION_NOT_FOUND"))?;
summary
.project_path
.as_deref()
@@ -19,6 +16,33 @@ pub(super) fn session_remote_workspace(
.map_err(|e| rpc_err(1002, e.to_string(), "INVALID_PARAMS"))
}
+/// The remote binding of a session that must exist.
+pub(super) fn session_remote_workspace(
+ state: &AppState,
+ session_id: &str,
+) -> Result<Option<RemoteWorkspace>, JsonRpcError> {
+ let summary = sessions::session_summary(&state.db, session_id)
+ .map_err(|e| rpc_err(1000, e.to_string(), "INTERNAL"))?
+ .ok_or_else(|| rpc_err(1007, "session not found", "SESSION_NOT_FOUND"))?;
+ remote_workspace_of(state, &summary)
+}
+
+/// `tools.execute` is reachable for a session the store does not have yet, and
+/// that path owns its own tool-level failure. A missing session therefore means
+/// "no remote binding" instead of an RPC error, so the local tool path stays
+/// exactly as it was before remote workspaces existed.
+pub(super) fn session_remote_workspace_optional(
+ state: &AppState,
+ session_id: &str,
+) -> Result<Option<RemoteWorkspace>, JsonRpcError> {
+ match sessions::session_summary(&state.db, session_id)
+ .map_err(|e| rpc_err(1000, e.to_string(), "INTERNAL"))?
+ {
+ Some(summary) => remote_workspace_of(state, &summary),
+ None => Ok(None),
+ }
+}
+
pub(super) fn decorate_session(db: &Database, mut value: Value) -> Result<Value, JsonRpcError> {
if let Some(path) = value.get("projectPath").and_then(Value::as_str) {
if let Some(remote) = db