Skip to content

chore: remove dead code — evaluation APIs, chunk_by_paragraphs, bundled installer, Reasoning.safety (#648)#675

Open
sypsyp97 wants to merge 1 commit intonearai:mainfrom
sypsyp97:fix/648-clean-dead-code
Open

chore: remove dead code — evaluation APIs, chunk_by_paragraphs, bundled installer, Reasoning.safety (#648)#675
sypsyp97 wants to merge 1 commit intonearai:mainfrom
sypsyp97:fix/648-clean-dead-code

Conversation

@sypsyp97
Copy link

@sypsyp97 sypsyp97 commented Mar 7, 2026

Summary

Closes #648.

Remove four pieces of dead code:

1. Evaluation module unused APIs (src/evaluation/success.rs)

  • Removed RuleBasedEvaluator::with_min_success_rate() and with_max_failures() — never called
  • Removed LlmEvaluator::new() — never called
  • Replaced RuleBasedEvaluator::new() with a default_evaluator() test helper (constructor was only used in tests)
  • Removed associated #[allow(dead_code)] annotations

2. chunk_by_paragraphs() (src/workspace/chunker.rs)

  • Removed the unused function and its two test functions
  • Only chunk_document() is used in production

3. install_bundled_channel_from_artifacts() (src/extensions/manager.rs)

  • Removed the function marked "Used by upcoming hot-activation flow" — never called anywhere

4. Reasoning::safety field (src/llm/reasoning.rs)

  • Removed the unused safety: Arc<SafetyLayer> field from Reasoning struct
  • This cascades through all callers: Reasoning::new() no longer takes a safety parameter
  • Updated 12 call sites across dispatcher, compaction, heartbeat, commands, worker, thread_ops, tool_builder, and tests

Verification

  • cargo clippy --all-targetszero warnings
  • cargo testall tests pass

Stats

17 files changed, 69 insertions(+), 287 deletions(-)

Copilot AI review requested due to automatic review settings March 7, 2026 19:36
@github-actions github-actions bot added scope: agent Agent core (agent loop, router, scheduler) scope: tool Tool infrastructure scope: tool/builder Dynamic tool builder scope: llm LLM integration scope: workspace Persistent memory / workspace scope: worker Container worker scope: extensions Extension management scope: evaluation Success evaluation size: XL 500+ changed lines risk: medium Business logic, config, or moderate-risk modules contributor: new First-time contributor labels Mar 7, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on significant code cleanup by removing several unused or dead code components across the codebase. The changes streamline the project by eliminating unnecessary evaluation APIs, an unused text chunking strategy, an unutilized extension installation mechanism, and a redundant safety field within the reasoning engine. This refactoring improves maintainability, reduces the project's footprint, and ensures that the codebase only contains actively used and relevant components.

Highlights

  • Evaluation Module Cleanup: Removed the unused LlmEvaluator struct and its SuccessEvaluator trait implementation. The RuleBasedEvaluator was moved to a test-only configuration (#[cfg(test)]) as it had no production callers, and its builder methods (with_min_success_rate, with_max_failures) were removed in favor of a simplified with_config() test helper.
  • Chunking Function Removal: Deleted the chunk_by_paragraphs() function and its two associated test cases from src/workspace/chunker.rs, as only chunk_document() was found to be in production use.
  • Bundled Channel Installer Removal: Removed the install_bundled_channel_from_artifacts() function from src/extensions/manager.rs, as its intended 'hot-activation flow' was never implemented or wired up.
  • Reasoning Safety Field Removal: Eliminated the safety: Arc<SafetyLayer> field and its corresponding constructor parameter from the Reasoning struct in src/llm/reasoning.rs. This change was cascaded through all affected callers, including dispatcher, compaction, heartbeat, commands, runtime, builder/core, tools/registry, and various test files, as tool output sanitization is handled elsewhere.
Changelog
  • src/agent/agent_loop.rs
    • Removed safety parameter from HeartbeatRunner::new call.
  • src/agent/commands.rs
    • Removed safety parameter from HeartbeatRunner::new and Reasoning::new calls.
  • src/agent/compaction.rs
    • Removed SafetyLayer import.
    • Removed safety field from ContextCompactor struct.
    • Removed safety parameter from ContextCompactor::new and Reasoning::new calls.
    • Simplified make_compactor test helper by removing SafetyLayer instantiation.
  • src/agent/dispatcher.rs
    • Removed safety parameter from Reasoning::new calls and related test setup.
  • src/agent/heartbeat.rs
    • Removed SafetyLayer import.
    • Removed safety field from HeartbeatRunner struct.
    • Removed safety parameter from HeartbeatRunner::new and Reasoning::new calls.
  • src/agent/thread_ops.rs
    • Removed safety parameter from ContextCompactor::new calls.
  • src/agent/worker.rs
    • Removed safety parameter from Reasoning::new call.
  • src/app.rs
    • Removed safety parameter from register_builder_tool call.
  • src/evaluation/success.rs
    • Removed LlmEvaluator struct and its SuccessEvaluator implementation.
    • Moved RuleBasedEvaluator struct and its implementation into a #[cfg(test)] block.
    • Removed with_min_success_rate and with_max_failures builder methods from RuleBasedEvaluator.
    • Added with_config test helper to RuleBasedEvaluator for simplified test setup.
    • Updated test cases to use the new RuleBasedEvaluator structure and with_config helper.
  • src/extensions/manager.rs
    • Removed the install_bundled_channel_from_artifacts function.
  • src/llm/reasoning.rs
    • Removed SafetyLayer import.
    • Removed safety field from Reasoning struct.
    • Removed safety parameter from Reasoning::new constructor.
    • Simplified make_test_reasoning helper by removing SafetyLayer instantiation.
  • src/tools/builder/core.rs
    • Removed SafetyLayer import.
    • Removed safety field from LlmSoftwareBuilder struct.
    • Removed safety parameter from LlmSoftwareBuilder::new and Reasoning::new calls.
  • src/tools/registry.rs
    • Removed SafetyLayer import.
    • Removed safety parameter from register_builder_tool function.
  • src/worker/runtime.rs
    • Removed safety parameter from Reasoning::new call.
  • src/workspace/chunker.rs
    • Removed the chunk_by_paragraphs function and its associated test cases.
  • tests/e2e_routine_heartbeat.rs
    • Removed SafetyConfig and SafetyLayer imports.
    • Removed safety parameter from HeartbeatRunner::new calls and related test setup.
  • tests/heartbeat_integration.rs
    • Removed SafetyLayer import.
    • Removed safety parameter from HeartbeatRunner::new call.
Activity
  • The pull request author, sypsyp97, has performed a comprehensive cleanup of dead code, resulting in a net reduction of 460 lines of code.
  • The author verified the changes by running cargo clippy --all --tests -- -D warnings, which reported 0 warnings.
  • All tests passed after the changes, as confirmed by cargo test.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This is an excellent pull request that significantly improves the codebase by removing dead code and simplifying several components. The removal of the unused safety field from Reasoning and ContextCompactor is a major cleanup, and the cascading changes have been applied consistently across all affected files. Moving the RuleBasedEvaluator to be test-only and deleting the unused LlmEvaluator and chunk_by_paragraphs function are great improvements to code organization and maintainability. The changes are well-documented and the tests have been updated appropriately. Overall, this is a high-quality contribution.

Note: Security Review did not run due to the size of the PR.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Removes multiple unused APIs and dead code paths to reduce maintenance overhead and eliminate #[allow(dead_code)] annotations, including simplifying Reasoning construction now that tool-output sanitization is handled outside Reasoning.

Changes:

  • Deleted unused evaluation APIs and moved the rule-based evaluator to test-only code with a with_config() helper.
  • Removed unused chunk_by_paragraphs() implementation and its tests.
  • Deleted an unused bundled channel installer helper and removed the unused SafetyLayer field/parameter from Reasoning, cascading signature updates through callers and tests.

Reviewed changes

Copilot reviewed 17 out of 17 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/heartbeat_integration.rs Updates heartbeat test to use new HeartbeatRunner::new signature (no SafetyLayer).
tests/e2e_routine_heartbeat.rs Removes safety setup from routine heartbeat E2E tests and updates runner construction.
src/workspace/chunker.rs Deletes unused chunk_by_paragraphs() and associated tests.
src/worker/runtime.rs Updates Reasoning::new call site to new signature.
src/tools/registry.rs Removes SafetyLayer from builder-tool registration API and updates builder construction.
src/tools/builder/core.rs Removes unused SafetyLayer threading and updates Reasoning::new call sites.
src/llm/reasoning.rs Removes SafetyLayer field/constructor parameter from Reasoning and updates internal tests.
src/extensions/manager.rs Deletes unused bundled channel installer helper.
src/evaluation/success.rs Removes unused evaluator APIs; makes rule-based evaluator test-only and adjusts tests.
src/app.rs Updates builder-tool registration call site for new signature.
src/agent/worker.rs Updates Reasoning::new call site for new signature.
src/agent/thread_ops.rs Updates ContextCompactor::new call sites for new signature.
src/agent/heartbeat.rs Removes SafetyLayer from HeartbeatRunner and updates reasoning construction.
src/agent/dispatcher.rs Updates Reasoning::new call sites in dispatcher and tests.
src/agent/compaction.rs Removes SafetyLayer from ContextCompactor and updates reasoning construction + tests.
src/agent/commands.rs Updates heartbeat runner and Reasoning::new call sites for new signatures.
src/agent/agent_loop.rs Updates heartbeat spawn call to match new spawn_heartbeat signature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +40 to +41
pub fn new(llm: Arc<dyn LlmProvider>) -> Self {
Self { llm }
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

ContextCompactor::new is public, and removing the SafetyLayer parameter is a breaking API change for any external callers. Consider leaving a deprecated constructor overload/shim that accepts the old parameter list (and ignores it), or ensure the change is called out in the changelog/versioning if this is intended to be breaking.

Copilot uses AI. Check for mistakes.
Comment on lines 109 to 114
pub fn new(
config: HeartbeatConfig,
hygiene_config: HygieneConfig,
workspace: Arc<Workspace>,
llm: Arc<dyn LlmProvider>,
safety: Arc<SafetyLayer>,
) -> Self {
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

HeartbeatRunner::new is public, and dropping the SafetyLayer argument is a breaking API change for downstream callers (including any external integrations). If maintaining API stability matters, consider adding a deprecated new(..., _safety) shim or documenting the breaking change + version bump.

Copilot uses AI. Check for mistakes.
Comment on lines 483 to 487
pub async fn register_builder_tool(
self: &Arc<Self>,
llm: Arc<dyn LlmProvider>,
safety: Arc<SafetyLayer>,
config: Option<BuilderConfig>,
) {
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

ToolRegistry::register_builder_tool is part of the public API (re-exported via the prelude) and its signature change (removing SafetyLayer) is breaking for downstream crates. Consider adding a deprecated wrapper with the old signature (ignoring the safety argument) to preserve compatibility, or ensure the change is reflected in changelog/versioning.

Copilot uses AI. Check for mistakes.
Comment on lines 258 to 262
pub fn new(
config: BuilderConfig,
llm: Arc<dyn LlmProvider>,
safety: Arc<SafetyLayer>,
tools: Arc<ToolRegistry>,
) -> Self {
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

LlmSoftwareBuilder::new is a public constructor; removing the SafetyLayer parameter is a breaking change for any external callers constructing builders directly. If API stability is desired, consider a deprecated shim that accepts the old parameter list (and ignores it) or documenting the breaking change in changelog/versioning.

Copilot uses AI. Check for mistakes.
impl Reasoning {
/// Create a new reasoning engine.
pub fn new(llm: Arc<dyn LlmProvider>, safety: Arc<SafetyLayer>) -> Self {
pub fn new(llm: Arc<dyn LlmProvider>) -> Self {
Copy link

Copilot AI Mar 7, 2026

Choose a reason for hiding this comment

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

Reasoning::new is a public constructor (re-exported from crate::llm) and its signature change is a breaking API change for downstream users. If this crate is consumed as a library, consider keeping a backwards-compatible/deprecated constructor (e.g., new_with_safety(llm, safety) or new(llm) plus a deprecated new(llm, _safety) shim) and/or documenting the breaking change in the changelog with an appropriate version bump.

Copilot uses AI. Check for mistakes.
…ed installer, Reasoning.safety (nearai#648)

Remove four pieces of dead code identified in nearai#648:

1. evaluation/success.rs: Remove unused RuleBasedEvaluator methods
   (with_min_success_rate, with_max_failures) and LlmEvaluator::new().
   Replace RuleBasedEvaluator::new() with a default_evaluator() test
   helper since the constructor was only used in tests.

2. workspace/chunker.rs: Remove unused chunk_by_paragraphs() function
   and its tests. Only chunk_document() is used in production.

3. extensions/manager.rs: Remove install_bundled_channel_from_artifacts()
   which was marked for "upcoming hot-activation flow" but never called.

4. llm/reasoning.rs: Remove unused safety field from Reasoning struct.
   This cascades through all callers (dispatcher, compaction, heartbeat,
   commands, worker, thread_ops, tool_builder) removing the now-unnecessary
   Arc<SafetyLayer> parameter from Reasoning::new().

All #[allow(dead_code)] annotations on removed items are also removed.
cargo clippy --all-targets produces zero warnings.
cargo test passes all tests.
@sypsyp97 sypsyp97 force-pushed the fix/648-clean-dead-code branch from 9b82a0a to 4b9ec1b Compare March 7, 2026 22:58
@github-actions github-actions bot added size: L 200-499 changed lines and removed size: XL 500+ changed lines labels Mar 7, 2026
@sypsyp97 sypsyp97 changed the title fix(#648): clean up dead code — unused evaluator APIs, chunk_by_paragraphs, bundled channel installer, reasoning safety field chore: remove dead code — evaluation APIs, chunk_by_paragraphs, bundled installer, Reasoning.safety (#648) Mar 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contributor: new First-time contributor risk: medium Business logic, config, or moderate-risk modules scope: agent Agent core (agent loop, router, scheduler) scope: evaluation Success evaluation scope: extensions Extension management scope: llm LLM integration scope: tool/builder Dynamic tool builder scope: tool Tool infrastructure scope: worker Container worker scope: workspace Persistent memory / workspace size: L 200-499 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Clean up dead code: unused evaluation APIs, chunk_by_paragraphs, bundled channel installer, reasoning safety field

2 participants