Skip to content

fix(backend): pass new start/end time through update_calendar_event_tool - #8312

Closed
ZachL111 wants to merge 3 commits into
BasedHardware:mainfrom
ZachL111:fix/calendar-update-event-time
Closed

ZachL111 wants to merge 3 commits into
BasedHardware:mainfrom
ZachL111:fix/calendar-update-event-time

Conversation

@ZachL111

@ZachL111 ZachL111 commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

update_calendar_event_tool is the agent tool that edits an existing Google Calendar event. Its docstring says it can change an event's title, description, location, time, or attendees, and the underlying writer update_google_calendar_event accepts start_time and end_time. But the tool never accepted new-time arguments and never passed any time through to the writer, so when a user asked to reschedule an event the tool returned a success message while the event's start and end time stayed exactly as they were. This PR adds new_start_time and new_end_time parameters, validates them the same way create_calendar_event_tool validates times, and threads them into both update_google_calendar_event calls so a reschedule actually changes the event.

Root cause

In backend/utils/retrieval/tools/calendar_tools.py, update_calendar_event_tool had no time parameters in its signature and built its update from title, description, location, and attendees only:

# Update the event
try:
    updated_event = await update_google_calendar_event(
        access_token=access_token,
        event_id=target_event_id,
        summary=update_summary,
        description=update_description,
        location=update_location,
        attendees=update_attendees,
    )

The post-token-refresh retry in the same function had the same call with no time arguments. update_google_calendar_event defaults start_time and end_time to None, and a None time is treated as "leave unchanged," so the patch body sent to Google never carried a new start or end. There is no exception here; the call succeeds and returns the event, so the tool replied with "Successfully updated calendar event" while the time was untouched. A reschedule request silently did nothing. The only path that could change a time was start_date / end_date, but those are the search range used to find the event, not its new time, so there was no way to actually move an event.

Fix

Add new_start_time and new_end_time parameters, validate them with parse_iso_with_tz (the same ISO plus timezone check create_calendar_event_tool uses), reject an end that is not after the start, and pass the parsed datetimes into both update_google_calendar_event calls:

# Parse new start/end times if the event is being rescheduled.
# Uses the same ISO + timezone validation as create_calendar_event_tool.
new_start_dt, err = parse_iso_with_tz('new_start_time', new_start_time, "in format YYYY-MM-DDTHH:MM:SS+HH:MM")
if err:
    return err
new_end_dt, err = parse_iso_with_tz('new_end_time', new_end_time, "in format YYYY-MM-DDTHH:MM:SS+HH:MM")
if err:
    return err

if new_start_dt is not None and new_end_dt is not None and new_end_dt <= new_start_dt:
    return f"Error: new_end_time must be after new_start_time. Start: {new_start_dt.strftime('%Y-%m-%d %H:%M:%S')}, End: {new_end_dt.strftime('%Y-%m-%d %H:%M:%S')}"
updated_event = await update_google_calendar_event(
    access_token=access_token,
    event_id=target_event_id,
    summary=update_summary,
    start_time=new_start_dt,
    end_time=new_end_dt,
    description=update_description,
    location=update_location,
    attendees=update_attendees,
)

The success message now also reports the new start and end when they are set. A request that does not pass new_start_time or new_end_time parses them as None, so the call is byte-for-byte the same as before for every non-reschedule edit.

Testing

Added backend/tests/unit/test_calendar_update_event_time.py, registered in backend/test.sh. The tool lives in a module with a heavy import graph, so the test loads calendar_tools.py from source under a stub meta-path finder that mocks the heavy leaf deps (database, firebase_admin, google, pinecone, redis, typesense, cachetools) while keeping parse_iso_with_tz and the google_utils chain real, then drives the tool coroutine with prepare_access, get_google_calendar_event, and update_google_calendar_event patched. Cases covered: a reschedule passes tz-aware start_time and end_time with the requested hours through to update_google_calendar_event; supplying only new_start_time threads start_time and leaves end_time as None; a naive time with no offset returns an error and never calls the writer; and a source assertion that both update calls (primary and retry) receive the parsed new times. Verified red to green: the test fails on current main and passes with this change.

PR status check

No open PR changes this logic. The pass-through of new times added here does not appear anywhere in this file's history, so this is not a previously reverted fix being resubmitted. No filed GitHub issue matches.

Review in cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 issues found across 3 files

Confidence score: 3/5

  • In backend/utils/retrieval/tools/calendar_tools.py, partial reschedules are not fully time-validated, so a single-field update can still produce an invalid start/end pair and send a bad calendar update; add validation that checks resulting event order even when only one side (start or end) is changed before merging.
  • In backend/utils/retrieval/tools/calendar_tools.py, the auth-refresh retry success path drops the reschedule start/end details, which can confuse callers that rely on confirmation payloads after a token refresh; align retry-path response formatting with the normal success output before merge.
  • In backend/tests/unit/test_calendar_update_event_time.py, the source-string assertion is tightly coupled to implementation details and may pass or fail for the wrong reasons, reducing confidence in future refactors; replace it with a behavioral test that exercises the retry path and verifies returned reschedule fields.

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="backend/utils/retrieval/tools/calendar_tools.py">

<violation number="1" location="backend/utils/retrieval/tools/calendar_tools.py:285">
P1: `_parse_event_dt` can return naive datetimes for Google `dateTime` values without offsets, causing a naive/aware datetime comparison crash in partial reschedule validation.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Fix all with cubic | Re-trigger cubic

return None
try:
if 'dateTime' in time_field:
return datetime.fromisoformat(time_field['dateTime'].replace('Z', '+00:00'))

@cubic-dev-ai cubic-dev-ai Bot Jun 25, 2026 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1: _parse_event_dt can return naive datetimes for Google dateTime values without offsets, causing a naive/aware datetime comparison crash in partial reschedule validation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At backend/utils/retrieval/tools/calendar_tools.py, line 285:

<comment>`_parse_event_dt` can return naive datetimes for Google `dateTime` values without offsets, causing a naive/aware datetime comparison crash in partial reschedule validation.</comment>

<file context>
@@ -272,6 +272,24 @@ async def get_google_calendar_event(access_token: str, event_id: str) -> dict:
+        return None
+    try:
+        if 'dateTime' in time_field:
+            return datetime.fromisoformat(time_field['dateTime'].replace('Z', '+00:00'))
+        if 'date' in time_field:
+            return datetime.fromisoformat(time_field['date'] + 'T00:00:00+00:00')
</file context>
Suggested change
return datetime.fromisoformat(time_field['dateTime'].replace('Z', '+00:00'))
parsed_dt = datetime.fromisoformat(time_field['dateTime'].replace('Z', '+00:00'))
if parsed_dt.tzinfo is None:
parsed_dt = parsed_dt.replace(tzinfo=timezone.utc)
return parsed_dt
Fix with cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Hi @ZachL111 — thank you for finding this and writing up a candidate fix.

We reviewed it during the ZachL111 aggregate triage. This one needs a bit more product/API/design decision than we want to bundle into the current aggregate PRs (#8362, #8364, #8366, #8367), so we’re deferring rather than merging this exact patch.

I’m closing the individual PR to keep the review queue manageable. The report is still appreciated and may be revisited as a more explicit follow-up. Thanks again for the contribution.

@Git-on-my-level

Copy link
Copy Markdown
Member

Closing after aggregate triage: deferring this design/API decision rather than merging the one-off patch. Thanks @ZachL111 for surfacing it.

@github-actions

Copy link
Copy Markdown
Contributor

Hey @ZachL111 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our roadmap and vision

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community! 💜

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants