Skip to content

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

refactor(inbound): script triage steps as answers or deferrals

Steven Enamakelc6c0fb4b1082
diff --git a/crates/openhuman-core/src/inbound/linked_fixture.rs b/crates/openhuman-core/src/inbound/linked_fixture.rs
index 355191ebc5..81454d6b03 100644
--- a/crates/openhuman-core/src/inbound/linked_fixture.rs
+++ b/crates/openhuman-core/src/inbound/linked_fixture.rs
@@ -31,7 +31,12 @@ use crate::triage::{
};
/// A decision of `action`.
-pub(crate) fn decision(action: TriageAction) -> TriageOutcome {
+pub(crate) fn decision(action: TriageAction) -> Step {
+ Step::Answer(decision_outcome(action))
+}
+
+/// The outcome of a decision of `action`.
+pub(crate) fn decision_outcome(action: TriageAction) -> TriageOutcome {
TriageOutcome::Decision(TriageRun {
decision: TriageDecision {
action,
@@ -45,27 +50,39 @@ pub(crate) fn decision(action: TriageAction) -> TriageOutcome {
})
}
-/// A deferral until `now + after_ms`.
-pub(crate) fn deferred(after_ms: i64) -> TriageOutcome {
- TriageOutcome::Deferred {
- defer_until_ms: chrono::Utc::now().timestamp_millis() + after_ms,
- reason: "scripted deferral".to_owned(),
+/// One scripted answer.
+#[derive(Debug, Clone)]
+pub(crate) enum Step {
+ /// Answer this outcome.
+ Answer(TriageOutcome),
+ /// Defer until `after_ms` after the triage that answers it.
+ DeferFor(i64),
+}
+
+impl From<TriageOutcome> for Step {
+ fn from(outcome: TriageOutcome) -> Self {
+ Self::Answer(outcome)
}
}
+/// A deferral of `after_ms`, counted from the triage that answers it.
+pub(crate) fn deferred(after_ms: i64) -> Step {
+ Step::DeferFor(after_ms)
+}
+
/// A triage runner that answers from a script and records what it did.
#[derive(Debug, Default)]
pub(crate) struct ScriptedTriage {
- script: Mutex<VecDeque<TriageOutcome>>,
+ script: Mutex<VecDeque<Step>>,
runs: AtomicUsize,
applied: Mutex<Vec<String>>,
}
impl ScriptedTriage {
- /// Answer `outcomes` in order, then acknowledge.
- pub(crate) fn new(outcomes: impl IntoIterator<Item = TriageOutcome>) -> Arc<Self> {
+ /// Answer `steps` in order, then acknowledge.
+ pub(crate) fn new<S: Into<Step>>(steps: impl IntoIterator<Item = S>) -> Arc<Self> {
Arc::new(Self {
- script: Mutex::new(outcomes.into_iter().collect()),
+ script: Mutex::new(steps.into_iter().map(Into::into).collect()),
..Self::default()
})
}
@@ -102,7 +119,14 @@ impl TriageRunner for ScriptedTriage {
) -> anyhow::Result<TriageOutcome> {
self.runs.fetch_add(1, Ordering::SeqCst);
let next = self.script.lock().unwrap().pop_front();
- Ok(next.unwrap_or_else(|| decision(TriageAction::Acknowledge)))
+ Ok(match next {
+ Some(Step::Answer(outcome)) => outcome,
+ Some(Step::DeferFor(after_ms)) => TriageOutcome::Deferred {
+ defer_until_ms: chrono::Utc::now().timestamp_millis() + after_ms,
+ reason: "scripted deferral".to_owned(),
+ },
+ None => decision_outcome(TriageAction::Acknowledge),
+ })
}
async fn apply(
diff --git a/crates/openhuman-core/src/integrations/composio/bus/trigger_subscriber_tests.rs b/crates/openhuman-core/src/integrations/composio/bus/trigger_subscriber_tests.rs
index 9e1915b3f1..814caf83ef 100644
--- a/crates/openhuman-core/src/integrations/composio/bus/trigger_subscriber_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/bus/trigger_subscriber_tests.rs
@@ -91,7 +91,7 @@ async fn with_the_queues_off_a_trigger_is_triaged_directly() {
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn without_a_config_a_trigger_is_triaged_directly() {
- let triage = ScriptedTriage::new([]);
+ let triage = ScriptedTriage::new(Vec::<crate::inbound::fixture::Step>::new());
let rig = Rig::new(triage.clone()).await;
route(&rig, None, trigger("uuid-no-config")).await;
@@ -105,7 +105,8 @@ async fn the_direct_path_logs_and_drops_a_deferral_and_a_terminal_outcome() {
deferred(10),
crate::triage::TriageOutcome::Terminal {
reason: "no fallback".into(),
- },
+ }
+ .into(),
]);
for uuid in ["uuid-d1", "uuid-d2"] {
triage_directly(DispatchCtx::host_default(), trigger(uuid), triage.clone())