Skip to content

Initial version of nexus_operation_as_tool #932

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

Draft
wants to merge 184 commits into
base: main
Choose a base branch
from

Conversation

dandavison
Copy link
Contributor

@dandavison dandavison commented Jul 1, 2025

This PR adds one commit on top of the nexus branch.

The nexusrpc Nexus SDK is not yet released; this branch installs it from GitHub currently.

dandavison added 29 commits July 2, 2025 21:46
Import types from nexusrpc
Rename: WorkflowRunOperation
Use Client.start_workflow with Temporal-specific context classes
Use temporal {Start,Cancel}OperationContext
Handle errors during cancellation
Failing test for requestID-based idempotency
Propagate Nexus request ID when starting a workflow
Move nexus http client into tests/helpers
Testing: Fix env http port
Test that Nexus request ID becomes Temporal StartWorkflow request ID
Test non-serializable operation output
Don't require HandlerError cause and fix test assertions
Respond to upstream: Unknown{Operation,Service}Error are just HandlerError
Rename argument in public Worker API: nexus_service_handlers
Respond to upstream: Executor rename
Sync/Async suffix names
Separate _TemporalNexusOperationContext from Nexus op ctx
_operation_handlers module
Make TemporalNexusOperationContext public
Add WorkflowRunOperationResult.to_workflow_handle
Pass nexus_operation to start_workflow.

But this seems problematic. The user may forget. But it seems that we
have no way to prevent them from forgetting since as far as
start_workflow knows this may be a valid start_workflow call in a
Nexus operation handler, precdeding the "final" / "backing"
start_workflow call.
This reverts commit 334b889fd196d1412b264c9197762645027cea22.
This reverts commit 1a74d64.
The only way to start a nexusified workflow is to create a
WorkflowStartOperationResult, passing it an Awaitable[WorkflowHandle].
Accordingly, you must go via this type to create a token encoding a
nexusified worfklow handle.

The method decorated by the shorthand decorator
@workflow_run_operation_handler must return
WorkflowStartOperationResult.

A manually-implemented OperationHandler start method may create a
token this way.
NexusStartWorkflowRequest holds start_workflow request params, and
exposes a method to start the workflow that injects the required Nexus
metadata, and populates outbound links.
tctx.start_workflow starts the workflow, injects Nexus metadata, but
returns a WorkflowOperationToken instead of a WorkflowHandle. This
means that users accidentally trying to start a Nexusified workflow
via the standard client.start_workflow will get both a type-check-time
error, and a run-time error.
- Move NexusCompletionCallback into client.py
@dandavison dandavison marked this pull request as ready for review July 4, 2025 00:14
@dandavison dandavison requested a review from a team as a code owner July 4, 2025 00:14
@dandavison dandavison marked this pull request as draft July 4, 2025 00:46
@dandavison dandavison force-pushed the nexus branch 10 times, most recently from 9a10b13 to 917873c Compare July 8, 2025 03:24
Base automatically changed from nexus to main July 8, 2025 04:03
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.

1 participant