Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions src/openhuman/composio/action_tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,24 @@ impl Tool for ComposioActionTool {
}
}

// Inject `timeZone` / `singleEvents` defaults for Google
// Calendar list slugs (issue #1714). The per-action surface is
// the spawn-time tool an integrations sub-agent picks when it
// wants a single Composio action, so the same defaults must
// fire here as on the dispatcher path.
let iana = super::googlecalendar_args::current_iana_timezone();
tracing::debug!(
target: "composio",
slug = %self.action_name,
iana = %iana,
"[composio][per-action] applying calendar query defaults pre-dispatch"
);
let args = super::googlecalendar_args::apply_calendar_query_defaults(
&self.action_name,
Some(args),
&iana,
);

// Resolve the client through the mode-aware factory on every
// call so a direct-mode toggle takes effect immediately
// (#1710). The pre-baked-client variant of this code routed all
Expand Down Expand Up @@ -186,8 +204,7 @@ impl Tool for ComposioActionTool {
// Wrap with auth_retry so a stale tinyhumans-tenant
// JWT gets refreshed-and-replayed once before surfacing
// (upstream behaviour).
super::auth_retry::execute_with_auth_retry(&client, &self.action_name, Some(args))
.await
super::auth_retry::execute_with_auth_retry(&client, &self.action_name, args).await
}
ComposioClientKind::Direct(direct) => {
tracing::debug!(
Expand All @@ -199,7 +216,7 @@ impl Tool for ComposioActionTool {
direct_execute(
&direct,
&self.action_name,
Some(args),
args,
&live_config.composio.entity_id,
)
.await
Expand Down
120 changes: 120 additions & 0 deletions src/openhuman/composio/googlecalendar_args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//! Default-args transformer for Composio Google Calendar list/find slugs.
//!
//! Background (issue #1714): when the agent asks Composio for calendar
//! events on behalf of the user, the per-call argument object is built
//! either inside the agent loop (model-constructed) or inside the
//! heartbeat planner (`heartbeat/planner/collectors.rs`). Both paths
//! historically went out with UTC-encoded `timeMin` / `timeMax` and no
//! `timeZone` / `singleEvents` field.
//!
//! Two practical consequences for users in non-UTC timezones (real
//! report: IST user with an event stored against `Asia/Riyadh` (GST)):
//!
//! 1. Without `singleEvents = true`, the Google Calendar API returns the
//! parent recurring-event entry, not the individual day's occurrence
//! — and our downstream filter is keyed on the occurrence's
//! `start.dateTime`. The user's recurring 12 PM IST stand-up never
//! shows up because the response is the never-occurring template.
//!
//! 2. Without `timeZone`, the API normalises returned `start.dateTime`
//! / `end.dateTime` against the *calendar's* default zone, which is
//! not necessarily the requester's local zone. Our display + window
//! filter both expect the requester's local zone, so events stored
//! against a different zone slide outside the window.
//!
//! The fix is to default both fields at the *execute* boundary so the
//! agent's prompt template, the heartbeat planner, and any future
//! direct call site all benefit — no per-call-site discipline required.
//! Callers that pass either field explicitly win; we never overwrite
//! user-supplied intent.

use serde_json::Value;

/// Composio action slugs whose arguments accept (and benefit from)
/// `timeZone` + `singleEvents` defaulting. Kept short on purpose: only
/// the slugs that take a `timeMin`/`timeMax` window go in here.
///
/// Adding a new slug is the right move when (a) it accepts both fields
/// and (b) at least one production call site has been observed to fire
/// it without an explicit zone in production. Speculative additions
/// just expand the transformer's blast radius for zero current win.
pub(crate) const TZ_DEFAULTING_SLUGS: &[&str] =
&["GOOGLECALENDAR_EVENTS_LIST", "GOOGLECALENDAR_FIND_EVENT"];

/// Resolve the host's IANA zone name (`Asia/Kolkata`, `America/Los_Angeles`).
/// Falls back to `"UTC"` when the host can't resolve a zone — e.g. CI
/// containers without `/etc/localtime`, or stripped Docker images. The
/// fall-back keeps the call site behaviour-equivalent to today (zone
/// implicitly UTC) rather than crashing.
pub(crate) fn current_iana_timezone() -> String {
match iana_time_zone::get_timezone() {
Ok(tz) => tz,
Err(error) => {
tracing::debug!(
target: "composio",
error = %error,
"[composio][googlecalendar] iana_time_zone lookup failed; falling back to UTC"
);
"UTC".to_string()
}
}
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

/// If `slug` is one of the [`TZ_DEFAULTING_SLUGS`] and `arguments` is a
/// JSON object, insert `singleEvents = true` and `timeZone = <iana>` —
/// but only when those keys are absent. Returns the (possibly
/// mutated) argument value.
///
/// Non-object payloads pass through untouched. The caller may pass
/// `None`/`null` to mean "no args supplied yet"; we treat that as an
/// empty object so the defaults still apply.
pub(crate) fn apply_calendar_query_defaults(
slug: &str,
arguments: Option<Value>,
iana: &str,
) -> Option<Value> {
if !TZ_DEFAULTING_SLUGS.contains(&slug) {
tracing::debug!(
target: "composio",
slug,
"[composio][googlecalendar] slug not in tz-defaulting allowlist; pass-through"
);
return arguments;
}
// Convert `None` to an empty object — the Composio backend treats
// missing args + `{}` identically, so this just gives us a place to
// hang our defaults without changing observable behaviour for
// existing no-arg callers.
let synthesised_object = arguments.is_none();
let mut value = arguments.unwrap_or_else(|| Value::Object(Default::default()));
let Some(map) = value.as_object_mut() else {
tracing::debug!(
target: "composio",
slug,
"[composio][googlecalendar] non-object payload; pass-through unchanged"
);
return Some(value);
};
let injected_time_zone = !map.contains_key("timeZone");
if injected_time_zone {
map.insert("timeZone".to_string(), Value::String(iana.to_string()));
}
let injected_single_events = !map.contains_key("singleEvents");
if injected_single_events {
map.insert("singleEvents".to_string(), Value::Bool(true));
}
tracing::debug!(
target: "composio",
slug,
iana,
synthesised_object,
injected_time_zone,
injected_single_events,
"[composio][googlecalendar] applied calendar query defaults"
);
Some(value)
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

#[cfg(test)]
#[path = "googlecalendar_args_tests.rs"]
mod tests;
124 changes: 124 additions & 0 deletions src/openhuman/composio/googlecalendar_args_tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
//! Tests for the Google Calendar default-args transformer in [`super`].
//!
//! See `googlecalendar_args.rs` for the bug background (#1714 — events
//! stored against a non-requester zone slipped outside the query window
//! because we shipped no `timeZone` / `singleEvents` defaults).

use serde_json::json;

use super::{apply_calendar_query_defaults, current_iana_timezone, TZ_DEFAULTING_SLUGS};

#[test]
fn injects_tz_and_single_events_when_absent() {
let args = apply_calendar_query_defaults(
"GOOGLECALENDAR_EVENTS_LIST",
Some(json!({
"connectionId": "conn-1",
"timeMin": "2026-05-14T00:00:00+05:30",
"timeMax": "2026-05-14T23:59:59+05:30",
"maxResults": 20
})),
"Asia/Kolkata",
)
.expect("transformer must return a payload");

assert_eq!(args["timeZone"], "Asia/Kolkata");
assert_eq!(args["singleEvents"], true);
assert_eq!(
args["connectionId"], "conn-1",
"must not perturb caller-supplied fields"
);
}

#[test]
fn does_not_overwrite_caller_supplied_time_zone() {
// Power-user / heartbeat path may pass an explicit zone that
// differs from the host. We must respect it, not silently swap to
// host zone — the caller has more context than the host clock.
let args = apply_calendar_query_defaults(
"GOOGLECALENDAR_EVENTS_LIST",
Some(json!({
"timeZone": "America/Los_Angeles",
"timeMin": "2026-05-14T00:00:00-07:00",
})),
"Asia/Kolkata",
)
.unwrap();

assert_eq!(args["timeZone"], "America/Los_Angeles");
assert_eq!(args["singleEvents"], true);
}

#[test]
fn does_not_overwrite_caller_supplied_single_events() {
let args = apply_calendar_query_defaults(
"GOOGLECALENDAR_EVENTS_LIST",
Some(json!({
"singleEvents": false,
})),
"UTC",
)
.unwrap();

assert_eq!(args["singleEvents"], false);
assert_eq!(args["timeZone"], "UTC");
}

#[test]
fn none_args_become_object_with_defaults() {
let args = apply_calendar_query_defaults("GOOGLECALENDAR_EVENTS_LIST", None, "Europe/London")
.expect("None must coerce to a populated default object");

assert!(args.is_object());
assert_eq!(args["timeZone"], "Europe/London");
assert_eq!(args["singleEvents"], true);
}

#[test]
fn non_calendar_slug_is_untouched() {
// The transformer must be a no-op for any slug not in the
// allowlist — we never want to inject TZ semantics into, say,
// gmail/notion/github args.
let original = json!({
"to": "alice@example.com",
"subject": "hi",
});
let passed =
apply_calendar_query_defaults("GMAIL_SEND_EMAIL", Some(original.clone()), "Asia/Kolkata")
.unwrap();

assert_eq!(passed, original);
}

#[test]
fn non_object_payload_is_untouched() {
// Defensive: if a caller hands us a stray scalar/array, don't
// synthesize an object — that would mask a real bug at the call
// site. Pass it through and let the backend's schema check reject.
let passed = apply_calendar_query_defaults(
"GOOGLECALENDAR_EVENTS_LIST",
Some(json!(["unexpected"])),
"Asia/Kolkata",
)
.unwrap();

assert_eq!(passed, json!(["unexpected"]));
}

#[test]
fn slug_allowlist_covers_known_window_taking_actions() {
// Sanity-check the allowlist content. EVENTS_LIST is the
// user-visible "today/tomorrow" entry point; FIND_EVENT is the
// sibling slug the model also picks for natural-language queries.
assert!(TZ_DEFAULTING_SLUGS.contains(&"GOOGLECALENDAR_EVENTS_LIST"));
assert!(TZ_DEFAULTING_SLUGS.contains(&"GOOGLECALENDAR_FIND_EVENT"));
}

#[test]
fn current_iana_timezone_returns_non_empty_string() {
// Behavioural contract: caller can always treat the return value
// as a non-empty `timeZone` value. Empty would break Google
// Calendar's validation.
let tz = current_iana_timezone();
assert!(!tz.is_empty(), "iana lookup must fall back to a value");
}
1 change: 1 addition & 0 deletions src/openhuman/composio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub mod action_tool;
pub mod auth_retry;
pub mod bus;
pub mod client;
pub mod googlecalendar_args;
pub mod ops;
pub mod periodic;
pub mod providers;
Expand Down
14 changes: 14 additions & 0 deletions src/openhuman/composio/tools.rs
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,20 @@ impl Tool for ComposioExecuteTool {
}
}

// Inject `timeZone` / `singleEvents` defaults for Google
// Calendar list slugs so the host's IANA zone reaches the API
// regardless of how the model built the args (issue #1714).
// No-op for every other slug; respects caller-supplied values.
let iana = super::googlecalendar_args::current_iana_timezone();
tracing::debug!(
target: "composio",
slug = %tool,
iana = %iana,
"[composio][dispatcher] applying calendar query defaults pre-dispatch"
);
let arguments =
super::googlecalendar_args::apply_calendar_query_defaults(&tool, arguments, &iana);

Comment thread
coderabbitai[bot] marked this conversation as resolved.
// Resolve the client through the mode-aware factory on every
// call so a direct-mode toggle takes effect immediately
// (#1710). The pre-baked-client variant of this code routed all
Expand Down
25 changes: 23 additions & 2 deletions src/openhuman/heartbeat/planner/collectors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,38 @@ pub(crate) async fn collect_calendar_meetings(
continue;
}

// Build base args, then let the shared transformer fill in
// `timeZone` + `singleEvents` so this poller behaves identically
// to the agent-driven dispatcher path (issue #1714). Routing
// both call sites through the same helper means a future change
// to the defaulting policy only has to land in one place.
let arguments = json!({
"connectionId": conn.id,
"timeMin": now.to_rfc3339(),
"timeMax": end_window.to_rfc3339(),
"maxResults": 20
});
let iana = crate::openhuman::composio::googlecalendar_args::current_iana_timezone();
tracing::debug!(
target: "composio",
slug = "GOOGLECALENDAR_EVENTS_LIST",
toolkit = %toolkit,
connection_id = %conn.id,
iana = %iana,
lookahead_minutes = config.heartbeat.meeting_lookahead_minutes.max(1),
"[composio][heartbeat-planner] applying calendar query defaults pre-poll"
);
let arguments =
crate::openhuman::composio::googlecalendar_args::apply_calendar_query_defaults(
"GOOGLECALENDAR_EVENTS_LIST",
Some(arguments),
&iana,
);

let resp: ComposioExecuteResponse = match &kind {
ComposioClientKind::Backend(client) => {
match client
.execute_tool("GOOGLECALENDAR_EVENTS_LIST", Some(arguments))
.execute_tool("GOOGLECALENDAR_EVENTS_LIST", arguments)
.await
{
Ok(resp) => resp,
Expand All @@ -186,7 +207,7 @@ pub(crate) async fn collect_calendar_meetings(
match direct_execute(
direct,
"GOOGLECALENDAR_EVENTS_LIST",
Some(arguments),
arguments,
&config.composio.entity_id,
)
.await
Expand Down
Loading
Loading