I need to understand how "stale dimensions" synthetic items work in the work queue. Specifically:
How stale dimensions are detected (look in desloppify/engine/_plan/stale_dimensions.py)
How the work queue handles stale dimensions as synthetic items (look in desloppify/engine/_work_queue/core.py and helpers.py and ranking.py)
How the "next" command renders/displays these items (look in desloppify/app/commands/next.py and desloppify/app/commands/next_parts/)
How the status command might show them (look in desloppify/app/commands/status_cmd.py and status_parts/)
I want to understand the full flow: detection -> queue insertion -> display. Look for any conditions that might prevent the stale dimension item from appearing when the queue is otherwise empty.
Be very thorough - read all the relevant files completely.
Assistant
I'll conduct a thorough investigation of how stale dimensions work as synthetic items in the work queue. Let me start by reading all the relevant files.
Assistant
Now let me search for how the work queue is built and whether stale dimensions synthetic items are being created:
Assistant
Let me look at the plan reconciliation and how it calls the sync functions:
Assistant
Now let me check where the sync functions are called:
Assistant
Perfect! Now let me look at the test for stale dimensions to understand the expected behavior:
Assistant
Now let me check where subjective items are converted to work queue items:
Assistant
Let me look at the build_subjective_items function more carefully and the condition for showing empty queue:
Assistant
Perfect! Now let me look for the scorecard_subjective_entries function to understand when stale items are included:
Assistant
Now let me check what scorecard_dimension_rows does:
Assistant
Now let me look for prepare_scorecard_dimensions:
Assistant
Perfect! Now I have a clear picture. Let me trace through one more critical piece - how show_empty_queue works:
Assistant
Perfect! Now I have all the pieces. Let me create a comprehensive summary document:
Summary: Stale Dimensions Synthetic Items in Work Queue
I've thoroughly analyzed the complete flow of how stale dimensions are detected, inserted into the work queue, and displayed. Here are my findings:
1. Detection of Stale Dimensions (stale_dimensions.py)
Key Function:_current_stale_ids(state) → set[str]
Source: Reads from state.dimension_scores[*].detectors.subjective_assessment
Condition for stale: Checks scorecard_subjective_entries() which examines each dimension
Stale marker: entry.get("stale") must be True
ID format: Converts to "subjective::<slugified_dimension_key>" (e.g., "subjective::design_coherence")
The stale status comes from subjective_assessments[dim_key]["needs_review_refresh"] being True (set during review processing).
2. Injection into Work Queue (sync_stale_dimensions())
Critical Logic (lines 224-279 in stale_dimensions.py):
python
def sync_stale_dimensions(plan, state) -> StaleDimensionSyncResult:
# Identify current stale dimension IDs
stale_ids = _current_stale_ids(state)
order = plan["queue_order"]
# Pruning: Remove non-stale subjective IDs
to_remove = [fid for fid in order
if fid.startswith("subjective::")
and fid not in stale_ids
and fid not in unscored_ids]
# Injection logic (KEY SECTION):
candidates = [sid for sid in sorted(stale_ids) if sid not in existing]
if not candidates:
return result
objective_backlog = _objective_backlog_size(order) # Count non-subjective items
if objective_backlog == 0:
# ✅ CONDITION 1: Queue is EMPTY or ONLY has subjective items
# → Append ALL stale candidates
for sid in candidates:
order.append(sid)
result.injected.append(sid)
else:
# ✅ CONDITION 2: Queue has objective items
# → Interleave bounded by scan count cadence
last_injected = _last_injected_scan(plan, _STALE_MARKER)
if (scan_count - last_injected) < _STALE_INTERLEAVE_EVERY_SCANS: # 3 scans
return result # Skip injection; cadence gate blocks it
selected = candidates[:_STALE_MAX_PER_SCAN] # Max 2 per scan
_insert_ids(order, selected, index=_STALE_INTERLEAVE_INDEX) # At position 24
Key Constants:
_STALE_INTERLEAVE_EVERY_SCANS = 3: Don't re-inject within 3 scans of last injection
_STALE_MAX_PER_SCAN = 2: Max 2 stale IDs injected per scan
_STALE_INTERLEAVE_INDEX = 24: Insert position when backlog exists
No dimension_scores in state: scorecard_subjective_entries() returns empty list
Check: Is state["dimension_scores"] populated?
B. Items injected but filtered during queue build (build_subjective_items() filters them)
Stale items don't pass threshold filter (line 294 in helpers.py):
python
if strict_val >= threshold:
continue # Stale item skipped!
Check: Is the stale dimension's strict score >= target threshold (default 95)?
For stale items to appear: stale_dimension_strict_score < target_strict_score
Stale items filtered by scorecard_subjective_entries():
If dimension has checks == 0 AND issues == 0, marked as placeholder
But stale dims should have been previously assessed, so should have checks > 0
Check: Does the stale dimension have non-zero checks?
include_subjective=False in queue options:
Line 486-492 in core.py: _can_include_subjective_items() checks:
python
return (
options.include_subjective
and status in {"open", "all"}
and not options.chronic
)
Check: Is include_subjective=True in options?
C. Queue filtered by tier or status
If a specific tier is requested (--tier N) and stale items are all T4, and all T4 items are filtered, queue becomes empty
If status is not "open" or "all", subjective items not included
7. The Empty Queue Display Flow
code
next command
↓
build_work_queue(state, options)
├─ build_finding_items() → objective findings
├─ _append_scoped_subjective_items()
│ └─ build_subjective_items() ← Stale items created here
├─ _apply_plan_order() ← Reorders by plan.queue_order
└─ return queue with "items" list
↓
show_empty_queue(queue)
├─ if queue.get("items"): return False
└─ else: print "Nothing to do!"
The condition that shows "Nothing to do!" when queue otherwise empty:
python
# In next.py line 113-114:
if next_render_mod.show_empty_queue(queue, tier=tier, strict=strict_score):
return # Early exit, no further output
8. Why Stale Items Might Not Appear When Queue Is Empty
Most likely scenario:
✅ Stale dimension detected and injected into plan.queue_order
✅ Plan synced during scan (scan_workflow.py lines 493-494)
❌ Stale dimension's score >= threshold (default 95.0)
Example: Stale dimension has score 98.0%, threshold 95.0 → filtered at line 294 in helpers.py
❌ No other queue items exist
Result: Empty queue, "Nothing to do!" message
Other scenarios:
Fresh scan after review: Stale dimension refreshed → no longer stale → pruned from plan
High objective backlog: Stale injection blocked by 3-scan cadence gate
No dimension_scores: Entire subjective system offline
Cadence gate: Last injection too recent, cadence blocks re-injection