Skip to content

feat: Include plan outcome in WorkerEvents#1357

Open
tpoliaw wants to merge 17 commits intomainfrom
plan-result
Open

feat: Include plan outcome in WorkerEvents#1357
tpoliaw wants to merge 17 commits intomainfrom
plan-result

Conversation

@tpoliaw
Copy link
Contributor

@tpoliaw tpoliaw commented Jan 27, 2026

The TaskStatus included in each WorkerEvent now contains a result
field that will be populated when the plan is complete. This can be
either a TaskResult that contains a serialized representation of the
return value from a plan that succeeded, or a TaskError containing the
Exception type and message raised by a plan that failed.

The existing task_complete and task_failed flags have been left for
backwards compatibility but are now redundant and may be removed in a
future version.

Error reporting in WorkerEvents is left unchanged for now but may also
change in future as plan errors are included in the worker error list
making it unclear where an error occurred.

The new outcome states in the returned TaskStatus allows better
feedback in the CLI and errors/return values are included in the output.

The BlueapiClient run_task method now returns only the TaskStatus as it
now contains all relevant information about the plan. A plan failing
will now not raise an exception with exceptions being raised only in the
case of the communication errors or internal server errors. Users of the
client should check if plans were successful.

@tpoliaw tpoliaw requested a review from DominicOram January 27, 2026 16:48
@tpoliaw tpoliaw linked an issue Jan 27, 2026 that may be closed by this pull request
@tpoliaw
Copy link
Contributor Author

tpoliaw commented Jan 27, 2026

This would need a matching change in GDA (back-ported to 9.38?) to add the result type to TaskStatus here.

@tpoliaw tpoliaw changed the title WIP returning results from plans Include plan return values in WorkerEvents Jan 29, 2026
@tpoliaw tpoliaw marked this pull request as ready for review January 29, 2026 16:15
@tpoliaw tpoliaw requested a review from a team as a code owner January 29, 2026 16:15
@tpoliaw
Copy link
Contributor Author

tpoliaw commented Jan 29, 2026

Ignoring the GDA change, I think the blueapi side of this is workable

@tpoliaw tpoliaw changed the title Include plan return values in WorkerEvents feat!: Include plan return values in WorkerEvents Jan 29, 2026
@tpoliaw
Copy link
Contributor Author

tpoliaw commented Jan 29, 2026

Change in gerrit: https://gerrit.diamond.ac.uk/c/gda/gda-core/+/44673

Copy link
Contributor

@DominicOram DominicOram left a comment

Choose a reason for hiding this comment

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

Looks good, thanks. Should: it would be nice to add some tests on the case where the plan is actually returning something, ideally parametrized against a few different return types.

@codecov
Copy link

codecov bot commented Feb 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.01%. Comparing base (fe35430) to head (094a152).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1357      +/-   ##
==========================================
- Coverage   95.03%   95.01%   -0.02%     
==========================================
  Files          43       43              
  Lines        2779     2829      +50     
==========================================
+ Hits         2641     2688      +47     
- Misses        138      141       +3     

☔ View full report in Codecov by Sentry.
📢 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 changed the title feat!: Include plan return values in WorkerEvents feat: Include plan return values in WorkerEvents Feb 9, 2026
@tpoliaw tpoliaw force-pushed the plan-result branch 2 times, most recently from 73dcfee to 6a697c4 Compare February 11, 2026 12:10
@tpoliaw
Copy link
Contributor Author

tpoliaw commented Feb 11, 2026

Putting this back to draft so #1312 can be included in the result

@tpoliaw tpoliaw marked this pull request as draft February 11, 2026 15:03
@tpoliaw tpoliaw marked this pull request as ready for review February 13, 2026 11:56
@tpoliaw tpoliaw requested a review from DominicOram February 13, 2026 11:56
@tpoliaw tpoliaw changed the title feat: Include plan return values in WorkerEvents feat: Include plan outcome in WorkerEvents Feb 13, 2026
Copy link
Contributor

@dan-fernandes dan-fernandes left a comment

Choose a reason for hiding this comment

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

Minor changes / questions, everything else looks reasonable 👍

) -> None:
"""Run a plan with parameters"""
client: BlueapiClient = obj["client"]
client: BlueapiClient = cast(BlueapiClient, obj["client"])
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the benefit of using cast instead of assuming obj["client"] will be of type BlueapiClient and just typing it as such?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For some reason the type-checker fails to recognise that it is a BlueapiClient otherwise. Using typing.reveal_type gives

$ uv run pyright src/blueapi/cli/cli.py                                                                      17:01:39
/dls/athena/blueapi/src/blueapi/cli/cli.py
  /dls/athena/blueapi/src/blueapi/cli/cli.py:295:17 - information: Type of "client" is "Unknown | BlueapiClient"

It might be ok to just use the cast though without the type-hint


if resp.task_status is not None and not resp.task_status.task_failed:
print("Plan Succeeded")
match resp.result:
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the success / failure of the task logged anywhere? I am open to print statements in a CLI for a human user, but I think that either:

  • These should be logs, or
  • TaskWorker should log outcome of task

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are logs from the CLI sent anywhere other than the terminal? I have added a success/fail log to the task worker but that won't affect the client output.

Arguably these should use click.echo but it used print before and I didn't want to change that at the same time.

@tpoliaw
Copy link
Contributor Author

tpoliaw commented Feb 16, 2026

Good spot on the unused loggers - they were left from an earlier iteration. Thanks

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.

Return plan_result to the client BlueAPI should expose type information from exceptions raised in plans to calling clients.

3 participants