Skip to content

refactor(config): extract config out of daemon.rs to fix cohesion gate - #76

Merged
rmems merged 2 commits into
mainfrom
refactor/daemon-config-cohesion
Oct 3, 2026
Merged

rmems merged 2 commits into
mainfrom
refactor/daemon-config-cohesion

Conversation

@kiro-agent

@kiro-agent kiro-agent Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

PR #74 (bounded PUB lifecycle / loss semantics / safe bind defaults — issue #68 / LIM-1320) merged to main while the CodeScene code-health gate was failing: "Prevent hotspot decline — Low Cohesion" on src/daemon.rs ("at least 6 different responsibilities amongst its 46 functions, threshold = 3"). Build and test CI were green and the functional review findings were fixed, but merging over a red quality gate left main in a not-clean state.

This is a fix-forward for that gate. It does not revert #74 — the bounded-PUB-lifecycle work stays on main.

Change

Pure move + re-export (zero behavior change): the CONFIG responsibility is extracted from src/daemon.rs into a new src/config.rs submodule.

Moved byte-for-byte (doc comments + #[serde(default)] attributes intact):

  • RuntimeMode enum and DaemonConfig struct (+ all field docs)
  • the four default_spine_pub_* serde-default fns
  • impl DaemonConfig { pub fn load }
  • validate_pub_socket_opts (pub(crate)) and pub_endpoint
  • the 11 config/endpoint unit tests + their write_config_toml helper

src/lib.rs gains pub mod config;; src/daemon.rs re-exports pub use crate::config::{DaemonConfig, RuntimeMode, pub_endpoint};.

Public API unchanged

All existing paths still resolve via re-exports — brainstem_daemon::daemon::{DaemonConfig, RuntimeMode, pub_endpoint}, DaemonConfig::load, and the lib.rs re-exports brainstem_daemon::{DaemonConfig, RuntimeMode}. No call site was edited (checkpoint, binary, smoke test). validate_pub_socket_opts stays pub(crate) at crate::config::validate_pub_socket_opts, still wired into the load path (its only caller moved with it, so no re-export is needed and none is added — that would be an unused import under clippy -D warnings).

Effect

src/daemon.rs: 2782 → 2415 lines (−367); one full cohesive responsibility (config definition + loading + validation + endpoint helper) removed as a cluster — directly targeting the cohesion metric.

Validation

  • Stub gate: cargo fmt --check silent; clippy --locked --all-targets -- -D warnings clean; build --locked ok; test --locked 154 passed / 0 failed / 1 ignored.
  • corpus-ipc gate (CC=gcc CXX=g++, 1.98.1): clippy --all-targets --all-features -D warnings clean; build --all-features ok; test --all-features 176 lib + 9 smoke passed / 0 failed.
  • Diff hygiene clean; MSRV/pins, wire payload, SUB ingress, and ZmqSpikeSink accounting untouched.

Limitations

  • CodeScene runs only in CI — it can't be executed in the sandbox. This extraction removes a full responsibility cluster, which is what the cohesion metric measures, so it should bring the count under threshold, but the actual gate result must be confirmed on this PR's CI run. If daemon.rs is still over threshold, the next cleanest extraction is the control-plane HTTP wiring (start_control/bind_control/spawn_control_task/stop_control) into a control submodule.

Tracking

Follow-up to #74; part of #68 / LIM-1320. Non-closing reference — #68 (v0.3.0 qualification blocker) stays open.


🤖 Delivered by the Kiro agent.


Summary by cubic

Pure move-and-re-export refactor that extracts the config responsibility out of daemon.rs into a new src/config.rs to clear the CodeScene low-cohesion gate that failed on PR #74, and consolidates the moved config tests to reduce code duplication.

  • daemon.rs re-exports DaemonConfig, RuntimeMode, and pub_endpoint, so every existing path and call site keeps resolving unchanged.
  • Config tests now share a common TOML body via config_toml_with_log_level and base_config_toml; the four reject cases fold into one table-driven test with preserved assertions.
  • No behavior, error-message, serde-attribute, or wire-payload changes; validate_pub_socket_opts stays pub(crate).
  • Verified with fmt, clippy -D warnings, build, and test (154 passed), plus the corpus-ipc gate; CodeScene itself only runs in CI.

Written for commit f59cd0b. Summary will update on new commits.

Review in cubic

…cohesion

Move the CONFIG responsibility (RuntimeMode, DaemonConfig + serde defaults,
DaemonConfig::load, validate_pub_socket_opts, pub_endpoint) out of daemon.rs
into a new src/config.rs and re-export it from daemon.rs so every public and
crate-internal path resolves unchanged. Pure code movement + re-exports: no
behavior, signature, error-message, serde-attribute, or wire-payload changes.

Fixes the CodeScene 'Prevent hotspot decline' / Low Cohesion gate that failed
on merged PR #74 by lowering daemon.rs's distinct-responsibility count.
@codeant-ai

codeant-ai Bot commented Sep 30, 2026

Copy link
Copy Markdown

Skipping PR review because a bot author is detected.

If you want to trigger CodeAnt AI, comment @codeant-ai review to trigger a manual review.

@rmems rmems added this to the 02 — v0.3.0 release qualification milestone Sep 30, 2026 — with Kiro Agent
@coderabbitai

coderabbitai Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: d3a10820-6e19-4eb3-8979-19e106f4f5f5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Autopilot is currently an internal CodeRabbit preview.


Comment @coderabbitai help to get the list of available commands.

codescene-access[bot]

This comment was marked as outdated.

@codacy-production

codacy-production Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 2 complexity · -4 duplication

Metric Results
Complexity 2
Duplication -4

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

Reduce Code Duplication in src/config.rs by factoring the shared valid
TOML body into config_toml_with_log_level/base_config_toml helpers and a
load_base_config helper, and by folding the four reject cases (unknown
log level, zero sndhwm, negative sndhwm, negative linger) into a single
table-driven test. All prior coverage and error-substring assertions are
preserved; only the #[cfg(test)] module changed.

@codescene-access codescene-access Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Health Improved (1 files improve in Code Health)

Gates Passed
6 Quality Gates Passed

See analysis details in CodeScene

View Improvements
File Code Health Impact Categories Improved
daemon.rs 5.22 → 5.37 Low Cohesion, Code Duplication

Quality Gate Profile: Pay Down Tech Debt
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

@rmems
rmems merged commit 59e8cc3 into main Oct 3, 2026
11 checks passed
@rmems
rmems deleted the refactor/daemon-config-cohesion branch October 3, 2026 05:13
@linear-code

linear-code Bot commented Oct 5, 2026

Copy link
Copy Markdown

LIM-1320

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant