I need to verify claims from a GitHub issue about stale subjective reruns surfacing too early. Check these specific code paths and report what you find:
next always includes subjective: Check desloppify/app/commands/next.py — does it pass include_subjective=True to the queue builder? Also check desloppify/engine/_work_queue/core.py for how subjective items are included.
Stale subjective action suggests --force-review-rerun: Check desloppify/engine/_work_queue/helpers.py — does primary_command add --force-review-rerun for stale subjective items? Also check desloppify/engine/_plan/auto_cluster.py for auto/stale-review cluster action.
Preflight gate bypassed with force flag: Check desloppify/app/commands/review/ for a preflight module — is there a gate that gets bypassed when is present?
--force-review-rerun
Stale injection based on plan queue only: Check desloppify/engine/_plan/stale_dimensions.py — does has_real_items or similar logic check only queue_order rather than actual objective findings?
Test enforcing current behavior: Check desloppify/tests/review/work_queue_cases.py for a test named something like test_subjective_items_always_appear_alongside_mechanical.
For each claim, report the exact code you found (with file paths and line numbers) and whether it confirms or contradicts the issue's description. Be thorough — read the actual files.
Assistant
I'll systematically check each of these claims. Let me start by searching and reading the key files.
Assistant
Now let me search for the preflight module in the review directory and check for any gates related to --force-review-rerun:
Assistant
Good! Now let me read the preflight module:
Assistant
Now let me search for the test file mentioned in claim 5:
Assistant
Now let me check the prepare.py file to understand the review command's handling of --force-review-rerun:
Assistant
Let me check the entrypoint to see how the preflight is called:
Assistant
Perfect! Now let me look at one more key part - let me search for where the stale markers are set/checked:
Assistant
Let me check how stale is computed in the scorecard projection:
Assistant
Perfect! Now I have all the information I need to compile my findings. Let me create a comprehensive report.
if (
resolved_options.include_subjective
and status in {"open", "all"}
and not resolved_options.chronic
):
subjective_items = build_subjective_items(
state,
state.get("findings", {}),
threshold=subjective_threshold_value,
)
for item in subjective_items:
if not scope_matches(item, resolved_options.scope):
continue
all_items.append(item)
When include_subjective=True, subjective items are to the queue (no backlog gating).
User
I need to understand the full work queue lifecycle in this project, specifically around:
How next decides what to show: Read desloppify/app/commands/next.py and desloppify/app/commands/next_parts/output.py thoroughly. How does the output change when the queue is empty? Is there a "queue empty" transition message?
Queue building and subjective gating: Read desloppify/engine/_work_queue/core.py fully. How does build_work_queue work? What's QueueBuildOptions? How are subjective items mixed in? Is there any existing gating logic for when subjective items should appear?
Subjective item building: Read desloppify/engine/_work_queue/helpers.py fully. How does build_subjective_items work? What makes an item "stale" vs "unassessed"? How are the primary_command fields constructed?
Stale dimension sync: Read desloppify/engine/_plan/stale_dimensions.py fully. How does sync_stale_dimensions decide when to inject stale IDs? What is has_real_items checking?
Queue ranking: Read desloppify/engine/_work_queue/ranking.py. How are items sorted? Where do subjective items end up in the ordering?
Report file paths, line numbers, and key function signatures for everything you find. Be very thorough.
Assistant
I'll conduct a thorough analysis of the work queue lifecycle. Let me start by reading all the key files you've identified.
Assistant
Now let me check the rendering code to understand the empty queue handling:
Assistant
Let me read the render_support module to see the show_empty_queue function:
Assistant
Perfect! Now let me search for more context on how the plan_order module applies plan reordering:
User
I need to understand the triage/planning lifecycle and how strict scores work. Explore these areas thoroughly:
Triage flow: Read desloppify/app/commands/plan/triage_handlers.py and desloppify/app/commands/plan/triage_playbook.py. What happens during triage? What's the flow after triage completes?
Plan done / resolve flow: Read desloppify/app/commands/plan/_resolve.py and desloppify/app/commands/resolve/cmd.py. What happens when the user does plan done? Does it trigger a rescan? How does the loop work?
Strict score management: Search for "strict" across the codebase — how is strict score computed, stored, frozen, and refreshed? Key files likely include desloppify/engine/_scoring/, desloppify/engine/_state/scoring.py, and the scoring results modules. When does strict get "frozen at plan start"? When does it get refreshed?
Scan workflow and reconciliation: Read desloppify/app/commands/scan/scan_workflow.py — what happens after a scan? Does it auto-refresh strict? Does it trigger reconciliation?
The overall loop: How does the user go from scan -> plan/triage -> next -> fix -> plan done -> (repeat)? And when subjective review comes in, how does that fit?
Auto-cluster for stale reviews: Read desloppify/engine/_plan/auto_cluster.py — focus on the stale review cluster logic. How does it decide to create the auto/stale-review cluster?
Report file paths, line numbers, and key function signatures. Be very thorough.
Assistant
I'll systematically explore the triage/planning lifecycle, strict score management, and the overall flow. Let me start with broad searches and then deep dives into specific files.
Assistant
Let me get the rest of that file:
Assistant
Perfect! Now let me look at the work_queue.py facade to understand how these pieces fit together:
Assistant
Good—files found. Now let me read the key files for the triage flow, plan done/resolve flow, and strict score management:
Assistant
Let me continue reading more critical files. The triage_handlers file is very large, so let me check the specific sections:
User
I need to understand the review lifecycle — preflight checks, import flow, and what happens after a subjective review completes. Explore:
Review preflight: Find and read the preflight module in desloppify/app/commands/review/. How does review_rerun_preflight work? What's _objective_and_subjective_backlog? How does --force-review-rerun bypass it?
Review import: Read desloppify/app/commands/review/import_cmd.py and related import helpers. What happens after a review is imported? Does it trigger a rescan? Does it update strict scores?
Post-review state updates: After a review import completes, what state changes happen? Are stale markers cleared? Is strict refreshed? Search for where needs_review_refresh gets set/cleared.
Score update helpers: Read desloppify/app/commands/helpers/score_update.py — what does this do? Is it called after review import?
Status command and phase display: Read desloppify/app/commands/status_cmd.py and desloppify/app/commands/status_parts/render.py. Does the status command show any phase information (like "objective phase" vs "subjective refresh phase")? How is strict score displayed?
Existing queue-empty detection: Search for any existing logic that detects when the objective queue is empty and transitions to a different phase or displays a different message.
Report file paths, line numbers, and key function signatures. Be very thorough.
Assistant
I'll help you understand the review lifecycle. Let me start by exploring these areas systematically.
Assistant
Now let me search for strict score management and scoring:
Assistant
Now let me read the key files:
Assistant
Now let me read the status command and related render files:
Assistant
Let me continue with more thorough exploration of the triage flow and plan lifecycle:
Assistant
Now let me search for queue-empty detection and needs_review_refresh:
Assistant
Let me look at the schema and state resolution files:
Assistant
Let me read more key sections, particularly the completion logic and plan lifecycle:
Assistant
Let me read the stale_dimensions and reconcile files:
Assistant
Let me look at the plan command structure and queue progress tracking:
Assistant
Now let me read the import_helpers file and search for more context on post-review state updates:
Assistant
Now let me find the cmd_plan_done implementation:
Assistant
Let me read more of the resolution file to see the full stale marking function:
Assistant
Let me read cmd_plan_done:
Assistant
Let me look at the scan_workflow to understand post-scan reconciliation:
Assistant
Let me look at the helpers file more fully, and check the score snapshot/frozen score logic:
Assistant
Excellent! Let me search for where queue_progress and queue_aware functions are located:
Assistant
Perfect! Now let me search for where strict scores are refreshed and get more context on the complete review flow:
Assistant
Now let me search for where the scoring and state interactions happen:
Assistant
Let me check the core scoring functions and schema:
Assistant
Excellent! Now let me look at test files to understand the preflight and import flows better:
Assistant
Let me check the schema_scores module:
Assistant
Excellent! Now I have a comprehensive picture. Let me create a detailed report of the work queue lifecycle:
: If user re-edits a stage, clears confirmations on all later stages
User
Design an implementation plan for fixing GitHub issue #184 in the desloppify project. The issue is about stale subjective reruns surfacing too early in the work queue.
Problem Summary
The work queue shows stale subjective review items alongside objective findings, when they should only become actionable after objective work is drained. The suggested commands auto-include --force-review-rerun which bypasses preflight backlog checks. And the stale injection logic checks plan["queue_order"] emptiness rather than actual objective findings in state.
Additionally, after subjective review completes (import), strict scores should be clearly refreshed/revealed — the lifecycle transition isn't explicit enough.
No distinction between "initial review" subjective items and "stale rerun" items at the gating level
Ranking in ranking.py: initial reviews get tier -3 (highest priority), stale reviews get tier 1 (same as findings)
2. next command (app/commands/next.py)
Always passes include_subjective=True to build_work_queue() (line ~198)
No awareness of objective backlog when deciding to include stale items
3. Stale subjective command construction (engine/_work_queue/helpers.py)
build_subjective_items() (line ~332): builds queue items for each subjective dimension
Stale items get force_review_rerun=True in _prepare_command(), which adds --force-review-rerun
Unassessed items get normal _prepare_command() without force flag
4. Stale dimension sync (engine/_plan/stale_dimensions.py)
sync_stale_dimensions() (line ~242): runs during post-scan reconciliation
has_real_items = any(fid for fid in order if not fid.startswith(SUBJECTIVE_PREFIX)) — checks ONLY plan["queue_order"], not actual state findings
Injects stale IDs only when not has_real_items and stale_ids
5. Auto-cluster (engine/_plan/auto_cluster.py)
Assistant
I'll start by thoroughly exploring the relevant files to understand the current implementation before designing the plan.
Assistant
Now let me read the remaining critical files.
Assistant
Now let me read the remaining critical files: the import command, queue progress helpers, scan workflow, and the tests.
Assistant
Now let me read the existing test file that will need updating and the render files for the score lifecycle.
Assistant
Now let me check the review preflight to understand the force-review-rerun bypass and look at how has_real_items could be replaced with a proper objective backlog check.
Assistant
Let me now check the scan_reporting_subjective.py for the subjective_rerun_command function and the _plan_start_scores_for_reveal usage.
Assistant
Now I have a thorough understanding of the codebase. Let me also check _sync_plan_after_review_change for the score refresh gap.
Assistant
Now I have a comprehensive understanding. Let me design the full implementation plan.
Implementation Plan for GitHub Issue #184: Stale Subjective Reruns Surfacing Too Early
Problem Overview
There are four interrelated bugs:
Queue building unconditionally includes stale subjective rerun items alongside objective findings, when stale reruns should only surface after objective work drains.
Suggested commands for stale items hardcode --force-review-rerun, bypassing the preflight backlog checks that exist precisely to prevent premature reruns.
Plan injection in sync_stale_dimensions() checks whether plan["queue_order"] has non-subjective IDs, but this is the wrong source of truth --- it should check actual open objective findings in state.
Strict score lifecycle after subjective review import lacks an explicit refresh/reveal checkpoint.
Design Approach
The fix follows four independent but coordinated change tracks (A-D). Each can be implemented and tested incrementally.
Change A: Actionability Gating for Stale Subjective Reruns in Queue Building
Goal: Stale subjective items only appear in the work queue when the objective backlog is zero. Initial-review (unassessed) items continue appearing unconditionally.
In build_work_queue(), after finding_items are built (line 83) and before subjective items are appended, compute the objective finding count:
python
all_items = list(finding_items)
# Count objective (non-subjective, non-review) open findings
objective_count = sum(
1 for item in finding_items
if item.get("status") == "open"
and not item.get("is_subjective")
)
Then modify the subjective item loop (lines 84-97) to filter out stale items when objective backlog exists:
python
User
I need to understand the two entry points for subjective review in the desloppify tool, and how the score gets presented after completion. Trace these flows carefully:
Flow 1: Initial review (beginning of list)
When subjective dimensions are first discovered (scan creates placeholders), they appear at the front of the queue as "initial review" items. Trace:
How unscored dimensions get into the queue — read desloppify/engine/_plan/stale_dimensions.pysync_unscored_dimensions()
How they rank — they get tier -3 in ranking.py. Confirm this.
What command they suggest (should be review --prepare without force)
What happens after initial review completes — does it trigger triage? Read the import path in desloppify/app/commands/review/import_cmd.py, specifically _sync_plan_after_review_change() — what does it do with the plan? Does it inject triage stages? Does it inject workflow::create-plan?
Flow 2: Stale rerun (end of list)
When the objective queue drains and dimensions become stale, they appear at the back of the queue. Trace:
How stale markers get set — search for where needs_review_refresh is set to True. Check desloppify/engine/_state/resolution.py and anywhere else.
When stale items appear in the queue
What happens during/after stale review completes — does the import path differ from initial review? Does it clear stale markers? Does it trigger triage/create-plan injection?
Post-review score lifecycle
After a review (either initial or stale) completes and gets imported:
Read desloppify/app/commands/review/import_cmd.pydo_import() — what score display happens at the end?
Read desloppify/app/commands/review/preflight.pyclear_stale_subjective_entries() — when exactly is this called?
After import, does the user need to run scan to see updated scores? Or are scores computed inline?
Read desloppify/app/commands/scan/scan_workflow.py_clear_plan_start_scores_if_queue_empty() — after subjective items are resolved, does this detect the queue is empty and clear frozen scores? Or do subjective items remain in the queue even after review import?
Key question: Do subjective items get auto-resolved after import?
After a review import, the subjective:: queue items need to be removed from the queue. How does this happen? Check _sync_plan_after_review_change() in import_cmd.py carefully — does it purge subjective IDs from queue_order? Or does that happen via the next sync_stale_dimensions during post-scan reconciliation?
Be very thorough — read the actual code, report line numbers.
Assistant
I'll trace these two entry points and the post-review score lifecycle carefully. Let me start by reading the key files.
Assistant
Now let me search for where needs_review_refresh is set in other places, and read the scan workflow and preflight code:
Assistant
Now let me read the preflight file:
Assistant
Now let me check the show_score_with_plan_context function and look at the triage/create-plan injection logic more carefully:
Assistant
Let me read the queue_progress file and the core queue building/ranking logic:
Assistant
Now let me read the build_subjective_items and related helpers in helpers.py:
Assistant
Now let me look at the reconcile module to understand what happens after review import:
Assistant
Perfect. Now let me create a comprehensive report. Let me gather one more piece of information about how review --prepare command specifies the suggestion for initial reviews:
Assistant
Now I have enough information. Let me create a comprehensive report on the two subjective review entry points and the post-review lifecycle.
Comprehensive Trace: Subjective Review Entry Points and Score Lifecycle
Based on a thorough code trace, here are the two distinct entry points for subjective dimension review, how scores are presented after completion, and the key queue lifecycle mechanics:
Fallback: state.dimension_scores[name]["detectors"]["subjective_assessment"]["placeholder"] (lines 110-132) — populated by scan
Injection strategy: Unconditionally prepends currently-unscored IDs to the front of queue_order (lines 227-233), respecting any promoted items by inserting after them via _after_promoted() (lines 177-190)
ID format: subjective::{slugified_dimension_key} (line 107, 131)
def review_rerun_preflight(
state: StateModel,
args,
*,
state_file=None,
save_fn=save_state,
) -> None:
"""Single entry point: gate check -> clear stale -> save.
Exits with code 1 when open backlog exists and ``--force-review-rerun`` is
not set. On success, clears stale subjective markers for targeted
dimensions and persists state.
"""
# ...
# --force-review-rerun bypasses the gate
if getattr(args, "force_review_rerun", False):
print(
colorize(
"--force-review-rerun: bypassing rerun backlog checks.", # Line 221
"yellow",
)
)
else:
# Only gate dimensions that are actually targeted by this review run.
blocking_dims = _blocking_scored_dimensions(...)
# No gate when none of the targeted dimensions have prior scores
if blocking_dims:
objective_total, subjective_total = _objective_and_subjective_backlog(...)
if objective_total > 0 or subjective_total > 0:
_print_backlog_blocked_message(...)
sys.exit(1) # Block unless force-rerun is set
The preflight check explicitly checks for force_review_rerun=True (line 218) and bypasses all backlog blocking when present.
def sync_stale_dimensions(
plan: PlanModel,
state: StateModel,
) -> StaleDimensionSyncResult:
"""Keep the plan queue in sync with stale subjective dimensions.
1. Remove any ``subjective::*`` IDs from ``queue_order`` that are no
longer stale and not unscored (avoids pruning IDs owned by
``sync_unscored_dimensions``).
2. If no objective items remain after cleanup, inject all currently-stale
dimension IDs so the plan surfaces them as actionable work.
"""
ensure_plan_defaults(plan)
result = StaleDimensionSyncResult()
stale_ids = _current_stale_ids(state)
unscored_ids = current_unscored_ids(state)
order: list[str] = plan["queue_order"]
# ... cleanup ...
# --- Inject: populate when no objective items remain -----------------
has_real_items = any(fid for fid in order if not fid.startswith(SUBJECTIVE_PREFIX))
if not has_real_items and stale_ids: # Line 273-274
existing = set(order)
for sid in sorted(stale_ids):
if sid not in existing:
order.append(sid)
result.injected.append(sid)
return result
Critical Issue Found: Line 273 checks only queue_order in the plan (has_real_items = any(fid for fid in order...)), NOT the actual objective findings in state. This means:
Stale dimensions get injected into the queue whenever there are no remaining items in plan["queue_order"], regardless of whether objective findings actually exist in state["findings"].
If a user has manually cleared the plan queue or moved all items to "deferred", stale items surface even though actionable objective work still exists.
def test_subjective_items_always_appear_alongside_mechanical():
"""Subjective items now appear in the queue alongside objective items
(no backlog gating), sorted by impact."""
objective_findings = [
_finding(f"smells::src/{c}.py::x", detector="smells", tier=3)
for c in "abcd"
]
state = _state(
objective_findings,
dimension_scores={
"Naming quality": {
"score": 70.0,
"strict": 70.0,
"issues": 1,
"detectors": {
"subjective_assessment": {"dimension_key": "naming_quality"},
},
},
},
)
state["subjective_assessments"] = {
"naming_quality": {
"score": 70.0,
"needs_review_refresh": True, # ← Stale marker
"stale_since": "2026-01-01T00:00:00+00:00",
}
}
queue = build_work_queue(state, count=None, include_subjective=True)
ids = [item["id"] for item in queue["items"]]
subj_ids = [i for i in ids if i.startswith("subjective::")]
# Subjective items are no longer suppressed
assert len(subj_ids) >= 1
assert len(ids) == 5 # 4 objective + 1 subjective
This test:
Explicitly marks the dimension as stale with "needs_review_refresh": True (line 559)
Has objective findings present (4 smell findings)
Asserts that the stale subjective item appears in the queue (lines 566-570)
The comment on line 537 says "Subjective items now appear in the queue alongside objective items (no backlog gating)" — explicitly documenting that stale items bypass the former backlog check
This test enforces and documents the problematic behavior where stale subjective items surface early.
Summary
All five claims are substantiated by the code:
Claim
Status
Impact
next always includes subjective
✓ Confirmed
Stale items surface in next output regardless of queue state
Stale action suggests --force-review-rerun
✓ Confirmed
Users automatically get commands that bypass the preflight
Preflight gate bypassed with force flag
✓ Confirmed
No backlog check when flag is used
Stale injection based on plan queue only
✓ Confirmed
Root cause: checks plan["queue_order"] not actual state findings
Test enforcing current behavior
✓ Confirmed
Test documents "no backlog gating" as intended behavior
The core problem: Stale subjective items surface whenever plan["queue_order"] is empty, even if objective findings remain in state. Combined with the auto-cluster action that suggests --force-review-rerun, this creates a loop where stale items encourage users to force a review rerun before handling backlog work.
count: int | None — max items to return
scan_path: str | None — scope findings to a path
scope: str | None — pattern matching on items
status: str — filter by status ("open", "all", etc.)
include_subjective: bool — include synthetic subjective dimension items
subjective_threshold: float — score threshold (default 100.0, meaning "none included")
chronic: bool — filter to chronic reopens
explain: bool — include explain metadata
plan: dict | None — living plan for order/clusters
include_skipped: bool — include plan-skipped items
cluster: str | None — drill into specific cluster
collapse_clusters: bool — replace members with meta-items
Returns set of f"subjective::{slugify(dim_key)}" IDs
Cleanup: Prune resolved IDs (lines 260-270):
Removes subjective::* IDs from queue_order that are:
NOT stale AND
NOT unscored
This prevents stale dimensions from getting "stuck" in queue after being assessed
Conditional Inject: Only when queue is empty (lines 272-279):
Gate: has_real_items = any(fid for fid in order if not fid.startswith(SUBJECTIVE_PREFIX))
Inject only if: not has_real_items and stale_ids
This means: Stale dimensions appear in queue ONLY when no objective findings remain
Appends stale IDs to end of queue
Critical Check: Line 273
python
has_real_items = any(fid for fid in order if not fid.startswith(SUBJECTIVE_PREFIX))
This checks if queue has any non-subjective items (workflows, findings, etc.). If objective queue is empty but unscored dimensions exist, sync_stale_dimensions does NOT inject stale dimensions — that's sync_unscored_dimensions' role.
Phase Display: No explicit phase information shown, but implicit detection exists:
Frozen Score Display (lines 110–124):
python
_plan_start_strict = get_plan_start_strict(_plan)
if _plan_start_strict is not None and _status_queue_remaining > 0:
print_frozen_score_with_queue_context(
_plan, _status_queue_remaining, breakdown=_breakdown,
)
When there's an active queue cycle (plan_start_scores set), the score is frozen and won't update until queue is empty.
Objective vs. Subjective Actionability (lines 148–169):
python
_objective_backlog = 0
if _breakdown is not None:
_objective_backlog = max(0, _breakdown.queue_total - _breakdown.subjective)
show_subjective_followup(
state,
dim_scores,
target_strict_score=target_strict_score,
objective_backlog=_objective_backlog,
)
Passes objective_backlog to subjective follow-up rendering — when objective_backlog <= 0, stale dimensions can be re-reviewed.
Stale Dimension Detection (lines 56–74 in /Users/user_c042661f/Documents/desloppify/desloppify/app/commands/status_parts/render.py):
python
stale_keys = [
str(e.get("dimension_key"))
for e in scorecard_subjective
if e.get("stale") and e.get("dimension_key")
]
if stale_keys:
print(colorize(" [stale] = assessment outdated", "yellow"))
if objective_backlog <= 0:
n = len(stale_keys)
dims_arg = ",".join(stale_keys)
print(
colorize(
f" {n} stale dimension{'s' if n != 1 else ''}"
f": `desloppify review --prepare --dimensions {dims_arg} --force-review-rerun`",
"yellow",
)
)
This is the critical transition point when objective queue becomes empty:
python
def _clear_plan_start_scores_if_queue_empty(
state: state_mod.StateModel, plan: dict[str, object]
) -> bool:
"""Clear plan-start score snapshot once the queue is fully drained."""
if not plan.get("plan_start_scores"):
return False
try:
queue_empty = plan_aware_queue_count(state, plan) == 0
except PLAN_LOAD_EXCEPTIONS as exc:
return False
if not queue_empty:
return False
state["_plan_start_scores_for_reveal"] = dict(plan["plan_start_scores"])
plan["plan_start_scores"] = {}
return True
What Happens:
Checks if queue is completely empty (plan_aware_queue_count(state, plan) == 0)
When empty, saves frozen scores to _plan_start_scores_for_reveal (for final reveal)
Clears plan["plan_start_scores"] to signal: frozen phase is over
On next scan, scores will be live again
Phase Synchronization in Stale Dimensions (lines 242–281 in /Users/user_c042661f/Documents/desloppify/desloppify/engine/_plan/stale_dimensions.py):
python
def sync_stale_dimensions(plan: PlanModel, state: StateModel) -> StaleDimensionSyncResult:
"""Keep the plan queue in sync with stale subjective dimensions.
1. Remove any subjective IDs that are no longer stale
2. If no objective items remain after cleanup, inject all currently-stale
dimension IDs so the plan surfaces them as actionable work.
"""
has_real_items = any(fid for fid in order if not fid.startswith(SUBJECTIVE_PREFIX))
if not has_real_items and stale_ids:
# Auto-inject stale dimensions when objective work is done
for sid in sorted(stale_ids):
if sid not in existing:
order.append(sid)
result.injected.append(sid)
Key Insight: When no objective items remain (has_real_items = False), stale subjective dimensions are automatically injected into the queue for review.
# Collect all subjective dimension IDs currently in queue_order
all_subjective_ids = sorted(
fid for fid in plan.get("queue_order", [])
if fid.startswith(SUBJECTIVE_PREFIX) # "subjective::"
)
# Current unscored IDs (from state)
unscored_state_ids = current_unscored_ids(state)
# Stale IDs = subjective IDs in queue but NOT in unscored_state_ids
stale_queue_ids = sorted(
fid for fid in all_subjective_ids if fid not in unscored_state_ids
)
Stale Review Cluster (lines 448-466):
Name: auto/stale-review
Key: subjective::stale
Minimum Size: 2 items (lines 449)
Description: f"Re-review {len(stale_queue_ids)} stale subjective dimensions"
Already has some awareness of objective vs subjective split via QueueBreakdown
10. Existing Test
test_subjective_items_always_appear_alongside_mechanical in work_queue_cases.py explicitly enforces current (broken) behavior — will need updating
Proposed Changes (from the issue)
A) Actionability gating for stale subjective reruns
Only surface stale subjective rerun items when objective backlog is zero. Keep unassessed/initial subjective handling as-is.
B) Remove force from default stale actions
Don't auto-suggest --force-review-rerun in per-item stale commands or auto/stale-review cluster action. Let preflight enforce drain-first.
C) Backlog source of truth
In sync_stale_dimensions, gate injection on actual open objective findings (state/work-queue), not just plan["queue_order"].
D) Strict score lifecycle UX
Checkpoint at queue-empty: show phase banner (objective done → subjective refresh), current strict snapshot, exact next command
Checkpoint after subjective rerun/import: ensure strict is refreshed/revealed, or print blocking command if still frozen
Design Constraints
Initial review (unassessed) subjective items should STILL appear alongside objective items — only STALE reruns should be gated
The ranking system already puts initial reviews at tier -3 (highest) and stale at tier 1 — this natural ordering should be preserved
Don't break the existing test expectations for unassessed items; only change stale behavior
Minimize blast radius — targeted changes, not a rewrite
The fix should work both with and without a living plan active
Please design a concrete implementation plan with:
Exact files to modify and what changes to make
The order of changes
How to handle the test updates
How the strict score refresh should work after subjective review import
Any edge cases or risks
if (
resolved_options.include_subjective
and status in {"open", "all"}
and not resolved_options.chronic
):
subjective_items = build_subjective_items(
state,
state.get("findings", {}),
threshold=subjective_threshold_value,
)
for item in subjective_items:
if not scope_matches(item, resolved_options.scope):
continue
# Gate stale reruns behind objective backlog
if item.get("stale_review") and objective_count > 0:
continue
all_items.append(item)
Key detail: item.get("stale_review") is already stamped on each item by build_subjective_items() at line 443 of helpers.py --- "stale_review": is_stale and not is_unassessed. So the existing metadata field is the exact discriminator needed.
No changes needed to ranking.py --- the tier -3 vs tier 1 ranking for initial vs stale is correct and should be preserved. The gating happens before items enter the sort.
Change B: Remove --force-review-rerun from Default Stale Actions
This means the suggested command becomes desloppify review --prepare --dimensions <keys> without --force-review-rerun. The preflight check in review/preflight.py will then correctly block the rerun if objective backlog exists, letting the user make an informed override if they really want to force it.
has_real_items = any(fid for fid in order if not fid.startswith(SUBJECTIVE_PREFIX))
This checks plan queue_order for non-subjective IDs, but queue_order can be stale, empty, or contain only workflow/triage IDs while real objective findings exist in state. Replace with a check against actual open findings in state:
python
# Check actual open objective findings in state, not just queue_order
_SUBJECTIVE_DETECTORS = frozenset({
"review", "concerns", "subjective_review", "subjective_assessment",
})
findings = state.get("findings", {})
has_objective_findings = any(
f.get("status") == "open"
and f.get("detector") not in _SUBJECTIVE_DETECTORS
and not f.get("suppressed")
for f in findings.values()
)
# Also check for non-subjective, non-workflow items in queue_order
# (covers triage stages, workflow items, etc.)
has_queue_work = any(
fid for fid in order
if not fid.startswith(SUBJECTIVE_PREFIX)
and not fid.startswith(WORKFLOW_PREFIX)
)
has_real_items = has_objective_findings or has_queue_work
The _SUBJECTIVE_DETECTORS frozenset should be defined at module scope. This approach:
Uses the actual source of truth (state findings) for objective backlog
Still respects triage/workflow items in the queue as "real work"
Does not inject stale items when there are unsuppressed open objective findings, even if they haven't been added to the plan queue yet
Note: The WORKFLOW_PREFIX constant is already defined in this module ("workflow::"), and TRIAGE_PREFIX is also available. The check should probably also exclude triage items from the "has real items" check:
python
has_queue_work = any(
fid for fid in order
if not any(fid.startswith(p) for p in SYNTHETIC_PREFIXES)
)
Wait --- SYNTHETIC_PREFIXES already exists as ("triage::", "workflow::", "subjective::"). So the cleaner version is:
python
has_real_items = has_objective_findings or any(
fid for fid in order
if not any(fid.startswith(p) for p in SYNTHETIC_PREFIXES)
)
This reads: "there are real items if either (a) open objective findings exist in state, or (b) the plan queue has non-synthetic IDs (i.e., actual finding IDs that were explicitly planned)."
Change D: Strict Score Lifecycle UX After Subjective Review Import
Problem: After do_import() in review/import_cmd.py, the code calls show_score_with_plan_context(state, prev) which delegates to print_execution_or_reveal(). If the plan has plan_start_scores and queue items remain, it shows the frozen score. But there is no awareness that the remaining items might be only stale subjective items (i.e., objective work is done), and no explicit transition to the "objective work complete, now do subjective refresh" phase.
Approach: Add a phase-aware checkpoint that detects the "objective drained, subjective remains" transition. This requires:
In _sync_plan_after_review_change() (line 165), after the plan is saved and the sync summary is printed, add the strict score refresh check. After line 226 (save_plan(plan)), before the sync summary print, add:
python
# Check if objective work just drained — clear frozen scores if so
from desloppify.app.commands.helpers.queue_progress import (
plan_aware_queue_breakdown,
)
try:
breakdown = plan_aware_queue_breakdown(state, plan)
objective_remaining = max(0, breakdown.queue_total - breakdown.subjective)
if objective_remaining == 0 and breakdown.queue_total > 0:
# All remaining items are subjective — clear frozen scores
# so the next `scan` reveals the updated score.
if plan.get("plan_start_scores"):
state["_plan_start_scores_for_reveal"] = dict(plan["plan_start_scores"])
plan["plan_start_scores"] = {}
save_plan(plan)
print(colorize(
" Score unfrozen — objective queue drained. "
"Run `desloppify scan` to see updated strict score.",
"green",
))
except PLAN_LOAD_EXCEPTIONS:
pass
Actually, a better approach: instead of clearing plan_start_scores eagerly in import_cmd.py, enhance print_execution_or_reveal to detect the "only subjective left" state and show a different message. This avoids mutating plan state from the review import path:
Modify print_execution_or_reveal() to detect the phase transition. Currently (lines 257-284):
python
def print_execution_or_reveal(state, prev, plan):
if plan and plan.get("plan_start_scores", {}).get("strict") is not None:
try:
breakdown = plan_aware_queue_breakdown(state, plan)
remaining = breakdown.queue_total
except PLAN_LOAD_EXCEPTIONS:
breakdown = None
remaining = 0
if remaining > 0 and breakdown is not None:
print_frozen_score_with_queue_context(plan, remaining, breakdown=breakdown)
return
# No active plan cycle or queue is clear — live scores
from desloppify.app.commands.helpers.score_update import print_score_update
print_score_update(state, prev)
Enhance to add the phase-transition awareness:
python
def print_execution_or_reveal(state, prev, plan):
if plan and plan.get("plan_start_scores", {}).get("strict") is not None:
try:
breakdown = plan_aware_queue_breakdown(state, plan)
remaining = breakdown.queue_total
except PLAN_LOAD_EXCEPTIONS:
breakdown = None
remaining = 0
if remaining > 0 and breakdown is not None:
objective_remaining = max(0, remaining - breakdown.subjective)
if objective_remaining == 0 and breakdown.subjective > 0:
# Objective work drained, only subjective left
# Show live scores instead of frozen, with phase banner
from desloppify.app.commands.helpers.score_update import print_score_update
print_score_update(state, prev)
frozen_strict = plan["plan_start_scores"]["strict"]
print(colorize(
f"\n Objective queue drained. "
f"Frozen plan-start was {frozen_strict:.1f}; live score above reflects current state.",
"cyan",
))
print(colorize(
f" {breakdown.subjective} subjective re-review(s) remain. "
f"Run `desloppify next` to see what's next.",
"dim",
))
return
print_frozen_score_with_queue_context(plan, remaining, breakdown=breakdown)
return
# No active plan cycle or queue is clear — live scores
from desloppify.app.commands.helpers.score_update import print_score_update
print_score_update(state, prev)
This approach is cleaner: no plan mutation from the import path, just smarter display logic.
This test currently asserts that a stale subjective item appears alongside 4 objective findings (total 5). With the fix, the stale item should be gated. Change the assertion:
python
def test_stale_subjective_items_gated_when_objective_backlog_exists():
"""Stale subjective items are hidden when objective findings remain."""
objective_findings = [
_finding(f"smells::src/{c}.py::x", detector="smells", tier=3)
for c in "abcd"
]
state = _state(
objective_findings,
dimension_scores={
"Naming quality": {
"score": 70.0,
"strict": 70.0,
"issues": 1,
"detectors": {
"subjective_assessment": {"dimension_key": "naming_quality"},
},
},
},
)
state["subjective_assessments"] = {
"naming_quality": {
"score": 70.0,
"needs_review_refresh": True,
"stale_since": "2026-01-01T00:00:00+00:00",
}
}
queue = build_work_queue(state, count=None, include_subjective=True)
ids = [item["id"] for item in queue["items"]]
subj_ids = [i for i in ids if i.startswith("subjective::")]
# Stale subjective items are gated when objective backlog > 0
assert len(subj_ids) == 0
assert len(ids) == 4 # only 4 objective
Add complementary test: stale items appear when objective backlog is zero:
Update test_no_injection_when_queue_has_real_items (line 211): This test uses an empty findings dict but puts a finding ID in queue_order. With the new check, we need actual findings in state to block injection:
python
def test_no_injection_when_objective_findings_exist():
plan = _plan_with_queue("some_finding::file.py::abc123")
state = _state_with_stale_dimensions("design_coherence")
# Add an actual open objective finding
state["findings"]["some_finding::file.py::abc123"] = {
"status": "open",
"detector": "smells",
"file": "file.py",
}
result = sync_stale_dimensions(plan, state)
assert result.injected == []
assert "subjective::design_coherence" not in plan["queue_order"]
Add test: stale injection happens when queue has items but no objective findings in state:
python
def test_injection_when_queue_has_only_resolved_ids():
"""Stale dims inject when queue_order has IDs but they're all resolved."""
plan = _plan_with_queue("old_finding::file.py::abc123")
state = _state_with_stale_dimensions("design_coherence")
# Finding exists but is resolved (not open)
state["findings"]["old_finding::file.py::abc123"] = {
"status": "fixed",
"detector": "smells",
"file": "file.py",
}
result = sync_stale_dimensions(plan, state)
assert len(result.injected) >= 1
Update test_stale_cluster_created (line 347): The auto/stale-review cluster action assertion needs to remove the --force-review-rerun expectation:
python
# Change from:
assert "--force-review-rerun" in cluster["action"]
# To:
assert "--force-review-rerun" not in cluster["action"]
Implementation Order
Change C first (backlog source of truth in sync_stale_dimensions) --- foundational fix; ensures the plan-level injection is correct.
Change A (queue building gating) --- the runtime filter that prevents stale items from appearing in next/show/etc.
Change B (remove --force-review-rerun from default commands) --- command cleanup that aligns with the gating.
Change D (strict score lifecycle UX) --- display improvement that depends on correct queue breakdown.
Tests can be updated incrementally with each change.
Edge Cases and Risks
No plan active: Changes A and B work without a living plan. Change C only fires during plan reconciliation (which only happens with a plan). Change D's print_execution_or_reveal already has null-plan guards.
Review findings as objective backlog: The _SUBJECTIVE_DETECTORS set in Change C excludes review and concerns from the objective count. This is correct because review findings are products of subjective review, not scan-detected objective findings. However, if someone considers review findings as "work to do before re-reviewing", the preflight check in review/preflight.py already covers this --- it counts both objective and subjective queue items.
Race condition in import: Change D modifies display logic only, not plan state, so there is no race risk.
Backward compatibility of stale commands: Users who have copy-pasted stale commands from previous output that include --force-review-rerun will still work (the flag is still accepted). The change only affects newly generated commands.
QueueBreakdown.subjective accuracy: In queue_progress.py line 51-54, subjective counts items with kind == "subjective_dimension". This is exactly the set we want to exclude for the phase-transition check. It does not count is_subjective finding items (e.g., review findings), which is correct.
build_finding_items counts review findings as objective: In Change A, the objective_count filter excludes is_subjective findings. Looking at ranking.py line 117, is_subjective is set by is_subjective_finding() which returns True for subjective_assessment and holistic_review detectors. Regular review findings have is_review=True but is_subjective=False. This is correct --- review findings are actionable objective-like work items (they require code changes).
Critical Files for Implementation
/Users/user_c042661f/Documents/desloppify/desloppify/engine/_work_queue/core.py - Core queue building: add objective backlog gating for stale subjective items
/Users/user_c042661f/Documents/desloppify/desloppify/engine/_plan/stale_dimensions.py - Plan-level injection: fix source of truth from queue_order to actual state findings
/Users/user_c042661f/Documents/desloppify/desloppify/engine/_work_queue/helpers.py - Remove --force-review-rerun from default stale command construction
/Users/user_c042661f/Documents/desloppify/desloppify/engine/_plan/auto_cluster.py - Remove --force-review-rerun from stale/under-target cluster actions
/Users/user_c042661f/Documents/desloppify/desloppify/app/commands/helpers/queue_progress.py - Phase-aware score display for objective-drained transitions
still_unscored = current_unscored_ids(state)
order = plan.get("queue_order", [])
subjective_in_queue = [fid for fid in order if fid.startswith("subjective::")]
covered_ids = [fid for fid in subjective_in_queue if fid not in still_unscored]
if covered_ids:
purge_ids(plan, covered_ids)
If the dimension is no longer unscored (i.e., now has an initial assessment), it's removed from the queue via purge_ids()
This is deterministic: if the import set a score for the dimension, it will be purged
Lines 203-209: Injects workflow::create-plan when conditions are met:
No unscored dimensions remain
Objective findings exist in the queue
sync_create_plan_needed(plan, state) is called (stale_dimensions.py, lines 364-409)
When injected, prints: "Plan: reviews complete — \workflow::create-plan` queued. Run `desloppify plan`."`
Lines 256-257: Calls _current_stale_ids(state) (lines 67-85) to find dimensions with needs_review_refresh: True
Conditional injection (lines 272-279):
python
has_real_items = any(fid for fid in order if not fid.startswith(SUBJECTIVE_PREFIX))
if not has_real_items and stale_ids:
# Inject stale IDs at back of queue
for sid in sorted(stale_ids):
if sid not in existing:
order.append(sid)
result.injected.append(sid)
Only injects when no objective items remain (else queue is dominated by objective work)
Appends to the back of queue_order (line 278)
3. What happens during/after stale review completes
If plan has plan_start_scores set and queue is not empty: shows frozen plan-start score (line 244-247)
Otherwise: shows live score update (line 282)
Frozen score display (lines 213-254):
code
Score (frozen at plan start): strict {frozen_strict}/100
Queue: {remaining} items remaining. Score will not update until the queue
is clear and you run `desloppify scan`.
The frozen score prevents false perception of progress while items are queued
At the end of do_import() (lines 421-425), also prints:
code
Next command to improve subjective scores: `{next_command}`
2. When clear_stale_subjective_entries() is called
still_unscored = current_unscored_ids(state)
subjective_in_queue = [fid for fid in order if fid.startswith("subjective::")]
covered_ids = [fid for fid in subjective_in_queue if fid not in still_unscored]
if covered_ids:
purge_ids(plan, covered_ids)
Covered: Subjective queue items no longer unscored (have an assessment now)
Not covered: If a dimension is still placeholder after import, it stays in queue
Called only when new findings are added to the plan (line 377 in import_cmd.py: if int(diff.get("new", 0) or 0) > 0 or ...)
For stale items: Same logic applies. If needs_review_refresh was cleared (lines 39-42 in preflight.py), the dimension is no longer stale, so it will be purged if in the queue.