Make unintentional deviation from the lifecycle impossible. Current state: 2 modes (plan/execute) work, but there are 5 ways to deviate: 1) resolve_workflow.py:368 is a side-channel that directly calls inject_triage_stages + set_lifecycle_phase outside reconcile. 2) clear_postflight_scan_completion called from 4 scattered places with inconsistent aftermath handling. 3) Snapshot and reconcile have separate phase derivation paths that can disagree. 4) synthetic.py does its own phase checking. 5) Nothing prevents adding new phases via set_lifecycle_phase. Fix: single reconcile entry point, single derivation function, explicit state machine with typed transitions. The plan-mode pipeline (scan -> review -> score -> triage) should be enforced by the state machine, not by hoping sync preconditions happen to gate correctly.
User notes and answers:
CONTEXT: Today we shipped lifecycle simplification (8 phases -> 2 modes) and UX cleanup. The infrastructure works but has scattered control points. DESIGN PRINCIPLE: The lifecycle state machine should be the ONLY way to change mode or advance the pipeline. No direct set_lifecycle_phase calls outside the state machine. No side-channels. The state machine enforces: execute -> (queue empties) -> plan:scan -> plan:review -> plan:score -> plan:triage -> execute. Each transition has a single code path. Consumers READ mode/stage, they never WRITE it. The state machine is the single writer. IMPORTANT: This is about architectural enforcement, not adding features. The behavior should be identical — we're just making it impossible to accidentally break.
Q1: Snapshot ordering is authoritative (it determines what users see). Pipeline should match it. The unified function should use the snapshot ordering. Q2: Full reconcile is fine — these are CLI commands. Dont add a lightweight mode, thats more complexity. Q3: Preserve the early return — skip reconcile if no objective issues touched. Keep the optimization.
code
Plan:
Lifecycle State Machine Enforcement
Problem Summary
Five deviation vectors let code change lifecycle mode or advance the pipeline outside the canonical reconcile_plan() path:
#
Vector
Location
Mechanism
1
resolve_workflow side-channel
resolve_workflow.py:364-390
Assistant
User
Assistant
Lifecycle review v2: I’m checking the specific engine/app boundaries, triage kickoff logic, and the proposed snapshot delegation against the current code so I can distinguish resolved items from still-open risks.
Assistant
The remaining questions are around whether the new reconcile flag would leak into non-workflow call sites and whether the snapshot delegation proposal really stays behavior-identical. I’m checking those next.
Assistant
I found a concrete risk in Step 1: the plan assumes reconcile only runs at boundaries and that snapshot inputs can be reconstructed from queue prefixes. The current snapshot logic is more nuanced than that, so I’m pulling the exact lines now.
Assistant
User
Assistant
The latest note does not change the repository facts: the written plan still carries the same three concrete risks because it hasn’t incorporated those fixes. I’m returning those as still-open and marking the earlier resolved concerns as verified.
Assistant
User
Assistant
I’m checking the one place v3 still looks under-specified: engine-side triage kickoff now wants to call command-layer helpers. That’s either an unstated extra refactor or an import-layer regression.
Assistant
There is one more repository-specific hole in v3: the plan still punts on what happens to living_plan.py’s drain-only progression path after Pattern A adds an unconditional reconcile. I’m pulling the exact lines before I decide whether that stays an open flag.
Assistant
{"flags":[{"id":"invalidation-sites-need-site-specific-reconcile-plumbing","concern":"The plan still does not fully resolve living_plan.py. Pattern A fixes the stale-mode problem, but the writeup leaves the existing queue-drain reconcile/progression path as an implementation audit instead of specifying the new single flow.","category":"correctness","severity_hint":"likely-significant","evidence":"In the current repo, is not just a phase helper in practice; it is what drives the branch that gates and in . v3 now adds an unconditional reconcile at the invalidation site but only says 'may become redundant' and should be audited. That still leaves a real ambiguity: either you reconcile twice, or you remove the helper and risk changing when progression events fire."},{"id":"engine-triage-kickoff-boundary-is-underplanned","concern":"Scope creep: Step 2 understates the engine/app refactor required for engine-owned triage kickoff. The repository does not currently have engine-level helpers for the full kickoff path the plan wants to perform.","category":"maintainability","severity_hint":"likely-significant","evidence":" lives in , but the full kickoff helper it wants to call, , exists only in . The helper the plan proposes moving, , also currently depends on from . v3 only plans to move , not the rest of the command-layer machinery that functionally participates in kickoff, so the stated file/work breakdown is incomplete: either engine will import app code, or more helpers need to move/create engine equivalents than the plan currently admits."}],"verified_flag_ids":["resolve-workflow-still-advances-pipeline-outside-reconcile","pipeline-snapshot-adapter-is-not-equivalent"],"disputed_flag_ids":[]}
Directly calls inject_triage_stages() + set_lifecycle_phase(plan, "plan") when WORKFLOW_CREATE_PLAN_ID resolved with open reviews — bypasses reconcile entirely
2
clear_postflight_scan_completion
refresh_lifecycle.py:210-224, 5 call sites
Directly writes refresh_state["lifecycle_phase"] = "execute" AND clears scan marker — bypasses even set_lifecycle_phase()
3
Dual phase derivation
snapshot.py:263-346 vs pipeline.py:97-149
Two independent functions derive display phase from queue contents with different logic and priority ordering
4
synthetic.py phase read
synthetic.py:240-261
Reads persisted mode to suppress stale refreshes — read-only, lowest risk
5
Unguarded set_lifecycle_phase
refresh_lifecycle.py:141-149
Public function, any caller can set mode to any valid value
Design
Single-writer principle: Only reconcile_plan() (and a new invalidate_scan() helper it delegates to) may mutate refresh_state["lifecycle_phase"]. All other code paths are refactored to either (a) call reconcile, or (b) request a state invalidation that reconcile will resolve on the next boundary.
Single derivation function: Extract one derive_display_phase() that both pipeline.py and snapshot.py call.
No new state machine abstraction: The two-mode system (plan/execute) with display phases derived from queue contents is already effectively a state machine. Adding a formal Transition enum or typed state machine class would be over-engineering — the real fix is eliminating the side-channels and unifying derivation, not adding infrastructure.
Implementation Steps
Step 0: Validate assumptions (30 min)
Run full test suite to establish green baseline
Confirm all 5 call sites of clear_postflight_scan_completion are accounted for
Confirm set_lifecycle_phase has exactly 2 non-test callers (pipeline.py:275, resolve_workflow.py:367)
Check that clear_postflight_scan_completion line 222 is the only place that writes _LIFECYCLE_PHASE_KEY outside set_lifecycle_phase
Problem: _resolve_reconcile_display_phase() in pipeline.py and _derive_display_phase() in snapshot.py compute display phase independently with subtly different logic. Pipeline checks result fields (injected IDs, triage snapshot); snapshot checks item partitions.
Fix:
Create a single derive_display_phase() in refresh_lifecycle.py that takes the queue partition counts/flags as input (not ReconcileResult or item lists — keep it decoupled)
Define a small PhaseInput dataclass (or kwargs) that both callers can construct from their respective data
Update pipeline.py:_resolve_reconcile_display_phase() to delegate to the shared function
Update snapshot.py:_phase_for_snapshot() to delegate to the shared function
Verify: both paths produce identical display phases for the same queue state
Key detail: The priority ordering must be reconciled. Pipeline checks PRE_REVIEW_WORKFLOW_IDS first; snapshot checks fresh_boundary + initial_review_items first. Determine which is correct and use one ordering.
Step 2: Make set_lifecycle_phase private (1 file changed)
In refresh_lifecycle.py:
Rename set_lifecycle_phase → _set_lifecycle_phase
Update the single legitimate caller in pipeline.py (reconcile_plan) to use the private name via a package-internal import
Remove from __all__
Any other caller that was using it directly will now get an import error — this is the enforcement mechanism
Note: Python's _ prefix is a convention, not hard enforcement. But it's the standard mechanism, and paired with removal from __all__, it makes accidental use unlikely. A runtime guard (checking call stack) would be over-engineering.
Step 3: Eliminate the resolve_workflow side-channel (1 file changed)
In resolve_workflow.py:_reconcile_if_queue_drained():
The side-channel at lines 364-390 does three things when WORKFLOW_CREATE_PLAN_ID is resolved with open reviews:
inject_triage_stages(plan) — adds triage items to queue
set_lifecycle_phase(plan, "plan") — forces plan mode
Fix: Remove the special-case branch entirely. Instead:
Before calling reconcile_plan(), call ensure_active_triage_issue_ids(plan, state_data) + inject_triage_stages(plan) to prep the queue (these are queue mutations, not lifecycle mutations — they're valid pre-reconcile setup)
Let reconcile_plan() handle the lifecycle phase derivation naturally — with triage items now in the queue, it will derive LIFECYCLE_PHASE_TRIAGE_POSTFLIGHT → mode "plan" automatically
Delete the direct set_lifecycle_phase call
The emit_transition_message("triage") moves to after the reconcile result check
Verify: Write a test that resolves WORKFLOW_CREATE_PLAN_ID with open reviews and confirms the plan ends up in mode "plan" with triage stages injected.
Step 4: Route clear_postflight_scan_completion through reconcile (2 files changed)
Problem: clear_postflight_scan_completion directly writes lifecycle_phase = "execute" AND clears the scan marker. It's called from 5 places (skip, unskip, backlog, reopen, resolve) that all then manually check the return value and set transition_phase = "execute".
Fix:
Rename to invalidate_postflight_scan() to clarify intent
Remove the lifecycle_phase write (line 222: refresh_state[_LIFECYCLE_PHASE_KEY] = "execute") — only clear the scan marker
Have each call site call reconcile_plan() after invalidation to let reconcile derive the correct phase
OR: simpler — have invalidate_postflight_scan() return a flag, and have the callers call reconcile. Since these callers already do if result: transition_phase = "execute" + emit_transition_message, they can instead do reconcile_plan() + check result.lifecycle_phase_changed.
Preferred approach: Option 2 (callers call reconcile after invalidation). This keeps the invalidation function simple and lets reconcile be the single phase-setting path.
Migration: All 5 call sites follow the same pattern. Refactor each:
python
# Before:
if clear_postflight_scan_completion(plan, issue_ids=ids, state=state):
transition_phase = "execute"
# ... later: emit_transition_message(transition_phase)
# After:
invalidate_postflight_scan(plan, issue_ids=ids, state=state)
result = reconcile_plan(plan, state, target_strict=target_strict)
if result.lifecycle_phase_changed:
emit_transition_message(result.lifecycle_phase)
Concern: Some call sites may not have state or target_strict readily available. Audit each:
skip.py (3 sites): has state from earlier load; needs target_strict from config
living_plan.py (1 site): has state; needs target_strict
misc.py:cmd_plan_reopen (1 site): has state_data; needs target_strict
All are CLI commands that load state anyway, so target_strict can be derived from state.get("config").
Step 5: Verify synthetic.py is read-only (no change needed)
synthetic.py:240-261 only reads current_lifecycle_phase(plan). This is the correct pattern — consumers READ mode, they never WRITE it. No change needed, but add a brief comment noting the read-only contract.
Step 6: Test coverage
Reconcile is the only writer: Add a test that greps production code for direct writes to _LIFECYCLE_PHASE_KEY — should only find _set_lifecycle_phase and the legacy migration in current_lifecycle_phase
Side-channel regression test: Test that resolving WORKFLOW_CREATE_PLAN_ID with open reviews goes through reconcile
Invalidation regression tests: Test that skip/unskip/backlog/reopen/resolve after invalidation produce correct lifecycle phase via reconcile
Display phase agreement: Test that the unified derive_display_phase() produces the same result regardless of whether called from snapshot or pipeline context
Run full suite: Confirm no regressions
Step 7: Cleanup
Remove set_lifecycle_phase from __all__ in refresh_lifecycle.py (done in Step 2)
Remove any dead imports of set_lifecycle_phase from resolve_workflow.py
Steps 3, 4, 5 are independent of each other after Step 2. Step 1 before Step 2 because the unified derivation function is needed for reconcile to be the single correct path.
Delegate to shared derive_display_phase(), use _set_lifecycle_phase
engine/_work_queue/snapshot.py
Delegate to shared derive_display_phase()
app/commands/plan/override/resolve_workflow.py
Remove side-channel, prep queue then call reconcile
app/commands/plan/override/skip.py
Replace clear_postflight_scan_completion pattern with invalidate + reconcile
app/commands/plan/override/misc.py
Same pattern replacement
app/commands/resolve/living_plan.py
Same pattern replacement
engine/_work_queue/synthetic.py
Comment only (read-only contract)
Tests
New regression tests for single-writer enforcement
code
Plan metadata:
{
"version": 1,
"timestamp": "2026-03-23T04:15:05Z",
"hash": "sha256:1fc2eb4615096055fe243fe997dd755e37724698d2a74282866bad9ab1a31682",
"questions": [
"The two display-phase derivation functions have different priority orderings (pipeline.py checks PRE_REVIEW_WORKFLOW_IDS first; snapshot.py checks fresh_boundary + initial_review_items first). Which ordering is authoritative? Or should the unified function handle both contexts with a flag?",
"Step 4 adds reconcile_plan() calls to 5 command sites that currently don't call it. This is correct architecturally but adds latency (reconcile does subjective sync, auto-cluster, etc.). Should we add a lightweight reconcile mode (e.g. phase_only=True) that skips the expensive boundary sync and only re-derives phase? Or is the full reconcile acceptable since these are already CLI commands with user-visible latency?",
"clear_postflight_scan_completion currently returns False (no-op) when the mutation doesn't touch objective issues. When we switch to calling reconcile_plan() after invalidation, reconcile will always run even if invalidation was a no-op. Should we preserve the early-return optimization (skip reconcile if no objective issues touched)?"
],
"success_criteria": [
"set_lifecycle_phase (or its private replacement) is called from exactly ONE location: inside reconcile_plan() in pipeline.py",
"refresh_state['lifecycle_phase'] is never written directly outside _set_lifecycle_phase (verified by grep-based test)",
"resolve_workflow.py:_reconcile_if_queue_drained no longer contains any direct set_lifecycle_phase call \u2014 it delegates to reconcile_plan()",
"clear_postflight_scan_completion (renamed invalidate_postflight_scan) no longer writes lifecycle_phase \u2014 only clears the scan marker",
"A single derive_display_phase() function exists and is called by both snapshot.py and pipeline.py",
"All existing tests pass with no behavioral changes",
"New regression test confirms: resolving WORKFLOW_CREATE_PLAN_ID with open reviews produces mode='plan' with triage stages via reconcile",
"New regression test confirms: skip/unskip/backlog/reopen produce correct lifecycle transitions via reconcile after invalidation"
],
"assumptions": [
"The two persisted modes (plan/execute) are sufficient \u2014 no new modes needed. The state machine is enforced by code structure (single writer), not by a formal state machine class or transition table.",
"Python's _prefix convention + removal from all is sufficient enforcement for _set_lifecycle_phase. We don't need runtime call-stack inspection or module-level getattr guards.",
"The 5 call sites of clear_postflight_scan_completion all have access to state data and can derive target_strict from config, so calling reconcile_plan() from each is feasible.",
"synthetic.py's phase read (current_lifecycle_phase) is the correct pattern and needs no change beyond a clarifying comment.",
"The display-phase derivation differences between pipeline.py and snapshot.py are unintentional drift, not deliberate context-dependent behavior. Unifying them is correct.",
"Performance of calling full reconcile_plan() at the 5 invalidation sites is acceptable \u2014 these are interactive CLI commands, not hot paths."
]
}
code
Existing flags:
[]
Requirements:
- Consider whether the plan is at the right level of abstraction.
- Reuse existing flag IDs when the same concern is still open.
- `verified_flag_ids` should list previously addressed flags that now appear resolved.
- Focus on concrete issues that would cause real problems.
- Robustness level: standard. Use balanced judgment. Flag significant risks, but do not spend flags on minor polish or executor-obvious boilerplate.
- Verify that the plan remains aligned with the user's original intent.
- Flag scope creep explicitly when the plan grows beyond the original idea or recorded user notes. Use the phrase "Scope creep:" in the concern.
- Assign severity_hint carefully. Implementation details the executor will naturally resolve should usually be `likely-minor`.
{"flags":[{"id":"state-machine-not-actually-enforced","concern":"The plan does not actually make lifecycle deviation impossible. It explicitly rejects the requested explicit state machine / typed transitions and instead relies on a private rename of the setter, which is only a convention.","category":"completeness","severity_hint":"likely-significant","evidence":"In the repo today, set_lifecycle_phase() in desloppify/engine/_plan/refresh_lifecycle.py:141 only checks membership in {\"plan\",\"execute\"} and then writes the value. There is no transition table or source->target validation. Renaming it to _set_lifecycle_phase and removing it from __all__ would still allow any internal module to import and call it, so the plan would reduce accidental misuse, not enforce the architectural rule the user asked for."},{"id":"single-writer-exemption-for-read-migration","concern":"The plan's stated single-writer goal is internally inconsistent because it still allows a non-state-machine read path to write lifecycle state.","category":"correctness","severity_hint":"likely-significant","evidence":"current_lifecycle_phase() mutates refresh_state[\"lifecycle_phase\"] during legacy migration in desloppify/engine/_plan/refresh_lifecycle.py:102-133. The plan's success criteria explicitly carve this out, but that means reconcile would still not be the only writer even after the refactor."},{"id":"resolve-workflow-still-advances-pipeline-outside-reconcile","concern":"Step 3 still preserves a pipeline side-channel. Removing the direct mode write is not enough if resolve_workflow still manually injects triage before reconcile.","category":"correctness","severity_hint":"likely-significant","evidence":"The current side-channel is in desloppify/app/commands/plan/override/resolve_workflow.py:364-367. The plan proposes keeping ensure_active_triage_issue_ids() and inject_triage_stages() there and only deleting set_lifecycle_phase(). But triage advancement already has a canonical reconcile path via sync_triage_needed() inside desloppify/engine/_plan/sync/pipeline.py:230-267. Keeping manual triage injection outside reconcile still leaves pipeline advancement outside the supposed single entry point."},{"id":"scope-creep-new-phase-derivation-layer","concern":"Scope creep: Step 1 adds a new shared phase-derivation layer in refresh_lifecycle.py instead of reusing the repository's existing canonical snapshot phase logic.","category":"maintainability","severity_hint":"likely-significant","evidence":"The codebase already documents snapshot-owned phase resolution as canonical: desloppify/engine/_work_queue/README.md:15-17 says phase is determined by _phase_for_snapshot(), and :40 calls build_queue_snapshot() the canonical entry point. The current authoritative ordering lives in desloppify/engine/_work_queue/snapshot.py:263-345. Moving derivation into refresh_lifecycle.py would create another owner for the same rules and risks recreating the very drift this plan is trying to remove."},{"id":"invalidation-sites-need-site-specific-reconcile-plumbing","concern":"Step 4 treats the five clear_postflight_scan_completion sites as a uniform mechanical refactor, but the repository has materially different state and reconcile flows at those sites.","category":"correctness","severity_hint":"likely-significant","evidence":"cmd_plan_skip() mutates and later saves a separate state_data object in desloppify/app/commands/plan/override/skip.py:223-259; reconciling against the earlier state would use stale issue status. update_living_plan_after_resolve() already has a queue-drained-only reconcile path plus progression bookkeeping in desloppify/app/commands/resolve/living_plan.py:48-60 and :134-150; adding another unconditional reconcile at invalidation time would risk duplicate reconcile/log/transition behavior unless that flow is redesigned, not just pattern-replaced."}],"verified_flag_ids":[],"disputed_flag_ids":[]}
You are an independent reviewer. Critique the plan against the actual repository.
Make unintentional deviation from the lifecycle impossible. Current state: 2 modes (plan/execute) work, but there are 5 ways to deviate: 1) resolve_workflow.py:368 is a side-channel that directly calls inject_triage_stages + set_lifecycle_phase outside reconcile. 2) clear_postflight_scan_completion called from 4 scattered places with inconsistent aftermath handling. 3) Snapshot and reconcile have separate phase derivation paths that can disagree. 4) synthetic.py does its own phase checking. 5) Nothing prevents adding new phases via set_lifecycle_phase. Fix: single reconcile entry point, single derivation function, explicit state machine with typed transitions. The plan-mode pipeline (scan -> review -> score -> triage) should be enforced by the state machine, not by hoping sync preconditions happen to gate correctly.
User notes and answers:
CONTEXT: Today we shipped lifecycle simplification (8 phases -> 2 modes) and UX cleanup. The infrastructure works but has scattered control points. DESIGN PRINCIPLE: The lifecycle state machine should be the ONLY way to change mode or advance the pipeline. No direct set_lifecycle_phase calls outside the state machine. No side-channels. The state machine enforces: execute -> (queue empties) -> plan:scan -> plan:review -> plan:score -> plan:triage -> execute. Each transition has a single code path. Consumers READ mode/stage, they never WRITE it. The state machine is the single writer. IMPORTANT: This is about architectural enforcement, not adding features. The behavior should be identical — we're just making it impossible to accidentally break.
Q1: Snapshot ordering is authoritative (it determines what users see). Pipeline should match it. The unified function should use the snapshot ordering. Q2: Full reconcile is fine — these are CLI commands. Dont add a lightweight mode, thats more complexity. Q3: Preserve the early return — skip reconcile if no objective issues touched. Keep the optimization.
Flag responses: 1) state-machine-not-enforced: Downgrade. _ prefix + eliminating all external callers is sufficient for an internal tool. No formal state machine class needed. 2) single-writer-exemption: Downgrade. Migration write is one-shot, not a control flow side-channel. Acceptable. 3) resolve-workflow side-channel: REAL ISSUE. Investigate whether sync_triage_needed() already covers the trigger condition. If yes, remove manual inject_triage_stages entirely from resolve_workflow — let reconcile handle it. If no, push the prep logic into sync_triage_needed so reconcile owns it. 4) scope-creep derivation: REAL ISSUE. Dont create a new derivation in refresh_lifecycle.py. Make pipeline.py delegate to snapshots existing _derive_display_phase (or better: have pipeline call build_queue_snapshot and read the phase from it). Snapshot is the canonical owner. 5) invalidation-sites: Handle during implementation. skip.py needs fresh state — note this as an audit item.
code
Plan:
Lifecycle State Machine Enforcement (v2)
Problem Summary
Five deviation vectors let code change lifecycle mode or advance the pipeline outside the canonical reconcile_plan() path:
#
Vector
Location
Mechanism
1
resolve_workflow side-channel
resolve_workflow.py:364-390
Directly calls inject_triage_stages() + set_lifecycle_phase(plan, "plan") when WORKFLOW_CREATE_PLAN_ID resolved with open reviews — bypasses reconcile entirely
2
clear_postflight_scan_completion
refresh_lifecycle.py:210-224, 5 call sites
Directly writes refresh_state["lifecycle_phase"] = "execute" AND clears scan marker — bypasses even set_lifecycle_phase()
3
Dual phase derivation
snapshot.py:263-346 vs pipeline.py:97-149
Two independent functions derive display phase from queue contents with different logic and priority ordering
4
synthetic.py phase read
synthetic.py:240-261
Reads persisted mode to suppress stale refreshes — read-only, correct pattern
5
Unguarded set_lifecycle_phase
refresh_lifecycle.py:141-149
Public function, any caller can set mode to any valid value
Design Principles
Single writer: Only reconcile_plan() in pipeline.py may call _set_lifecycle_phase(). Enforcement: _ prefix + removal from __all__ + elimination of all other callers. Sufficient for an internal tool.
Snapshot is canonical: _derive_display_phase() in snapshot.py is the single source of display-phase logic. Pipeline delegates to it.
Reconcile owns pipeline advancement: No manual inject_triage_stages + set_lifecycle_phase outside reconcile. Push the WORKFLOW_CREATE_PLAN_ID triage prep into sync_triage_needed().
One-shot data migration is exempt: current_lifecycle_phase() persists a migrated value on first read of legacy state. This is a one-shot data fixup, not a control flow side-channel.
Implementation Steps
Step 0: Validate baseline
Run full test suite — establish green
Confirm set_lifecycle_phase has exactly 2 non-test callers: pipeline.py:275, resolve_workflow.py:367
Confirm clear_postflight_scan_completion line 222 is the only place writing _LIFECYCLE_PHASE_KEY outside set_lifecycle_phase
Step 1: Make snapshot's _derive_display_phase the single derivation function
Problem: pipeline.py's _resolve_reconcile_display_phase() (lines 97-149) and snapshot.py's _derive_display_phase() (lines 313-346) independently derive display phase with different priority orderings. Snapshot is documented as canonical (README.md).
Fix: Make pipeline delegate to snapshot's derivation.
Rewrite pipeline.py's _resolve_reconcile_display_phase() to:
Translate its queue_order + ReconcileResult into the boolean flags derive_display_phase expects:
fresh_boundary=True (pipeline only runs at empty-queue boundaries)
initial_review_items → non-empty if unscored subjective IDs in queue (use policy.unscored_ids)
postflight_assessment_items → non-empty if scored subjective IDs in queue
postflight_workflow_items → non-empty if any workflow:: IDs in queue (including result.workflow_injected_ids)
triage_items → non-empty if any triage:: IDs in queue (including result.triage.injected)
postflight_review_items → non-empty if triage completed + open review IDs (existing triage_snapshot check at line 129)
anchored_execution_items / explicit_queue_items → non-empty if real (non-synthetic, non-skipped) work in queue
scan_items → non-empty if postflight_scan_pending
prefer_scan=False (pipeline runs after scan completes)
Call derive_display_phase(...) with these flags
Return the result
Verify: For all test scenarios, pipeline now produces the same display phase as snapshot would for the same plan state.
Note: Pipeline passes placeholder WorkQueueItem lists (single-element lists for truthy, empty for falsy) — the function only checks emptiness, not item contents.
Step 2: Make set_lifecycle_phase private
Rename set_lifecycle_phase → _set_lifecycle_phase in refresh_lifecycle.py
Remove from __all__
Update the single legitimate caller in pipeline.py to import _set_lifecycle_phase
All other callers will break at import time — this is the enforcement
Step 3: Eliminate the resolve_workflow side-channel
Investigation result: sync_triage_needed() does NOT cover the WORKFLOW_CREATE_PLAN_ID trigger. It uses review-hash-change detection and appends only unconfirmed stages. The resolve_workflow case needs full triage kickoff (freeze active issue IDs + inject all 7 stages).
Fix: Push the triage prep logic into reconcile's triage sync path.
Move ensure_active_triage_issue_ids() from app/commands/plan/triage/review_coverage.py to engine/_plan/triage/ (it's pure plan/state manipulation — belongs in engine, not app). Add a re-import in the old location for backward compat during transition (can be removed later since no backward compat policy).
Add workflow_plan_resolved: bool = False parameter to reconcile_plan() in pipeline.py. Pass it through to sync_triage_needed().
Add workflow_plan_resolved: bool = False parameter to sync_triage_needed() in triage.py. When True AND has_open_review_issues(state):
Call ensure_active_triage_issue_ids(plan, state) to freeze the active set
Call inject_triage_stages(plan) for full aggressive injection (all 7 stages, cleared skips)
Return a QueueSyncResult with injected=True
This short-circuits the normal hash-change detection
# Before (lines 364-390): manual inject + set_lifecycle_phase
# After: single reconcile call with flag
result = reconcile_plan(
plan, state_data,
target_strict=target_strict_score_from_config(state_data.get("config")),
workflow_plan_resolved=(WORKFLOW_CREATE_PLAN_ID in synthetic_ids),
)
save_plan(plan)
# progression + transition_message from result
Remove the entire if WORKFLOW_CREATE_PLAN_ID in synthetic_ids special-case branch.
Step 4: Remove lifecycle write from clear_postflight_scan_completion
Problem: clear_postflight_scan_completion (refresh_lifecycle.py:210-224) directly writes refresh_state["lifecycle_phase"] = "execute" at line 222 — a second side-channel.
Fix:
Rename to invalidate_postflight_scan() to clarify it only invalidates the scan marker
Remove line 222 (refresh_state[_LIFECYCLE_PHASE_KEY] = "execute") — only clear _POSTFLIGHT_SCAN_KEY
Keep the early-return optimization: still returns False when no objective issues touched
Refactor each call site — 5 sites, each needs site-specific handling:
Pattern A — sites where no reconcile follows (skip.py: skip/unskip/backlog, misc.py: reopen):
python
# Before:
if clear_postflight_scan_completion(plan, issue_ids=ids, state=state):
transition_phase = "execute"
# After:
if invalidate_postflight_scan(plan, issue_ids=ids, state=state):
result = reconcile_plan(plan, state_data, target_strict=target_strict)
if result.lifecycle_phase_changed:
transition_phase = result.lifecycle_phase
Preserves the early-return: if invalidate_postflight_scan returns False, no reconcile runs.
Pattern B — living_plan.py (already has reconcile via _reconcile_if_queue_drained):
No separate reconcile needed; the existing _reconcile_if_queue_drained will pick up the cleared scan marker.
Audit items for implementation:
skip.py cmd_plan_skip: loads state_data at line 223 via _apply_state_skip_resolution() which mutates state. Reconcile MUST use state_data (the fresh copy), not state (the stale original). Verify this.
skip.py cmd_plan_unskip: loads state_data at line 320 for reopening. Same concern — reconcile must use the freshest state.
skip.py cmd_plan_backlog: verify which state variable is current after mutations.
living_plan.py: When queue is NOT drained, _reconcile_if_queue_drained doesn't run. The invalidation just clears the scan marker without a phase write. This is correct — the next boundary reconcile will derive the right phase.
Step 5: Verify synthetic.py is read-only (no code change)
synthetic.py:240-261 only reads current_lifecycle_phase(plan) to suppress stale subjective refreshes during planning. This is the correct consumer pattern: read mode, never write. No change needed.
Step 6: Test coverage
Single-writer enforcement test: Grep production code (non-test) for writes to lifecycle_phase string literal. Should only find _set_lifecycle_phase and the one-shot migration in current_lifecycle_phase.
Resolve-workflow regression: Test that resolving WORKFLOW_CREATE_PLAN_ID with open reviews goes through reconcile and produces mode="plan" with triage stages.
Invalidation regression: Test that skip/unskip/backlog/reopen after invalidation produce correct lifecycle transitions via reconcile.
Derivation agreement: Test that derive_display_phase (now public in snapshot.py) produces consistent results when called with pipeline-constructed inputs vs snapshot-constructed inputs.
Rename _derive_display_phase → derive_display_phase, add to __all__
engine/_plan/sync/pipeline.py
Rewrite _resolve_reconcile_display_phase to delegate to snapshot's derive_display_phase; import _set_lifecycle_phase; add workflow_plan_resolved param to reconcile_plan
Replace clear_postflight_scan_completion with invalidate_postflight_scan + conditional reconcile
app/commands/plan/override/misc.py
Same pattern replacement
app/commands/resolve/living_plan.py
Replace clear_postflight_scan_completion with invalidate_postflight_scan (existing reconcile handles phase)
app/commands/plan/triage/review_coverage.py
Remove ensure_active_triage_issue_ids (moved to engine) or re-import from new location
Tests
New regression tests per Step 6
code
Plan metadata:
{
"version": 2,
"timestamp": "2026-03-23T04:26:16Z",
"hash": "sha256:edcdd1d5093403f647c83faaf78cb08e2a47d862d418ef8073cf07389a985655",
"changes_summary": "\nv1 \u2192 v2 changes:\n\n1. Flag 1 (state-machine-not-enforced) \u2014 DOWNGRADED. _ prefix + eliminating all callers is sufficient for an internal tool. No formal state machine class. Justification added to Design Principles.\n\n2. Flag 2 (single-writer-exemption) \u2014 DOWNGRADED. One-shot data migration in current_lifecycle_phase() is a data fixup, not a control flow side-channel. Explicitly called out as exempt in Design Principles.\n\n3. Flag 3 (resolve-workflow side-channel) \u2014 FIXED. Investigation confirmed sync_triage_needed() does NOT cover the trigger (it uses hash-change detection, not workflow resolution). Fix: push the full triage kickoff logic INTO sync_triage_needed() via workflow_plan_resolved=True parameter. ensure_active_triage_issue_ids moves from app/ to engine/. resolve_workflow.py's entire special-case branch is deleted \u2014 it just calls reconcile_plan(..., workflow_plan_resolved=True).\n\n4. Flag 4 (scope-creep derivation) \u2014 FIXED. No new derive_display_phase in refresh_lifecycle.py. Instead: make snapshot.py's _derive_display_phase public, have pipeline.py translate its data and call it. Snapshot remains the single canonical owner.\n\n5. Flag 5 (invalidation sites) \u2014 ADDRESSED with site-specific handling. Pattern A (no existing reconcile: skip/unskip/backlog/reopen) adds conditional reconcile after invalidation. Pattern B (living_plan.py, already has reconcile) just calls invalidation before existing reconcile. Audit items documented for state freshness in skip.py.\n",
"flags_addressed": [
"state-machine-not-actually-enforced",
"single-writer-exemption-for-read-migration",
"resolve-workflow-still-advances-pipeline-outside-reconcile",
"scope-creep-new-phase-derivation-layer",
"invalidation-sites-need-site-specific-reconcile-plumbing"
],
"questions": [
"ensure_active_triage_issue_ids currently lives in app/commands/plan/triage/review_coverage.py. The plan moves it to engine/_plan/triage/. Should it go into the existing engine/_plan/triage/snapshot.py, a new engine/_plan/triage/review_coverage.py, or somewhere else in the triage package?"
],
"success_criteria": [
"_set_lifecycle_phase is called from exactly ONE location: reconcile_plan() in pipeline.py (verified by grep)",
"refresh_state['lifecycle_phase'] is never written directly outside _set_lifecycle_phase, except for the one-shot migration in current_lifecycle_phase (verified by grep-based test)",
"resolve_workflow.py:_reconcile_if_queue_drained no longer contains any direct set_lifecycle_phase or inject_triage_stages call \u2014 it calls reconcile_plan(workflow_plan_resolved=True)",
"invalidate_postflight_scan (formerly clear_postflight_scan_completion) only clears the scan marker \u2014 no lifecycle_phase write",
"snapshot.py's derive_display_phase is the single display-phase derivation function, called by both snapshot and pipeline",
"All existing tests pass with no behavioral changes",
"New test: resolving WORKFLOW_CREATE_PLAN_ID with open reviews produces mode='plan' with triage stages via reconcile",
"New test: skip/unskip/backlog/reopen produce correct lifecycle transitions via reconcile after invalidation",
"New test: grep-based enforcement that no production code writes lifecycle_phase outside _set_lifecycle_phase + migration"
],
"assumptions": [
"The two persisted modes (plan/execute) are sufficient. Enforcement via _ prefix + removing all callers is appropriate for an internal tool with no backward compat guarantees.",
"The one-shot data migration write in current_lifecycle_phase() is exempt from the single-writer rule \u2014 it fires once per legacy state file on first read, then persists.",
"ensure_active_triage_issue_ids belongs in engine/_plan/triage/ (pure plan/state manipulation), not in app/commands/. Moving it fixes the import direction violation.",
"Pipeline can construct the boolean flags derive_display_phase expects by classifying queue_order items \u2014 it doesn't need actual WorkQueueItem lists since the function only checks emptiness.",
"For living_plan.py, when invalidation clears the scan marker but the queue is NOT drained, no immediate phase transition is needed \u2014 the next boundary reconcile will handle it correctly.",
"Performance of adding reconcile_plan() calls to skip/unskip/backlog/reopen is acceptable \u2014 these are interactive CLI commands."
],
"delta_from_previous_percent": 83.2
}
code
Existing flags:
[
{
"id": "state-machine-not-actually-enforced",
"concern": "The plan does not actually make lifecycle deviation impossible. It explicitly rejects the requested explicit state machine / typed transitions and instead relies on a private rename of the setter, which is only a convention.",
"status": "addressed",
"severity": "significant"
},
{
"id": "single-writer-exemption-for-read-migration",
"concern": "The plan's stated single-writer goal is internally inconsistent because it still allows a non-state-machine read path to write lifecycle state.",
"status": "addressed",
"severity": "significant"
},
{
"id": "resolve-workflow-still-advances-pipeline-outside-reconcile",
"concern": "Step 3 still preserves a pipeline side-channel. Removing the direct mode write is not enough if resolve_workflow still manually injects triage before reconcile.",
"status": "addressed",
"severity": "significant"
},
{
"id": "scope-creep-new-phase-derivation-layer",
"concern": "Scope creep: Step 1 adds a new shared phase-derivation layer in refresh_lifecycle.py instead of reusing the repository's existing canonical snapshot phase logic.",
"status": "addressed",
"severity": "significant"
},
{
"id": "invalidation-sites-need-site-specific-reconcile-plumbing",
"concern": "Step 4 treats the five clear_postflight_scan_completion sites as a uniform mechanical refactor, but the repository has materially different state and reconcile flows at those sites.",
"status": "addressed",
"severity": "significant"
}
]
code
Requirements:
- Consider whether the plan is at the right level of abstraction.
- Reuse existing flag IDs when the same concern is still open.
- `verified_flag_ids` should list previously addressed flags that now appear resolved.
- Focus on concrete issues that would cause real problems.
- Robustness level: standard. Use balanced judgment. Flag significant risks, but do not spend flags on minor polish or executor-obvious boilerplate.
- Verify that the plan remains aligned with the user's original intent.
- Flag scope creep explicitly when the plan grows beyond the original idea or recorded user notes. Use the phrase "Scope creep:" in the concern.
- Assign severity_hint carefully. Implementation details the executor will naturally resolve should usually be `likely-minor`.
{"flags":[{"id":"resolve-workflow-still-advances-pipeline-outside-reconcile","concern":"The manual branch is gone, but the plan replaces it with a caller-supplied workflow_plan_resolved flag. That still makes pipeline advancement depend on out-of-band command context rather than just plan/state, which is a softer version of the same side-channel.","category":"correctness","severity_hint":"likely-significant","evidence":"reconcile_plan() is currently a state-driven engine API in desloppify/engine/_plan/sync/pipeline.py:201-207. The plan proposes adding workflow_plan_resolved=True so sync_triage_needed() can short-circuit into a special kickoff path. But sync_triage_needed() is also a generic engine sync used outside workflow resolution, including desloppify/engine/_plan/sync/review_import.py:186-190. With the proposed flag, the same plan + state can produce different lifecycle/queue results depending on who called reconcile, which conflicts with the stated goal that reconcile/state machine be the single canonical path."},{"id":"invalidation-sites-need-site-specific-reconcile-plumbing","concern":"Step 4 is still incomplete for living_plan.py. Pattern B removes the current immediate execute-mode transition when postflight is invalidated but the queue is not drained, so persisted mode can stay stale until some later boundary.","category":"correctness","severity_hint":"likely-significant","evidence":"Today update_living_plan_after_resolve() flips to execute immediately via clear_postflight_scan_completion() before the queue-drained reconcile path runs (desloppify/app/commands/resolve/living_plan.py:134-140). The proposed Pattern B removes that phase write and does nothing when _reconcile_if_queue_drained() does not run. That is not behavior-identical, and it matters because some code still reads persisted mode directly: desloppify/engine/_work_queue/synthetic.py:240-262 suppresses same-cycle refreshes based on current_lifecycle_phase(plan) == \"plan\"."},{"id":"pipeline-snapshot-adapter-is-not-equivalent","concern":"Step 1's pipeline-to-snapshot adapter is not a behavior-preserving way to make snapshot canonical. It assumes reconcile only runs at boundaries and that snapshot inputs can be reconstructed from queue prefixes, but the current snapshot logic is more nuanced than that.","category":"correctness","severity_hint":"likely-significant","evidence":"reconcile_plan() always recomputes lifecycle phase, not just at empty-queue boundaries: only the heavier sync block is gated by live_planned_queue_empty(plan) or force_rescan, while lifecycle resolution still runs afterward in desloppify/engine/_plan/sync/pipeline.py:230-275. There are existing mid-cycle tests, e.g. desloppify/tests/plan/test_reconcile_pipeline.py:161-169, where reconcile_plan() runs with real work still in queue_order. Snapshot execution/phase inputs also are not simple prefix checks: _merge_execution_candidates() and _executable_review_issue_items() in desloppify/engine/_work_queue/snapshot.py:158-214 exclude queued review items unless triage is current and treat active-cluster items specially. The proposed adapter's fresh_boundary=True plus placeholder truthy lists can still diverge from snapshot behavior even though it calls the same helper."}],"verified_flag_ids":["state-machine-not-actually-enforced","single-writer-exemption-for-read-migration","scope-creep-new-phase-derivation-layer"],"disputed_flag_ids":[]}
You are an independent reviewer. Critique the plan against the actual repository.
Make unintentional deviation from the lifecycle impossible. Current state: 2 modes (plan/execute) work, but there are 5 ways to deviate: 1) resolve_workflow.py:368 is a side-channel that directly calls inject_triage_stages + set_lifecycle_phase outside reconcile. 2) clear_postflight_scan_completion called from 4 scattered places with inconsistent aftermath handling. 3) Snapshot and reconcile have separate phase derivation paths that can disagree. 4) synthetic.py does its own phase checking. 5) Nothing prevents adding new phases via set_lifecycle_phase. Fix: single reconcile entry point, single derivation function, explicit state machine with typed transitions. The plan-mode pipeline (scan -> review -> score -> triage) should be enforced by the state machine, not by hoping sync preconditions happen to gate correctly.
User notes and answers:
CONTEXT: Today we shipped lifecycle simplification (8 phases -> 2 modes) and UX cleanup. The infrastructure works but has scattered control points. DESIGN PRINCIPLE: The lifecycle state machine should be the ONLY way to change mode or advance the pipeline. No direct set_lifecycle_phase calls outside the state machine. No side-channels. The state machine enforces: execute -> (queue empties) -> plan:scan -> plan:review -> plan:score -> plan:triage -> execute. Each transition has a single code path. Consumers READ mode/stage, they never WRITE it. The state machine is the single writer. IMPORTANT: This is about architectural enforcement, not adding features. The behavior should be identical — we're just making it impossible to accidentally break.
Q1: Snapshot ordering is authoritative (it determines what users see). Pipeline should match it. The unified function should use the snapshot ordering. Q2: Full reconcile is fine — these are CLI commands. Dont add a lightweight mode, thats more complexity. Q3: Preserve the early return — skip reconcile if no objective issues touched. Keep the optimization.
Flag responses: 1) state-machine-not-enforced: Downgrade. _ prefix + eliminating all external callers is sufficient for an internal tool. No formal state machine class needed. 2) single-writer-exemption: Downgrade. Migration write is one-shot, not a control flow side-channel. Acceptable. 3) resolve-workflow side-channel: REAL ISSUE. Investigate whether sync_triage_needed() already covers the trigger condition. If yes, remove manual inject_triage_stages entirely from resolve_workflow — let reconcile handle it. If no, push the prep logic into sync_triage_needed so reconcile owns it. 4) scope-creep derivation: REAL ISSUE. Dont create a new derivation in refresh_lifecycle.py. Make pipeline.py delegate to snapshots existing _derive_display_phase (or better: have pipeline call build_queue_snapshot and read the phase from it). Snapshot is the canonical owner. 5) invalidation-sites: Handle during implementation. skip.py needs fresh state — note this as an audit item.
Gate was too lenient. The 3 remaining flags need real fixes, not implementation-level handwaving. 1) workflow_plan_resolved flag: Instead of a flag, have resolve_workflow write a marker to the plan dict (e.g. plan[refresh_state][workflow_plan_just_resolved]=True) BEFORE calling reconcile. Then sync_triage_needed reads that marker from plan state, not from a function parameter. This way reconcile is still purely state-driven. 2) living_plan.py Pattern B: Use Pattern A everywhere, no exceptions. Always invalidate then reconcile. 3) pipeline-to-snapshot adapter: Drop it. Accept that pipeline and snapshot have different derivation paths. The pipeline derives from queue_order prefixes, snapshot derives from materialized partitions. They produce equivalent results because sync preconditions ensure the same items exist in both representations. Document this equivalence invariant with a test, dont try to force them through the same function.
See latest add-note for specific fixes for all 3 flags.
code
Plan:
Lifecycle State Machine Enforcement (v2)
Problem Summary
Five deviation vectors let code change lifecycle mode or advance the pipeline outside the canonical reconcile_plan() path:
#
Vector
Location
Mechanism
1
resolve_workflow side-channel
resolve_workflow.py:364-390
Directly calls inject_triage_stages() + set_lifecycle_phase(plan, "plan") when WORKFLOW_CREATE_PLAN_ID resolved with open reviews — bypasses reconcile entirely
2
clear_postflight_scan_completion
refresh_lifecycle.py:210-224, 5 call sites
Directly writes refresh_state["lifecycle_phase"] = "execute" AND clears scan marker — bypasses even set_lifecycle_phase()
3
Dual phase derivation
snapshot.py:263-346 vs pipeline.py:97-149
Two independent functions derive display phase from queue contents with different logic and priority ordering
4
synthetic.py phase read
synthetic.py:240-261
Reads persisted mode to suppress stale refreshes — read-only, correct pattern
5
Unguarded set_lifecycle_phase
refresh_lifecycle.py:141-149
Public function, any caller can set mode to any valid value
Design Principles
Single writer: Only reconcile_plan() in pipeline.py may call _set_lifecycle_phase(). Enforcement: _ prefix + removal from __all__ + elimination of all other callers. Sufficient for an internal tool.
Snapshot is canonical: _derive_display_phase() in snapshot.py is the single source of display-phase logic. Pipeline delegates to it.
Reconcile owns pipeline advancement: No manual inject_triage_stages + set_lifecycle_phase outside reconcile. Push the WORKFLOW_CREATE_PLAN_ID triage prep into sync_triage_needed().
One-shot data migration is exempt: current_lifecycle_phase() persists a migrated value on first read of legacy state. This is a one-shot data fixup, not a control flow side-channel.
Implementation Steps
Step 0: Validate baseline
Run full test suite — establish green
Confirm set_lifecycle_phase has exactly 2 non-test callers: pipeline.py:275, resolve_workflow.py:367
Confirm clear_postflight_scan_completion line 222 is the only place writing _LIFECYCLE_PHASE_KEY outside set_lifecycle_phase
Step 1: Make snapshot's _derive_display_phase the single derivation function
Problem: pipeline.py's _resolve_reconcile_display_phase() (lines 97-149) and snapshot.py's _derive_display_phase() (lines 313-346) independently derive display phase with different priority orderings. Snapshot is documented as canonical (README.md).
Fix: Make pipeline delegate to snapshot's derivation.
Rewrite pipeline.py's _resolve_reconcile_display_phase() to:
Translate its queue_order + ReconcileResult into the boolean flags derive_display_phase expects:
fresh_boundary=True (pipeline only runs at empty-queue boundaries)
initial_review_items → non-empty if unscored subjective IDs in queue (use policy.unscored_ids)
postflight_assessment_items → non-empty if scored subjective IDs in queue
postflight_workflow_items → non-empty if any workflow:: IDs in queue (including result.workflow_injected_ids)
triage_items → non-empty if any triage:: IDs in queue (including result.triage.injected)
postflight_review_items → non-empty if triage completed + open review IDs (existing triage_snapshot check at line 129)
anchored_execution_items / explicit_queue_items → non-empty if real (non-synthetic, non-skipped) work in queue
scan_items → non-empty if postflight_scan_pending
prefer_scan=False (pipeline runs after scan completes)
Call derive_display_phase(...) with these flags
Return the result
Verify: For all test scenarios, pipeline now produces the same display phase as snapshot would for the same plan state.
Note: Pipeline passes placeholder WorkQueueItem lists (single-element lists for truthy, empty for falsy) — the function only checks emptiness, not item contents.
Step 2: Make set_lifecycle_phase private
Rename set_lifecycle_phase → _set_lifecycle_phase in refresh_lifecycle.py
Remove from __all__
Update the single legitimate caller in pipeline.py to import _set_lifecycle_phase
All other callers will break at import time — this is the enforcement
Step 3: Eliminate the resolve_workflow side-channel
Investigation result: sync_triage_needed() does NOT cover the WORKFLOW_CREATE_PLAN_ID trigger. It uses review-hash-change detection and appends only unconfirmed stages. The resolve_workflow case needs full triage kickoff (freeze active issue IDs + inject all 7 stages).
Fix: Push the triage prep logic into reconcile's triage sync path.
Move ensure_active_triage_issue_ids() from app/commands/plan/triage/review_coverage.py to engine/_plan/triage/ (it's pure plan/state manipulation — belongs in engine, not app). Add a re-import in the old location for backward compat during transition (can be removed later since no backward compat policy).
Add workflow_plan_resolved: bool = False parameter to reconcile_plan() in pipeline.py. Pass it through to sync_triage_needed().
Add workflow_plan_resolved: bool = False parameter to sync_triage_needed() in triage.py. When True AND has_open_review_issues(state):
Call ensure_active_triage_issue_ids(plan, state) to freeze the active set
Call inject_triage_stages(plan) for full aggressive injection (all 7 stages, cleared skips)
Return a QueueSyncResult with injected=True
This short-circuits the normal hash-change detection
# Before (lines 364-390): manual inject + set_lifecycle_phase
# After: single reconcile call with flag
result = reconcile_plan(
plan, state_data,
target_strict=target_strict_score_from_config(state_data.get("config")),
workflow_plan_resolved=(WORKFLOW_CREATE_PLAN_ID in synthetic_ids),
)
save_plan(plan)
# progression + transition_message from result
Remove the entire if WORKFLOW_CREATE_PLAN_ID in synthetic_ids special-case branch.
Step 4: Remove lifecycle write from clear_postflight_scan_completion
Problem: clear_postflight_scan_completion (refresh_lifecycle.py:210-224) directly writes refresh_state["lifecycle_phase"] = "execute" at line 222 — a second side-channel.
Fix:
Rename to invalidate_postflight_scan() to clarify it only invalidates the scan marker
Remove line 222 (refresh_state[_LIFECYCLE_PHASE_KEY] = "execute") — only clear _POSTFLIGHT_SCAN_KEY
Keep the early-return optimization: still returns False when no objective issues touched
Refactor each call site — 5 sites, each needs site-specific handling:
Pattern A — sites where no reconcile follows (skip.py: skip/unskip/backlog, misc.py: reopen):
python
# Before:
if clear_postflight_scan_completion(plan, issue_ids=ids, state=state):
transition_phase = "execute"
# After:
if invalidate_postflight_scan(plan, issue_ids=ids, state=state):
result = reconcile_plan(plan, state_data, target_strict=target_strict)
if result.lifecycle_phase_changed:
transition_phase = result.lifecycle_phase
Preserves the early-return: if invalidate_postflight_scan returns False, no reconcile runs.
Pattern B — living_plan.py (already has reconcile via _reconcile_if_queue_drained):
No separate reconcile needed; the existing _reconcile_if_queue_drained will pick up the cleared scan marker.
Audit items for implementation:
skip.py cmd_plan_skip: loads state_data at line 223 via _apply_state_skip_resolution() which mutates state. Reconcile MUST use state_data (the fresh copy), not state (the stale original). Verify this.
skip.py cmd_plan_unskip: loads state_data at line 320 for reopening. Same concern — reconcile must use the freshest state.
skip.py cmd_plan_backlog: verify which state variable is current after mutations.
living_plan.py: When queue is NOT drained, _reconcile_if_queue_drained doesn't run. The invalidation just clears the scan marker without a phase write. This is correct — the next boundary reconcile will derive the right phase.
Step 5: Verify synthetic.py is read-only (no code change)
synthetic.py:240-261 only reads current_lifecycle_phase(plan) to suppress stale subjective refreshes during planning. This is the correct consumer pattern: read mode, never write. No change needed.
Step 6: Test coverage
Single-writer enforcement test: Grep production code (non-test) for writes to lifecycle_phase string literal. Should only find _set_lifecycle_phase and the one-shot migration in current_lifecycle_phase.
Resolve-workflow regression: Test that resolving WORKFLOW_CREATE_PLAN_ID with open reviews goes through reconcile and produces mode="plan" with triage stages.
Invalidation regression: Test that skip/unskip/backlog/reopen after invalidation produce correct lifecycle transitions via reconcile.
Derivation agreement: Test that derive_display_phase (now public in snapshot.py) produces consistent results when called with pipeline-constructed inputs vs snapshot-constructed inputs.
Rename _derive_display_phase → derive_display_phase, add to __all__
engine/_plan/sync/pipeline.py
Rewrite _resolve_reconcile_display_phase to delegate to snapshot's derive_display_phase; import _set_lifecycle_phase; add workflow_plan_resolved param to reconcile_plan
Replace clear_postflight_scan_completion with invalidate_postflight_scan + conditional reconcile
app/commands/plan/override/misc.py
Same pattern replacement
app/commands/resolve/living_plan.py
Replace clear_postflight_scan_completion with invalidate_postflight_scan (existing reconcile handles phase)
app/commands/plan/triage/review_coverage.py
Remove ensure_active_triage_issue_ids (moved to engine) or re-import from new location
Tests
New regression tests per Step 6
code
Plan metadata:
{
"version": 2,
"timestamp": "2026-03-23T04:26:16Z",
"hash": "sha256:edcdd1d5093403f647c83faaf78cb08e2a47d862d418ef8073cf07389a985655",
"changes_summary": "\nv1 \u2192 v2 changes:\n\n1. Flag 1 (state-machine-not-enforced) \u2014 DOWNGRADED. _ prefix + eliminating all callers is sufficient for an internal tool. No formal state machine class. Justification added to Design Principles.\n\n2. Flag 2 (single-writer-exemption) \u2014 DOWNGRADED. One-shot data migration in current_lifecycle_phase() is a data fixup, not a control flow side-channel. Explicitly called out as exempt in Design Principles.\n\n3. Flag 3 (resolve-workflow side-channel) \u2014 FIXED. Investigation confirmed sync_triage_needed() does NOT cover the trigger (it uses hash-change detection, not workflow resolution). Fix: push the full triage kickoff logic INTO sync_triage_needed() via workflow_plan_resolved=True parameter. ensure_active_triage_issue_ids moves from app/ to engine/. resolve_workflow.py's entire special-case branch is deleted \u2014 it just calls reconcile_plan(..., workflow_plan_resolved=True).\n\n4. Flag 4 (scope-creep derivation) \u2014 FIXED. No new derive_display_phase in refresh_lifecycle.py. Instead: make snapshot.py's _derive_display_phase public, have pipeline.py translate its data and call it. Snapshot remains the single canonical owner.\n\n5. Flag 5 (invalidation sites) \u2014 ADDRESSED with site-specific handling. Pattern A (no existing reconcile: skip/unskip/backlog/reopen) adds conditional reconcile after invalidation. Pattern B (living_plan.py, already has reconcile) just calls invalidation before existing reconcile. Audit items documented for state freshness in skip.py.\n",
"flags_addressed": [
"state-machine-not-actually-enforced",
"single-writer-exemption-for-read-migration",
"resolve-workflow-still-advances-pipeline-outside-reconcile",
"scope-creep-new-phase-derivation-layer",
"invalidation-sites-need-site-specific-reconcile-plumbing"
],
"questions": [
"ensure_active_triage_issue_ids currently lives in app/commands/plan/triage/review_coverage.py. The plan moves it to engine/_plan/triage/. Should it go into the existing engine/_plan/triage/snapshot.py, a new engine/_plan/triage/review_coverage.py, or somewhere else in the triage package?"
],
"success_criteria": [
"_set_lifecycle_phase is called from exactly ONE location: reconcile_plan() in pipeline.py (verified by grep)",
"refresh_state['lifecycle_phase'] is never written directly outside _set_lifecycle_phase, except for the one-shot migration in current_lifecycle_phase (verified by grep-based test)",
"resolve_workflow.py:_reconcile_if_queue_drained no longer contains any direct set_lifecycle_phase or inject_triage_stages call \u2014 it calls reconcile_plan(workflow_plan_resolved=True)",
"invalidate_postflight_scan (formerly clear_postflight_scan_completion) only clears the scan marker \u2014 no lifecycle_phase write",
"snapshot.py's derive_display_phase is the single display-phase derivation function, called by both snapshot and pipeline",
"All existing tests pass with no behavioral changes",
"New test: resolving WORKFLOW_CREATE_PLAN_ID with open reviews produces mode='plan' with triage stages via reconcile",
"New test: skip/unskip/backlog/reopen produce correct lifecycle transitions via reconcile after invalidation",
"New test: grep-based enforcement that no production code writes lifecycle_phase outside _set_lifecycle_phase + migration"
],
"assumptions": [
"The two persisted modes (plan/execute) are sufficient. Enforcement via _ prefix + removing all callers is appropriate for an internal tool with no backward compat guarantees.",
"The one-shot data migration write in current_lifecycle_phase() is exempt from the single-writer rule \u2014 it fires once per legacy state file on first read, then persists.",
"ensure_active_triage_issue_ids belongs in engine/_plan/triage/ (pure plan/state manipulation), not in app/commands/. Moving it fixes the import direction violation.",
"Pipeline can construct the boolean flags derive_display_phase expects by classifying queue_order items \u2014 it doesn't need actual WorkQueueItem lists since the function only checks emptiness.",
"For living_plan.py, when invalidation clears the scan marker but the queue is NOT drained, no immediate phase transition is needed \u2014 the next boundary reconcile will handle it correctly.",
"Performance of adding reconcile_plan() calls to skip/unskip/backlog/reopen is acceptable \u2014 these are interactive CLI commands."
],
"delta_from_previous_percent": 83.2
}
code
Existing flags:
[
{
"id": "resolve-workflow-still-advances-pipeline-outside-reconcile",
"concern": "The manual branch is gone, but the plan replaces it with a caller-supplied workflow_plan_resolved flag. That still makes pipeline advancement depend on out-of-band command context rather than just plan/state, which is a softer version of the same side-channel.",
"status": "open",
"severity": "significant"
},
{
"id": "invalidation-sites-need-site-specific-reconcile-plumbing",
"concern": "Step 4 is still incomplete for living_plan.py. Pattern B removes the current immediate execute-mode transition when postflight is invalidated but the queue is not drained, so persisted mode can stay stale until some later boundary.",
"status": "open",
"severity": "significant"
},
{
"id": "pipeline-snapshot-adapter-is-not-equivalent",
"concern": "Step 1's pipeline-to-snapshot adapter is not a behavior-preserving way to make snapshot canonical. It assumes reconcile only runs at boundaries and that snapshot inputs can be reconstructed from queue prefixes, but the current snapshot logic is more nuanced than that.",
"status": "open",
"severity": "significant"
}
]
code
Requirements:
- Consider whether the plan is at the right level of abstraction.
- Reuse existing flag IDs when the same concern is still open.
- `verified_flag_ids` should list previously addressed flags that now appear resolved.
- Focus on concrete issues that would cause real problems.
- Robustness level: standard. Use balanced judgment. Flag significant risks, but do not spend flags on minor polish or executor-obvious boilerplate.
- Verify that the plan remains aligned with the user's original intent.
- Flag scope creep explicitly when the plan grows beyond the original idea or recorded user notes. Use the phrase "Scope creep:" in the concern.
- Assign severity_hint carefully. Implementation details the executor will naturally resolve should usually be `likely-minor`.
{"flags":[{"id":"resolve-workflow-still-advances-pipeline-outside-reconcile","concern":"The plan still leaves reconcile driven by out-of-band command context. Replacing the manual branch with a workflow_plan_resolved parameter is not a real fix for the side-channel; it just moves the side-channel into the reconcile API.","category":"correctness","severity_hint":"likely-significant","evidence":"In the repo today, reconcile_plan() is a generic engine sync entrypoint that derives behavior from plan + state (desloppify/engine/_plan/sync/pipeline.py:201-207). sync_triage_needed() is likewise a generic state sync used outside workflow resolution, including review import (desloppify/engine/_plan/sync/review_import.py:186-190). Adding workflow_plan_resolved=True means identical persisted state can reconcile differently depending on which caller invoked it, which is still a lifecycle advancement side-channel instead of a state-driven reconcile."},{"id":"invalidation-sites-need-site-specific-reconcile-plumbing","concern":"The living_plan.py exception is still not behavior-preserving. Pattern B drops the current immediate execute transition when postflight is invalidated but the queue is not drained, leaving persisted mode stale until some later reconcile.","category":"correctness","severity_hint":"likely-significant","evidence":"Current behavior in desloppify/app/commands/resolve/living_plan.py:134-140 is to flip to execute immediately via clear_postflight_scan_completion() and only then optionally run the queue-drained reconcile path. The proposed Pattern B removes that write and does nothing if _reconcile_if_queue_drained() does not run. That matters because persisted mode is still consumed directly in production code: desloppify/engine/_work_queue/synthetic.py:240-262 suppresses same-cycle refreshes when current_lifecycle_phase(plan) == \"plan\"."},{"id":"pipeline-snapshot-adapter-is-not-equivalent","concern":"The Step 1 adapter is still not a safe way to unify derivation. It assumes reconcile only runs at boundaries and that snapshot inputs can be reconstructed from queue prefixes, but the repository's actual snapshot logic is more nuanced than that.","category":"correctness","severity_hint":"likely-significant","evidence":"reconcile_plan() always recomputes lifecycle phase after sync, not just at empty-queue boundaries; only the heavier auto-cluster/workflow block is boundary-gated (desloppify/engine/_plan/sync/pipeline.py:230-275). There are existing mid-cycle cases, e.g. desloppify/tests/plan/test_reconcile_pipeline.py:161-169, where reconcile_plan() runs with real work already in queue_order. Snapshot phase inputs are also richer than prefix checks: _merge_execution_candidates() and _executable_review_issue_items() in desloppify/engine/_work_queue/snapshot.py:158-214 exclude queued review items unless triage is current and treat active-cluster items specially. A hand-built boolean/list adapter can still diverge from the snapshot it is supposed to mirror."}],"verified_flag_ids":["state-machine-not-actually-enforced","single-writer-exemption-for-read-migration","scope-creep-new-phase-derivation-layer"],"disputed_flag_ids":[]}
You are an independent reviewer. Critique the plan against the actual repository.
Make unintentional deviation from the lifecycle impossible. Current state: 2 modes (plan/execute) work, but there are 5 ways to deviate: 1) resolve_workflow.py:368 is a side-channel that directly calls inject_triage_stages + set_lifecycle_phase outside reconcile. 2) clear_postflight_scan_completion called from 4 scattered places with inconsistent aftermath handling. 3) Snapshot and reconcile have separate phase derivation paths that can disagree. 4) synthetic.py does its own phase checking. 5) Nothing prevents adding new phases via set_lifecycle_phase. Fix: single reconcile entry point, single derivation function, explicit state machine with typed transitions. The plan-mode pipeline (scan -> review -> score -> triage) should be enforced by the state machine, not by hoping sync preconditions happen to gate correctly.
User notes and answers:
CONTEXT: Today we shipped lifecycle simplification (8 phases -> 2 modes) and UX cleanup. The infrastructure works but has scattered control points. DESIGN PRINCIPLE: The lifecycle state machine should be the ONLY way to change mode or advance the pipeline. No direct set_lifecycle_phase calls outside the state machine. No side-channels. The state machine enforces: execute -> (queue empties) -> plan:scan -> plan:review -> plan:score -> plan:triage -> execute. Each transition has a single code path. Consumers READ mode/stage, they never WRITE it. The state machine is the single writer. IMPORTANT: This is about architectural enforcement, not adding features. The behavior should be identical — we're just making it impossible to accidentally break.
Q1: Snapshot ordering is authoritative (it determines what users see). Pipeline should match it. The unified function should use the snapshot ordering. Q2: Full reconcile is fine — these are CLI commands. Dont add a lightweight mode, thats more complexity. Q3: Preserve the early return — skip reconcile if no objective issues touched. Keep the optimization.
Flag responses: 1) state-machine-not-enforced: Downgrade. _ prefix + eliminating all external callers is sufficient for an internal tool. No formal state machine class needed. 2) single-writer-exemption: Downgrade. Migration write is one-shot, not a control flow side-channel. Acceptable. 3) resolve-workflow side-channel: REAL ISSUE. Investigate whether sync_triage_needed() already covers the trigger condition. If yes, remove manual inject_triage_stages entirely from resolve_workflow — let reconcile handle it. If no, push the prep logic into sync_triage_needed so reconcile owns it. 4) scope-creep derivation: REAL ISSUE. Dont create a new derivation in refresh_lifecycle.py. Make pipeline.py delegate to snapshots existing _derive_display_phase (or better: have pipeline call build_queue_snapshot and read the phase from it). Snapshot is the canonical owner. 5) invalidation-sites: Handle during implementation. skip.py needs fresh state — note this as an audit item.
Gate was too lenient. The 3 remaining flags need real fixes, not implementation-level handwaving. 1) workflow_plan_resolved flag: Instead of a flag, have resolve_workflow write a marker to the plan dict (e.g. plan[refresh_state][workflow_plan_just_resolved]=True) BEFORE calling reconcile. Then sync_triage_needed reads that marker from plan state, not from a function parameter. This way reconcile is still purely state-driven. 2) living_plan.py Pattern B: Use Pattern A everywhere, no exceptions. Always invalidate then reconcile. 3) pipeline-to-snapshot adapter: Drop it. Accept that pipeline and snapshot have different derivation paths. The pipeline derives from queue_order prefixes, snapshot derives from materialized partitions. They produce equivalent results because sync preconditions ensure the same items exist in both representations. Document this equivalence invariant with a test, dont try to force them through the same function.
See latest add-note for specific fixes for all 3 flags.
code
Plan:
Lifecycle State Machine Enforcement (v3)
Problem Summary
Five deviation vectors let code change lifecycle mode or advance the pipeline outside the canonical reconcile_plan() path:
#
Vector
Location
Mechanism
1
resolve_workflow side-channel
resolve_workflow.py:364-390
Directly calls inject_triage_stages() + set_lifecycle_phase(plan, "plan") when WORKFLOW_CREATE_PLAN_ID resolved with open reviews — bypasses reconcile entirely
2
clear_postflight_scan_completion
refresh_lifecycle.py:210-224, 5 call sites
Directly writes refresh_state["lifecycle_phase"] = "execute" AND clears scan marker — bypasses even set_lifecycle_phase()
3
Dual phase derivation
snapshot.py:263-346 vs pipeline.py:97-149
Two independent functions derive display phase from queue contents with different logic and priority ordering
4
synthetic.py phase read
synthetic.py:240-261
Reads persisted mode to suppress stale refreshes — read-only, correct pattern
5
Unguarded set_lifecycle_phase
refresh_lifecycle.py:141-149
Public function, any caller can set mode to any valid value
Design Principles
Single writer: Only reconcile_plan() in pipeline.py may call _set_lifecycle_phase(). Enforcement: _ prefix + removal from __all__ + elimination of all other callers. Sufficient for an internal tool.
Reconcile is state-driven: reconcile_plan() derives all behavior from plan + state dicts. No function parameters carry command-context side-channels. When a caller needs to influence reconcile, it writes a marker to plan state BEFORE calling reconcile.
Two derivation paths, one invariant: Pipeline derives display phase from queue_order prefixes. Snapshot derives from materialized item partitions. They produce equivalent results because sync preconditions ensure the same items exist in both representations. This equivalence is enforced by test, not by forcing them through the same function.
One-shot data migration is exempt: current_lifecycle_phase() persists a migrated value on first read of legacy state. This is a one-shot data fixup, not a control flow side-channel.
Implementation Steps
Step 0: Validate baseline
Run full test suite — establish green
Confirm set_lifecycle_phase has exactly 2 non-test callers: pipeline.py:275, resolve_workflow.py:367
Confirm clear_postflight_scan_completion line 222 is the only place writing _LIFECYCLE_PHASE_KEY outside set_lifecycle_phase
Rename set_lifecycle_phase → _set_lifecycle_phase in refresh_lifecycle.py
Remove from __all__
Update the single legitimate caller in pipeline.py to import _set_lifecycle_phase
All other callers will break at import time — this is the enforcement
Step 2: Eliminate the resolve_workflow side-channel via plan-state marker
Problem: resolve_workflow.py:364-390 directly calls inject_triage_stages() + set_lifecycle_phase(plan, "plan") outside reconcile when WORKFLOW_CREATE_PLAN_ID is resolved with open reviews.
v2 approach (rejected): Added workflow_plan_resolved parameter to reconcile_plan(). This is still a side-channel — identical plan state reconciles differently depending on which caller invoked it.
v3 fix: Make reconcile purely state-driven. The caller writes a marker to plan state; sync_triage_needed() reads it from the plan dict.
Move ensure_active_triage_issue_ids() from app/commands/plan/triage/review_coverage.py to engine/_plan/triage/ (pure plan/state manipulation — belongs in engine, not app).
resolve_workflow.py — before calling reconcile, write a marker:
python
# Before: manual inject + set_lifecycle_phase (lines 364-390)
# After: write marker, then call reconcile
if WORKFLOW_CREATE_PLAN_ID in synthetic_ids and has_open_review_issues(state_data):
plan.setdefault("refresh_state", {})["workflow_plan_just_resolved"] = True
result = reconcile_plan(
plan, state_data,
target_strict=target_strict_score_from_config(state_data.get("config")),
)
Delete the entire special-case branch (inject_triage_stages, set_lifecycle_phase, separate save_plan).
sync_triage_needed() in triage.py — read and consume the marker:
python
# At the top of sync_triage_needed(), before existing logic:
marker = meta.get("workflow_plan_just_resolved") or
plan.get("refresh_state", {}).get("workflow_plan_just_resolved")
if marker:
# Clear marker so it doesn't fire on subsequent reconcile calls
plan.get("refresh_state", {}).pop("workflow_plan_just_resolved", None)
if has_open_review_issues(state):
ensure_active_triage_issue_ids(plan, state)
inject_triage_stages(plan)
return QueueSyncResult(injected=True)
# ... existing hash-change detection follows
No new parameters on reconcile_plan() or sync_triage_needed(). Both remain purely state-driven.
Step 3: Remove lifecycle write from clear_postflight_scan_completion
Problem: clear_postflight_scan_completion (refresh_lifecycle.py:210-224) directly writes refresh_state["lifecycle_phase"] = "execute" at line 222 — a second side-channel.
Fix:
Rename to invalidate_postflight_scan() to clarify it only invalidates the scan marker
Remove line 222 (refresh_state[_LIFECYCLE_PHASE_KEY] = "execute") — only clear _POSTFLIGHT_SCAN_KEY
Keep the early-return optimization: still returns False when no objective issues touched
Refactor all 5 call sites uniformly with Pattern A (invalidate + reconcile):
python
# Before (all sites):
if clear_postflight_scan_completion(plan, issue_ids=ids, state=state):
transition_phase = "execute"
# After (all sites):
if invalidate_postflight_scan(plan, issue_ids=ids, state=state):
result = reconcile_plan(plan, state_data, target_strict=target_strict)
if result.lifecycle_phase_changed:
transition_phase = result.lifecycle_phase
Preserves the early-return: if invalidate_postflight_scan returns False, no reconcile runs.
Site-specific details:
skip.py cmd_plan_skip (line 252): Reconcile MUST use state_data (the fresh copy from _apply_state_skip_resolution() at line 223), not state (the stale original loaded earlier).
skip.py cmd_plan_unskip (line 315): Same — use freshest state after any reopening mutations at line 320.
skip.py cmd_plan_backlog (line 389): Verify which state variable is current after mutations.
misc.py cmd_plan_reopen (line 120): Has state_data available.
living_plan.py update_living_plan_after_resolve (line 135): Replace Pattern B with Pattern A. The existing _reconcile_if_queue_drained at line 138 may become redundant since Pattern A now runs reconcile unconditionally when invalidation fires. Implementation audit: verify whether _reconcile_if_queue_drained serves a distinct purpose beyond phase derivation (e.g., progression events triggered only on queue drain). If its only purpose was phase transition, it can be simplified or removed. If it also handles progression bookkeeping, keep it but ensure double-reconcile doesn't produce duplicate effects.
Step 4: Add equivalence test for pipeline vs snapshot derivation
Problem: pipeline.py and snapshot.py have separate display-phase derivation functions. v2 tried to force them through the same function via an adapter, but the snapshot's item-partition logic is richer than what pipeline can reconstruct from queue_order prefixes (active-cluster handling, triage-current gating, etc.).
v3 fix: Accept that they're separate implementations of the same rule. Enforce equivalence with a test, not structural unification.
Keep both functions as-is: _resolve_reconcile_display_phase() in pipeline.py and _derive_display_phase() in snapshot.py.
Add equivalence test: For a matrix of plan states (empty queue, subjective-only, workflow items, triage items, mixed real+synthetic, post-triage with open reviews, etc.), run both derivation paths and assert they produce the same display phase. This catches drift if either function is modified.
Document the invariant with a comment at the top of each function: "This function must produce the same display phase as [the other]. See test_phase_derivation_equivalence."
Step 5: Verify synthetic.py is read-only (no code change)
synthetic.py:240-261 only reads current_lifecycle_phase(plan) to suppress stale subjective refreshes during planning. Correct consumer pattern. No change needed.
Step 6: Test coverage
Single-writer enforcement test: Grep production code (non-test) for writes to lifecycle_phase string literal. Should only find _set_lifecycle_phase and the one-shot migration in current_lifecycle_phase.
Resolve-workflow regression: Test that resolving WORKFLOW_CREATE_PLAN_ID with open reviews goes through reconcile via plan-state marker and produces mode="plan" with triage stages.
Marker cleanup test: Verify workflow_plan_just_resolved marker is cleared after sync_triage_needed consumes it — subsequent reconcile calls don't re-trigger triage injection.
Invalidation regression: Test that skip/unskip/backlog/reopen/resolve after invalidation produce correct lifecycle transitions via reconcile.
Phase derivation equivalence (from Step 4): Matrix test that pipeline and snapshot derivation agree.
Rename set_lifecycle_phase → _set_lifecycle_phase; rename clear_postflight_scan_completion → invalidate_postflight_scan (remove lifecycle write); remove both from __all__
engine/_plan/sync/pipeline.py
Import _set_lifecycle_phase; no new parameters
engine/_plan/sync/triage.py
Read + consume workflow_plan_just_resolved marker from plan state; call ensure_active_triage_issue_ids + inject_triage_stages when marker is set
engine/_plan/triage/
New home for ensure_active_triage_issue_ids (moved from app/)
app/commands/plan/override/resolve_workflow.py
Remove side-channel branch; write marker to refresh_state, then call reconcile_plan()
app/commands/plan/override/skip.py
Replace clear_postflight_scan_completion with invalidate_postflight_scan + conditional reconcile (Pattern A)
app/commands/plan/override/misc.py
Same Pattern A replacement
app/commands/resolve/living_plan.py
Same Pattern A replacement; audit _reconcile_if_queue_drained for redundancy
app/commands/plan/triage/review_coverage.py
Re-import ensure_active_triage_issue_ids from new engine/ location
Tests
New tests per Step 6
code
Plan metadata:
{
"version": 3,
"timestamp": "2026-03-23T04:35:25Z",
"hash": "sha256:00849a381798f3f2c75741676d02a37c6fd1e58205a031eca0b0a9132714d109",
"changes_summary": "\nv2 \u2192 v3 changes (3 targeted fixes per user directives):\n\n1. resolve-workflow flag \u2192 plan-state marker: Replaced the workflow_plan_resolved parameter on reconcile_plan() and sync_triage_needed() with a marker written to plan[\"refresh_state\"][\"workflow_plan_just_resolved\"] by resolve_workflow before calling reconcile. sync_triage_needed reads and clears the marker from plan state. Reconcile stays purely state-driven \u2014 no function parameters carry command context. Removed workflow_plan_resolved parameter from both function signatures.\n\n2. living_plan.py Pattern B \u2192 Pattern A: Eliminated Pattern B entirely. All 5 invalidation sites now use the same Pattern A (invalidate + conditional reconcile). Added implementation audit note for _reconcile_if_queue_drained redundancy in living_plan.py.\n\n3. Dropped pipeline-to-snapshot adapter: Removed Step 1's rewrite of _resolve_reconcile_display_phase. Both derivation functions stay as-is. Added equivalence test (Step 4) that verifies pipeline and snapshot produce the same display phase for a matrix of plan states. Updated Design Principle 3 to document the "two paths, one invariant" approach.\n",
"flags_addressed": [
"resolve-workflow-still-advances-pipeline-outside-reconcile",
"invalidation-sites-need-site-specific-reconcile-plumbing",
"pipeline-snapshot-adapter-is-not-equivalent"
],
"questions": [],
"success_criteria": [
"_set_lifecycle_phase is called from exactly ONE location: reconcile_plan() in pipeline.py (verified by grep)",
"refresh_state['lifecycle_phase'] is never written directly outside _set_lifecycle_phase, except for the one-shot migration in current_lifecycle_phase (verified by grep-based test)",
"resolve_workflow.py:_reconcile_if_queue_drained no longer contains any direct set_lifecycle_phase or inject_triage_stages call \u2014 it writes a plan-state marker and calls reconcile_plan()",
"reconcile_plan() has no command-context parameters \u2014 it derives all behavior from plan + state dicts",
"invalidate_postflight_scan (formerly clear_postflight_scan_completion) only clears the scan marker \u2014 no lifecycle_phase write",
"All 5 invalidation sites use Pattern A uniformly (invalidate + conditional reconcile)",
"Equivalence test verifies pipeline and snapshot derivation agree for a matrix of plan states",
"All existing tests pass with no behavioral changes",
"New test: resolving WORKFLOW_CREATE_PLAN_ID with open reviews produces mode='plan' with triage stages via plan-state marker + reconcile",
"New test: workflow_plan_just_resolved marker is cleared after consumption by sync_triage_needed",
"New test: skip/unskip/backlog/reopen/resolve produce correct lifecycle transitions via reconcile after invalidation",
"New test: grep-based enforcement that no production code writes lifecycle_phase outside _set_lifecycle_phase + migration"
],
"assumptions": [
"The two persisted modes (plan/execute) are sufficient. Enforcement via _ prefix + removing all callers is appropriate for an internal tool with no backward compat guarantees.",
"The one-shot data migration write in current_lifecycle_phase() is exempt from the single-writer rule \u2014 it fires once per legacy state file on first read, then persists.",
"ensure_active_triage_issue_ids belongs in engine/_plan/triage/ (pure plan/state manipulation), not in app/commands/. Moving it fixes the import direction violation.",
"Pipeline and snapshot derivation functions produce equivalent results because sync preconditions ensure the same items in both representations \u2014 this is validated by test, not structural unification.",
"Performance of adding reconcile_plan() calls to all 5 invalidation sites is acceptable \u2014 these are interactive CLI commands.",
"The workflow_plan_just_resolved marker in refresh_state is safe to persist transiently \u2014 sync_triage_needed clears it after consumption, so it never survives to a subsequent reconcile call."
],
"delta_from_previous_percent": 64.96
}
code
Existing flags:
[
{
"id": "resolve-workflow-still-advances-pipeline-outside-reconcile",
"concern": "The plan still leaves reconcile driven by out-of-band command context. Replacing the manual branch with a workflow_plan_resolved parameter is not a real fix for the side-channel; it just moves the side-channel into the reconcile API.",
"status": "addressed",
"severity": "significant"
},
{
"id": "invalidation-sites-need-site-specific-reconcile-plumbing",
"concern": "The living_plan.py exception is still not behavior-preserving. Pattern B drops the current immediate execute transition when postflight is invalidated but the queue is not drained, leaving persisted mode stale until some later reconcile.",
"status": "addressed",
"severity": "significant"
},
{
"id": "pipeline-snapshot-adapter-is-not-equivalent",
"concern": "The Step 1 adapter is still not a safe way to unify derivation. It assumes reconcile only runs at boundaries and that snapshot inputs can be reconstructed from queue prefixes, but the repository's actual snapshot logic is more nuanced than that.",
"status": "addressed",
"severity": "significant"
}
]
code
Requirements:
- Consider whether the plan is at the right level of abstraction.
- Reuse existing flag IDs when the same concern is still open.
- `verified_flag_ids` should list previously addressed flags that now appear resolved.
- Focus on concrete issues that would cause real problems.
- Robustness level: standard. Use balanced judgment. Flag significant risks, but do not spend flags on minor polish or executor-obvious boilerplate.
- Verify that the plan remains aligned with the user's original intent.
- Flag scope creep explicitly when the plan grows beyond the original idea or recorded user notes. Use the phrase "Scope creep:" in the concern.
- Assign severity_hint carefully. Implementation details the executor will naturally resolve should usually be `likely-minor`.
“You are an independent reviewer. Critique the plan against the actual repository.….” Conversation with gpt-5.4, from the Peter O’Mallet DataClaw Conversations dataset. The Chat Archive, 2026. https://thechatarchive.com/c/01m80epwgrnwcq9y9qf0gz6pfh