Repository navigation
refactor(executor): eliminate GLOBAL_EXECUTOR — pure DI (task #224, Stage A) - #1569
Merged
Merged
Conversation
…dule::install_executor (task #224) Stage A of the headless-Rust hygiene refactor Joel signed off on: "do stage a, get everything merged then migrate commands we want to keep, then build our node as thin and using the uniform client api." ## The disease this kills `static GLOBAL_EXECUTOR: OnceLock<Arc<CommandExecutor>>` + the panic accessor `runtime::executor()` made "is X initialized before Y" an unsolvable-by-types property. PR #1568 round-1 BLOCK caught the exact shape: PIM::new fetched the global eagerly at construction; init_executor ran ~265 lines later in start_server; production boots panicked. Round-2 fixed PIM with a lazy lookup. This commit kills the global entirely so the failure mode can't recur on any other module. Also kills `runtime::command_executor::execute_ts*` free helpers — the silent-fallback into the legacy TS bridge for unmigrated commands. The bridge still exists (`executor.execute_ts_json` is a method on the struct), but every call site is now an explicit `executor.execute_ts_json(...)` — a legible smell that task #219's per-command migration can pick off. Per `[[no-fallbacks-ever]]` + `[[rust-is-the-core-node-is-the-shell]]`: the type system now enforces "if you have Arc<CommandExecutor>, the executor exists." ## The shape 1. `ServiceModule::install_executor(executor: Arc<CommandExecutor>)` — default-impl no-op on the trait. Modules that dispatch commands override to populate their own `OnceLock<Arc<CommandExecutor>>` field. 2. `ModuleRegistry::install_executor_on_all(executor)` — walks every registered module once at boot, calls `install_executor` on each. Modules that don't dispatch get the default no-op for free. 3. `start_server` boot sequence — builds the executor inline AFTER the registry is fully populated, then `install_executor_on_all`. No more boot-ordering oneshot gate (deleted alongside PR #1568's round-2 workaround — the gate is structurally unnecessary now). ## Per-module updates Every consumer of the deleted globals now holds an `Arc<CommandExecutor>` threaded in by construction or by `install_executor`: - ChannelModule, ChatModule, CognitionModule, AIProviderModule, GridModule, GridState, PersonaInstanceManagerModule, SentinelModule — store `OnceLock<Arc<CommandExecutor>>`, override `install_executor`. - `cognition::vision_describe::describe_image` — takes `&Arc<CommandExecutor>` parameter; CognitionModule threads its installed executor through. - `sentinel::PipelineContext` — gains an `executor: Option<&Arc<CommandExecutor>>` field; step functions (web_research, coding_agent, command, llm) consult `pipeline_ctx.executor` instead of the deleted free helper. - `sentinel::executor::execute_pipeline` + `execute_pipeline_direct` — take `executor: Option<Arc<CommandExecutor>>` parameter; SentinelModule threads its installed executor through. - `live::transport::livekit_agent::LiveKitAgent` + `LiveKitAgentManager` (the feature-gated legacy module) — gain executor field + install_executor, threaded through `connect` and `spawn_stt_listener`. ## New error variant `PersonaAircRuntimeError::ExecutorNotInstalled { agent_name }` — what PIM::bootstrap_one returns if dispatched somehow before install (a structural impossibility today; named so future regressions surface as typed errors, not panics). ## Verified - `cargo check -p continuum-core --lib --features metal,accelerate` -> clean (32 pre-existing warnings, 0 errors). - `cargo check -p continuum-core --tests --features metal,accelerate,test-fixtures` -> clean except the pre-existing canary breakage in `tests/vision_integration.rs:182` (E0308, Box vs Arc adapter — NOT in scope of this refactor). ## What's next (Stage B + C, separate PRs) - Stage B: per-command migration off the `execute_ts*` legacy bridge — task #219. Every TS command we want to keep gets a Rust ServiceModule; the rest get deleted. Each migration is a small standalone PR. - Stage C: thin Node client rebuilt on the uniform `Commands.execute` API (task #143 / #215). ## Doctrinal alignment - `[[no-fallbacks-ever]]` — the global panic accessor + silent TS-bridge fallthrough were both fallbacks. Both gone. Failure now surfaces as typed errors at the call site. - `[[rust-is-the-core-node-is-the-shell]]` — TS-bridge call sites are now individually visible; the per-command migration to pure Rust becomes mechanical. - `[[commands-are-kernel-level-and-compose]]` — `CommandExecutor` is now a normal dependency-injected service, not a hidden global. Every module that composes commands holds its own handle, explicitly. Co-Authored-By: Claude Opus 4.7 <[email protected]>
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
GLOBAL_EXECUTOR+executor()panic accessor +init_executor*+execute_ts*free helpersServiceModule::install_executor(default no-op) +ModuleRegistry::install_executor_on_allArc<CommandExecutor>through 8 modules +vision_describe+sentinel::PipelineContext+livekit_agentlegacy pathStage A of the headless-Rust hygiene refactor. Stage B = per-command migration off
execute_ts*(task #219). Stage C = thin Node client on the uniformCommands.executeAPI (#143 / #215).What's gone
static GLOBAL_EXECUTOR: OnceLock<Arc<CommandExecutor>>— the boot-order panic surface that bit PR feat(persona): wire PersonaCommandInboundPump into bootstrap — the install actually runs in prod now (task #222) #1568 R1runtime::executor()— the panic accessorinit_executor*(3 variants) — replaced by inline build instart_serverexecute_ts*free helpers — silent TS-bridge fallthrough is now an explicitexecutor.execute_ts_json(...)at every call sitepersona_supervisor_executor_ready_txoneshot gate — structurally unnecessary now that install happens inlineexecutor_overridesmell — replaced by the uniforminstall_executorpathNew error variant
PersonaAircRuntimeError::ExecutorNotInstalled { agent_name }— what PIM::bootstrap_one returns if dispatched before install (a structural impossibility today; named so future regressions surface as typed errors instead of panics).Verified
* Pre-existing
vision_integration.rs:182Box→Arc breakage is NOT in scope (already broken on canary).Doctrinal alignment
[[no-fallbacks-ever]]— the global panic accessor + silent TS-bridge fallthrough were both fallbacks. Both gone. Failure now surfaces as typed errors at the call site.[[rust-is-the-core-node-is-the-shell]]— TS-bridge call sites are now individually visible; per-command migration becomes mechanical.[[commands-are-kernel-level-and-compose]]—CommandExecutoris now a normal dependency-injected service, not a hidden global.Test plan
🤖 Generated with Claude Code