Where/how sync_triage_needed or similar functions decide triage should be injected
Where triage stages actually get inserted into queue_order
Any "beginning/end of queue" guards (or lack thereof)
The relationship between scan reconcile and triage injection
Any recent changes (the files are modified in git status)
Read ALL of these files completely. Give me a thorough understanding of the flow.
Assistant
I'll read all these files to understand the triage injection flow. Let me start by reading them in parallel.
Assistant
Now let me read the remaining files:
Assistant
Now let me read the lifecycle and plan facade files:
Assistant
Now let me check the constants file and reconcile flow to understand the full picture:
Assistant
Let me continue reading the reconcile file and check where the sync functions are actually called:
Assistant
Now let me check the key orchestration points - the queue building and scan plan reconcile command:
Assistant
Let me continue reading the queue core to see how synthetic items are gathered:
Assistant
Perfect! Now I have a complete picture. Let me create a comprehensive summary document by checking the reconcile_review_import file quickly to round out the understanding:
Assistant
Excellent! Now I have the full picture. Let me provide a comprehensive summary:
Triage Injection Flow: Complete Understanding
I've traced the entire triage injection mechanism across the codebase. Here's the thorough analysis:
High-Level Architecture
The system uses a multi-sync orchestration pattern that keeps the plan queue in sync with state changes. Triage stage IDs are injected at the back of the queue (never reordering existing items) when review/concerns issues change mid-cycle.
1. Decision Point: sync_triage_needed() in sync_triage.py
This is the core decision function that determines whether triage stages should be injected or pruned.
Injection Logic:
Condition 1: No triage stages currently in queue_order AND
Condition 2: The review/concerns issue snapshot hash has changed AND
Condition 3: The change is due to new issues appearing (not resolved issues)
Key Implementation Details:
python
def sync_triage_needed(plan, state) -> QueueSyncResult:
# Line 111-112: Get current snapshot hash
current_hash = stale_policy_mod.review_issue_snapshot_hash(state)
last_hash = meta.get("issue_snapshot_hash", "")
# Line 114: Check if stages already present
already_present = any(sid in order for sid in TRIAGE_IDS)
if already_present:
# Lines 114-130: Auto-prune when stages are stale (issues resolved)
# Only prunes if: last_hash exists AND no unconfirmed stages AND no new issues
if current_hash and current_hash != last_hash:
# Lines 132-149: NEW ISSUES DETECTED
new_since_triage = _new_review_ids_since_triage(state, meta)
if new_since_triage:
# INJECT triage stages
injected = _inject_pending_triage_stages(
order,
confirmed,
skipped=plan.get("skipped", {}),
)
This filter gates triage visibility after injection — ensuring triage doesn't block while objective work remains.
Triage Visibility Rules (lines 59-66):
python
if _has_triage_stages(items):
# Triage should not block while objective queue work still exists.
if _has_objective_items(items):
return [item for item in items if not _is_triage_stage(item)] # Hide triage
return [
item for item in items
if item.get("kind") in ("workflow_stage", "workflow_action") # Show only triage/workflow
]
Objective items = issues with kind == "issue" and detector NOT in subjective set
Converts triage stage IDs in queue_order into displayable work items.
Key Logic:
python
def build_triage_stage_items(plan, state) -> list[WorkQueueItem]:
order = plan.get("queue_order", [])
order_set = set(order)
present = order_set & TRIAGE_IDS # Which triage stages are in the queue?
if not present:
return [] # No triage stages → no items
meta = plan.get("epic_triage_meta", {})
confirmed = set(meta.get("triage_stages", {}).keys())
items: list[WorkQueueItem] = []
for sid, name in zip(TRIAGE_STAGE_IDS, stage_names):
if sid not in present:
continue
if name in confirmed:
continue # Already completed
# Compute blocked_by: dependency stages still in queue
deps = TRIAGE_STAGE_DEPENDENCIES.get(name, set())
blocked_by = sorted(f"triage::{dep}" for dep in deps if ...)
item: WorkQueueItem = {
"id": sid,
"tier": 1,
"kind": "workflow_stage",
"summary": f"Triage: {label}",
...
}
items.append(item)
return items
No Beginning/End Guards: The code simply iterates through TRIAGE_STAGE_IDS in order — there are no special guards preventing triage stages from appearing at the beginning or end of the queue_order list.
6. Review Import Flow: sync_plan_after_review_import() in reconcile_review_import.py
This moved the orchestration from a monolithic function into composable, independently-testable modules. The reconcile_plan_post_scan() function is the orchestrator that sequences all of them.
Summary: Where Triage Gets Injected
Decision:sync_triage_needed() checks if new review/concerns issues appeared since last triage
Injection:_inject_pending_triage_stages() appends stage IDs to plan["queue_order"] back
Orchestration:reconcile_plan_post_scan() calls sync after every scan (last sync operation)
Visibility:apply_lifecycle_filter() hides triage when objective work remains
Display:build_triage_stage_items() converts queued stage IDs into displayable work items
Alternative Path:sync_plan_after_review_import() can also trigger injection when reviews are imported mid-cycle