Skip to content

feat: register scratch threads for scratch events#316

Merged
oco777 merged 1 commit intomainfrom
codex/register-scratch-threads-for-other-events
Nov 16, 2025
Merged

feat: register scratch threads for scratch events#316
oco777 merged 1 commit intomainfrom
codex/register-scratch-threads-for-other-events

Conversation

@oco777
Copy link
Copy Markdown
Owner

@oco777 oco777 commented Nov 16, 2025

Summary

  • register Scratch thread tracking in key press, message receive, and clone start Scratch event units
  • document that these events now register scripts as Scratch threads

Testing

  • not run (not requested)

Codex Task

@oco777 oco777 merged commit 6ae8cca into main Nov 16, 2025
3 checks passed
@oco777 oco777 deleted the codex/register-scratch-threads-for-other-events branch November 16, 2025 05:13
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 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".

Comment on lines +80 to +84
yield break;
}

var coroutine = machine.StartCoroutine(Routine());
ScratchUnitUtil.EnsureScratchThreadRegistered(flow, adapter, graph, coroutine);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +185 to +189
yield break;
}

var coroutine = machine.StartCoroutine(Routine());
ScratchUnitUtil.EnsureScratchThreadRegistered(flow, adapter, graph, coroutine);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Comment on lines +199 to +203
yield break;
}

var coroutine = machine.StartCoroutine(Routine());
ScratchUnitUtil.EnsureScratchThreadRegistered(flow, adapter, graph, coroutine);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant