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

feat(robot-server): start logic for dynamic error recovery policy #15707

Merged
merged 13 commits into from
Jul 24, 2024

Conversation

aaron-kulkarni
Copy link
Contributor

Overview

Create robot-server function that turns a List of ErrorRecoveryRules into a full ErrorRecoveryPolicy. A future PR will implement the HTTP calls that actually create the list of rules.

EXEC-589

Test Plan

Changelog

Review requests

Risk assessment

Create robot-server function that turns a List of ErrorRecoveryRules into a full ErrorRecovery
policy. A future PR will implement the HTTP calls that actually create the list of rules.

EXEC-589
@aaron-kulkarni aaron-kulkarni requested a review from a team as a code owner July 18, 2024 18:16
Copy link
Contributor

@SyntaxColoring SyntaxColoring left a comment

Choose a reason for hiding this comment

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

This all looks great.

I think we should add some unit tests for create_error_recovery_policy_from_rules() before we move on, so we don't forget, but other than that I only have minor suggestions.

robot-server/robot_server/service/error_recovery.py Outdated Show resolved Hide resolved
robot-server/robot_server/service/error_recovery.py Outdated Show resolved Hide resolved
robot-server/robot_server/runs/error_recovery_models.py Outdated Show resolved Hide resolved
robot-server/robot_server/runs/error_recovery_models.py Outdated Show resolved Hide resolved
robot-server/robot_server/runs/error_recovery_models.py Outdated Show resolved Hide resolved
from typing import Optional


def create_error_recovery_policy_from_rules(
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good, but can we add a unit test for this?

Fortunately it's the fun (to me) kind of unit test. No mocks, just lots of black-box input and output, living in the moment, aah.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately I had to resort to mocks to create fake errors/commands/etc. If you think there's a cleaner or better way to do it just let me know

Copy link
Contributor

Choose a reason for hiding this comment

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

I would just construct actual full errors/command/etc. objects. Possibly with helper functions to make it more convenient.

This is a good guideline, in general:

Object type Usage in tests
"Behavioral" (it exists for its methods) Replace the object and its methods with test doubles (mocks)
"Data" (it exists to group stuff together) Actually construct actual objects, in full

But, you know, this only holds up to a certain point. There's a threshold where a data object gets so big and annoying to construct, that it clutters up the tests, and you would rather just create the parts that you really need, using something like a mock. I feel like our JSON protocol and labware definition models are like that, for example. Personally, the objects in this PR don't meet my threshold for that, but I can certainly see how they would.

But I think this works, no need to change it.

Copy link
Contributor

@SyntaxColoring SyntaxColoring 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.

We can update the NotImplementedError comment and I think there's a missing == on one if the assert statements, but other than that, this looks good to me to merge. Feel free to merge after fixing those and checking that all the CI is still passing.

robot-server/tests/runs/test_error_recovery_mapping.py Outdated Show resolved Hide resolved
from typing import Optional


def create_error_recovery_policy_from_rules(
Copy link
Contributor

Choose a reason for hiding this comment

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

I would just construct actual full errors/command/etc. objects. Possibly with helper functions to make it more convenient.

This is a good guideline, in general:

Object type Usage in tests
"Behavioral" (it exists for its methods) Replace the object and its methods with test doubles (mocks)
"Data" (it exists to group stuff together) Actually construct actual objects, in full

But, you know, this only holds up to a certain point. There's a threshold where a data object gets so big and annoying to construct, that it clutters up the tests, and you would rather just create the parts that you really need, using something like a mock. I feel like our JSON protocol and labware definition models are like that, for example. Personally, the objects in this PR don't meet my threshold for that, but I can certainly see how they would.

But I think this works, no need to change it.

Comment on lines +59 to +69
class ErrorRecoveryRule(BaseModel):
"""Request/Response model for new error recovery rule creation."""

matchCriteria: list[MatchCriteria] = Field(
default_factory=list,
description="The criteria that must be met for this rule to be applied.",
)
ifMatch: list[ReactionIfMatch] = Field(
default_factory=list,
description="The specific recovery setting that will be in use if the type parameters match.",
)
Copy link
Contributor

@SyntaxColoring SyntaxColoring Jul 24, 2024

Choose a reason for hiding this comment

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

OK so it looks like this is modeling a structure that's like this (in loose sketchy form):

rules
    matchCriteria
        criteria 1 (with one commandType and one errorType)
        criteria 2 (with one commandType and one errorType)
        criteria 3 (with one commandType and one errorType)
    ifMatch
        reaction 1
        reaction 2
        reaction 3

Where criteria 1 gets paired with reaction 1, criteria 2 gets paired with reaction 2, etc.

I think instead, we want:

rules
    rule 1
        matchCriteria (with one commandType and one errorType)
        ifMatch reaction
    rule 2
        matchCriteria (with one commandType and one errorType)
        ifMatch reaction

But I think we can merge this as-is and address it separately. On its own terms, this looks correctly-implemented, and this PR nicely unblocks both the HTTP API work and the internal opentrons.protocol_engine work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

robot-server/robot_server/runs/error_recovery_mapping.py Outdated Show resolved Hide resolved
Copy link
Contributor

A PR has been opened to address analyses snapshot changes. Please review the changes here: https://github.com/Opentrons/opentrons/pull/

@Opentrons Opentrons deleted a comment from github-actions bot Jul 24, 2024
@Opentrons Opentrons deleted a comment from github-actions bot Jul 24, 2024
@aaron-kulkarni aaron-kulkarni merged commit e4ff49a into edge Jul 24, 2024
36 checks passed
@SyntaxColoring SyntaxColoring deleted the exec-589-error-recovery-policy branch July 24, 2024 17:19
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.

3 participants