Skip to main content

Module broker

Module broker 

Source
Expand description

This module hosts two independent brokers, sharing this top-level namespace deliberately: “broker” is this codebase’s general name for “the one place that owns a fragmented concern and mediates access to it,” applied twice on purpose, not a coincidence of naming. broker::process is the second application of that pattern, per docs/specs/REPORT_PROCESS_ARCHITECTURE_STATE_AND_RETHINK_2026_07_22.md’s §6.6 — see that module’s own doc comment for its scope.

§Credential Broker (scheduler) — Phase A of the auth-architecture consolidation

See docs/specs/REPORT_AUTH_ARCHITECTURE_STATE_AND_RETHINK_2026_07_21.md for the full rationale. AgentMux runs three independent OAuth/credential systems today (provider-CLI identity, MuxBus cloud login, an unused service-account OAuth scaffold) with no shared refresh or storage model. This module is the consolidation point: a single, generic, single-flight-guarded, proactively-scheduled refresher (scheduler), with each credential system registering its own load/refresh/save behavior against its own real backing store.

Phase A scope: MuxBus is the only registered source (it’s the only system that already does active token refresh today, so it’s the smallest, lowest-risk slice to prove the broker out on). CLI-provider credentials and the service-account OAuth scaffold are future backends (Phase C+), not touched here.

Re-exports§

pub use process::ProcessBroker;
pub use scheduler::RefreshScheduler;
pub use state::CredentialState;
pub use state::RefreshErrorKind;

Modules§

process
Process Broker — Phase A of the process-tracking consolidation.
scheduler
Generic, single-flight-guarded, proactively-scheduled credential refresh.
state
Pure reducer for the Credential Broker’s per-credential coordination state — fresh / refreshing / failed / needs-reauth. Same shape as every other reducer in this codebase (crates/launcher/src/reducer/, crates/srv/src/reducer.rs, crates/cef/src/reducer/mod.rs): update(&mut State, Command) -> Vec<Event>, no I/O, no async, sub-millisecond lock hold when called from scheduler.rs’s orchestrator.

Statics§

GLOBAL_SCHEDULER 🔒

Functions§

get_global
The global credential-broker scheduler, if init_global has already run.
init_global
Initialize the global credential broker scheduler and start its background sweep. Idempotent — the sweep loop is spawned exactly once no matter how many times this is called; later calls just return the existing scheduler. Not to be confused with process::set_global/ process::global (the unrelated Process Broker, see module doc above).