refactor(llm): split router/mod.rs monolith into focused submodules#4920
Merged
Conversation
Split the 4140-line router/mod.rs (4 scattered `impl RouterProvider` blocks plus inline cache and config structs) into focused submodules: - config.rs RouterStrategy and the three *RouterConfig structs - embed_cache.rs BanditEmbedCache, TurnEmbedCache - builder.rs constructor, with_* builders, save_*, *_stats - select.rs provider ordering/selection, embed cache, ASI updates - chat.rs bandit_chat, cascade_chat(_stream), stream helpers - provider_impl.rs impl LlmProvider for RouterProvider - tests.rs unit tests mod.rs (now ~170 lines) keeps the module docs, declarations and re-exports, the RouterProvider struct, the shared blocking_load helper, and the ASI rate-limit statics. Cross-submodule helper methods are bumped to pub(crate); the public API is unchanged — RouterStrategy, the config types, and RouterProvider remain re-exported from router. Closes #4875
bug-ops
enabled auto-merge (squash)
June 6, 2026 14:08
This was referenced Jun 6, 2026
Closed
bug-ops
added a commit
that referenced
this pull request
Jun 6, 2026
Adds profiling-gated tracing::instrument spans to the four pub(crate) async methods that perform embedding I/O or an LLM-judge call — bandit_features, bandit_select_provider, evaluate_quality, embed_cached — matching the convention already used in router/chat.rs. They were left uninstrumented by the router/mod.rs split (#4920). Closes #4926
bug-ops
added a commit
that referenced
this pull request
Jun 6, 2026
…#4929, #4930) (#4934) * refactor(config): remove duplicate validate_unit_f32 in hebbian.rs validate_unit_f32 was semantically identical to the pub(crate) validate_similarity_threshold in memory/mod.rs (both reject non-finite values and values outside [0.0, 1.0]). The write-gate min_edge_relevance and conflict-recency slow-threshold fields now reuse validate_similarity_threshold via deserialize_with, matching the existing usage for the other Hebbian unit-interval fields. Closes #4928 * fix(config): mark SpreadingActivationConfig and AconConfig validate as must_use Both validate(&self) methods return Result<(), String> but lacked #[must_use], allowing callers to silently discard the validation error via a bare config.validate(); statement. The reason-string form is used to satisfy clippy::double_must_use (Result is already #[must_use]). Closes #4930 * perf(core): instrument rpe_should_skip on the persistence path rpe_should_skip performs an embedding call with a timeout but was the only uninstrumented function in persistence/extract.rs after the persistence.rs split. Adds a core.persist.rpe_should_skip span so it surfaces in local Chrome JSON traces / Perfetto. enqueue_graph_extraction_task and load_history were already instrumented in #4921. Closes #4929 * perf(llm): instrument router/select.rs provider-selection async fns Adds profiling-gated tracing::instrument spans to the four pub(crate) async methods that perform embedding I/O or an LLM-judge call — bandit_features, bandit_select_provider, evaluate_quality, embed_cached — matching the convention already used in router/chat.rs. They were left uninstrumented by the router/mod.rs split (#4920). Closes #4926
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
crates/zeph-llm/src/router/mod.rswas a 4140-line monolith with 4 scatteredimpl RouterProviderblocks (at the original lines 346, 1399, 2165, 2279) plus inline cache and config structs. This split it into focused submodules, resolving both complaints in the issue.mod.rsshrinks 4140 → ~170 lines and now holds only: module docs, declarations/re-exports, theRouterProviderstruct, the sharedblocking_loadhelper, and the ASI rate-limit statics.Module layout
mod.rsblocking_load, staticsconfig.rsRouterStrategy+Bandit/Asi/CascadeRouterConfigembed_cache.rsBanditEmbedCache,TurnEmbedCachebuilder.rswith_*builders,save_*,*_stats,set_status_tx,list_models_remoteselect.rschat.rsbandit_chat,cascade_chat(_stream),CascadeEvalResult,CollectedStreamprovider_impl.rsimpl LlmProvider for RouterProvider,record_fallback_errortests.rsNotes
RouterStrategy, the three*RouterConfigtypes, andRouterProviderare re-exported fromrouter;router::aware/router::coe/ strategy submodules are untouched.pub(crate); struct fields stay private (submodules are descendants of the module that defines the struct, so they retain field access without visibility changes).Verification
cargo +nightly fmt --checkcargo clippy -p zeph-llm --all-targets --features profiling,testing,gonka,cocoon -- -D warningscargo nextest run -p zeph-llm --lib— 892 passedRUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps -p zeph-llmcargo test --doc -p zeph-llm— 22 passedRUSTFLAGS="-D warnings" cargo check --workspace --all-targets --features desktop,ide,server,chat,pdf,scheduler --lockedCloses #4875