Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(session-host): derive the session id from the definition it was given

sanil-2327dad3b0871c
diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs
index 5f447e1e12..fe251ce892 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_build.rs
@@ -50,10 +50,27 @@ impl SessionHostBuilder {
// Resolved here rather than at its historical position below: the pack
// withholding is per-agent (a pack is skipped for the specialist that
// owns its family), so the id has to exist before the strip.
- let agent_definition_name = self
- .agent_definition_name
- .clone()
- .unwrap_or_else(|| "main".to_string());
+ // A caller-supplied definition is resolved by the id the session was
+ // stamped with (`OpenHumanDefinitionRegistry::host_definition` matches
+ // `session_definition.id` against it), so the two must agree or the
+ // definition is unreachable and every turn is refused for want of it.
+ // Deriving the name from the definition makes the common case correct
+ // without a second call, and a name that contradicts the definition is
+ // a build error rather than a turn-time mystery.
+ let agent_definition_name = match (
+ self.agent_definition_name.clone(),
+ self.session_definition.as_deref(),
+ ) {
+ (Some(name), Some(definition)) if name.trim() != definition.id.trim() => {
+ return Err(anyhow::anyhow!(
+ "agent_definition_name `{name}` does not match the supplied agent definition `{}`; the session is resolved by the name it is stamped with, so a definition under a different id can never answer for it",
+ definition.id
+ ));
+ }
+ (Some(name), _) => name,
+ (None, Some(definition)) => definition.id.clone(),
+ (None, None) => "main".to_string(),
+ };
// On-demand tool disclosure: withhold packed tools' schemas from the
// provider and advertise `use_skill` in their place. The
// tools stay in the registry below and stay executable — only the
diff --git a/crates/openhuman-core/src/agent/session_host/builder/builder_tests_session_definition_tests.rs b/crates/openhuman-core/src/agent/session_host/builder/builder_tests_session_definition_tests.rs
index ec71c795cf..a1fbe3eb13 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/builder_tests_session_definition_tests.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/builder_tests_session_definition_tests.rs
@@ -29,17 +29,21 @@ fn definition(id: &str, tools: Vec<&str>) -> Arc<AgentDefinition> {
Arc::new(def)
}
-fn seat(
- definition: Option<Arc<AgentDefinition>>,
-) -> crate::agent::session_host::types::OpenHumanSessionHost {
+/// A builder with everything a session needs and no identity yet.
+fn bare() -> crate::agent::SessionHostBuilder {
let model: Arc<dyn tinyinference_llm::model::ChatModel<()>> =
Arc::new(tinyagents_harness::testkit::ScriptedModel::new(Vec::new()));
- let mut builder = crate::agent::SessionHostBuilder::new()
+ crate::agent::SessionHostBuilder::new()
.chat_model(model)
.tools(Vec::new())
.memory(crate::memory::test_support::noop_memory())
.tool_dispatcher(Box::new(tinytools_agent::dialect::XmlDialect))
- .agent_definition_name(SEAT);
+}
+
+fn seat(
+ definition: Option<Arc<AgentDefinition>>,
+) -> crate::agent::session_host::types::OpenHumanSessionHost {
+ let mut builder = bare().agent_definition_name(SEAT);
if let Some(definition) = definition {
builder = builder.agent_definition(definition);
}
@@ -105,7 +109,12 @@ async fn the_sessions_own_definition_outranks_a_registry_entry_sharing_its_id()
// A library host may reuse an id the process registry also knows. Its own
// definition must win, or the host silently runs someone else's agent.
let _ = AgentDefinitionRegistry::init_global_builtins();
- let agent = seat(Some(definition("orchestrator", vec!["desk_say"])));
+ // Named by the definition, which is the only spelling the build accepts:
+ // a session stamped with some other id could never resolve to it.
+ let agent = bare()
+ .agent_definition(definition("orchestrator", vec!["desk_say"]))
+ .build()
+ .expect("a seat may reuse a built-in id");
let resolved = catalogue(&agent)
.resolve("orchestrator")
@@ -140,3 +149,43 @@ async fn without_a_definition_the_same_id_is_still_unknown() {
"the id must not resolve without the caller's definition"
);
}
+
+#[tokio::test]
+async fn the_session_is_stamped_with_the_definitions_own_id() {
+ // A caller that supplies a definition should not also have to name it:
+ // the two must agree or the definition is unreachable, so the name is
+ // derived rather than left to be got right twice.
+ let agent = bare()
+ .agent_definition(definition(SEAT, vec!["desk_say"]))
+ .build()
+ .expect("a definition alone is enough identity");
+
+ assert_eq!(agent.agent_definition_name(), SEAT);
+ assert!(
+ catalogue(&agent)
+ .resolve(SEAT)
+ .await
+ .expect("resolution never errors")
+ .is_some(),
+ "the derived id must be the one the definition answers for"
+ );
+}
+
+#[test]
+fn a_name_the_definition_contradicts_fails_the_build() {
+ // Silently preferring either one would leave a session that resolves to
+ // nothing, and every turn refused for want of a definition.
+ // `OpenHumanSessionHost` is not `Debug`, so the `Ok` arm cannot be
+ // unwrapped into a panic message.
+ let Err(error) = bare()
+ .agent_definition_name("some-other-id")
+ .agent_definition(definition(SEAT, vec!["desk_say"]))
+ .build()
+ else {
+ panic!("a name the definition contradicts must fail the build");
+ };
+
+ let message = error.to_string();
+ assert!(message.contains("some-other-id"), "{message}");
+ assert!(message.contains(SEAT), "{message}");
+}
diff --git a/crates/openhuman-core/src/agent/session_host/builder/setters.rs b/crates/openhuman-core/src/agent/session_host/builder/setters.rs
index 5a883449ed..a28c105232 100644
--- a/crates/openhuman-core/src/agent/session_host/builder/setters.rs
+++ b/crates/openhuman-core/src/agent/session_host/builder/setters.rs
@@ -316,10 +316,14 @@ impl SessionHostBuilder {
/// The definition outranks the registry for this session's own id (see
/// [`OpenHumanDefinitionRegistry::with_session_definition`]), so a host
/// that brings its own agents is not shadowed by a built-in that happens
- /// to share an id. Set
- /// [`agent_definition_name`](Self::agent_definition_name) to the same id,
- /// or the definition is unresolvable by the id the session was stamped
- /// with.
+ /// to share an id.
+ ///
+ /// The session is stamped with the definition's own id, so
+ /// [`agent_definition_name`](Self::agent_definition_name) does not have to
+ /// be set alongside this. Setting it to something the definition
+ /// contradicts fails the build: the session is resolved by the name it is
+ /// stamped with, so a definition filed under a different id could never
+ /// answer for it, and every turn would be refused for want of one.
///
/// Note that the resolved definition's tool list *is* the turn's
/// allow-list, intersected with the tools the session was built with, and
diff --git a/docs/TEST-COVERAGE-MATRIX.md b/docs/TEST-COVERAGE-MATRIX.md
index 6c22b90656..37e236d2bb 100644
--- a/docs/TEST-COVERAGE-MATRIX.md
+++ b/docs/TEST-COVERAGE-MATRIX.md
@@ -226,7 +226,7 @@ End-to-end coverage of the agent harness via the web-chat RPC surface against an
| 4.4.13 | Grounded Close (no final text / breaker halt) | RU | `crates/openhuman-core/src/agent/session_host/turn_final_reply_grounding_tests.rs`, `crates/openhuman-core/src/agent/session_host/turn_checkpoint_tests.rs` | ✅ | Tool-records wrap-up, check rejects intent narration / contradicted claims, fallback quotes failure messages; breaker stop note never shown verbatim (#6278, #6279) |
| 4.4.14 | Session todo list (the `todo` tool) | RI+VU+WD | `tests/agent_harness_e2e.rs`, `crates/openhuman-core/src/agent/tools/todo_tests.rs`, `vendor/tinyagents/crates/tinyagents-graph/src/todos/test.rs`, `app/src/features/conversations/utils/harnessState.test.ts`, `app/src/features/conversations/components/TodoChecklist.test.tsx`, `app/src/features/conversations/hooks/useThreadHarnessState.test.ts`, `app/test/e2e/specs/chat-todos-goals.spec.ts` | ✅ | Whole-list write per call (Claude/Codex shape), single-`in_progress` invariant, per-session scoping; five items ticked off across turns, live on the socket, persisted in the turn state, and rendered as the chat pane's checklist |
| 4.4.15 | Thread goal (`goal_set` / `goal_get` / `goal_complete`) | RI+RU+VU+WD | `tests/agent_harness_e2e.rs`, `crates/openhuman-core/src/agent/goals/{tools_tests.rs,runtime_tests.rs,continuation_tests.rs}`, `vendor/tinyagents/crates/tinyagents-graph/src/goals/test.rs`, `app/src/features/conversations/utils/harnessState.test.ts`, `app/src/features/conversations/components/GoalBanner.test.tsx`, `app/src/features/conversations/hooks/useThreadHarnessState.test.ts`, `app/test/e2e/specs/chat-todos-goals.spec.ts` | ✅ | Objective + token budget set, read back across turns, and completed; structured `{goal, text}` payload drives the chat pane's goal banner. Budget accounting and the budget-limit stop hook are unit-covered (the scripted e2e upstream reports no usage) |
-| 4.4.16 | Builder-supplied session definition (library host) | RU | `crates/openhuman-core/src/agent/session_host/builder/builder_tests_session_definition_tests.rs` | ✅ | `SessionHostBuilder::agent_definition` stamps a caller's own `AgentDefinition` on the session, so a hosted root invocation resolves an id the process registry never held; it outranks a registry entry sharing its id, it carries the turn's tool allow-list, and without it the same id stays unknown |
+| 4.4.16 | Builder-supplied session definition (library host) | RU | `crates/openhuman-core/src/agent/session_host/builder/builder_tests_session_definition_tests.rs` | ✅ | `SessionHostBuilder::agent_definition` stamps a caller's own `AgentDefinition` on the session, so a hosted root invocation resolves an id the process registry never held; it outranks a registry entry sharing its id, it carries the turn's tool allow-list, the session is stamped with the definition's own id, a contradicting `agent_definition_name` fails the build, and without it the same id stays unknown |
---