-
Notifications
You must be signed in to change notification settings - Fork 9
feat(temporal): opt-in continue-as-new for long-lived agent workflows #447
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
danielmillerp
wants to merge
1
commit into
next
Choose a base branch
from
dm/temporal-continue-as-new
base: next
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.
+253
−23
Open
Changes from all commits
Commits
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
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
75 changes: 75 additions & 0 deletions
75
tests/lib/core/temporal/test_base_workflow_continue_as_new.py
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,75 @@ | ||
| """Unit tests for BaseWorkflow's continue-as-new lifecycle helpers. | ||
| These exercise the pure decision helpers (``should_continue_as_new`` and | ||
| ``is_continued_run``) by faking ``workflow.info()`` so we don't need a running | ||
| Temporal server. The drain + ``workflow.continue_as_new`` mechanics in | ||
| ``drain_and_continue_as_new`` / ``run_until_complete`` are best covered by a | ||
| replay/integration test against a Temporal test environment (a follow-up). | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import override | ||
|
|
||
| import pytest | ||
|
|
||
| from agentex.lib.core.temporal.workflows import workflow as base_workflow_module | ||
| from agentex.lib.core.temporal.workflows.workflow import BaseWorkflow | ||
|
|
||
|
|
||
| class _ConcreteWorkflow(BaseWorkflow): | ||
| """Minimal concrete subclass so we can instantiate the ABC in a test.""" | ||
|
|
||
| def __init__(self) -> None: | ||
| self.display_name = "test" | ||
|
|
||
| @override | ||
| async def on_task_event_send(self, params) -> None: # pragma: no cover - unused | ||
| raise NotImplementedError | ||
|
|
||
| @override | ||
| async def on_task_create(self, params) -> None: # pragma: no cover - unused | ||
| raise NotImplementedError | ||
|
|
||
|
|
||
| class _FakeInfo: | ||
| def __init__(self, *, suggested: bool, continued_run_id: str | None = None) -> None: | ||
| self._suggested = suggested | ||
| self.continued_run_id = continued_run_id | ||
|
|
||
| def is_continue_as_new_suggested(self) -> bool: | ||
| return self._suggested | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def patch_info(monkeypatch): | ||
| """Patch ``workflow.info`` used inside the BaseWorkflow module.""" | ||
|
|
||
| def _apply(*, suggested: bool = False, continued_run_id: str | None = None) -> None: | ||
| monkeypatch.setattr( | ||
| base_workflow_module.workflow, | ||
| "info", | ||
| lambda: _FakeInfo(suggested=suggested, continued_run_id=continued_run_id), | ||
| ) | ||
|
|
||
| return _apply | ||
|
|
||
|
|
||
| def test_recycles_when_temporal_suggests(patch_info): | ||
| patch_info(suggested=True) | ||
| assert _ConcreteWorkflow().should_continue_as_new() is True | ||
|
|
||
|
|
||
| def test_no_recycle_when_not_suggested(patch_info): | ||
| patch_info(suggested=False) | ||
| assert _ConcreteWorkflow().should_continue_as_new() is False | ||
|
|
||
|
|
||
| def test_is_continued_run_false_on_original_run(patch_info): | ||
| patch_info(continued_run_id=None) | ||
| assert _ConcreteWorkflow().is_continued_run() is False | ||
|
|
||
|
|
||
| def test_is_continued_run_true_after_recycle(patch_info): | ||
| patch_info(continued_run_id="run-123") | ||
| assert _ConcreteWorkflow().is_continued_run() is True |
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.
Uh oh!
There was an error while loading. Please reload this page.