CodeWhale icon indicating copy to clipboard operation
CodeWhale copied to clipboard

Dead-code candidates that need a maintainer decision

Open luochen211 opened this issue 3 weeks ago • 3 comments

Refs #4785

A dead-code sweep found these items. Each one is either never produced or only reached from tests. They were not removed because each looks like the start of a feature, and someone needs to decide whether to finish it or delete it. Every claim below was checked with grep -rn across crates/ on current main.

1. SidebarRowAction::PrefillCommand is never created (crates/tui/src/tui/app.rs:1289)

  • What happens: the variant is matched in mouse_ui.rs:898 and mouse_ui.rs:1643. The only constructor (mouse_ui.rs:1650) re-wraps a value that is already a PrefillCommand. No sidebar row ever starts out as one, so the destructive-command "prefill, then press Enter" path cannot be reached. The allow comment cites TUI-DOG-008, but that ID is about working/phase chrome (docs/MOTION_CONTRACT.md:25), not this path.
  • Expected: either a destructive sidebar row produces PrefillCommand, or the variant and its two match arms are removed.

2. FleetListOutcome::OpenDetail / FleetListOutcome::None are never created (crates/tui/src/tui/views/fleet_list.rs:46-55)

  • What happens: select_highlighted and confirm_delete only return FleetListOutcome::Done. outcome_to_action (line 602) maps OpenDetail to ViewEvent::FleetListOpenDetailRequested, and ui/handlers.rs:2582 handles that event by opening FleetDetailView. That whole chain cannot run. The allow says it is "reserved for the qualified-name flow".
  • Expected: wire the qualified-name flow so selecting a fleet can open its detail view, or remove OpenDetail, None, ViewEvent::FleetListOpenDetailRequested and its handler.

3. RunReceipt / VerificationReceipt / VerificationOutcome are only used by tests (crates/engine/src/core/runtime_contract/termination.rs:111-165)

  • What happens: no non-test code outside termination.rs names these types. RunReceipt::validate and RunReceipt::pass_at_one run only in that file's tests. The removed module allow said that "stream JSON is the first consumer", but no stream JSON code builds a RunReceipt.
  • Expected: emit a run receipt from the stream-JSON / exec surface, or delete the types and their tests.

4. SkillMutationReceipt.before_digest / after_digest are written but never read (crates/skills/src/mutation.rs:113-116)

  • What happens: every mutation path fills both fields (mutation.rs:615-994), and a TUI test builds them as None (tui/src/commands/contract.rs:7038). No code reads either field. The allow says "reserved for digest-diff UI". action on the same struct has a similar "future receipt toast" allow.
  • Expected: show the digest diff in the skills manager / receipt toast, or stop computing and storing the digests.

5. Fleet ledger/scheduler/executor functions only reached from tests (crates/engine/src/fleet/)

  • ledger.rs:1770 FleetLedger::claim_next: only callers are tests (ledger.rs:3306, 3401)
  • ledger.rs:1533 FleetLedger::record_alert: only caller is a test (ledger.rs:4453)
  • ledger.rs:788 FleetLedger::mark_task_terminal_status_if_unchanged: only caller is a test (ledger.rs:3707)
  • scheduler.rs:107 FleetScheduler::cancel_run: only caller is a test (scheduler.rs:1048)
  • executor.rs:1150 all_terminal: only callers are tests (executor.rs:2016, 2303)
  • task_spec.rs:617 record_verification_receipt: only caller is a test (task_spec.rs:1393)
  • roster.rs:729 shadowed_for: only caller is a test (fleet/tests/roster_shadow_and_trust.rs:38)

What happens: ledger.rs, scheduler.rs and executor.rs have #![allow(dead_code)] for the whole module. task_spec.rs and roster.rs items are pub. In both cases the compiler does not flag these functions. Production code claims tasks, cancels runs and records verification some other way, or does not do it yet. Expected: for each function, either route the production path through it (for example operator cancel → cancel_run, alert delivery → record_alert), or move it under #[cfg(test)] / delete it. Then drop the module-level allows so new dead code shows up again.


Body:

What and why

