Repository navigation
feat(runtime): support external wait pause reasons #446
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d0a696f
feat(runtime): support external wait pause reasons
zyssyz123 a48f309
docs: update document review timestamps
autofix-ci[bot] acc7794
refactor(runtime): generalize external wait pause payload
zyssyz123 e85a4cb
feat(runtime): include node and frame identity in external waits
QuantumGhost 6a79dc6
refactor(runtime): deprecate HitlRequired in favor of ExternalWait
QuantumGhost 805bca3
fix(runtime): accept unknown fields on external waits
QuantumGhost a0f2431
docs(runtime): document the wait_type PEG in its field comment
QuantumGhost 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 |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| """Check host pause identities across engine events and runtime snapshots.""" | ||
|
|
||
| import pytest | ||
| from pydantic import ValidationError | ||
|
|
||
| from graphon.engine_events.graph import GraphRunPausedEvent | ||
| from graphon.engine_events.node import NodeRunPauseRequestedEvent | ||
| from graphon.node_events.node import PauseRequestedEvent | ||
| from graphon.runtime import RuntimeState, VariablePool | ||
|
|
||
|
|
||
| def make_external_wait_payload(frame_id: str, execution_id: str) -> dict[str, str]: | ||
| return { | ||
| "TYPE": "external_wait", | ||
| "wait_id": f"external-job:{frame_id}", | ||
| "node_id": "worker", | ||
| "node_title": "External worker", | ||
| "execution_id": execution_id, | ||
| "frame_id": frame_id, | ||
| } | ||
|
|
||
|
|
||
| def test_external_wait_identity_survives_events_and_snapshot() -> None: | ||
| state = RuntimeState( | ||
| workflow_id="workflow", variable_pool=VariablePool(), start_at=0 | ||
| ) | ||
| expected_payloads = [] | ||
| for frame_id in ("iteration:0", "iteration:1"): | ||
| execution = state.graph_execution.get_or_create_node_execution( | ||
| frame_id=frame_id, node_id="worker" | ||
| ) | ||
| reason_payload = make_external_wait_payload(frame_id, execution.execution_id) | ||
| pause_request = PauseRequestedEvent.model_validate({"reason": reason_payload}) | ||
| node_pause = NodeRunPauseRequestedEvent( | ||
| id=execution.execution_id, | ||
| node_id=reason_payload["node_id"], | ||
| node_type="worker", | ||
| frame_id=frame_id, | ||
| reason=pause_request.reason, | ||
| ) | ||
| restored_node_pause = NodeRunPauseRequestedEvent.model_validate_json( | ||
| node_pause.model_dump_json() | ||
| ) | ||
| assert restored_node_pause.reason.model_dump(mode="json") == reason_payload | ||
| state.graph_execution.pause(restored_node_pause.reason) | ||
| expected_payloads.append(reason_payload) | ||
|
|
||
| graph_pause = GraphRunPausedEvent(reasons=state.graph_execution.pause_reasons) | ||
| restored_graph_pause = GraphRunPausedEvent.model_validate_json( | ||
| graph_pause.model_dump_json() | ||
| ) | ||
| assert restored_graph_pause.model_dump(mode="json")["reasons"] == expected_payloads | ||
|
|
||
| restored_state = RuntimeState.from_snapshot(state.dumps()) | ||
| assert restored_state.graph_execution.paused | ||
| assert [ | ||
| reason.model_dump(mode="json") | ||
| for reason in restored_state.graph_execution.pause_reasons | ||
| ] == expected_payloads | ||
| for reason_payload in expected_payloads: | ||
| execution = restored_state.graph_execution.get_or_create_node_execution( | ||
| frame_id=reason_payload["frame_id"], node_id=reason_payload["node_id"] | ||
| ) | ||
| assert execution.execution_id == reason_payload["execution_id"] | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("field", "value", "error_type"), | ||
| [ | ||
| ("wait_id", "", "string_too_short"), | ||
| ("node_id", "", "string_too_short"), | ||
| ("execution_id", "", "string_too_short"), | ||
| ("frame_id", "", "string_too_short"), | ||
| ("deadline", "host-owned", "extra_forbidden"), | ||
| ], | ||
| ) | ||
| def test_external_wait_rejects_invalid_fields( | ||
| field: str, value: str, error_type: str | ||
| ) -> None: | ||
| reason_payload = make_external_wait_payload("root", "execution") | {field: value} | ||
| with pytest.raises(ValidationError) as error: | ||
| PauseRequestedEvent.model_validate({"reason": reason_payload}) | ||
| assert any( | ||
| item["loc"][-1] == field and item["type"] == error_type | ||
| for item in error.value.errors() | ||
| ) |
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.