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

refactor(robot-server): Use last run command for /runs/:runId/currentState links #16557

Merged
merged 5 commits into from
Oct 22, 2024

Conversation

mjhuff
Copy link
Contributor

@mjhuff mjhuff commented Oct 21, 2024

Overview

In #16417, it was noted that links should include a reference to the last completed command as opposed to the "current" command in order to prevent torn state. This PR updates the link to do just that.

Test Plan and Hands on Testing

  • Ran some protocols, noted that the command was in fact the last command at the time of query.

Changelog

  • Updated the links property within the runs/runId/currentState response.

Review requests

c8dce60 - Updates the behavior for get_current_command for historical runs with the behavior that I think we want given the comment, but is this actually the case? CC: @SyntaxColoring

Risk assessment

low

@mjhuff mjhuff requested review from a team as code owners October 21, 2024 20:08
@mjhuff mjhuff force-pushed the robot-server_update-curren-state-links branch 4 times, most recently from 363018f to d2778af Compare October 22, 2024 13:20
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 great, thank you!

@@ -132,9 +132,9 @@ class AllRunsLinks(BaseModel):
class CurrentStateLinks(BaseModel):
"""Links returned with the current state of a run."""

current: Optional[CommandLinkNoMeta] = Field(
last: Optional[CommandLinkNoMeta] = Field(
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 consider naming this lastCompleted instead of just last, in order to avoid confusion with the last queued command, which hasn't necessarily executed yet, and so is a different thing.

command_id=command.id,
command_key=command.key,
created_at=command.createdAt,
index=command_slice.total_length - 1,
Copy link
Contributor

Choose a reason for hiding this comment

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

It should be equivalent, but you might find it clearer to do index=command_slice.cursor instead of index=command_slice.total_length - 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhh yep, that is cleaner, thanks

@@ -554,3 +564,22 @@ def _get_run_time_parameters(self, run_id: str) -> List[RunTimeParameter]:
return self._run_orchestrator_store.get_run_time_parameters()
else:
return self._run_store.get_run_time_parameters(run_id=run_id)

def _get_historical_run_last_command(self, run_id: str) -> Optional[CommandPointer]:
command_slice = self._run_store.get_commands_slice(
Copy link
Contributor

Choose a reason for hiding this comment

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

Heads up that for older historical JSON runs, which enqueued all of their commands up-front instead of one-by-one as the run proceeded, this will return the last command in the whole protocol, not the last command that actually ran.

I think this is close enough that we shouldn't worry about it.

@mjhuff mjhuff force-pushed the robot-server_update-curren-state-links branch 2 times, most recently from 7f53850 to db5dda4 Compare October 22, 2024 18:58
@mjhuff mjhuff merged commit 18598cf into edge Oct 22, 2024
25 checks passed
@mjhuff mjhuff deleted the robot-server_update-curren-state-links branch October 22, 2024 19: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.

2 participants