Skip to content

feat: Run blocking plans via websockets - #1413

Merged
tpoliaw merged 68 commits into
mainfrom
ws
Aug 21, 2026
Merged

feat: Run blocking plans via websockets#1413
tpoliaw merged 68 commits into
mainfrom
ws

Conversation

@tpoliaw

@tpoliaw tpoliaw commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

As an intermediate step before (or instead of?) redesigning the server sub-process handling, add a websocket endpoint to run the same submit-listen-start approach that the client runs remotely. This is an experimental feature subject to change in minor releases in future. Everything is opt-in and existing behaviour should not change.

For the CLI, the websocket connection is enabled using the --ws flag to the run subcommand. A stomp configuration will not be required in this case.

For the BlueapiClient, users should use the run_blocking method instead of the run_task. The signatures and behaviour are the same (other than the ignored timeout parameter of run_task).

On the server there is a new endpoint on the new /api/v2/ tree. This re-uses the existing submit and start methods on the task runner but adds a new subscribe method to pipe events from the worker process to the websocket.

@tpoliaw

tpoliaw commented Feb 25, 2026

Copy link
Copy Markdown
Contributor Author

Rough next steps in no particular order

  • Move websocket client method into BlueapiRestClient
  • Add wrapper method in BlueapiClient?
  • Add unstable/preview --ws flag to cli run method
  • Deal with auth. Browser websocket api can't set headers
  • Users + user-agents
  • Include data/progress events
  • Add service/meta events for error handling etc
  • Handle client aborting
  • Check interaction with server being busy
  • Wrap pipe/unpipe into something that doesn't need finally handling
  • See what happens when listeners fall over/slow down - do messages back up
  • Add middleware for debug logging

@abbiemery

Copy link
Copy Markdown
Contributor
  • store api url withouth scheme, and add scheme to http and ws calls respectively. (request_and_deserialise)

Comment thread src/blueapi/service/interface.py Outdated
Comment thread src/blueapi/service/interface.py Outdated
Comment thread src/blueapi/service/runner.py
@tpoliaw
tpoliaw force-pushed the ws branch 2 times, most recently from 910d91b to b5c01e6 Compare March 12, 2026 16:41
@tpoliaw
tpoliaw force-pushed the ws branch 2 times, most recently from 71bdbcf to 2371239 Compare April 14, 2026 15:28
Comment thread src/blueapi/service/interface.py Fixed
Comment thread src/blueapi/service/middleware.py Fixed
Comment thread src/blueapi/service/middleware.py Fixed
Comment thread src/blueapi/service/interface.py Dismissed
@codecov

codecov Bot commented Jun 29, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.31%. Comparing base (5d7e2fa) to head (f304709).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1413      +/-   ##
==========================================
+ Coverage   95.96%   96.31%   +0.35%     
==========================================
  Files          45       46       +1     
  Lines        3323     3641     +318     
==========================================
+ Hits         3189     3507     +318     
  Misses        134      134              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tpoliaw
tpoliaw force-pushed the ws branch 2 times, most recently from b5c32f7 to 40cbd59 Compare July 3, 2026 09:59
@tpoliaw
tpoliaw force-pushed the ws branch 2 times, most recently from 9d061e9 to b2936d4 Compare July 27, 2026 19:49
@tpoliaw
tpoliaw marked this pull request as ready for review August 3, 2026 12:12
@tpoliaw
tpoliaw requested a review from a team as a code owner August 3, 2026 12:12
Comment thread src/blueapi/service/protocol.py
Comment thread src/blueapi/service/main.py
@tpoliaw tpoliaw linked an issue Aug 3, 2026 that may be closed by this pull request
@tpoliaw

tpoliaw commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

Should probably have a way for plans run via the plan cache to use websockets. They currently default to using the existing message bus approach. Something like

bc = BlueapiClient.from_config_file(...)
bc.use_ws(True)

bc.plans.count(detectors=[bc.devices.det])

It's not ideal though so open to suggestions. A new client only config field?

Comment thread src/blueapi/service/runner.py Outdated

@fajinyuan fajinyuan left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please see my comments.

Comment thread src/blueapi/service/interface.py Outdated
# * Submit task
# * Pause
# * Resume
# * Abort

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more use case - stop or abort after current point, ensure data collected so far are saved. like finish earlier!

Comment thread src/blueapi/cli/cli.py Outdated
@abbiemery

Copy link
Copy Markdown
Contributor

Approved. It works locally for me as expected, but given the size of the PR I think we just get it into a release and let people play with it.

@tpoliaw
tpoliaw added this pull request to the merge queue Aug 21, 2026
Merged via the queue into main with commit 1dc22b6 Aug 21, 2026
21 checks passed
@tpoliaw
tpoliaw deleted the ws branch August 21, 2026 12:29
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.

Add websocket end point to run plan

4 participants