This removes code that nothing calls and dead_code allows on items that are in use, which lowers the dead-code budget from 137 to 119.

  • engine: drop the stale allows on SubAgentManager.workspace, ProjectContext.project_root, the four McpConnection/McpPool accessors, UserInputProvenance, the four TokenEstimateCache methods, and the module allows in termination.rs and auto_review.rs
  • engine: remove unused _assert_var_handle_shape, merge_contexts (and its test), and the private FleetManager::record_task_timeout
  • engine: delete trailing_start_marker_prefix_len; its caller now uses trailing_marker_prefix_len(.., &TOOL_CALL_START_MARKERS), which checks the same 30 markers in the same order
  • engine: the workflow tool reuses cargo_failure_summary::truncate_chars instead of keeping its own copy
  • tui: drop the stale allows on App::cell_at_virtual_index, AppAction::LoadSession and ActiveCell::revision (all have live callers)
  • runtime: reduce resource_telemetry to estimate_output_tokens_from_text, its only outside use; remove SessionJournal::children_of
  • app-server: remove the unused run_daemon_socket, run_stdio and daemon_client::forward_stdio (all platform variants and the re-export)
  • scripts/dead-code-budget.json regenerated

Items that need a decision instead of removal are listed in #ISSUE.

Related issue (optional)

Refs #4785 Refs #ISSUE

How I tested it

  • cargo check -p codewhale-engine and cargo check -p codewhale-engine --all-targets: no warnings
  • cargo clippy -p codewhale-runtime -p codewhale-app-server -p codewhale-engine -p codewhale-tui --all-targets --all-features --locked -- -D warnings: clean
  • cargo test -p codewhale-runtime --lib -- resource_telemetry session_tree: 26 passed
  • cargo test -p codewhale-app-server --lib -- daemon_socket daemon_client: 20 passed
  • cargo test -p codewhale-engine --lib -- tool_call marker cargo_failure_summary tools::workflow project_context: 385 passed (with RUST_MIN_STACK=16777216)
  • cargo fmt --all -- --check, python3 scripts/check-dead-code-budget.py: pass

Checklist

  • [x] One focused change, started from current main (no need to rebase when main moves)
  • [x] cargo fmt --all passes, and tests cover new or changed behavior

Also test-only after the cleanup PR (pub, so the lint never fires): TokenEstimateCache::{bump_messages_revision, invalidate, stats, recent_audit} (crates/engine/src/core/engine/token_estimate_cache.rs) and the ProjectContext.project_root field, read only in project_context_cache.rs tests.

luochen211 avatar Nov 10 '26 11:11 luochen211

Thank you @luochen211 for separating these five design-sensitive candidates out of your dead-code sweep and for landing the unambiguous removals in 4d3bd65eee (#7272, dead-code budget 137 to 119); that is on main as 0.10.3 candidate work, not yet in a published release.

Each of the five items (SidebarRowAction::PrefillCommand, FleetListOutcome::OpenDetail, RunReceipt / VerificationReceipt, the before/after digests on SkillMutationReceipt, and the test-only fleet/ methods) is still present on current main and is a choice between finishing an unwired surface and deleting scaffolding. We are not making those calls during the 0.10.3 release freeze; they are not part of the 0.10.3 candidate. We will reply with a keep-or-remove decision per item after 0.10.3 is tagged.

Written by Claude Sonnet 5.5 for the Codewhale maintainers.

Hmbown avatar Nov 16 '26 13:11 Hmbown

Thanks again @luochen211 for checking each of these five by hand and keeping them separate from the removals that landed in v0.10.3 (4d3bd65eee). 0.10.3 is tagged, so here is where they stand: all five are still on main, and we're taking them into 0.10.5, which is a release about removing unused paths. Our default for each is removal unless we wire it up in the same release. That covers the PrefillCommand variant, FleetListOutcome::OpenDetail/None with its event and handler, the test-only RunReceipt/VerificationReceipt, and the never-read digests on SkillMutationReceipt. If you'd like to take any of the removals as a PR, it would be very welcome. Tell us which ones and we'll make sure nobody duplicates them.

Written by Claude Fable 5.2 (AI), working with Hmbown.

Hmbown avatar Nov 23 '26 04:11 Hmbown

Thanks @Hmbown. I took the four removals you listed in one PR: #7491.

Item 5 (the test-only fleet/ methods) is not in it.

luochen211 avatar Nov 23 '26 06:11 luochen211