Skip to content

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

refactor(goals, artifacts): improve goal store and add unavailable artifact store

Steven Enamakelf46e3eb3daa7
diff --git a/crates/openhuman-core/src/agent/goals/mod.rs b/crates/openhuman-core/src/agent/goals/mod.rs
index 21481051ac..e76615b295 100644
--- a/crates/openhuman-core/src/agent/goals/mod.rs
+++ b/crates/openhuman-core/src/agent/goals/mod.rs
@@ -61,10 +61,11 @@ pub fn goal_store(
/// A lost-scope caller gets isolated state, without permission to publish
/// goal changes into the host's thread or web-channel event streams.
fn isolated_goal_store() -> Arc<GoalStore> {
- Arc::new(GoalStore::new(
+ Arc::new(GoalStore::with_observer(
tinyagents_session::port::InMemorySessionStores::new()
.for_agent("ephemeral")
.kv,
+ Arc::new(OpenHumanGoalObserver),
))
}
diff --git a/crates/openhuman-core/src/artifacts/tiny_store.rs b/crates/openhuman-core/src/artifacts/tiny_store.rs
index c0aac5f3bc..0b5540303a 100644
--- a/crates/openhuman-core/src/artifacts/tiny_store.rs
+++ b/crates/openhuman-core/src/artifacts/tiny_store.rs
@@ -100,6 +100,29 @@ struct LegacyFileImportStore {
roots: tiny_artifacts::FileRoots,
}
+/// Refuses all versioned-record operations when a tenant storage binding
+/// could not be resolved, rather than substituting ambient workspace data.
+struct UnavailableArtifactStore;
+
+#[async_trait]
+impl ArtifactStore for UnavailableArtifactStore {
+ async fn list(&self) -> anyhow::Result<Vec<ArtifactRecord>> {
+ anyhow::bail!("artifact tenant storage is unavailable")
+ }
+
+ async fn get(&self, _id: &str) -> anyhow::Result<Option<ArtifactRecord>> {
+ anyhow::bail!("artifact tenant storage is unavailable")
+ }
+
+ async fn upsert(&self, _artifact: &ArtifactRecord) -> anyhow::Result<()> {
+ anyhow::bail!("artifact tenant storage is unavailable")
+ }
+
+ async fn delete(&self, _id: &str) -> anyhow::Result<bool> {
+ anyhow::bail!("artifact tenant storage is unavailable")
+ }
+}
+
impl LegacyFileImportStore {
async fn import_record(&self, mut record: ArtifactRecord) -> anyhow::Result<ArtifactRecord> {
if !record.kind.holds_file() {
@@ -171,6 +194,7 @@ pub struct LegacyUiBridge {
files: FileRoots,
file_store: Option<Arc<dyn FileStore>>,
chat: Option<ApprovalChatContext>,
+ ctx: crate::core::runtime::DispatchCtx,
}
impl LegacyUiBridge {
@@ -181,12 +205,14 @@ impl LegacyUiBridge {
files: FileRoots,
file_store: Option<Arc<dyn FileStore>>,
chat: Option<&ApprovalChatContext>,
+ ctx: &crate::core::runtime::DispatchCtx,
) -> Self {
Self {
workspace_dir: workspace_dir.into(),
files,
file_store,
chat: chat.cloned(),
+ ctx: ctx.clone(),
}
}
@@ -194,6 +220,10 @@ impl LegacyUiBridge {
/// mark it ready: the content for text kinds, a copy of the file for file
/// kinds (unless the file already is the one the artifact owns).
pub(crate) async fn show_newest(&self, record: &ArtifactRecord) -> anyhow::Result<()> {
+ self.ctx.enter(self.show_newest_in_scope(record)).await
+ }
+
+ async fn show_newest_in_scope(&self, record: &ArtifactRecord) -> anyhow::Result<()> {
let (Some(latest), Some((legacy_kind, ext))) = (record.latest(), legacy_shape(record))
else {
return Ok(());
@@ -280,9 +310,13 @@ fn same_file(a: &Path, b: &Path) -> bool {
#[async_trait]
impl ArtifactObserver for LegacyUiBridge {
async fn on_event(&self, event: &ArtifactEvent) -> anyhow::Result<()> {
+ self.ctx.enter(self.on_event_in_scope(event)).await
+ }
+
+ async fn on_event_in_scope(&self, event: &ArtifactEvent) -> anyhow::Result<()> {
let id = &event.record.id;
match event.kind {
- ArtifactEventKind::Ready => self.show_newest(&event.record).await,
+ ArtifactEventKind::Ready => self.show_newest_in_scope(&event.record).await,
ArtifactEventKind::Failed => {
let reason = event.record.error.as_deref().unwrap_or("failed");
// Only an artifact the UI already shows has a row to fail.
@@ -435,7 +469,7 @@ pub(super) fn build_artifacts_service_with_scope(
Some(scoped) => {
super::version_documents::DocumentArtifactStore::over(workspace_dir, scoped)
}
- None => versioned_store(workspace_dir),
+ None => UnavailableArtifactStore,
});
if let Some(store) = file_store.as_ref() {
records = Arc::new(LegacyFileImportStore {
@@ -450,6 +484,7 @@ pub(super) fn build_artifacts_service_with_scope(
files,
file_store.clone(),
chat,
+ ctx,
)))
.with_file_roots(guarded_roots(roots));
if let Some(file_store) = file_store.as_ref() {