Skip to content

refactor(llm): split router/mod.rs monolith into focused submodules#4920

Merged
bug-ops merged 1 commit into
mainfrom
refactor/4875-router-submodules
Jun 6, 2026
Merged

refactor(llm): split router/mod.rs monolith into focused submodules#4920
bug-ops merged 1 commit into
mainfrom
refactor/4875-router-submodules

Conversation

@bug-ops

@bug-ops bug-ops commented Jun 6, 2026

Copy link
Copy Markdown
Owner

Summary

crates/zeph-llm/src/router/mod.rs was a 4140-line monolith with 4 scattered impl RouterProvider blocks (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.rs shrinks 4140 → ~170 lines and now holds only: module docs, declarations/re-exports, the RouterProvider struct, the shared blocking_load helper, and the ASI rate-limit statics.

Module layout

File Lines Responsibility
mod.rs 171 docs, declarations, re-exports, struct, blocking_load, statics
config.rs 128 RouterStrategy + Bandit/Asi/CascadeRouterConfig
embed_cache.rs 75 BanditEmbedCache, TurnEmbedCache
builder.rs 585 constructor, with_* builders, save_*, *_stats, set_status_tx, list_models_remote
select.rs 626 provider ordering/selection, bandit features, availability recording, embed cache, ASI spawn
chat.rs 533 bandit_chat, cascade_chat(_stream), CascadeEvalResult, CollectedStream
provider_impl.rs 675 impl LlmProvider for RouterProvider, record_fallback_error
tests.rs 1464 unit tests

Notes

  • Public API unchanged. RouterStrategy, the three *RouterConfig types, and RouterProvider are re-exported from router; router::aware / router::coe / strategy submodules are untouched.
  • Helper methods called across submodule boundaries are bumped from private to pub(crate); struct fields stay private (submodules are descendants of the module that defines the struct, so they retain field access without visibility changes).
  • Pure refactor: no behavior change.

Verification

  • cargo +nightly fmt --check
  • cargo clippy -p zeph-llm --all-targets --features profiling,testing,gonka,cocoon -- -D warnings
  • cargo nextest run -p zeph-llm --lib — 892 passed
  • RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps -p zeph-llm
  • cargo test --doc -p zeph-llm — 22 passed
  • RUSTFLAGS="-D warnings" cargo check --workspace --all-targets --features desktop,ide,server,chat,pdf,scheduler --locked

Closes #4875

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
@github-actions github-actions Bot added documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) rust Rust code changes refactor Code refactoring without functional changes size/XL Extra large PR (500+ lines) labels Jun 6, 2026
@bug-ops
bug-ops enabled auto-merge (squash) June 6, 2026 14:08
@bug-ops
bug-ops merged commit 46e5e5a into main Jun 6, 2026
32 checks passed
@bug-ops
bug-ops deleted the refactor/4875-router-submodules branch June 6, 2026 14:14
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation llm zeph-llm crate (Ollama, Claude) refactor Code refactoring without functional changes rust Rust code changes size/XL Extra large PR (500+ lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(llm): RouterProvider has 4 separate impl blocks in router/mod.rs — consolidate or extract submodules

1 participant