-
Notifications
You must be signed in to change notification settings - Fork 133
Avoid token detaching from different context #1153
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
VegetarianOrc
wants to merge
17
commits into
main
Choose a base branch
from
otel/context-detach
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 16 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
fc2a2e6
ensure that the context used to detach the token is the same as what …
VegetarianOrc 7a51529
Update test to use LogCapturer helper. Move shared test workflow and …
VegetarianOrc 1b8d9e1
run formatter
VegetarianOrc b656e84
Fix up test with log capturer. Only log warnings if there are no hook…
VegetarianOrc 5abc5a4
run formatter
VegetarianOrc d1bf879
Move to a class based context manager to manually manage context
VegetarianOrc 6ca781c
apply context management to openai_agents tracing
VegetarianOrc 6060b35
use 3.11 create_task when possible to avoid an extra context copy
VegetarianOrc 13e99a3
run formatter
VegetarianOrc 853f603
fix typing lint errors
VegetarianOrc 7ae97d0
Fix a few more typing errors
VegetarianOrc aaccb00
Use a lambda to wrap task creation to appease the type linter
VegetarianOrc 6deb5b1
Merge branch 'main' into otel/context-detach
VegetarianOrc fe8b0a5
revert manual context management explorations
VegetarianOrc 2274ba4
Add comment explaining the check. Use to ensure that the context is …
VegetarianOrc 460ed71
use original variable name
VegetarianOrc 83ae1fb
Fix typo
VegetarianOrc 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
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,68 @@ | ||
import asyncio | ||
from datetime import timedelta | ||
|
||
from temporalio import activity, workflow | ||
|
||
|
||
@activity.defn | ||
async def wait_forever_activity() -> None: | ||
await asyncio.Future() | ||
|
||
|
||
@workflow.defn | ||
class WaitForeverWorkflow: | ||
@workflow.run | ||
async def run(self) -> None: | ||
await asyncio.Future() | ||
|
||
|
||
@workflow.defn | ||
class CacheEvictionTearDownWorkflow: | ||
def __init__(self) -> None: | ||
self._signal_count = 0 | ||
|
||
@workflow.run | ||
async def run(self) -> None: | ||
# Start several things in background. This is just to show that eviction | ||
# can work even with these things running. | ||
tasks = [ | ||
asyncio.create_task( | ||
workflow.execute_activity( | ||
wait_forever_activity, start_to_close_timeout=timedelta(hours=1) | ||
) | ||
), | ||
asyncio.create_task( | ||
workflow.execute_child_workflow(WaitForeverWorkflow.run) | ||
), | ||
asyncio.create_task(asyncio.sleep(1000)), | ||
asyncio.shield( | ||
workflow.execute_activity( | ||
wait_forever_activity, start_to_close_timeout=timedelta(hours=1) | ||
) | ||
), | ||
asyncio.create_task(workflow.wait_condition(lambda: False)), | ||
] | ||
gather_fut = asyncio.gather(*tasks, return_exceptions=True) | ||
# Let's also start something in the background that we never wait on | ||
asyncio.create_task(asyncio.sleep(1000)) | ||
try: | ||
# Wait for signal count to reach 2 | ||
await asyncio.sleep(0.01) | ||
await workflow.wait_condition(lambda: self._signal_count > 1) | ||
finally: | ||
# This finally, on eviction, is actually called but the command | ||
# should be ignored | ||
await asyncio.sleep(0.01) | ||
await workflow.wait_condition(lambda: self._signal_count > 2) | ||
# Cancel gather tasks and wait on them, but ignore the errors | ||
for task in tasks: | ||
task.cancel() | ||
await gather_fut | ||
|
||
@workflow.signal | ||
async def signal(self) -> None: | ||
self._signal_count += 1 | ||
|
||
@workflow.query | ||
def signal_count(self) -> int: | ||
return self._signal_count |
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.
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.
Nice