Skip to content

feat: settle the enable gate from the carrier's own enable - #1

Merged
residua1 merged 2 commits into
mainfrom
feat/carrier-enable-signal
Nov 26, 2026
Merged

residua1 merged 2 commits into
mainfrom
feat/carrier-enable-signal

Conversation

@residua1

Copy link
Copy Markdown
Contributor

What

PluginEnableGate settles from the carrier's own onEnable instead of waiting for a poll.

The carrier enables after the children it loaded (load = Startup on the carrier, children stay PostWorld), so a component that only watched a poll timer attached too late: every child OnEnable had already returned and read the capability as unavailable.

The gate now subscribes to CarrierEnableSignal, which the carrier raises from onEnable on the server thread, and runs its callback there directly.

Why the timer had to change too

Running the callback unscheduled on the signal path is only half of it. The gate's 50 ms timer races the signal and wins about one run in ten:

  • Endstone sets the enabled flag before calling onEnable (plugin_loader.h:110), so the timer sees isEnabled() == true a moment ahead of the signal
  • it takes the claim first, and then hands the work to a scheduler tick
  • the signal's own callback finds the claim taken and returns silently
  • the probe's OnEnable reads the capability before that tick runs

Poll therefore runs synchronously as well whenever the signal has already been raised. HasRaised is also what the late-subscription backstop uses: a component whose assembly loads after the raise starts immediately instead of waiting for an event already past.

Thread handling

No thread check on either the signal path or the raise-time backstop. isPrimaryThread() answers false during EndstoneServer::init — the server thread id is not recorded yet and it falls through to comparing mainThread() (server.cpp:693-705) — so anything queued from there runs after every child OnEnable. Polling keeps the check for its ordinary path and only short-circuits on it when genuinely on the server thread.

Evidence

  • Before: 20 runs, 5 failed with onenable.async=False
  • After: 35 runs with diagnostics, 15 more after they were removed, 50 in total, zero failures
  • Disable order, no CLR assert, both ondisable reads true throughout

Measured on a real v2 host (Endstone 0.11.16, Windows), driven by run-capability-smoke.ps1.

Depends on

Framework side, must merge first:

The carrier enables after the children it loaded, so a component that only
watched a poll timer attached too late: the children's OnEnable had already
returned and read every capability as unavailable.

The gate now subscribes to CarrierEnableSignal, which the carrier raises from
its onEnable on the server thread, and runs its callback there directly. No
thread check on that path: isPrimaryThread() answers false during
EndstoneServer::init because the server thread id is not recorded yet, and the
work would be queued onto a tick that runs after every child OnEnable.

Polling stays as the timeout and as a fallback. It must also run synchronously
when the signal has already been raised — the timer ticks every 50ms and
Endstone sets the enabled flag before calling onEnable, so it can steal the
claim just ahead of the signal and hand the work to that same tick. That cost
one run in ten before the fix; 50 consecutive runs are green after it.
The gate subscribes to CarrierEnableSignal, which only exists from 59461a7 on.
The previous pin predates it and the job would fail to resolve the type.

The commit is not on the default branch yet, so the pin names it in full;
actions/checkout resolves a full SHA from any branch.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T01:44:45.695691Z eaf2075 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

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

Copy link
Copy Markdown

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.

Reviewed commit: eaf2075b54

ℹ️ 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".

// work to a tick that runs after every child OnEnable has already returned. The thread
// check cannot be relied on to tell those apart: during EndstoneServer::init it answers
// false even on the server thread (server.cpp:693-705).
if (IsServerThread() || CarrierEnableSignal.HasRaised)

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 Preserve server-thread execution when the timer wins the claim

If the timer observes isEnabled() and claims the gate immediately before the carrier raises its signal, the signal handler returns because _claimed is already set. The timer can then observe HasRaised == true and execute _onEnabled() directly on its ThreadPool thread. A raised signal establishes that enable occurred, not that the current thread is the server thread. This violates the gate's thread-affinity contract and causes EventPublisherComponent.Register to register native listeners from a background thread, potentially concurrently with child plugin enable callbacks. Keep direct execution on the signal's server thread; a timer-owned callback must retain server-thread dispatch rather than bypassing it based on HasRaised.

Useful? React with 👍 / 👎.

@residua1
residua1 merged commit d8dd517 into main Nov 26, 2026
4 checks passed
@residua1
residua1 deleted the feat/carrier-enable-signal branch November 26, 2026 01:47
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.

2 participants