Skip to content

refactor(executor): eliminate GLOBAL_EXECUTOR — pure DI (task #224, Stage A) - #1569

Merged
joelteply merged 1 commit into
canaryfrom
refactor/eliminate-global-executor
Jun 9, 2026
Merged

joelteply merged 1 commit into
canaryfrom
refactor/eliminate-global-executor

Conversation

@joelteply

Copy link
Copy Markdown
Contributor

Summary

  • Kills GLOBAL_EXECUTOR + executor() panic accessor + init_executor* + execute_ts* free helpers
  • Replaces with ServiceModule::install_executor (default no-op) + ModuleRegistry::install_executor_on_all
  • Boot sequence: build executor inline AFTER registry populated, walk every module once
  • Threads Arc<CommandExecutor> through 8 modules + vision_describe + sentinel::PipelineContext + livekit_agent legacy path

Stage A of the headless-Rust hygiene refactor. Stage B = per-command migration off execute_ts* (task #219). Stage C = thin Node client on the uniform Commands.execute API (#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 R1
  • runtime::executor() — the panic accessor
  • init_executor* (3 variants) — replaced by inline build in start_server
  • execute_ts* free helpers — silent TS-bridge fallthrough is now an explicit executor.execute_ts_json(...) at every call site
  • persona_supervisor_executor_ready_tx oneshot gate — structurally unnecessary now that install happens inline
  • ChatModule's executor_override smell — replaced by the uniform install_executor path

New 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

cargo check -p continuum-core --lib   --features metal,accelerate                         -> clean
cargo check -p continuum-core --tests --features metal,accelerate,test-fixtures           -> clean*
cargo check -p continuum-core --bins  --features metal,accelerate                         -> clean
cargo test  -p continuum-core --lib   --features metal,accelerate runtime::               -> 173/173
cargo test  -p continuum-core --lib   --features metal,accelerate persona::airc_runtime   -> 7/7

* Pre-existing vision_integration.rs:182 Box→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]] — CommandExecutor is now a normal dependency-injected service, not a hidden global.

Test plan

  • Library compiles clean on canary base
  • Tests compile clean (except pre-existing vision_integration)
  • Binaries compile clean
  • Runtime test suite green (173/173)
  • Persona airc runtime suite green (7/7)
  • Joel signed off ("Merge this and port commands next, as we clean them up with our idealism")

🤖 Generated with Claude Code

…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]>
@joelteply
joelteply changed the base branch from main to canary June 9, 2026 05:14
@joelteply
joelteply merged commit eea469d into canary Jun 9, 2026
1 check passed
@joelteply
joelteply deleted the refactor/eliminate-global-executor branch June 9, 2026 05:14
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.

1 participant