From 8dd972b00620bf44cd72a35eaf599b1aca34920d Mon Sep 17 00:00:00 2001 From: eric8810 Date: Thu, 26 Nov 2026 22:21:26 +0800 Subject: [PATCH 1/2] fix(route): answer an uninstalled service as NoService A routed call that selects a Session or line where no provider of the service is installed was answered as the owner's own failure ("... is not provided now"). No owner ran, so the holder answers it: RouteError::NoService { service }, and `no_service` on `sessions.call`, final and not retryable, as the #2127 decision states. Refs #2127 --- .../tests/routing_flow.rs | 27 ++++++++++++++++++- crates/dim-agent-runtime/src/route.rs | 20 ++++++++------ crates/dim-app-server/src/agents.rs | 4 +-- crates/dim-app-server/src/agents/sessions.rs | 6 ++++- .../contracts/runtime-owner-operations.md | 5 ++-- docs/typescript-plugin-authoring.md | 7 ++--- npm/branch-services.d.ts | 8 +++--- npm/plugin.d.ts | 5 ++-- runtime/plugin-sdk.test.mjs | 2 +- 9 files changed, 61 insertions(+), 23 deletions(-) diff --git a/crates/dim-agent-capabilities/tests/routing_flow.rs b/crates/dim-agent-capabilities/tests/routing_flow.rs index 81ced4a78f..419127708a 100644 --- a/crates/dim-agent-capabilities/tests/routing_flow.rs +++ b/crates/dim-agent-capabilities/tests/routing_flow.rs @@ -1,5 +1,6 @@ //! Flow: a Session's parts and their runtimes reach its own lines and faces by -//! id, and answer `SessionClosing`, `NoLine` or a reach refusal otherwise +//! id, and answer `SessionClosing`, `NoLine`, `NoService` or a reach refusal +//! otherwise //! ([#2127](https://github.com/arcships/dim/issues/2127)). use dim_agent_capabilities::defaults; @@ -76,6 +77,10 @@ impl Rig { ("sessionScope", "session"), ("toolRegistry", "session"), ("branchLifecycle", "branch"), + // A face the catalog shares but this rig's profile does not + // install. + ("notInstalled", "branch"), + ("notInstalledHere", "session"), ] { builder.catalog_mut().register_shared_instance(name, group); } @@ -596,6 +601,26 @@ async fn routing_resolves_only_data_faces_of_the_scope_it_reaches() { }, "a Session face is not a line face" ); + assert_eq!( + scope + .line_call(LineCall::new("main", "notInstalled", "read", vec![])) + .await + .unwrap_err(), + RouteError::NoService { + service: "notInstalled".into() + }, + "the holder answers a face the line does not install" + ); + assert_eq!( + scope + .call(SessionCall::new("notInstalledHere", "read", vec![])) + .await + .unwrap_err(), + RouteError::NoService { + service: "notInstalledHere".into() + }, + "the holder answers a face the Session does not install" + ); let error = scope .line_call(LineCall::new("main", "timeline", "absent", vec![])) .await diff --git a/crates/dim-agent-runtime/src/route.rs b/crates/dim-agent-runtime/src/route.rs index 4ada4e43b5..02b7c78cda 100644 --- a/crates/dim-agent-runtime/src/route.rs +++ b/crates/dim-agent-runtime/src/route.rs @@ -23,7 +23,7 @@ //! takes the same two forms for a process caller. //! //! Each call looks the target up again, so a caller never keeps a live target -//! (D4). Rust calls the same two operations: it builds `args` from the target +//! (D4). Rust calls the same operations: it builds `args` from the target //! operation's request type and reads the reply as its reply type. //! //! What a call resolves is the target scope's data face in the catalog. A name @@ -40,7 +40,9 @@ //! closing answers [`RouteError::SessionClosing`], and a line target answers it //! too, because closing the Session closes its lines. A line that is closing or //! closed, or that belongs to another Session, answers [`RouteError::NoLine`]; -//! that is final for the line: routing never retries it. +//! that is final for the line: routing never retries it. A selected scope +//! that has no provider of the service answers [`RouteError::NoService`], for +//! example when its profile does not install that service. use crate::*; use rutis::Ctx; @@ -81,6 +83,11 @@ pub enum RouteError { /// lines. Final for that line: no hold and no retry. #[error("no line {line} in Session {session}")] NoLine { session: String, line: String }, + /// The Session or line was selected, but no provider of `service` is + /// installed there, for example when its profile leaves the service out. + /// The holder answers it, not an owner; final, no retry. + #[error("{service} is not provided there")] + NoService { service: String }, /// The name is not a data face a route resolves there: the assembly marks /// it internal, it is a mechanism registration point, or it is a scope /// lifecycle service. A permanent answer: the request is wrong. @@ -120,6 +127,7 @@ impl RouteError { Self::SessionReloading(_) => "session_reloading", Self::SessionUnavailable { .. } => "session_unavailable", Self::NoLine { .. } => "no_line", + Self::NoService { .. } => "no_service", Self::NotDataFace { .. } => "not_data_face", Self::MethodNotRoutable { .. } => "method_not_routable", Self::WrongScope { .. } => "wrong_scope", @@ -437,12 +445,8 @@ pub(crate) async fn call_face( ) -> Routed> { let dispatch = ctx .get_at::(&host_key_in(service, instance)) - .ok_or_else(|| RouteError::Owner { - name: service.into(), - code: None, - message: format!("{service} is not provided now"), - data: None, - reloading: false, + .ok_or_else(|| RouteError::NoService { + service: service.into(), })?; let args = BridgeValue::List( args.iter() diff --git a/crates/dim-app-server/src/agents.rs b/crates/dim-app-server/src/agents.rs index 75d510f486..3b47a1fc3e 100644 --- a/crates/dim-app-server/src/agents.rs +++ b/crates/dim-app-server/src/agents.rs @@ -1823,8 +1823,8 @@ impl AgentIndex { /// the Session is loaded for the call and held while it runs, its own scope /// resolves a line, and the target's reply and error come back unchanged. /// A target that cannot be selected answers `NoSession`, - /// `SessionClosing`, `SessionReloading`, `SessionUnavailable` or `NoLine` - /// before the target's operation runs. + /// `SessionClosing`, `SessionReloading`, `SessionUnavailable`, `NoLine` or + /// `NoService` before the target's operation runs. pub(crate) async fn call( &self, request: crate::agents::sessions::CallRequest, diff --git a/crates/dim-app-server/src/agents/sessions.rs b/crates/dim-app-server/src/agents/sessions.rs index 3126b4ca91..aa132cd12d 100644 --- a/crates/dim-app-server/src/agents/sessions.rs +++ b/crates/dim-app-server/src/agents/sessions.rs @@ -299,7 +299,7 @@ pub enum SessionsError { /// A routed call could not select its target. These are the same codes a /// Session's own scope answers: `no_session`, `session_closing`, /// `session_reloading` (retryable), `session_unavailable`, `no_line`, - /// `not_data_face`, `method_not_routable` and `wrong_scope`. + /// `no_service`, `not_data_face`, `method_not_routable` and `wrong_scope`. #[error("{message}")] NoSession { message: String }, #[error("{message}")] @@ -312,6 +312,9 @@ pub enum SessionsError { /// The line is not the Session's, or it is gone; `line` names it. #[error("{message}")] NoLine { message: String, line: String }, + /// The target was selected but does not provide `service`. + #[error("{message}")] + NoService { message: String, service: String }, #[error("{message}")] NotDataFace { message: String, service: String }, #[error("{message}")] @@ -935,6 +938,7 @@ fn routed(error: dim_agent_runtime::RouteError) -> SessionsError { SessionsError::SessionUnavailable { message, reason } } RouteError::NoLine { line, .. } => SessionsError::NoLine { message, line }, + RouteError::NoService { service } => SessionsError::NoService { message, service }, RouteError::Owner { name, code, diff --git a/docs/design/contracts/runtime-owner-operations.md b/docs/design/contracts/runtime-owner-operations.md index 3ceebfd579..491bc5d770 100644 --- a/docs/design/contracts/runtime-owner-operations.md +++ b/docs/design/contracts/runtime-owner-operations.md @@ -46,8 +46,9 @@ envelope leaves `value` out so a process caller reads `undefined`; a direct call (`undefined`) either way. Agents loads the Session for the call and holds it while it runs (ADR 027 D5). A target that cannot be selected answers `no_session`, `session_closing`, `session_reloading` (retry later), -`session_unavailable` (report the reason) or `no_line` (final for that line), before the -target's operation runs. Tree history, directory and batch input continue to use the +`session_unavailable` (report the reason), `no_line` (final for that line) or `no_service` +(the selected target does not provide the service; final), before the target's operation +runs. Tree history, directory and batch input continue to use the tree's own methods. | Session caller | Target operation | diff --git a/docs/typescript-plugin-authoring.md b/docs/typescript-plugin-authoring.md index 3325678403..f8480f3783 100644 --- a/docs/typescript-plugin-authoring.md +++ b/docs/typescript-plugin-authoring.md @@ -36,7 +36,8 @@ the id instead, and the owner of the index looks it up at the call: `sessionScop for a line of its own Session, `sessions.call` for a Session or a line of it, from the process. Both carry `{service, method, args}` — the target's own operation — and answer `no_session`, `session_closing`, `session_reloading`, `session_unavailable` or `no_line` when -the target cannot be selected; the target owner's own failure arrives unchanged +the target cannot be selected, and `no_service` when the selected target does not provide the +service (its profile leaves it out); the target owner's own failure arrives unchanged ([#2127](https://github.com/arcships/dim/issues/2127), ADR 027). ```ts @@ -61,11 +62,11 @@ again. The two entries name a failure with different spellings. `sessions.call` answers the `sessions` envelope with snake_case codes — `no_session`, `session_closing`, -`session_reloading`, `session_unavailable`, `no_line`, `not_data_face`, +`session_reloading`, `session_unavailable`, `no_line`, `no_service`, `not_data_face`, `method_not_routable`, `wrong_scope`, and `routed` for the owner's own failure. `sessionScope.lineCall`/`call` throw a `RouteError` whose variants carry the same kinds in camelCase (`noSession`, `sessionClosing`, `sessionReloading`, `sessionUnavailable`, -`noLine`, `notDataFace`, `methodNotRoutable`, `wrongScope`, `owner`), and `owner` keeps the +`noLine`, `noService`, `notDataFace`, `methodNotRoutable`, `wrongScope`, `owner`), and `owner` keeps the owner's `name`, `message`, `data` and `reloading`. Only `session_reloading`/`sessionReloading` and an owner failure that says it reloads may be retried. A routed method that replies nothing answers `null` through `sessionScope`; `sessions.call` leaves `value` out, so a process caller diff --git a/npm/branch-services.d.ts b/npm/branch-services.d.ts index e03ce36b8c..1d08732b7c 100644 --- a/npm/branch-services.d.ts +++ b/npm/branch-services.d.ts @@ -1416,6 +1416,7 @@ export type RouteError = | /** Agents is reloading and cannot take calls yet. A process caller retries later. */ { sessionReloading: string } | /** The Session exists but cannot be loaded now: its restore failed, or the Agent that owns it is unavailable. The caller reports the reason and does not retry. */ { sessionUnavailable: { session: string; reason: string } } | /** The Session is live but the line is closing, closed, or not one of its lines. Final for that line: no hold and no retry. */ { noLine: { session: string; line: string } } + | /** The Session or line was selected, but no provider of `service` is installed there, for example when its profile leaves the service out. The holder answers it, not an owner; final, no retry. */ { noService: { service: string } } | /** The name is not a data face a route resolves there: the assembly marks it internal, it is a mechanism registration point, or it is a scope lifecycle service. A permanent answer: the request is wrong. */ { notDataFace: { service: string } } | /** The service is a data face a route resolves, but this operation of it is not: its call needs a cancellation or a cleanup the routed call cannot carry, so only a direct call keeps its lifetime behaviour. */ { methodNotRoutable: { service: string; method: string } } | /** The name is a data face, but not of the scope the route reaches. */ { wrongScope: { service: string; group: string } } @@ -1478,11 +1479,12 @@ export type PermissionState = { /** A Session service failure; generated exports throw this serde value. */ export type SessionsError = | { code: "rejected"; message: string } - | /** A routed call could not select its target. These are the same codes a Session's own scope answers: `no_session`, `session_closing`, `session_reloading` (retryable), `session_unavailable`, `no_line`, `not_data_face`, `method_not_routable` and `wrong_scope`. */ { code: "no_session"; message: string } + | /** A routed call could not select its target. These are the same codes a Session's own scope answers: `no_session`, `session_closing`, `session_reloading` (retryable), `session_unavailable`, `no_line`, `no_service`, `not_data_face`, `method_not_routable` and `wrong_scope`. */ { code: "no_session"; message: string } | { code: "session_closing"; message: string } | { code: "session_reloading"; message: string } | /** The Session exists but cannot load; `reason` says why. */ { code: "session_unavailable"; message: string; reason: string } | /** The line is not the Session's, or it is gone; `line` names it. */ { code: "no_line"; message: string; line: string } + | /** The target was selected but does not provide `service`. */ { code: "no_service"; message: string; service: string } | { code: "not_data_face"; message: string; service: string } | { code: "method_not_routable"; message: string; service: string; method: string } | { code: "wrong_scope"; message: string; service: string; group: string } @@ -1821,13 +1823,13 @@ export type ReservedMethodsErrorThrown = RustError<"ReservedMethodsError", "rese export type ResourceErrorThrown = RustError<"ResourceError", string, ResourceError> /** What a method returning `Err(RouteError)` throws. */ -export type RouteErrorThrown = RustError<"RouteError", "noSession" | "sessionClosing" | "sessionReloading" | "sessionUnavailable" | "noLine" | "notDataFace" | "methodNotRoutable" | "wrongScope" | "owner", RouteError> +export type RouteErrorThrown = RustError<"RouteError", "noSession" | "sessionClosing" | "sessionReloading" | "sessionUnavailable" | "noLine" | "noService" | "notDataFace" | "methodNotRoutable" | "wrongScope" | "owner", RouteError> /** What a method returning `Err(SessionInstanceError)` throws. */ export type SessionInstanceErrorThrown = RustError<"SessionInstanceError", "Create" | "NotReady" | "Cleanup", undefined> /** What a method returning `Err(SessionsError)` throws. */ -export type SessionsErrorThrown = RustError<"SessionsError", "rejected" | "no_session" | "session_closing" | "session_reloading" | "session_unavailable" | "no_line" | "not_data_face" | "method_not_routable" | "wrong_scope" | "routed" | "agent_unknown" | "session_closed" | "branch_missing" | "branch_ended" | "reloading" | "future_sequence" | "ambiguous" | "publication_unknown" | "failed", SessionsError> +export type SessionsErrorThrown = RustError<"SessionsError", "rejected" | "no_session" | "session_closing" | "session_reloading" | "session_unavailable" | "no_line" | "no_service" | "not_data_face" | "method_not_routable" | "wrong_scope" | "routed" | "agent_unknown" | "session_closed" | "branch_missing" | "branch_ended" | "reloading" | "future_sequence" | "ambiguous" | "publication_unknown" | "failed", SessionsError> /** What a method returning `Err(TaskError)` throws. */ export type TaskErrorThrown = RustError<"TaskError", "read" | "unknown" | "closed" | "running", TaskError> diff --git a/npm/plugin.d.ts b/npm/plugin.d.ts index 64df6bdc5b..141ab31283 100644 --- a/npm/plugin.d.ts +++ b/npm/plugin.d.ts @@ -308,8 +308,9 @@ export interface Sessions { * (#2127). Agents loads and holds the Session for the call. A target that * cannot be selected answers `no_session`, `session_closing`, * `session_reloading` (retry later), `session_unavailable` (report the - * reason) or `no_line`; the target owner's own failure is `routed` with its - * name and message. */ + * reason), `no_line` or `no_service` (the target does not provide the + * service); the target owner's own failure is `routed` with its name and + * message. */ call( request: C, ): Promise>>; diff --git a/runtime/plugin-sdk.test.mjs b/runtime/plugin-sdk.test.mjs index e41764ad34..0a2e787ccd 100644 --- a/runtime/plugin-sdk.test.mjs +++ b/runtime/plugin-sdk.test.mjs @@ -137,7 +137,7 @@ const preset: 'read-only' | 'workspace-write' | 'full-access' = defaults.preset; const allowed: string[] = livePolicy.allowedTools; const disallowed: string[] = defaults.disallowedTools; declare const permissionError: SessionsErrorThrown; -const permissionCode: 'rejected' | 'routed' | 'no_session' | 'session_closing' | 'session_reloading' | 'session_unavailable' | 'no_line' | 'not_data_face' | 'method_not_routable' | 'wrong_scope' | 'agent_unknown' | 'session_closed' | 'branch_missing' | 'branch_ended' | 'reloading' | 'future_sequence' | 'ambiguous' | 'publication_unknown' | 'failed' = permissionError.code; +const permissionCode: 'rejected' | 'routed' | 'no_session' | 'session_closing' | 'session_reloading' | 'session_unavailable' | 'no_line' | 'no_service' | 'not_data_face' | 'method_not_routable' | 'wrong_scope' | 'agent_unknown' | 'session_closed' | 'branch_missing' | 'branch_ended' | 'reloading' | 'future_sequence' | 'ambiguous' | 'publication_unknown' | 'failed' = permissionError.code; void permissionVersion; void preset; void allowed; void disallowed; void permissionCode; // @ts-expect-error permission reads require a branch identity. void permissions.permission({ sessionId: 'session' }); From d0bb9106977dfb9547dea2a7e79dd993f6df3ed9 Mon Sep 17 00:00:00 2001 From: eric8810 Date: Thu, 26 Nov 2026 23:08:11 +0800 Subject: [PATCH 2/2] test(route): pin no_service on the sessions.call envelope Restores the route docs to name the two SessionScope operations Rust calls, and adds a process-envelope case: an uninstalled branch face answers no_service, non-retryable, and an absent line still answers no_line first. Refs #2127 --- crates/dim-agent-runtime/src/route.rs | 2 +- .../dim-app-server/tests/routed_call_flow.rs | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/crates/dim-agent-runtime/src/route.rs b/crates/dim-agent-runtime/src/route.rs index 02b7c78cda..c82c141388 100644 --- a/crates/dim-agent-runtime/src/route.rs +++ b/crates/dim-agent-runtime/src/route.rs @@ -23,7 +23,7 @@ //! takes the same two forms for a process caller. //! //! Each call looks the target up again, so a caller never keeps a live target -//! (D4). Rust calls the same operations: it builds `args` from the target +//! (D4). Rust calls the same two `SessionScope` operations: it builds `args` from the target //! operation's request type and reads the reply as its reply type. //! //! What a call resolves is the target scope's data face in the catalog. A name diff --git a/crates/dim-app-server/tests/routed_call_flow.rs b/crates/dim-app-server/tests/routed_call_flow.rs index 06010f5435..1f3ee3c515 100644 --- a/crates/dim-app-server/tests/routed_call_flow.rs +++ b/crates/dim-app-server/tests/routed_call_flow.rs @@ -71,6 +71,10 @@ impl Rig { let mut builder = AgentBuilder::new(AgentConfig::default()); defaults::mock_hosts(&mut builder); defaults::install(&mut builder); + // A face the catalog shares but this profile does not install. + builder + .catalog_mut() + .register_shared_instance("notInstalled", "branch"); let observed = Arc::new(OnceLock::new()); let probe = observed.clone(); builder.plugin(move |_| Ok(Box::new(Probe(probe.clone())) as Box)); @@ -163,6 +167,40 @@ async fn a_routed_call_loads_and_holds_an_admitted_session() { rig.server.join().await.unwrap(); } +#[tokio::test(flavor = "multi_thread", worker_threads = 4)] +async fn an_uninstalled_service_answers_no_service_after_the_line() { + let rig = Rig::start().await; + let launched = rig + .call("launch", json!({"cwd": rig.home.path().to_string_lossy()})) + .await; + let id = launched["value"]["sessionId"] + .as_str() + .unwrap_or_else(|| panic!("a Session launches through Agents: {launched}")) + .to_owned(); + let missing = rig + .call( + "call", + json!({"sessionId": id, "lineId": "main", "service": "notInstalled", "method": "read"}), + ) + .await; + assert_eq!(missing["ok"], false, "{missing}"); + assert_eq!(missing["error"]["code"], "no_service", "{missing}"); + assert_eq!(missing["error"]["service"], "notInstalled", "{missing}"); + assert_eq!(missing["error"]["retryable"], false, "{missing}"); + let no_line = rig + .call( + "call", + json!({"sessionId": id, "lineId": "absent", "service": "notInstalled", "method": "read"}), + ) + .await; + assert_eq!( + no_line["error"]["code"], "no_line", + "the line is selected before the service: {no_line}" + ); + rig.server.shutdown(); + rig.server.join().await.unwrap(); +} + #[tokio::test(flavor = "multi_thread", worker_threads = 4)] async fn a_call_during_an_agents_restart_is_retryable() { let rig = Rig::start().await;