Repository navigation
fix(composio): default singleEvents + timeZone for googlecalendar list (#1714) #1735
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
senamakel
merged 5 commits into
tinyhumansai:main
from
obchain:fix/1714-googlecalendar-tz-defaults
May 15, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b501bb6
fix(composio): default singleEvents + timeZone for googlecalendar lis…
obchain 8899687
fix(composio): verbose tracing on googlecalendar tz-defaults application
obchain aec7237
fix(composio): debug-log calendar tz-defaults at each wire site
obchain 5fd42d0
Merge branch 'main' into pr/1735
senamakel a596db9
Merge remote-tracking branch 'upstream/main' into pr/1735
senamakel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// 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) | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| #[cfg(test)] | ||
| #[path = "googlecalendar_args_tests.rs"] | ||
| mod tests; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.