Investigate GitHub issue #412: "Rust scan keeps stale deleted files and reports…
- User
Investigate GitHub issue #412: "Rust scan keeps stale deleted files and reports clippy-clean imports as unused"
The problem has two parts:
- After deleting/renaming Rust files, the old paths persist in
state-rust.json— stale state not cleaned up on rescan - Rust
unusedfindings contradict a cleancargo clippyrun
I need to understand:
For stale files:
- How does the Rust scan pipeline work? Look at
desloppify/languages/rust/for the scan entry point - How does state persistence work? Look at
desloppify/engine/for how state is written after a scan - Is there a "prune deleted files" step? How do other languages (Python, TypeScript) handle this?
- Look at how the scan discovers files and how findings get reconciled with existing state
For unused import false positives:
- Look at
desloppify/languages/rust/detectors/for the unused import detector - How does the Rust unused detector work? Does it shell out to cargo clippy or does it do its own analysis?
- The issue mentions
custom.pywas deleted (see git status:D desloppify/languages/rust/detectors/custom.py) — is this related?
For the
showcommand mismatch:- The issue says
show orphaned --status openreturns nothing but the issues exist in state. Look at howshowfilters issues.
Search thoroughly across the Rust language plugin, the engine state management, and the scan pipeline. Be very thorough.
- After deleting/renaming Rust files, the old paths persist in
Assistant
I'll investigate this GitHub issue thoroughly. Let me start by exploring the codebase structure to understand the scan pipeline, state persistence, and Rust-specific handling.
Assistant
Let me read the key files to understand the scan pipeline and state persistence:
Assistant
Now let me look at the scan orchestrator and the state merge logic:
- User
Review PR #413: "Fix planner deadlock when triage goes stale mid-cycle"
The PR description says: when triage is stale but deferred behind objective backlog, both
plan resolve --confirmandplan triage --run-stageswere blocked — a deadlock. The fix allows objective resolves to continue while keeping direct review resolves blocked.I need to understand the changes and whether they're correct. Please:
- Get the full diff: run
gh pr diff 413 - Read the key files being modified to understand the context
- Check if the tests listed in the PR actually pass: look at what test files are added/modified
- Look for any issues: edge cases, missed spots, inconsistencies
Focus on understanding:
- The resolve guard logic and how "pending" vs "blocked" states differ
- Whether the banner/lifecycle copy changes are consistent
- Whether the plan reloading optimization (passing already-loaded plan) is safe
- Whether test coverage is adequate for the new behavior
Be very thorough in reading the diff and the surrounding code.
- Get the full diff: run
Assistant
Let me continue reading the workflow file to see the merge logic:
Assistant
I'll systematically review PR #413. Let me start by getting the diff and understanding the changes.
Assistant
Let me get the full diff:
Assistant
Let me continue reading to find the merge_scan_results function:
Assistant
Now let me understand the key functions involved. Let me read the context helpers:
Assistant
Good. Now let me read the guardrails.py file to understand the full context before and after:
Assistant
Now let me look at the merge_scan function which is key:
Assistant
I notice the file on disk is the OLD version. Let me check the state module to understand match_issues:
Assistant
Let me continue reading the merge_scan function:
Assistant
Now let me look at the merge_issues module to understand the auto-resolution of disappeared issues:
Assistant
Let me continue reading and also look at the Rust detectors to understand the false positive issue:
Assistant
Wait, let me check if match_issues is re-exported from the state module:
Assistant
Now let me check the import hygiene detector:
Assistant
Let me check the state module more carefully:
Assistant
Now let me look at the detectors/init.py to see what's exported and look at the deleted custom.py reference:
Assistant
Good,
match_issuesis re-exported. Now let me check the new tests to understand what the PR expects:Assistant
Let me look at the test_custom.py to understand what was in custom.py:
Assistant
Right, the test file is new. Let me check the resolve command to see how it calls the guardrail:
Assistant
Good! So the test file mentions
import_hygiene. Now let me check if there's any "unused" detector or clippy-based detector, and look at the show command for filtering:Assistant
Now let me check the plan triage file to see the banner changes:
Assistant
Let me check the test for triage_phase_banner that's mentioned in the diff:
Assistant
Let me look for the "show" command implementation:
Assistant
Good! Now let me look at the lifecycle file that was modified:
Assistant
Now let me run the new tests to see if they pass:
Assistant
Let me look at the scope module to understand filtering:
Assistant
Right, the PR hasn't been merged yet. Let me check what the current state of the resolve cmd.py is:
Assistant
Let me continue reading and look at the load_matches function:
Assistant
I see - the current cmd.py still has the OLD version. Let me check the PR more carefully. Let me look at the patch for the lifecycle.py banner:
Assistant
Good. Now let me look at the build_work_queue to understand how the status filter is applied:
Assistant
Good - the current lifecycle.py still has the old message at line 65. Now let me look at the resolve plan loading to understand the pattern parameter:
Assistant
Let me look at select_queue_items to understand the status filtering:
Assistant
Now let me check what args.patterns is to understand the new parameters being passed:
Assistant
Now let me look at build_issue_items to understand how issues are filtered by status:
Assistant
Good! Line 141 shows the status filter is checked with
status_matches(). Let me look at that function:Assistant
Good, so
args.patternsalready exists. Now let me look at the full diff more carefully to understand all the changes. Let me check the imports in the PR diff:Assistant
Perfect! Now let me check how path_scoped_issues works to understand how issues are filtered by scan_path:
Assistant
Let me check if there are specific commits related to this PR:
Assistant
Let me check if the "objective work" detection logic using the detectors is correct. First let me understand the detector categorization:
Assistant
Let me check the actual implementation in scope.py:
Assistant
Excellent! Now let me look for information about how detector discovery works during scan. Let me check the phases in Rust:
Assistant
Perfect! Now I can see that "review" and "concerns" are non-objective detectors. The PR uses
_REVIEW_DETECTORS = frozenset({"review", "concerns"})which aligns with this. Now let me look at the logic more carefully. Let me trace through the new logic in guardrails.py more carefully:The PR shows:
-
New field in TriageGuardrailResult:
pending_behind_objective_backlog: bool = False -
New detection logic in triage_guardrail_status: checks if:
- Triage is stale
- Triage is NOT already in queue (
not snapshot.has_triage_in_queue) - State exists (
bool(resolved_state)) - Plan is mid-cycle (
is_mid_cycle(resolved_plan)) - Objective backlog exists (
has_objective_backlog(resolved_state, None))
-
New conditional in require_triage_current_or_exit:
- If AND patterns are provided:
-
Assistant
Let me continue looking at the Rust phases, particularly the clippy phase:
Assistant
Good. Now let me examine the logic flow more carefully and look for potential issues. Let me check what the test fixture produces:
Assistant
Now let me look at the auto_prune module that might clean up stale files:
Assistant
Perfect! Now let me trace through the logic step by step to look for issues:
-
Test fixture setup:
- Plan has
plan_start_scores = {"strict": 72.0}(mid-cycle) - Plan has
epic_triage_meta = {"triaged_ids": ["review::old"]} - State has 3 issues: obj::1 (objective), review::old (triaged), review::new (new)
- Plan has
-
Condition check: For pending_behind_objective_backlog to be TRUE:
not snapshot.has_triage_in_queue- TRUE (no triage in queue_order)bool(resolved_state)- TRUEis_mid_cycle(resolved_plan)- TRUE (scores set to 72.0)has_objective_backlog(resolved_state, None)- TRUE (obj::1 is objective)
Now let me check a potential issue - let me look at what TriageSnapshot's
has_triage_in_queueactually checks:-
Assistant
This is only for plan clusters. Let me now search more systematically for how issues are cleaned up when files no longer exist:
Assistant
Good. Now let me look at the message copy changes to understand what they're changing. Let me look at the diff for messages:
Assistant
Now let me check if there's an issue with the function signatures and imports. Let me verify that
match_issuesis correctly accessible:Assistant
Let me search for how verify_disappeared works more carefully - that seems to be the key function for handling deleted files:
Assistant
Good! Now let me check the TriageSnapshot more carefully to understand what it looks for in determining staleness:
Assistant
Perfect! Now I understand the core issue. Let me check if there's a step that removes stale issues entirely or if they only get marked as resolved:
Assistant
Now let me verify the logic in the new triage_phase_banner condition. Let me trace through what happens in plan_triage.py:
The PR diff shows this new condition at line 82:
pythonif not resolved_snapshot.has_triage_in_queue: if ( resolved_state and resolved_snapshot.is_triage_stale and is_mid_cycle(plan) and has_objective_backlog(resolved_state, None) ): return ( "TRIAGE PENDING — review issues changed since last triage and will " "activate after objective work is complete." )This is BEFORE checking for
undispositioned. Let me verify this is the right order by checking the full condition flow:Assistant
Let me check if there's explicit deletion or just resolution:
Assistant
Let me check what these removal operations are:
Assistant
This is just removing corrupted issues. Let me look at a critical insight: the GitHub issue mentioned that
show orphaned --status openreturns nothing but the state has issues. Let me trace through the orphaned detector:Assistant
Let me look for "orphaned" in the Rust context as a detector:
Assistant
Assistant
Let me now look up what detectors the Rust plugin actually runs. Let me review the phases again and understand the detector registry:
Assistant
Good, the messages match what the test expects. Now let me verify the banner change one more time. Let me check the test_triage_phase_banner addition:
Assistant
Perfect. Let me now check one more potential issue - does the state structure need to use "work_items" vs "issues"? Let me check the _matched_open_targets function:
Assistant
Good. The
match_issuesfunction handles the state structure conversion internally, so that's fine. Let me check the imports one more time to make sure everything is imported:Assistant
Excellent! Now I see "clippy_warning" and "rust_import_hygiene" are registered detectors. Let me look at the catalog to see if there's an "unused" detector for Rust:
Assistant
Good! Now let me check one final thing - is there a potential issue with the message copy and lifecycle copy consistency? Let me check the lifecycle message change:
Assistant
So "unused" is a general detector. Let me check if there's a Rust-specific "unused" detector or if it's supposed to use clippy:
Assistant
This is a minor wording change that's fine - makes it more consistent with the new "pending" terminology.
Now let me check for one important consistency issue - the test shows that when patterns match non-review work while pending, it should print the banner. But I need to make sure that the banner being printed doesn't have contradictory information. Let me trace through that code path one more time:
pythonif result.pending_behind_objective_backlog and patterns: matched_targets = _matched_open_targets(state, patterns) if matched_targets and not _targets_include_review_work(matched_targets): banner = triage_phase_banner( result._plan or {}, state, snapshot=result._snapshot, ) if banner: print(colorize(f" {banner}", "yellow")) returnAssistant
Let me check if there's a Python "unused" detector implementation:
Assistant
Let me check if ensure_plan_defaults can handle an empty dict:
Assistant
Interesting! So Python and TypeScript have "unused" detectors, but Rust does not. This is the key insight. Let me check if Rust is supposed to use its "import_hygiene" detector or something else. Let me look at the Rust init.py again to see all detectors:
Assistant
Good. So Rust uses
tool_phase_clippy()which runscargo clippy. Now, the key insight is that the GitHub issue says:- Stale deleted files persist in state after rescan
cargo clippyreports clean (no unused imports), but Desloppify reports them as "unused"
This suggests that maybe Rust is reporting "unused" issues from somewhere else (perhaps clippy is being parsed for "unused-*" warnings). Let me check how clippy messages are parsed:
Assistant
Perfect! I can see that
parse_clippy_messagesis used and it parses compiler warnings/messages, including "unused variable" messages. So Rust IS using clippy to report "unused" style issues. The problem is that:- When files are deleted, the old issues persist in state
- When a re-scan happens, those old deleted files' issues don't get cleaned up
- The
show orphaned --status openreturns nothing because the old issues have somehow gotten a different status (maybe they were auto-resolved but still in state?)
Let me now create a comprehensive summary. First, let me check what the git status shows about deleted custom.py:
Assistant
Assistant
Perfect! The test file looks complete. Now let me check if there are any other files that might need updating. Let me look for any other files that call require_triage_current_or_exit:
Assistant
Perfect! So
custom.pywas a compatibility/re-export wrapper. Now let me check the state IO to understand if there's a prune mechanism:Assistant
Good, only resolve/cmd.py calls it, and the PR already updates that. Now let me check if there are any other callers of triage_guardrail_status or triage_guardrail_messages:
Assistant
There's a call in queue_flow.py. Let me check that:
Assistant
Assistant
Good - the call at line 405 is without passing a plan. This is fine because the PR's changes make the parameter optional with a default of . So this existing call will continue to work as before.
Assistant
Perfect. Now let me verify the test fixture actually triggers the right conditions. Let me trace through one more time with the fixture:
Fixture State:
- obj::1: status=open, detector=complexity (OBJECTIVE)
- review::old: status=open, detector=review (NOT objective)
- review::new: status=open, detector=review (NOT objective)
Fixture Plan:
- plan_start_scores = {"strict": 72.0} → is_mid_cycle() = TRUE
- epic_triage_meta = {"triaged_ids": ["review::old"]} → has review::old but not review::new
Snapshot computation:
- triaged_ids = {"review::old"}
- live_open = all open review issues = {"review::old", "review::new"}
- new_since = live_open - triaged_ids = {"review::new"} ✓
- is_triage_stale = bool(new_since) = TRUE ✓
- has_triage_in_queue = check if any TRIAGE_IDS in queue_order = FALSE (empty_plan has no queue_order) ✓
pending_behind_objective_backlog computation:
- not snapshot.has_triage_in_queue = TRUE ✓
Assistant
Perfect! All imports are available. Now let me check if there are any issues with backward compatibility or breaking changes:
-
Function signature changes:
require_triage_current_or_exit()now accepts optionalplanandpatternsparameters- These are backward compatible because they have defaults (None)
- Existing calls will continue to work
-
TriageGuardrailResult changes:
- New field
pending_behind_objective_backlogwith default False - Backward compatible since it's a dataclass with a default
- New field
-
Other function signatures:
triage_guardrail_status()already accepted optionalplanparameter (unchanged)triage_guardrail_messages()already accepted optionalplanparameter (unchanged)
Let me check one final edge case - what if resolve is called with no patterns (is that even possible)?
-
Assistant
So
patternsis part of the ResolveQueryContext and is a list of strings. In the require_triage_current_or_exit call, it passesargs.patternswhich should always be set (at least as an empty list).Let me verify this by checking if patterns validation happens before:
Assistant
Good,
args.patternsis used directly. The patterns should always exist because they're part of the argparse args. Let me verify there's no case where patterns could be None:Assistant
So patterns is a positional argument in some parsers. Let me check resolve specifically:
Assistant
Let me search more broadly:
Assistant
Let me check the resolve command itself:
Assistant
Let me check cli_main or the resolve command handler directly:
Assistant