Skip to content

OpenService: Implement remote command execution#35068

Merged
JReinhold merged 4 commits into
norbert/service-clientsfrom
norbert/remote-command-execution
Jun 5, 2026
Merged

OpenService: Implement remote command execution#35068
JReinhold merged 4 commits into
norbert/service-clientsfrom
norbert/remote-command-execution

Conversation

@ndelangen

@ndelangen ndelangen commented Jun 5, 2026

Copy link
Copy Markdown
Member

Tracked by: #34824

What I did

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

Caution

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Declare whether manual QA will be needed for this PR during the next release, through qa:needed or qa:skip

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

Release Notes

  • New Features

    • Enabled remote command execution with error serialization for improved service reliability
    • Enhanced error handling for service commands with detailed error recovery
  • Documentation

    • Updated service documentation to describe remote command execution, error handling, and multi-runtime topologies
  • Tests

    • Added comprehensive test coverage for remote command transport and error serialization

@ndelangen ndelangen self-assigned this Jun 5, 2026
@ndelangen ndelangen requested a review from JReinhold June 5, 2026 13:52
@ndelangen ndelangen added feature request ci:normal Run our default set of CI jobs (choose this for most PRs). qa:needed Pull Requests that will need manual QA prior to release. labels Jun 5, 2026
ndelangen added 3 commits June 5, 2026 15:52
Enhanced the README documentation for the remote command execution section, clarifying the roles of requester and responder, the command invocation process, and the event structure. This update aims to provide clearer guidance on how commands are executed across different runtimes, improving overall understanding for developers.
@storybook-app-bot

Copy link
Copy Markdown

Package Benchmarks

Commit: 333f57c, ran on 5 June 2026 at 14:07:25 UTC

The following packages have significant changes to their size or dependencies:

storybook

Before After Difference
Dependency count 74 74 0
Self size 20.61 MB 20.64 MB 🚨 +29 KB 🚨
Dependency size 36.65 MB 36.65 MB 0 B
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 205 205 0
Self size 908 KB 908 KB 🚨 +144 B 🚨
Dependency size 89.34 MB 89.37 MB 🚨 +29 KB 🚨
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 198 198 0
Self size 32 KB 32 KB 🎉 -36 B 🎉
Dependency size 87.83 MB 87.86 MB 🚨 +29 KB 🚨
Bundle Size Analyzer Link Link

create-storybook

Before After Difference
Dependency count 75 75 0
Self size 1.08 MB 1.08 MB 🎉 -66 B 🎉
Dependency size 57.26 MB 57.29 MB 🚨 +29 KB 🚨
Bundle Size Analyzer node node

@JReinhold JReinhold marked this pull request as ready for review June 5, 2026 20:13
@JReinhold

Copy link
Copy Markdown
Contributor

Merging this into the base branch, to finish both of them up together.

@JReinhold JReinhold merged commit ef9f323 into norbert/service-clients Jun 5, 2026
141 of 142 checks passed
@JReinhold JReinhold deleted the norbert/remote-command-execution branch June 5, 2026 20:14
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

Too many files changed? Review this PR in Change Stack to see how the pieces fit before you dive in.

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0cf9e0d1-33a8-4841-80c5-d295bcd64234

📥 Commits

Reviewing files that changed from the base of the PR and between 1336062 and 333f57c.

📒 Files selected for processing (11)
  • code/.storybook/background-service/definition.ts
  • code/.storybook/background-service/server.ts
  • code/core/src/server-errors.ts
  • code/core/src/shared/open-service/README.md
  • code/core/src/shared/open-service/service-channel.ts
  • code/core/src/shared/open-service/service-command-transport.test.ts
  • code/core/src/shared/open-service/service-error-serialization.test.ts
  • code/core/src/shared/open-service/service-error-serialization.ts
  • code/core/src/shared/open-service/service-registration.test.ts
  • code/core/src/shared/open-service/service-registry.ts
  • code/core/src/shared/open-service/service-transport.ts

📝 Walkthrough

Walkthrough

This PR implements remote command execution for Open Service, enabling runtimes to invoke commands on services without local handlers. It introduces error serialization, expands channel contracts, implements a two-sided protocol over the service channel, integrates the transport into service registration, and demonstrates the pattern with a Storybook example.

Changes

Remote Command Execution for Open Service

Layer / File(s) Summary
Error serialization for transport
code/core/src/shared/open-service/service-error-serialization.ts, service-error-serialization.test.ts, code/core/src/server-errors.ts
SerializedError shape and roundtrip helpers preserve error name, message, stack, nested cause chains, and extra fields while ensuring structured-clone safety. New OpenServiceRemoteCommandDisconnectedError represents command rejection when service unregisters before response.
Command channel contracts
code/core/src/shared/open-service/service-channel.ts
Introduces SERVICE_COMMAND_ACK constant and expands CommandInvokePayload, CommandResultPayload, CommandErrorPayload with clientId, serviceId, and SerializedError wire type for identity tracking and cross-runtime error transport.
Command transport protocol implementation
code/core/src/shared/open-service/service-transport.ts, service-command-transport.test.ts
connectCommandTransport wires responder (validates/ACKs invokes, executes local commands, replies with result/error) and requester (tracks in-flight calls by callId, settles first response, routes unimplemented commands remotely). Tests verify both sides: invoke emission, result/error handling, duplicate-response ignoring, and disconnect rejection.
Service registration integration
code/core/src/shared/open-service/service-registry.ts
registerService now derives implementedCommandNames from local handlers, calls connectCommandTransport, routes instance commands through the transport (local when handler exists, remote otherwise), and splits teardown into sync and async phases.
Registration behavior clarification
code/core/src/shared/open-service/service-registration.test.ts
Updates test to clarify missing command handlers do not throw at registration (handled remotely by peers); only missing query handlers throw locally.
Storybook background-service example
code/.storybook/background-service/definition.ts, server.ts
Removes setColor handler from shared definition and implements it only at server registration, demonstrating end-to-end remote command execution across runtimes.
Conceptual documentation
code/core/src/shared/open-service/README.md
Adds error-serialization module to file layout; clarifies commands may be handled only in some runtimes; introduces comprehensive "Remote Command Execution" section covering execution-mode decisions, requester/responder roles, channel events (services:command-invoke/ack/result/error), callId correlation, multiple-implementer behavior, and disconnect/timeout semantics; updates testing and agent-notes guidance.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • storybookjs/storybook#34960: Both PRs directly touch the open-service registration plumbing, with this PR adding remote command transport routing into service-registry.ts while the related PR reverts/removes server-side registration modules.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

Comment @coderabbitai help to get the list of available commands and usage tips.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:normal Run our default set of CI jobs (choose this for most PRs). feature request qa:needed Pull Requests that will need manual QA prior to release.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants