Can you sense-check thsi from top to bottom? Be extremely thorough, any lost…
- User
Can you sense-check thsi from top to bottom? Be extremely thorough, any lost functionality? Anything inelegant? Centralize the postflight pipeline
Context
Two orchestrators independently implement the same "queue empty → what comes next?" pipeline:
- app/commands/scan/plan_reconcile.py → _sync_post_scan_with_policy()
- app/commands/review/importing/plan_sync.py → sync_plan_after_import()
Both call the same gate functions in sequence (subjective dims → communicate-score → create-plan → triage), then resolve the lifecycle phase — but via different mechanisms and with duplicated helpers. The user's insight: this is ONE pipeline (scan → subjective review → fetch score → triage) that fires whenever the real work queue is empty, regardless of whether we're at the start or end of a cycle.
Approach
Extract the shared gate sequence into a single run_postflight_gates() function in a new engine/_plan/sync/pipeline.py module. Both callers shrink to: domain-specific work → call pipeline → display/log from results → save.
Files to create
desloppify/engine/_plan/sync/pipeline.py
Contains:
-
PostflightResult dataclass — per-gate results + aggregate dirty flag: @dataclass class PostflightResult: subjective: QueueSyncResult auto_cluster_changes: int communicate_score: QueueSyncResult import_scores: QueueSyncResult create_plan: QueueSyncResult triage: QueueSyncResult plan_start_scores_seeded: bool plan_start_scores_cleared: bool postflight_scan_completed: bool lifecycle_phase: str lifecycle_phase_changed: bool
@property def dirty(self) -> bool: ...
-
Moved pure helpers from plan_reconcile.py (these are plan-mutation logic, not display):
- _seed_plan_start_scores(plan, state) -> bool
- _clear_plan_start_scores_if_queue_empty(state, plan) -> bool
- _has_objective_cycle(state, plan) -> bool | None
- _mark_postflight_scan_completed_if_ready(state, plan) -> bool
Note: _clear_plan_start_scores_if_queue_empty has a lazy import from app.commands.helpers.queue_progress. This is an existing layering violation — keep the lazy import for now, fix in a follow-up. 3. Shared helper has_postflight_review_work(state, *, policy) -> bool — currently copy-pasted in both files. Move here once. 4. run_postflight_gates() — the pipeline itself: def run_postflight_gates( plan, state, *, policy, target_strict=DEFAULT_TARGET_STRICT_SCORE, cycle_just_completed=False, scores_just_imported=False, current_scores=None, assessment_mode=None, import_file=None, import_payload=None, skip_auto_cluster=False, skip_plan_start_scores=False, skip_postflight_scan=False, ) -> PostflightResult:
- Pipeline sequence (matches the user's mental model): a. sync_subjective_dimensions(plan, state, policy=policy, cycle_just_completed=...) b. Auto-cluster (unless skip_auto_cluster) c. sync_communicate_score_needed(plan, state, policy=policy, scores_just_imported=..., current_scores=...) d. sync_import_scores_needed(...) (only when assessment_mode is provided) e. sync_create_plan_needed(plan, state, policy=policy) f. sync_triage_needed(plan, state, policy=policy) g. Seed or clear plan_start_scores (unless skip_plan_start_scores) h. Mark postflight scan completed (unless skip_postflight_scan) i. Resolve + persist lifecycle phase (unified — always use snapshot approach via coarse_phase_name(queue_context(...).snapshot.phase))
- Assistant
Using the
desloppifyskill here because this is a code-health/refactor review. I’m checking the current scan/import orchestration paths and the surrounding lifecycle helpers to verify whether the proposed central pipeline preserves behavior or drops edge cases. - Assistant
I’ve confirmed both paths do have parallel-but-not-identical orchestration today. Next I’m reading the concrete implementations and the lifecycle resolver so I can check for subtle divergence, especially around import-specific state, force-rescan behavior, and phase persistence.
- Assistant
I’ve got the high-level flow now. I’m drilling into the individual gate contracts next, because the main risk in centralizing this is not the obvious ordering, it’s whether one caller currently depends on fields like
injected/deferred/pruneddifferently than the other. - Assistant
The main open question now is lifecycle equivalence. The scan path already uses
queue_context(...).snapshot.phase; the import path still uses fact-basedsync_lifecycle_phase(...). I’m comparing those two resolvers, because that’s the place a “shared pipeline” can accidentally change visible behavior without touching any gate function. - Assistant
I’ve found one concrete behavior regression in the proposed ordering and one definite hole in the call-site sketch. I’m pulling exact line references now so I can give you a precise punch list instead of a vague architecture opinion.
- Assistant
I found a second semantic mismatch: the proposed lifecycle unification is probably the right direction, but it is not actually behavior-preserving. The current import path treats “any unscored subjective IDs exist” as
revieweven mid-cycle; the snapshot resolver only does that at a fresh boundary. I’m getting the exact references so I can call that out clearly. - Assistant
- User
- User
can you save this as a .md doc to tasks folder
- Assistant
I can format it as the exact Markdown doc for
tasks/, but I can’t write the file while still in Plan Mode because that would mutate the repo.If you want, I can give you the final
.mdcontents in the next message so it’s ready to drop intotasks/, or once Plan Mode is ended I can write it directly. - User
now do it please, add the folder to .gitignore
- Assistant
I’m creating a Markdown task doc from the agreed plan and wiring
tasks/into.gitignore. First I’m checking the current repo state so I don’t collide with an existing tasks convention or ignore entry. - Assistant
There’s a single repo-level
.gitignoreand no existingtasks/directory. I’m adding a newtasks/folder with one Markdown plan doc and appending atasks/ignore entry at the repo root. - Assistant
I found
tasks/is already ignored in the repo root.gitignore, so I’m leaving that unchanged and just adding the doc file under that folder. - Assistant
The task doc is written. I’m doing one quick readback so I can give you the exact path and confirm the ignore state without guessing.
- Assistant
Saved the doc at tasks/centralize-postflight-pipeline.md.
I did not change
.gitignorebecausetasks/was already present there at .gitignore#L42.