Skip to content

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

test(session_store): cover ledger sync and finalize paths

Steven Enamakel8f7d36d191e5
diff --git a/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime_tests.rs b/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime_tests.rs
index e382c7d979..5837e0613f 100644
--- a/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/agent_teams/runtime_tests.rs
@@ -20,8 +20,8 @@ use crate::agent::prompts::ToolCallFormat;
use crate::config::{AgentConfig, Config};
use tinyagents_orchestration::teams::{SessionTeamLedger, TeamService};
use tinyagents_session::run_ledger::{
- AgentTeam, AgentTeamMember, AgentTeamMemberStatus, AgentTeamMemberUpsert, AgentTeamStatus,
- AgentTeamTask, AgentTeamTaskStatus, AgentTeamTaskUpsert, AgentTeamUpsert, ClaimOutcome,
+ AgentTeamMemberStatus, AgentTeamMemberUpsert, AgentTeamStatus, AgentTeamTaskStatus,
+ AgentTeamTaskUpsert, AgentTeamUpsert,
};
use tinyinference_llm::model::{ChatModel, ModelRequest, ModelResponse};
use tinytools::Tool;
@@ -98,82 +98,7 @@ fn team_service(config: &Config) -> TeamService<SessionTeamLedger> {
TeamService::new(SessionTeamLedger::new(ledger).unwrap())
}
-/// Synchronous views of the team ledger the tests seed and inspect, on the
-/// storage backend of the test's workspace.
-mod run_ledger {
- use super::*;
- use crate::agent::session_store::with_ledger;
- use std::path::Path;
-
- type Res<T> = anyhow::Result<T>;
-
- pub(super) fn upsert_agent_team(ws: &Path, upsert: AgentTeamUpsert) -> Res<AgentTeam> {
- Ok(with_ledger(ws, |l| async move { l.upsert_agent_team(upsert).await })?)
- }
-
- pub(super) fn upsert_agent_team_member(
- ws: &Path,
- upsert: AgentTeamMemberUpsert,
- ) -> Res<AgentTeamMember> {
- Ok(with_ledger(ws, |l| async move { l.upsert_agent_team_member(upsert).await })?)
- }
-
- pub(super) fn upsert_agent_team_task(
- ws: &Path,
- upsert: AgentTeamTaskUpsert,
- ) -> Res<AgentTeamTask> {
- Ok(with_ledger(ws, |l| async move { l.upsert_agent_team_task(upsert).await })?)
- }
-
- pub(super) fn claim_agent_team_task(
- ws: &Path,
- team_id: &str,
- task_id: &str,
- member_id: &str,
- token: &str,
- ) -> Res<ClaimOutcome> {
- let (team_id, task_id, member_id, token) = (
- team_id.to_string(),
- task_id.to_string(),
- member_id.to_string(),
- token.to_string(),
- );
- Ok(with_ledger(ws, |l| async move {
- l.claim_agent_team_task(&team_id, &task_id, &member_id, &token).await
- })?)
- }
-
- pub(super) fn mark_agent_team_member_running(
- ws: &Path,
- team_id: &str,
- member_id: &str,
- task_id: &str,
- worker: &str,
- run_id: &str,
- ) -> Res<Option<AgentTeamMember>> {
- let (team_id, member_id, task_id, worker, run_id) = (
- team_id.to_string(),
- member_id.to_string(),
- task_id.to_string(),
- worker.to_string(),
- run_id.to_string(),
- );
- Ok(with_ledger(ws, |l| async move {
- l.mark_agent_team_member_running(&team_id, &member_id, &task_id, &worker, &run_id)
- .await
- })?)
- }
-
- pub(super) fn get_agent_team_task(ws: &Path, id: &str) -> Res<Option<AgentTeamTask>> {
- let id = id.to_string();
- Ok(with_ledger(ws, |l| async move { l.get_agent_team_task(&id).await })?)
- }
-
- pub(super) fn get_agent_team_member(ws: &Path, id: &str) -> Res<Option<AgentTeamMember>> {
- let id = id.to_string();
- Ok(with_ledger(ws, |l| async move { l.get_agent_team_member(&id).await })?)
- }
-}
+use crate::agent::session_store::ledger_sync as run_ledger;
fn seed_team(config: &Config, team_id: &str) {
run_ledger::upsert_agent_team(
diff --git a/crates/openhuman-core/src/agent/orchestration/run_ledger_finalize_tests.rs b/crates/openhuman-core/src/agent/orchestration/run_ledger_finalize_tests.rs
index cc191c5776..8f1fe67c08 100644
--- a/crates/openhuman-core/src/agent/orchestration/run_ledger_finalize_tests.rs
+++ b/crates/openhuman-core/src/agent/orchestration/run_ledger_finalize_tests.rs
@@ -5,9 +5,8 @@ use super::*;
use serde_json::json;
use tempfile::TempDir;
-use tinyagents_session::run_ledger::{
- get_agent_run, upsert_agent_run, AgentRunKind, AgentRunStatus, AgentRunUpsert,
-};
+use crate::agent::session_store::ledger_sync::{get_agent_run, upsert_agent_run};
+use tinyagents_session::run_ledger::{AgentRunKind, AgentRunStatus, AgentRunUpsert};
use tinybus::EventHandler;
fn test_config(dir: &TempDir) -> Config {
diff --git a/crates/openhuman-core/src/agent/session_store/ledger_sync.rs b/crates/openhuman-core/src/agent/session_store/ledger_sync.rs
new file mode 100644
index 0000000000..f696a6f22b
--- /dev/null
+++ b/crates/openhuman-core/src/agent/session_store/ledger_sync.rs
@@ -0,0 +1,141 @@
+//! Synchronous, workspace-keyed views of the calling tenant's run ledger.
+//!
+//! The run ledger itself is TinyAgents' async [`RunLedgerStore`], reached for a
+//! tenant through [`require_ledger`](super::require_ledger). Hosts and tests
+//! that hold a workspace directory and want one record in or out (seeding a
+//! run, reading it back) use these: each opens the tenant's ledger for
+//! `workspace_dir` and runs one port call on the shared storage bridge
+//! ([`with_ledger`]).
+
+use std::path::Path;
+
+use tinyagents_session::run_ledger::{
+ AgentRun, AgentRunUpsert, AgentTeam, AgentTeamMember, AgentTeamTask, AgentTeamTaskUpsert,
+ AgentTeamUpsert, AgentTeamMemberUpsert, ClaimOutcome, LedgerResult, RunEvent,
+ RunEventAppend, RunEventListRequest, RunEventListResponse, WorkflowRun, WorkflowRunUpsert,
+};
+
+use super::with_ledger;
+
+/// Inserts or merges an agent run.
+pub fn upsert_agent_run(workspace_dir: &Path, upsert: AgentRunUpsert) -> LedgerResult<AgentRun> {
+ with_ledger(workspace_dir, |l| async move { l.upsert_agent_run(upsert).await })
+}
+
+/// One agent run by id.
+pub fn get_agent_run(workspace_dir: &Path, id: &str) -> LedgerResult<Option<AgentRun>> {
+ let id = id.to_string();
+ with_ledger(workspace_dir, |l| async move { l.get_agent_run(&id).await })
+}
+
+/// Inserts or merges a workflow run.
+pub fn upsert_workflow_run(
+ workspace_dir: &Path,
+ upsert: WorkflowRunUpsert,
+) -> LedgerResult<WorkflowRun> {
+ with_ledger(workspace_dir, |l| async move { l.upsert_workflow_run(upsert).await })
+}
+
+/// One workflow run by id.
+pub fn get_workflow_run(workspace_dir: &Path, id: &str) -> LedgerResult<Option<WorkflowRun>> {
+ let id = id.to_string();
+ with_ledger(workspace_dir, |l| async move { l.get_workflow_run(&id).await })
+}
+
+/// Appends an event to a run's log.
+pub fn append_run_event(workspace_dir: &Path, event: RunEventAppend) -> LedgerResult<RunEvent> {
+ with_ledger(workspace_dir, |l| async move { l.append_run_event(event).await })
+}
+
+/// A run's events in sequence order.
+pub fn list_recent_run_events(
+ workspace_dir: &Path,
+ request: &RunEventListRequest,
+) -> LedgerResult<RunEventListResponse> {
+ let request = request.clone();
+ with_ledger(workspace_dir, |l| async move {
+ l.list_recent_run_events(&request).await
+ })
+}
+
+/// Inserts or updates a team.
+pub fn upsert_agent_team(workspace_dir: &Path, upsert: AgentTeamUpsert) -> LedgerResult<AgentTeam> {
+ with_ledger(workspace_dir, |l| async move { l.upsert_agent_team(upsert).await })
+}
+
+/// Inserts or updates a team member.
+pub fn upsert_agent_team_member(
+ workspace_dir: &Path,
+ upsert: AgentTeamMemberUpsert,
+) -> LedgerResult<AgentTeamMember> {
+ with_ledger(workspace_dir, |l| async move {
+ l.upsert_agent_team_member(upsert).await
+ })
+}
+
+/// Inserts or updates a team task.
+pub fn upsert_agent_team_task(
+ workspace_dir: &Path,
+ upsert: AgentTeamTaskUpsert,
+) -> LedgerResult<AgentTeamTask> {
+ with_ledger(workspace_dir, |l| async move {
+ l.upsert_agent_team_task(upsert).await
+ })
+}
+
+/// One team task by id.
+pub fn get_agent_team_task(workspace_dir: &Path, id: &str) -> LedgerResult<Option<AgentTeamTask>> {
+ let id = id.to_string();
+ with_ledger(workspace_dir, |l| async move { l.get_agent_team_task(&id).await })
+}
+
+/// One team member by id.
+pub fn get_agent_team_member(
+ workspace_dir: &Path,
+ id: &str,
+) -> LedgerResult<Option<AgentTeamMember>> {
+ let id = id.to_string();
+ with_ledger(workspace_dir, |l| async move { l.get_agent_team_member(&id).await })
+}
+
+/// Atomically claims a task for a member.
+pub fn claim_agent_team_task(
+ workspace_dir: &Path,
+ team_id: &str,
+ task_id: &str,
+ member_id: &str,
+ claim_token: &str,
+) -> LedgerResult<ClaimOutcome> {
+ let (team_id, task_id, member_id, claim_token) = (
+ team_id.to_string(),
+ task_id.to_string(),
+ member_id.to_string(),
+ claim_token.to_string(),
+ );
+ with_ledger(workspace_dir, |l| async move {
+ l.claim_agent_team_task(&team_id, &task_id, &member_id, &claim_token)
+ .await
+ })
+}
+
+/// Marks a member as running a task.
+pub fn mark_agent_team_member_running(
+ workspace_dir: &Path,
+ team_id: &str,
+ member_id: &str,
+ task_id: &str,
+ worker_thread_id: &str,
+ run_id: &str,
+) -> LedgerResult<Option<AgentTeamMember>> {
+ let (team_id, member_id, task_id, worker_thread_id, run_id) = (
+ team_id.to_string(),
+ member_id.to_string(),
+ task_id.to_string(),
+ worker_thread_id.to_string(),
+ run_id.to_string(),
+ );
+ with_ledger(workspace_dir, |l| async move {
+ l.mark_agent_team_member_running(&team_id, &member_id, &task_id, &worker_thread_id, &run_id)
+ .await
+ })
+}
diff --git a/crates/openhuman-core/src/agent/session_store/mod.rs b/crates/openhuman-core/src/agent/session_store/mod.rs
index 179b9f7e5a..d45604ff89 100644
--- a/crates/openhuman-core/src/agent/session_store/mod.rs
+++ b/crates/openhuman-core/src/agent/session_store/mod.rs
@@ -20,6 +20,7 @@ pub use agent_transcripts::{agent_transcript_root, AgentTranscriptFiles};
use tinyagents_session::port::{AgentStores, SessionStoreProvider};
mod agent_transcripts;
+pub mod ledger_sync;
mod rebound;
mod workspace;