feat: register scratch threads for scratch events#316
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| yield break; | ||
| } | ||
|
|
||
| var coroutine = machine.StartCoroutine(Routine()); | ||
| ScratchUnitUtil.EnsureScratchThreadRegistered(flow, adapter, graph, coroutine); |
There was a problem hiding this comment.
Register Scratch thread before coroutine completes
The new OnKeyPressed trigger wraps the event in a coroutine that contains no yield before yield break, so StartCoroutine(Routine()) executes the entire flow and disposes flow before EnsureScratchThreadRegistered is called. That registers a coroutine that has already finished and only sets the thread context after the script has run, meaning key-press scripts still execute without a Scratch thread ID and stop/stop-this-script units cannot stop them. The registration needs to occur before invoking the graph or the routine needs to yield so the thread is tracked while the script runs.
Useful? React with 👍 / 👎.
| yield break; | ||
| } | ||
|
|
||
| var coroutine = machine.StartCoroutine(Routine()); | ||
| ScratchUnitUtil.EnsureScratchThreadRegistered(flow, adapter, graph, coroutine); |
There was a problem hiding this comment.
Clone event registers thread only after script finishes
When the clone-start event fires, the coroutine used to run the flow has no yield before yield break, so StartCoroutine(Routine()) executes synchronously and disposes flow before calling EnsureScratchThreadRegistered. That registers a completed coroutine and sets thread context after the graph has already executed, leaving scripts started by "クローンされたとき" without a tracked Scratch thread while they run, so stop/stop-this-script/stop-all cannot control them.
Useful? React with 👍 / 👎.
| yield break; | ||
| } | ||
|
|
||
| var coroutine = machine.StartCoroutine(Routine()); | ||
| ScratchUnitUtil.EnsureScratchThreadRegistered(flow, adapter, graph, coroutine); |
There was a problem hiding this comment.
Message receive scripts not tracked during execution
The message-receive trigger runs the flow in a coroutine that immediately hits yield break, so StartCoroutine(Routine()) finishes before EnsureScratchThreadRegistered runs. Thread registration therefore happens after the script has already executed (with flow disposed), so handlers for "メッセージを受け取ったとき" still run without a Scratch thread ID and cannot be stopped by the Scratch thread manager. Registration must happen before invoking the graph or the routine needs to yield to keep the thread alive while the script runs.
Useful? React with 👍 / 👎.
Summary
Testing
Codex Task