Skip to content

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

feat(agent): add channel_session field to AgentTurnOrigin

Steven Enamakelb28252c3cb51
diff --git a/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs b/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs
index 6a775b7fe5..8bd5225cfc 100644
--- a/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs
+++ b/crates/openhuman-core/src/agent/attachments/mod_access_tests.rs
@@ -10,6 +10,7 @@ fn external_origin() -> crate::agent::turn_origin::AgentTurnOrigin {
reply_target: "test".into(),
message_id: "test".into(),
history_key: None,
+ channel_session: None,
}
}
diff --git a/crates/openhuman-core/src/agent/attachments/provider_tests.rs b/crates/openhuman-core/src/agent/attachments/provider_tests.rs
index 52006c9024..a095e790df 100644
--- a/crates/openhuman-core/src/agent/attachments/provider_tests.rs
+++ b/crates/openhuman-core/src/agent/attachments/provider_tests.rs
@@ -188,6 +188,7 @@ async fn external_channel_cannot_rehydrate_a_local_image() {
reply_target: "chat".into(),
message_id: "message".into(),
history_key: None,
+ channel_session: None,
};
let mut context = crate::agent::tinyagents::host::OpenHumanRunContext::new();
context.origin = Some(origin);
diff --git a/crates/openhuman-core/src/agent/queued_turn_tests.rs b/crates/openhuman-core/src/agent/queued_turn_tests.rs
index cf5a7058e0..55fdcb86a5 100644
--- a/crates/openhuman-core/src/agent/queued_turn_tests.rs
+++ b/crates/openhuman-core/src/agent/queued_turn_tests.rs
@@ -26,6 +26,7 @@ fn trusted_turn(session_key: &str) -> Arc<super::super::turn_host::TrustedAgentT
reply_target: "conversation-a".into(),
message_id: "message-a".into(),
history_key: Some("legacy-history-a".into()),
+ channel_session: None,
},
approval: crate::security::approval::ApprovalTurnContext::chat(
crate::security::approval::ApprovalChatContext {
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context_tests.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context_tests.rs
index bb84b548ca..9023e1b5b1 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/turn_context_tests.rs
@@ -13,6 +13,7 @@ async fn attachment_scope_is_request_local_and_contains_only_typed_authority() {
reply_target: "room".into(),
message_id: "message".into(),
history_key: None,
+ channel_session: None,
},
);
data.workspace = Some(tinytools::WorkspaceDescriptor::new(root.clone()));
diff --git a/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs b/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs
index f86a4490ae..0e2f446ffc 100644
--- a/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/tool_registration_tests.rs
@@ -126,6 +126,7 @@ async fn shared_adapter_scopes_tool_execution_to_the_run_origin() {
reply_target: "room".into(),
message_id: "message".into(),
history_key: None,
+ channel_session: None,
},
);
let run = host.into_tinyagents(RunConfig::new("origin-observer"));
diff --git a/crates/openhuman-core/src/agent/triage/evaluator/arm.rs b/crates/openhuman-core/src/agent/triage/evaluator/arm.rs
index f92e177ada..521484ba8e 100644
--- a/crates/openhuman-core/src/agent/triage/evaluator/arm.rs
+++ b/crates/openhuman-core/src/agent/triage/evaluator/arm.rs
@@ -145,6 +145,7 @@ pub(super) async fn try_arm(
reply_target: envelope.display_label.clone(),
message_id: envelope.external_id.clone(),
history_key: None,
+ channel_session: None,
},
// Triage is not an interactive chat turn: no approval surface.
approval: Default::default(),
diff --git a/crates/openhuman-core/src/agent/turn_origin.rs b/crates/openhuman-core/src/agent/turn_origin.rs
index 5e9ae7f4c3..de956dddb6 100644
--- a/crates/openhuman-core/src/agent/turn_origin.rs
+++ b/crates/openhuman-core/src/agent/turn_origin.rs
@@ -62,6 +62,10 @@ pub enum AgentTurnOrigin {
/// conversation (MCP server callers, triage, voice), so scheduling can tell a
/// real chat from those.
history_key: Option<String>,
+ /// Trusted host-derived channel session identity captured from the
+ /// prepared inbound envelope. Absent on non-conversation channel
+ /// origins; legacy history keys remain attribution only.
+ channel_session: Option<tinyflows_bus::schedule::types::ChannelSessionIdentity>,
},
/// Internal automation the user explicitly authorized (cron job the
/// user created, internal background job on local data). `source`
diff --git a/crates/openhuman-core/src/agent/turn_origin_tests.rs b/crates/openhuman-core/src/agent/turn_origin_tests.rs
index dae8a7724f..43a215345a 100644
--- a/crates/openhuman-core/src/agent/turn_origin_tests.rs
+++ b/crates/openhuman-core/src/agent/turn_origin_tests.rs
@@ -70,6 +70,7 @@ async fn inherited_origin_preserves_a_non_cli_origin_verbatim() {
reply_target: "chat-7".into(),
message_id: "m-9".into(),
history_key: None,
+ channel_session: None,
},
async {
let captured = capture();
@@ -266,6 +267,7 @@ async fn spawn_preserves_an_untrusted_origin_verbatim() {
reply_target: "chat-7".into(),
message_id: "m-9".into(),
history_key: None,
+ channel_session: None,
},
async {
spawn(async { current() })
diff --git a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
index 5c3d41b7a1..bbb5a8bb46 100644
--- a/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
+++ b/crates/openhuman-core/src/channels/providers/relay/ops_tests.rs
@@ -19,6 +19,7 @@ async fn relayed_thread_and_external_authority_survive_scoped_spawn() {
reply_target: "-100".into(),
message_id: "spawned-turn".into(),
history_key: None,
+ channel_session: None,
};
let thread = params("spawned-turn", "hello").thread_id();
CoreContext::scope(context, async {
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture_tests.rs b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture_tests.rs
index a7df3a5833..ee804b5dfe 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture_tests.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/host_agent/posture_tests.rs
@@ -13,6 +13,7 @@ fn external() -> AgentTurnOrigin {
reply_target: "42".into(),
message_id: "m1".into(),
history_key: Some("telegram_alice".into()),
+ channel_session: None,
}
}
diff --git a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
index 856fa5fffd..580888aa33 100644
--- a/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
+++ b/crates/openhuman-core/src/channels/runtime/dispatch/processor/turn.rs
@@ -430,6 +430,7 @@ pub(crate) async fn process_channel_runtime_message(
reply_target: msg.reply_target.clone(),
message_id: msg.id.clone(),
history_key: Some(history_key.clone()),
+ channel_session: None,
};
// Sub-issue 2 of #3098: give the agent turn an `ApprovalTurnContext` for
diff --git a/crates/openhuman-core/src/core/runtime/context_turn_origin_tests.rs b/crates/openhuman-core/src/core/runtime/context_turn_origin_tests.rs
index cec66735b2..8a4ab71ef8 100644
--- a/crates/openhuman-core/src/core/runtime/context_turn_origin_tests.rs
+++ b/crates/openhuman-core/src/core/runtime/context_turn_origin_tests.rs
@@ -10,6 +10,7 @@ async fn dispatch_scope_uses_explicit_origin_without_mutating_shared_context() {
reply_target: "room".into(),
message_id: "message".into(),
history_key: None,
+ channel_session: None,
};
CoreContext::scope_with_turn_origin(ctx.clone(), Some(origin), async {
assert!(matches!(
@@ -32,6 +33,7 @@ async fn missing_child_origin_inherits_bound_external_authority() {
reply_target: "room".into(),
message_id: "message".into(),
history_key: None,
+ channel_session: None,
};
CoreContext::scope_with_turn_origin(ctx, Some(external), async {
let parent = CoreContext::current().expect("parent context");
@@ -59,6 +61,7 @@ async fn explicit_origin_scope_bridges_legacy_and_core_context_without_cross_tal
reply_target: format!("{channel}-room"),
message_id: format!("{channel}-message"),
history_key: None,
+ channel_session: None,
};
CoreContext::scope(context, async {
turn_origin::with_origin(origin, async {
@@ -106,6 +109,7 @@ async fn bound_external_authority_wins_over_legacy_trusted_automation() {
reply_target: "room".into(),
message_id: "message".into(),
history_key: None,
+ channel_session: None,
};
CoreContext::scope_with_turn_origin(parent, Some(external), async {
assert!(matches!(
@@ -171,6 +175,7 @@ async fn concurrent_channel_turns_keep_tenant_agent_thread_and_policy_isolated()
reply_target: format!("room-{label}"),
message_id: format!("message-{label}"),
history_key: None,
+ channel_session: None,
};
let turn = context.derive_channel_turn(Some(thread.clone()), Some(origin));
CoreContext::scope(turn, async move {
diff --git a/crates/openhuman-core/src/mcp/server/tools/dispatch.rs b/crates/openhuman-core/src/mcp/server/tools/dispatch.rs
index c6a1b569c5..af255074f5 100644
--- a/crates/openhuman-core/src/mcp/server/tools/dispatch.rs
+++ b/crates/openhuman-core/src/mcp/server/tools/dispatch.rs
@@ -374,6 +374,7 @@ async fn run_subagent_tool(
reply_target: agent_id.to_string(),
message_id: uuid::Uuid::new_v4().to_string(),
history_key: None,
+ channel_session: None,
};
// Run the subagent one level deeper in the chain, so its own Claude Code
// turns stamp `child_depth` onto any grandchildren they spawn. The agent
diff --git a/crates/openhuman-core/src/memory/lifecycle/sender_tests.rs b/crates/openhuman-core/src/memory/lifecycle/sender_tests.rs
index 6b9ac4a6a9..7af70e04a2 100644
--- a/crates/openhuman-core/src/memory/lifecycle/sender_tests.rs
+++ b/crates/openhuman-core/src/memory/lifecycle/sender_tests.rs
@@ -8,6 +8,7 @@ fn origin(channel: &str, sender: Option<&str>, name: Option<&str>) -> AgentTurnO
reply_target: "chat".into(),
message_id: "m-1".into(),
history_key: Some("k".into()),
+ channel_session: None,
}
}
@@ -78,6 +79,7 @@ fn nothing_is_attributed_without_a_channel_sender() {
reply_target: "42".into(),
message_id: "cron:job-1:run-1".into(),
history_key: Some("k".into()),
+ channel_session: None,
};
assert_eq!(channel_actor(&cron), None, "a cron run is the job's prompt");
}
diff --git a/crates/openhuman-core/src/platform/cost/scope_tests.rs b/crates/openhuman-core/src/platform/cost/scope_tests.rs
index 3ad1352e07..945bb78386 100644
--- a/crates/openhuman-core/src/platform/cost/scope_tests.rs
+++ b/crates/openhuman-core/src/platform/cost/scope_tests.rs
@@ -16,6 +16,7 @@ fn each_origin_maps_to_its_thread_and_label() {
sender: None,
sender_name: None,
history_key: None,
+ channel_session: None,
reply_target: "r".into(),
message_id: "m".into(),
};
@@ -29,6 +30,7 @@ fn each_origin_maps_to_its_thread_and_label() {
sender: None,
sender_name: None,
history_key: Some("telegram:42".into()),
+ channel_session: None,
reply_target: "r".into(),
message_id: "m".into(),
};
diff --git a/crates/openhuman-core/src/security/approval/gate_forced_tests.rs b/crates/openhuman-core/src/security/approval/gate_forced_tests.rs
index fc38a6870d..ae25ea55d3 100644
--- a/crates/openhuman-core/src/security/approval/gate_forced_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_forced_tests.rs
@@ -115,6 +115,7 @@ async fn forced_approval_still_denies_automation_and_channel_origins() {
reply_target: "chat".into(),
message_id: "m".into(),
history_key: None,
+ channel_session: None,
},
AgentTurnOrigin::Unknown,
] {
diff --git a/crates/openhuman-core/src/security/approval/gate_origin_intercept_tests.rs b/crates/openhuman-core/src/security/approval/gate_origin_intercept_tests.rs
index 40538c8efc..3ec17369f9 100644
--- a/crates/openhuman-core/src/security/approval/gate_origin_intercept_tests.rs
+++ b/crates/openhuman-core/src/security/approval/gate_origin_intercept_tests.rs
@@ -147,6 +147,7 @@ async fn intercept_with_external_channel_origin_persists_and_ttl_denies() {
reply_target: "tg-chat-1".into(),
message_id: "msg-1".into(),
history_key: None,
+ channel_session: None,
};
let g = gate.clone();
diff --git a/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs b/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs
index 89c28d5b9b..b6c0486a0a 100644
--- a/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs
+++ b/crates/openhuman-core/src/threads/ops/crud_message_append_tests.rs
@@ -187,6 +187,7 @@ async fn external_origin_cannot_reuse_an_existing_attachment_marker() {
reply_target: "room".into(),
message_id: "message".into(),
history_key: None,
+ channel_session: None,
};
assert!(
append_with_test_config(request("external", &staged, "user"), &config, Some(&origin))
diff --git a/crates/openhuman-core/src/tools/impl/browser/browser_unattended_tests.rs b/crates/openhuman-core/src/tools/impl/browser/browser_unattended_tests.rs
index 58322fc929..da332e11f3 100644
--- a/crates/openhuman-core/src/tools/impl/browser/browser_unattended_tests.rs
+++ b/crates/openhuman-core/src/tools/impl/browser/browser_unattended_tests.rs
@@ -58,6 +58,7 @@ fn external_channel() -> AgentTurnOrigin {
reply_target: "chat-1".into(),
message_id: "m-1".into(),
history_key: None,
+ channel_session: None,
}
}
diff --git a/crates/openhuman-core/src/voice/live/session.rs b/crates/openhuman-core/src/voice/live/session.rs
index 169e377845..cb9881650b 100644
--- a/crates/openhuman-core/src/voice/live/session.rs
+++ b/crates/openhuman-core/src/voice/live/session.rs
@@ -180,6 +180,7 @@ pub(crate) async fn start(
reply_target: session_id.to_string(),
message_id: format!("voice-live-{session_id}"),
history_key: None,
+ channel_session: None,
};
let approval = ApprovalChatContext {
thread_id: thread_id.clone(),
diff --git a/crates/openhuman-core/src/voice/realtime_harness/agent.rs b/crates/openhuman-core/src/voice/realtime_harness/agent.rs
index 9dd9fe94ba..961085d476 100644
--- a/crates/openhuman-core/src/voice/realtime_harness/agent.rs
+++ b/crates/openhuman-core/src/voice/realtime_harness/agent.rs
@@ -159,6 +159,7 @@ async fn run_single_with_timeout(
reply_target: correlation_id.to_string(),
message_id: format!("voice-{correlation_id}"),
history_key: None,
+ channel_session: None,
},
scoped_run,
);