Fix stack overflow from nested 'on ready' scripts#1779
Merged
Conversation
When _pendingCallbackCount was 0, AddOnReady called RunScriptAsync directly. If the callback (or anything it called) contained another 'on ready' statement, that also saw count == 0 and called RunScriptAsync again, creating infinite mutual recursion. Fix: bump the pending count before running the callback so nested 'on ready' calls queue themselves rather than recurse, then drain the queue via EndPendingCallbackAsync as normal. Same Begin/End pattern used by WaitScript, ShowMenuScript, etc. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Verifies that an 'on ready' encountered inside another 'on ready' callback runs sequentially after the outer callback completes, not nested inside it. This ordering difference is observable and would fail on the pre-fix code (which ran inner callbacks immediately, producing "outer before" → "inner" → "outer after" instead of the correct "outer before" → "outer after" → "inner"). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AddOnReadywas callingRunScriptAsync(callback)directly when_pendingCallbackCount == 0on readystatement, that also saw count == 0 and calledRunScriptAsyncagain — infinite mutual recursion betweenOnReadyScript.ExecuteAsync↔AddOnReady, causing a stack overflow in prodBeginPendingCallback()before running the script so any nestedon readycalls queue themselves; drain the queue viaEndPendingCallbackAsync()after — the same Begin/End pattern used byWaitScript,ShowMenuScript, etc.Bumps version to 6.0.0-beta.26.
Test plan
on readycalls (e.g.on readyinside an action triggered by anotheron ready) no longer stack overflow🤖 Generated with Claude Code