Skip to content

feat: Add ability to set custom clock and UUID providers#964

Open
DABH wants to merge 6 commits into
google:mainfrom
DABH:add-platform-time-uuid-providers
Open

feat: Add ability to set custom clock and UUID providers#964
DABH wants to merge 6 commits into
google:mainfrom
DABH:add-platform-time-uuid-providers

Conversation

@DABH

@DABH DABH commented Jun 4, 2026

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Please include a summary of passed go test results.

Full go test ./... run on the branch yields 55 passed, 1 failed. The failure is identical to a failure occurring on main right now and seems unrelated to the changes in this branch.

Manual End-to-End (E2E) Tests:

Please provide instructions on how to manually test your changes, including any
necessary setup or configuration. Please provide logs or screenshots to help
reviewers better understand the fix.

A representative E2E test is here: https://gist.github.com/DABH/91c0d0a45788b4e152d53ca175b92980 . You can run this go run . and get e.g.

  [run-1] id=det-id-3 ts=2026-01-01T00:00:02Z
  [run-2] id=det-id-3 ts=2026-01-01T00:00:02Z

which demonstrates that all the plumbing in the PR works as expected (we inject deterministic providers and get the same output on each run). You can replace deterministicCtx(context.Background()) with context.Background() in that test file to see the results diverge (matching the current/default ADK behavior).

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional Information

  • The platform naming here mimics what's in adk-python (google.adk.platform.time / google.adk.platform.uuid), but open to other naming based on feedback. My goal was to try to make things as close to adk-python as possible with this attempt.

  • One important callout is a proposed breaking change for session.NewEvent - adding a context variable as a first parameter. It's possible to avoid this (have NewEvent stay as-is and have it call NewEventWithContext(context.Background() ...), but modifying NewEvent seemed cleaner. Let me know what you think.

DABH added 2 commits June 4, 2026 16:50
…ent creation

Introduce a platform package whose current time and UUID generation can be
overridden per-context, mirroring the ContextVar-based seams in ADK-Python:

  - platform.Now(ctx) / platform.WithTimeProvider(ctx, fn)
  - platform.NewUUID(ctx) / platform.WithUUIDProvider(ctx, fn)

Both fall back to time.Now and uuid.NewString when no provider is installed,
so default behavior is unchanged.

session.NewEvent now takes a context and sources its ID and timestamp from
these seams, and all event/session creation call sites are threaded with
context accordingly. This lets a host runtime make event and session
creation deterministic and replay-safe (e.g. a Temporal workflow that must
reproduce an execution exactly on replay).
Comment thread platform/doc.go Outdated
Comment thread platform/doc.go Outdated
Comment thread platform/time.go Outdated
Comment thread platform/time.go Outdated
@DABH DABH force-pushed the add-platform-time-uuid-providers branch from d7e7e50 to 6acb142 Compare June 5, 2026 17:14
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.

Custom providers for time and UUIDs

3 participants