Skip to content
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

perf(robot-server): Discriminate command unions #14286

Merged
merged 7 commits into from
Jan 9, 2024

Conversation

SyntaxColoring
Copy link
Contributor

@SyntaxColoring SyntaxColoring commented Jan 4, 2024

Overview

Now that we have Pydantic 1.9, we can close RSS-128. This dramatically improves error reporting when you misspell something in a Protocol Engine command, and it also improves performance anywhere we're parsing Protocol Engine commands.

Test Plan

For "this doesn't break anything," I'm mostly leaning on integration tests.

  • To do: Also push this to an OT-2 to make sure the new typing.Annotated usage hasn't broken anything across Python versions.

For improved error reporting:

  • I've manually used Postman to check POST /runs/commands
  • I've manually used Postman to check POST /maintenance_runs/commands
  • I've manually used Postman to check POST /commands

For improved performance:

  • I've manually used Postman on a dev server to check the speed of POST /runs with a JSON protocol. Seems ~20-30% better.
  • The slowest test in tests/integration/http_api/persistence/test_compatibility.py goes from ~23s to ~16s.

Changelog

  • Annotate our command unions as being discriminated by their commandType field. See the Pydantic documentation: https://docs.pydantic.dev/1.10/usage/types/#discriminated-unions-aka-tagged-unions
  • Unfortunately, before Pydantic v2, there appear to be bugs that prevent this from working when the union appears inside a pydantic.Generic model. To work around this, I unfortunately had to make some non-generic duplicates of our RequestModel, which is unfortunate.

Review requests

  • Are there any HTTP endpoints I missed where we're parsing Protocol Engine commands?
  • Can you think of a better workaround for the pydantic.Generic thing?

Risk assessment

Low—if this broke anything, I think integration tests would cover it, unless there's weirdness across Python versions.

Copy link

codecov bot commented Jan 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (ca70ab0) 67.96% compared to head (ef02312) 68.08%.
Report is 2 commits behind head on edge.

❗ Current head ef02312 differs from pull request most recent head be08e43. Consider uploading reports for the commit be08e43 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             edge   #14286      +/-   ##
==========================================
+ Coverage   67.96%   68.08%   +0.12%     
==========================================
  Files        2467     2509      +42     
  Lines       70000    71445    +1445     
  Branches     8868     9063     +195     
==========================================
+ Hits        47573    48645    +1072     
- Misses      20356    20689     +333     
- Partials     2071     2111      +40     
Flag Coverage Δ
app 65.38% <ø> (ø)
g-code-testing 96.48% <ø> (ø)
labware-library 41.10% <ø> (ø)
notify-server 89.13% <ø> (ø)
protocol-designer 34.93% <ø> (ø)
step-generation 86.90% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
...entrons/protocol_engine/commands/command_unions.py 100.00% <ø> (ø)
robot-server/robot_server/commands/router.py 100.00% <ø> (ø)
...server/robot_server/commands/stateless_commands.py 100.00% <ø> (ø)
...server/robot_server/runs/router/commands_router.py 100.00% <ø> (ø)

... and 42 files with indirect coverage changes

@SyntaxColoring SyntaxColoring requested a review from a team January 4, 2024 20:39
@SyntaxColoring SyntaxColoring marked this pull request as ready for review January 8, 2024 18:57
@SyntaxColoring SyntaxColoring requested a review from a team as a code owner January 8, 2024 18:57
@SyntaxColoring SyntaxColoring requested a review from a team as a code owner January 8, 2024 20:32
@jbleon95
Copy link
Contributor

jbleon95 commented Jan 8, 2024

Are the changes made to the command schema compatible with the make command-schema target? Mostly in that it doesn't overwrite that information, but also if it would (or can) add that discriminator information automatically.

@SyntaxColoring
Copy link
Contributor Author

Are the changes made to the command schema compatible with the make command-schema target? Mostly in that it doesn't overwrite that information, but also if it would (or can) add that discriminator information automatically.

Yep, changes to 8.json in this PR were generated automatically via make -C api command-schema COMMAND_SCHEMA_VERSION=8 && make format-js.

Copy link
Contributor

@jbleon95 jbleon95 left a comment

Choose a reason for hiding this comment

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

Looks great, glad we could finally get to this with the Python updates

@SyntaxColoring SyntaxColoring merged commit 7cc14a1 into edge Jan 9, 2024
54 checks passed
@SyntaxColoring SyntaxColoring deleted the discriminate_command_unions branch January 9, 2024 15:59
mjhuff pushed a commit that referenced this pull request Jan 23, 2024
Closes RSS-128.

* Update command unions.
* Update stateless command unions.
* Work around Pydantic bug.
* Fix names and docstrings for union workarounds.
* Update tests.
* Update command schema.
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