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

halted waiting robots are stuck in limbo and cannot be reprogrammed #2253

Closed
byorgey opened this issue Dec 31, 2024 · 0 comments · Fixed by #2254
Closed

halted waiting robots are stuck in limbo and cannot be reprogrammed #2253

byorgey opened this issue Dec 31, 2024 · 0 comments · Fixed by #2254
Labels
Bug The observed behaviour is incorrect or unexpected. C-Low Hanging Fruit Ideal issue for new contributors. G-CESK machine This issue has to do with the CESK machine (the Swarm language interpreter). G-Robots An issue having to do with robots. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact.

Comments

@byorgey
Copy link
Member

byorgey commented Dec 31, 2024

Describe the bug
If a robot is waiting and is killed via halt, it seems to get stuck in a state where its CESK machine is Up, waiting to propagate an exception up to the top level to cancel its running process, but it never gets a chance to run since it is waiting. This means, for example, that it cannot be reprogrammed or salvaged, since the system still considers it to be actively running a program.

To Reproduce
In creative mode:

> r <- build {move; wait 1024}
> halt r
> reprogram r {selfdestruct}

This should work and result in the built robot disappearing. Instead, we get an error about not being able to reprogram a running robot. However, if you wait the 1024 ticks and then try reprogram again, it works.

For comparison, if we replace the wait with a busy loop then it works fine:

> def forever = \c. c; forever c end
> r <- build {move; forever (turn left)}
> halt r
> reprogram r {selfdestruct}

Expected behavior
Calling halt on a robot should move it out of the "waiting" state so it can immediately do finalization/cleanup and transition to an idle state.

@byorgey byorgey added Bug The observed behaviour is incorrect or unexpected. C-Low Hanging Fruit Ideal issue for new contributors. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. G-CESK machine This issue has to do with the CESK machine (the Swarm language interpreter). G-Robots An issue having to do with robots. labels Dec 31, 2024
@byorgey byorgey changed the title halted waiting robots are stuck in a strange limbo state and cannot be reprogrammed halted waiting robots are stuck in limbo and cannot be reprogrammed Dec 31, 2024
@mergify mergify bot closed this as completed in #2254 Jan 3, 2025
mergify bot pushed a commit that referenced this issue Jan 3, 2025
The code for `halt` used to (1) cancel the robot's CESK machine, and then (2) put it to sleep forever.  However, at some point the way we cancel CESK machines changed: instead of immediately putting the machine into a finished state, we simply put it into a state which will propagate an uncatchable error all the way up the stack.  This is necessary to make sure we finalize things appropriately, persist any definitions in the environment which ought to be persisted, etc., but it means that a "canceled" robot still has to run for a bit longer to do the finalization work.  Robots which were inactive when they were canceled thus never got a chance to finalize.  The solution is to *wake up* the robot after canceling rather than putting it to sleep!

Closes #2253.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug The observed behaviour is incorrect or unexpected. C-Low Hanging Fruit Ideal issue for new contributors. G-CESK machine This issue has to do with the CESK machine (the Swarm language interpreter). G-Robots An issue having to do with robots. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant