Skip to content

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

refactor(composio): drop task-local recency window in favor of run context

Steven Enamakel32a3fe840137
diff --git a/crates/openhuman-core/src/cron/scheduler/agent_run.rs b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
index 9043671cda..b65d036c61 100644
--- a/crates/openhuman-core/src/cron/scheduler/agent_run.rs
+++ b/crates/openhuman-core/src/cron/scheduler/agent_run.rs
@@ -10,7 +10,7 @@ use {tinyflows_schedule::types::CronJob, tinyflows_schedule::types::SessionTarge
/// Recency window the morning briefing installs around its turn so Composio
/// task-fetch tools only surface tasks created/changed in the last day. Read
-/// by the `composio_execute` handler via `current_task_recency_window`.
+/// by the `composio_execute` handler via the run context (`OpenHumanRunExt`).
pub(super) const MORNING_BRIEFING_TASK_RECENCY_SECS: u64 = 24 * 60 * 60;
/// [`run_agent_job_for_run`] under a fresh run id.
@@ -202,28 +202,7 @@ pub(super) async fn run_agent_job_for_run(
}
None => Box::pin(turn),
};
- // Morning briefing only: install a 24h task-recency window
- // so Composio task-fetch tools (Linear/ClickUp/Notion/Asana)
- // surface only recently created/changed tasks. Other cron
- // agents and all chat turns leave the window unset.
- if is_morning_briefing_job(job) {
- tracing::debug!(
- job_id = %job.id,
- recency_window_secs = MORNING_BRIEFING_TASK_RECENCY_SECS,
- "[cron] applying morning-briefing task recency window"
- );
- crate::integrations::composio::task_recency_context::with_task_recency_window(
- std::time::Duration::from_secs(MORNING_BRIEFING_TASK_RECENCY_SECS),
- turn,
- )
- .await
- } else {
- tracing::trace!(
- job_id = %job.id,
- "[cron] task recency window not applied for this job"
- );
- turn.await
- }
+ turn.await
}
Err(e) => Err(e),
}
diff --git a/crates/openhuman-core/src/integrations/composio/task_recency_context.rs b/crates/openhuman-core/src/integrations/composio/task_recency_context.rs
deleted file mode 100644
index 870236479f..0000000000
--- a/crates/openhuman-core/src/integrations/composio/task_recency_context.rs
+++ /dev/null
@@ -1,63 +0,0 @@
-//! Task-local carrier for a **task-recency window** so the Composio tool
-//! surface can restrict task-fetch results to "recently created/changed"
-//! without widening the [`tinytools::Tool`] trait signature.
-//!
-//! This Composio product policy is installed by the morning briefing runner
-//! and applied to curated task-fetch actions through the connector bus.
-//!
-//! Why a task-local instead of a `Tool::execute` argument: the tool trait is
-//! invoked from many call sites (CLI, JSON-RPC, tests, agent loops). A
-//! task-local keeps the additive path scoped to the one agent runtime that
-//! needs it — today only the `morning_briefing` cron agent installs a window.
-//!
-//! When the task-local isn't set (normal chat, CLI, JSON-RPC, unit tests),
-//! [`current_task_recency_window`] returns `None` and the tool surface keeps
-//! its default unbounded behavior. This is strictly additive: a user asking
-//! "show all my Linear issues" in chat is never silently 24h-filtered.
-
-use std::time::Duration;
-
-tokio::task_local! {
- /// Recency window installed for the currently-executing agent turn.
- /// Scoped per turn by the cron agent runner; any tool executed inside
- /// that turn can read it. Unset (→ `None`) everywhere else.
- pub static TASK_RECENCY_WINDOW: Duration;
-}
-
-/// Returns the active task-recency window, if the scope is installed.
-///
-/// `None` outside [`with_task_recency_window`] — i.e. normal chat turns,
-/// direct CLI/JSON-RPC tool dispatch, or unit tests calling a [`tinytools::Tool`]
-/// directly. Callers treat `None` as "no recency restriction".
-pub fn current_task_recency_window() -> Option<Duration> {
- let window = TASK_RECENCY_WINDOW.try_with(|w| *w).ok();
- tracing::trace!(
- has_window = window.is_some(),
- window_secs = window.map(|w| w.as_secs()),
- "[composio][task-window] read current window"
- );
- window
-}
-
-/// Run `future` with `window` installed as the current task-recency window.
-///
-/// Intended call site is the cron agent runner, wrapped around the turn for
-/// agents (today: `morning_briefing`) that should only see recently-touched
-/// task data. The scope does not leak into detached tasks spawned inside
-/// `future` — standard [`tokio::task_local!`] semantics.
-pub async fn with_task_recency_window<F, R>(window: Duration, future: F) -> R
-where
- F: std::future::Future<Output = R>,
-{
- tracing::trace!(
- window_secs = window.as_secs(),
- "[composio][task-window] scope enter"
- );
- let out = TASK_RECENCY_WINDOW.scope(window, future).await;
- tracing::trace!("[composio][task-window] scope exit");
- out
-}
-
-#[cfg(test)]
-#[path = "task_recency_context_tests.rs"]
-mod tests;
diff --git a/crates/openhuman-core/src/integrations/composio/task_recency_context_tests.rs b/crates/openhuman-core/src/integrations/composio/task_recency_context_tests.rs
deleted file mode 100644
index dae18c3238..0000000000
--- a/crates/openhuman-core/src/integrations/composio/task_recency_context_tests.rs
+++ /dev/null
@@ -1,40 +0,0 @@
-use super::*;
-
-#[tokio::test]
-async fn current_window_returns_none_outside_scope() {
- assert_eq!(current_task_recency_window(), None);
-}
-
-#[tokio::test]
-async fn with_window_installs_value() {
- let observed = with_task_recency_window(Duration::from_secs(86_400), async {
- current_task_recency_window()
- })
- .await;
- assert_eq!(observed, Some(Duration::from_secs(86_400)));
-}
-
-#[tokio::test]
-async fn with_window_does_not_leak_across_scopes() {
- with_task_recency_window(Duration::from_secs(60), async {
- assert_eq!(current_task_recency_window(), Some(Duration::from_secs(60)));
- })
- .await;
- assert_eq!(current_task_recency_window(), None);
-}
-
-#[tokio::test]
-async fn nested_scope_overrides_outer() {
- with_task_recency_window(Duration::from_secs(60), async {
- assert_eq!(current_task_recency_window(), Some(Duration::from_secs(60)));
- with_task_recency_window(Duration::from_secs(120), async {
- assert_eq!(
- current_task_recency_window(),
- Some(Duration::from_secs(120))
- );
- })
- .await;
- assert_eq!(current_task_recency_window(), Some(Duration::from_secs(60)));
- })
- .await;
-}