Skip to content

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

refactor(attachments): simplify staged attachment logic

Steven Enamakel3ebb446aa739
diff --git a/crates/openhuman-core/src/threads/attachments.rs b/crates/openhuman-core/src/threads/attachments.rs
index fb2fe63a50..c85c1c9a9d 100644
--- a/crates/openhuman-core/src/threads/attachments.rs
+++ b/crates/openhuman-core/src/threads/attachments.rs
@@ -11,10 +11,7 @@ use tinychannels_bus::{ContentPart, MediaReference};
use tinystoragedrivers::Precondition;
use crate::agent::attachments::Attachment;
-use crate::storage::{
- self,
- documents::{Repo, compare_and_swap},
-};
+use crate::storage::{self, documents::Repo};
const STORAGE_KEY: &str = "__openhumanStoredAttachments";
@@ -22,8 +19,8 @@ const STORAGE_KEY: &str = "__openhumanStoredAttachments";
mod staged;
use staged::*;
pub(crate) use staged::{
- bind_staged_refs, consume_staged_parts, discard_staged_parts, resolve_staged_parts,
- stage_queued_parts, validate_opaque_parts,
+ bind_staged_refs, consume_staged_parts, discard_staged_parts, stage_queued_parts,
+ validate_opaque_parts,
};
#[derive(Debug, Clone, Serialize, Deserialize)]
diff --git a/crates/openhuman-core/src/threads/attachments/staged.rs b/crates/openhuman-core/src/threads/attachments/staged.rs
index 02c03307b0..132f18afe8 100644
--- a/crates/openhuman-core/src/threads/attachments/staged.rs
+++ b/crates/openhuman-core/src/threads/attachments/staged.rs
@@ -298,34 +298,7 @@ pub(crate) async fn stage_queued_parts(
Ok(public)
}
-/// Resolve staged queue refs immediately before execution. The caller gets
-/// trusted relative paths only after exact tenant, thread, token, and limit
-/// checks pass.
-pub(crate) async fn resolve_staged_parts(
- ctx: &crate::core::runtime::DispatchCtx,
- thread_id: &str,
- requested: &[ContentPart],
-) -> Result<Vec<ContentPart>, String> {
- if thread_id.is_empty() || requested.is_empty() {
- return Err("staged attachment scope and refs must be non-empty".into());
- }
- let config = ctx
- .load_config()
- .await
- .map_err(|error| format!("staged attachment configuration unavailable: {error}"))?;
- let entries = read_staged_entries(ctx, thread_id, requested, &config).await?;
- validate_staged_files(ctx, thread_id, &config, &entries).await?;
- let mut resolved = Vec::with_capacity(entries.len());
- for mut entry in entries {
- let media = opaque_media_mut(&mut entry.part)
- .ok_or_else(|| "staged attachment has an unsupported kind".to_string())?;
- media.path = Some(entry.path);
- resolved.push(entry.part);
- }
- Ok(resolved)
-}
-
-pub(super) async fn validate_staged_files(
+async fn validate_staged_files(
ctx: &crate::core::runtime::DispatchCtx,
thread_id: &str,
config: &crate::config::Config,
diff --git a/crates/openhuman-core/src/threads/attachments_tests.rs b/crates/openhuman-core/src/threads/attachments_tests.rs
index e81c60e25b..7d5859990d 100644
--- a/crates/openhuman-core/src/threads/attachments_tests.rs
+++ b/crates/openhuman-core/src/threads/attachments_tests.rs
@@ -130,6 +130,7 @@ async fn staged_claim_and_cancellation_have_one_atomic_document_winner() {
let repo = repo.clone();
let bound = bound.clone();
let part = part.clone();
+ let id = id.clone();
tokio::spawn(async move {
barrier.wait().await;
claim_staged_record(&repo, &bound.tenant, "thread", &id, &part, &bound)
@@ -140,6 +141,7 @@ async fn staged_claim_and_cancellation_have_one_atomic_document_winner() {
let repo = repo.clone();
let canceled = canceled.clone();
let part = part.clone();
+ let id = id.clone();
tokio::spawn(async move {
barrier.wait().await;
cancel_staged_record(&repo, &canceled.tenant, "thread", &id, &part, &canceled)
diff --git a/crates/openhuman-core/src/threads/ops/crud_queued_attachment_tests.rs b/crates/openhuman-core/src/threads/ops/crud_queued_attachment_tests.rs
index 70e9ef1bdf..2dcc217b2e 100644
--- a/crates/openhuman-core/src/threads/ops/crud_queued_attachment_tests.rs
+++ b/crates/openhuman-core/src/threads/ops/crud_queued_attachment_tests.rs
@@ -1,7 +1,5 @@
-use super::*;
use crate::threads::ops::persist_queued_user_message;
use crate::threads::store as conversations;
-use base64::Engine as _;
async fn setup() -> (tempfile::TempDir, crate::config::Config) {
let temp = tempfile::tempdir().unwrap();
@@ -29,7 +27,6 @@ async fn setup() -> (tempfile::TempDir, crate::config::Config) {
#[tokio::test]
async fn queued_user_append_reuses_exact_request_row_and_rejects_conflicts() {
use crate::core::runtime::{CoreContext, DispatchCtx, DomainSet};
- use base64::Engine as _;
use tinychannels_bus::{ContentPart, MediaReference};
let (_temp, config) = setup().await;
@@ -100,7 +97,6 @@ async fn queued_user_append_reuses_exact_request_row_and_rejects_conflicts() {
#[tokio::test]
async fn concurrent_queued_attachment_transfer_has_one_exact_owner() {
use crate::core::runtime::{CoreContext, DispatchCtx, DomainSet};
- use base64::Engine as _;
use tinychannels_bus::{ContentPart, MediaReference};
let (_temp, config) = setup().await;