Skip to content

fix(cloud_scheduler): key deduplication on the scheduled minute - #14783

Open
iennae wants to merge 2 commits into
mainfrom
fix/cloud-scheduler-dedup-minute-key
Open

iennae wants to merge 2 commits into
mainfrom
fix/cloud-scheduler-dedup-minute-key

Conversation

@iennae

@iennae iennae commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Description

Fixes duplicate processing in cloudscheduler_deduplicate_job_requests (from #14772) and cloudscheduler_receiver, found while live-testing the equivalent Workflows sample (#14782).

Both samples identified a scheduled run by the raw X-CloudScheduler-ScheduleTime header. In testing, a forced run (gcloud scheduler jobs run) sent before a job's first scheduled run carried the schedule time without Cloud Scheduler's per-job offset of a few seconds, for example 01:00:00-08:00, while later deliveries of the same run carried 01:00:02.202379-08:00. The two values produced different keys, so the same scheduled run was processed twice.

Both samples now key on the scheduled minute in UTC, which matches either form. A schedule time that can't be parsed returns HTTP 400.

Tests

  • New unit tests in both samples: a delivery with and without the offset counts as one run, and an invalid schedule time is rejected.
  • The deduplication sample's integration tests use the same minute key.

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended. Unit tests pass for both samples, and the deduplication sample's integration tests pass against a live Firestore database, on Python 3.13.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

The deduplication and receiver samples identified a scheduled run by the
raw X-CloudScheduler-ScheduleTime header. A forced run sent before a
job's first scheduled run carries the schedule time without Cloud
Scheduler's per-job offset of a few seconds, so the same run could get
two keys and be processed twice.

Key on the scheduled minute in UTC instead, and reject a schedule time
that can't be parsed with HTTP 400. Add unit tests for a delivery with
and without the offset, and for an invalid schedule time.
@iennae
iennae requested review from a team as code owners November 10, 2026 17:29
@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Nov 10, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the Cloud Scheduler deduplication logic in both the deduplicate_job_requests and receiver services to key on the scheduled minute rather than the exact schedule time, ensuring that forced runs (which omit the few-second offset) are correctly identified as duplicates. Feedback highlights a compatibility issue where datetime.datetime.fromisoformat does not support the Z suffix in Python versions prior to 3.11, and suggests normalizing the suffix to +00:00 before parsing.

Comment thread cloud_scheduler/receiver/main.py Resolved
Replace the three-line explanation in the deduplication and receiver
samples with a single line, and drop redundant comments from the tests
whose names already describe the behavior.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant