Repository navigation
feat: settle the enable gate from the carrier's own enable - #1
Conversation
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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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) |
There was a problem hiding this comment.
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 👍 / 👎.
What
PluginEnableGatesettles from the carrier's ownonEnableinstead of waiting for a poll.The carrier enables after the children it loaded (
load = Startupon the carrier, children stayPostWorld), so a component that only watched a poll timer attached too late: every childOnEnablehad already returned and read the capability as unavailable.The gate now subscribes to
CarrierEnableSignal, which the carrier raises fromonEnableon 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:
onEnable(plugin_loader.h:110), so the timer seesisEnabled() == truea moment ahead of the signalOnEnablereads the capability before that tick runsPolltherefore runs synchronously as well whenever the signal has already been raised.HasRaisedis 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 duringEndstoneServer::init— the server thread id is not recorded yet and it falls through to comparingmainThread()(server.cpp:693-705) — so anything queued from there runs after every childOnEnable. Polling keeps the check for its ordinary path and only short-circuits on it when genuinely on the server thread.Evidence
onenable.async=Falseondisablereads true throughoutMeasured on a real v2 host (Endstone 0.11.16, Windows), driven by
run-capability-smoke.ps1.Depends on
Framework side, must merge first:
CarrierEnableSignal(Subscribe/Unsubscribe); this branch does not compile without itCarrierEnabledentry point, contract 3load = Startup, raises the signal fromonEnable