-
Notifications
You must be signed in to change notification settings - Fork 3k
feat: durable runtime support #4200
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
Open
marcusmotill
wants to merge
8
commits into
google:main
Choose a base branch
from
marcusmotill:motill/durable-support
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
78b1c4e
feat: extract durable runtime support changes
marcusmotill 57ddf8f
chore: remove pr_description.md
marcusmotill 08d099d
address Bo comments, move runtime to platform
marcusmotill cc58fa5
updates for durable execution
marcusmotill 5abb519
back out a2a changes
marcusmotill 544af2d
update for concurrency and review feedback
marcusmotill f518ee6
cover more bases with regards to durable utils
marcusmotill 0c695cc
revert rounding
marcusmotill 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
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 |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ | |
| from typing import Optional | ||
| import uuid | ||
|
||
|
|
||
| from google.adk.platform import time as platform_time | ||
| from google.adk.platform import uuid as platform_uuid | ||
| from google.genai import types | ||
| from pydantic import alias_generators | ||
| from pydantic import ConfigDict | ||
|
|
@@ -70,7 +72,7 @@ class Event(LlmResponse): | |
| # Do not assign the ID. It will be assigned by the session. | ||
| id: str = '' | ||
| """The unique identifier of the event.""" | ||
| timestamp: float = Field(default_factory=lambda: datetime.now().timestamp()) | ||
| timestamp: float = Field(default_factory=lambda: platform_time.get_time()) | ||
| """The timestamp of the event.""" | ||
|
|
||
| def model_post_init(self, __context): | ||
|
|
@@ -125,4 +127,4 @@ def has_trailing_code_execution_result( | |
|
|
||
| @staticmethod | ||
| def new_id(): | ||
| return str(uuid.uuid4()) | ||
| return platform_uuid.new_uuid() | ||
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,43 @@ | ||
| # Copyright 2026 Google LLC | ||
sasha-gitg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Platform module for abstracting system time generation.""" | ||
|
|
||
| import time | ||
| from typing import Callable | ||
|
|
||
| _default_time_provider: Callable[[], float] = time.time | ||
sasha-gitg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| _time_provider: Callable[[], float] = _default_time_provider | ||
|
|
||
|
|
||
| def set_time_provider(provider: Callable[[], float]) -> None: | ||
marcusmotill marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| """Sets the provider for the current time. | ||
| Args: | ||
| provider: A callable that returns the current time in seconds since the | ||
| epoch. | ||
| """ | ||
| global _time_provider | ||
| _time_provider = provider | ||
|
|
||
|
|
||
| def reset_time_provider() -> None: | ||
| """Resets the time provider to its default implementation.""" | ||
| global _time_provider | ||
| _time_provider = _default_time_provider | ||
|
|
||
|
|
||
| def get_time() -> float: | ||
| """Returns the current time in seconds since the epoch.""" | ||
| return _time_provider() | ||
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,42 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Platform module for abstracting unique ID generation.""" | ||
|
|
||
| import uuid | ||
| from typing import Callable | ||
|
|
||
| _default_id_provider: Callable[[], str] = lambda: str(uuid.uuid4()) | ||
| _id_provider: Callable[[], str] = _default_id_provider | ||
|
|
||
|
|
||
| def set_id_provider(provider: Callable[[], str]) -> None: | ||
| """Sets the provider for generating unique IDs. | ||
|
|
||
| Args: | ||
| provider: A callable that returns a unique ID string. | ||
| """ | ||
| global _id_provider | ||
| _id_provider = provider | ||
|
|
||
|
|
||
| def reset_id_provider() -> None: | ||
| """Resets the ID provider to its default implementation.""" | ||
| global _id_provider | ||
| _id_provider = _default_id_provider | ||
|
|
||
|
|
||
| def new_uuid() -> str: | ||
| """Returns a new unique ID.""" | ||
| return _id_provider() |
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
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,40 @@ | ||
| # Copyright 2026 Google LLC | ||
marcusmotill marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Unit tests for the platform time module.""" | ||
|
|
||
| import time | ||
| import unittest | ||
|
|
||
| from google.adk.platform import time as platform_time | ||
|
|
||
|
|
||
| class TestTime(unittest.TestCase): | ||
|
|
||
| def tearDown(self): | ||
| # Reset provider to default after each test | ||
| platform_time.reset_time_provider() | ||
|
|
||
| def test_default_time_provider(self): | ||
| # Verify it returns a float that is close to now | ||
| now = time.time() | ||
| rt_time = platform_time.get_time() | ||
| self.assertIsInstance(rt_time, float) | ||
| self.assertAlmostEqual(rt_time, now, delta=1.0) | ||
|
|
||
| def test_custom_time_provider(self): | ||
| # Test override | ||
| mock_time = 123456789.0 | ||
| platform_time.set_time_provider(lambda: mock_time) | ||
| self.assertEqual(platform_time.get_time(), mock_time) | ||
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,40 @@ | ||
| # Copyright 2026 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| """Unit tests for the platform uuid module.""" | ||
|
|
||
| import uuid | ||
| import unittest | ||
|
|
||
| from google.adk.platform import uuid as platform_uuid | ||
|
|
||
|
|
||
| class TestUUID(unittest.TestCase): | ||
|
|
||
| def tearDown(self): | ||
| # Reset provider to default after each test | ||
| platform_uuid.reset_id_provider() | ||
|
|
||
| def test_default_id_provider(self): | ||
| # Verify it returns a string uuid | ||
| uid = platform_uuid.new_uuid() | ||
| self.assertIsInstance(uid, str) | ||
| # Should be parseable as uuid | ||
| uuid.UUID(uid) | ||
|
|
||
| def test_custom_id_provider(self): | ||
| # Test override | ||
| mock_id = "test-id-123" | ||
| platform_uuid.set_id_provider(lambda: mock_id) | ||
| self.assertEqual(platform_uuid.new_uuid(), mock_id) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are multiple uuid.uuid4() and time.time() call sites throughout the SDK that are not changed in this PR. Is that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, the intention is to only change the things we need to limit the PR. While we could swap out all instances, we don't need to. Now the real question is, did I get all the ones we need? I am not positive but this batch is a good start for the most common paths I see.
open to taking more of a blanket approach and change more than we need, open to thoughts...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Having two patterns side-by-side is a maintenance trap. A new contributor won't know which to use, and nobody will want to audit whether their code is "on the workflow path" before picking one.
A single rule is much easier to follow than "use them only if your code might run in a Temporal workflow." The cost of converting the remaining sites is low and it eliminates the ambiguity entirely.
Honestly it would be best to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't disagree, will do a further audit of other locations and look into a linting rule 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be resolved, suggestion on the mechanism for lint rule?