Skip to content

Record the service of each operation - #58

Open
VegetarianOrc wants to merge 2 commits into
mainfrom
amazzeo/operation-service
Open

VegetarianOrc wants to merge 2 commits into
mainfrom
amazzeo/operation-service

Conversation

@VegetarianOrc

@VegetarianOrc VegetarianOrc commented Oct 2, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

  • Add Operation.service. @nexusrpc.service and @service_handler set this value to the service definition of the decorated class. Thus, a caller can find the service from an operation or from a handler method alone.
  • Each decorated class now has its own operations. A service definition copies each inherited operation. A service handler wraps each inherited operation method. Thus, an operation reports the service of the class that holds it, not the service of the parent class.
  • Handler method operations now get their name and types from the service definition. Before this change, when a service definition renamed an operation, the handler method reported the method name and not the operation name.
  • service is not part of Operation equality or repr.

Why

This was added to provide some convenience to targeting operations with Nexus Handler Callbacks in the Temporal Python SDK.

@nexusrpc.handler.service_handler(name="callback.test.NotificationService")
class ExampleHandler:
    @nexusrpc.handler.sync_operation
    async def on_complete(
        self,
        _ctx: nexusrpc.handler.StartOperationContext,
        input: notifications.OnCompleteRequest[EchoOutput, CallbackContext],
    ) -> notifications.OnCompleteResponse:
        ...


# Referencing the operation by reference previously only gave access to the operation definition.
# After this change, this reference is enough to resolve both the Nexus service as well as the operation
# name.
operation = ExampleHandler.on_complete


# The change allows users to provide a reference without needing to provide both the service and the
# operation. It helps provide more ergonomic APIs like:

nexus.create_completion_callback(
    # service and operation read from this one reference
    operation=ExampleHandler.on_complete,
    task_queue=completion_task_queue,
    source_context=CallbackContext(label="success"),
)

Test plan

  • uv run poe lint (basedpyright, pyright, mypy, ruff)
  • uv run pytest (112 passed)
  • New tests in tests/test_operation_service.py cover definitions, handlers, inheritance, renamed operations, sync and async methods, and @operation_handler factories.

🤖 Generated with Claude Code

VegetarianOrc and others added 2 commits October 2, 2026 11:48
Add Operation.service, which @nexusrpc.service and @service_handler set to
the service definition of the decorated class. Callers can then find the
service from an operation or a handler method alone.

Each decorated class now gets its own operations. A service definition
copies inherited operations, and a service handler wraps inherited
operation methods, so that an operation reports the service of the class
it was accessed on rather than the parent class.

Handler method operations now take their name and types from the service
definition. Before, a handler for a definition that renames an operation
reported the method name instead of the operation name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rewrite the new prose in plain, active-voice English.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@VegetarianOrc
VegetarianOrc marked this pull request as ready for review October 2, 2026 21:45
@VegetarianOrc
VegetarianOrc requested a review from a team as a code owner October 2, 2026 21:45
@bergundy

bergundy commented Oct 2, 2026

Copy link
Copy Markdown

Can you add a "why" section to the PR description?

@bergundy

bergundy commented Oct 2, 2026

Copy link
Copy Markdown

And do you see us adding this to all of the Nexus SDKs?

@VegetarianOrc

Copy link
Copy Markdown
Collaborator Author

And do you see us adding this to all of the Nexus SDKs?

Spoke offline about this, but at this time I don't think it's necessary for other SDKs as they already have avenues for idiomatic/ergonomic operation targeting.

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.

2 participants