Skip to content

Fix stale delayTimeout execution after Stop#5827

Merged
walterbender merged 1 commit intosugarlabs:masterfrom
Ady0333:fix/run-stop-delay-timeout-cleanup
Mar 8, 2026
Merged

Fix stale delayTimeout execution after Stop#5827
walterbender merged 1 commit intosugarlabs:masterfrom
Ady0333:fix/run-stop-delay-timeout-cleanup

Conversation

@Ady0333
Copy link
Contributor

@Ady0333 Ady0333 commented Feb 20, 2026

Summary

This PR fixes an issue where pending block execution timers created during Run Slowly mode were not cancelled when Stop was pressed. These stale delayTimeout timers could fire after stopping the program and execute blocks from the previous run into the next run’s execution lifecycle.


What changed

Added cleanup in doStopTurtles() to:

  • Cancel any pending turtle.delayTimeout timers using clearTimeout()
  • Reset _alreadyRunning to false before the next run begins

Why this change was needed

runFromBlock() schedules execution using setTimeout and stores the handle in turtle.delayTimeout. When Stop was pressed, doStopTurtles() set stopTurtle = true but never cleared these timers. As a result, delayed callbacks from the previous run could still fire after Stop and execute runFromBlockNow() without any stop guard.

This caused _alreadyRunning to be set during the next run, which made runLogoCommands() treat the run as a premature restart. The natural-end path then suppressed onStopTurtle(), leaving the Stop button stuck in the active state and Save/Record controls disabled even after execution finished.


Scope

Affects only run/stop lifecycle cleanup in doStopTurtles().
No changes to block execution logic or scheduling behavior.


Verification

Enabled Run Slowly mode and ran a multi-block program.
Pressed Stop mid-execution and immediately pressed Play again.
Verified that execution completes normally and the Stop button resets.
Confirmed Save and Record buttons re-enable after run completion.


Impact

Prevents stale execution from leaking into the next run.
Ensures correct lifecycle termination after Stop → Play.
Restores proper UI state (Stop button, Save/Record) after execution.
No breaking changes.

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
@Ady0333
Copy link
Contributor Author

Ady0333 commented Feb 20, 2026

@walterbender and @vanshika2720

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

Copy link
Contributor

@vanshika2720 vanshika2720 left a comment

Choose a reason for hiding this comment

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

LGTM @walterbender please review

@walterbender walterbender merged commit f855408 into sugarlabs:master Mar 8, 2026
7 checks passed
parthdagia05 pushed a commit to parthdagia05/musicblocks that referenced this pull request Mar 15, 2026
Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
parthdagia05 pushed a commit to parthdagia05/musicblocks that referenced this pull request Mar 15, 2026
Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
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