feat(events): enrich PLAN_CANCELLED event with progress and resource cleanup context #1301

Merged
freemo merged 1 commits from feature/m6-plan-cancelled-enrichment into master 2026-04-02 17:07:42 +00:00

1 Commits

Author SHA1 Message Date
freemo 6efbd4f7d2 feat(events): enrich PLAN_CANCELLED event with progress and resource cleanup context
CI / lint (pull_request) Failing after 2s
CI / typecheck (pull_request) Failing after 1s
CI / coverage (pull_request) Has been skipped
CI / security (pull_request) Failing after 1s
CI / quality (pull_request) Failing after 1s
CI / integration_tests (pull_request) Failing after 2s
CI / e2e_tests (pull_request) Failing after 2s
CI / build (pull_request) Failing after 1s
CI / helm (pull_request) Failing after 2s
CI / unit_tests (pull_request) Successful in 6m19s
CI / docker (pull_request) Has been skipped
CI / status-check (pull_request) Failing after 1s
CI / benchmark-publish (pull_request) Has been skipped
CI / benchmark-regression (pull_request) Has been skipped
Enriches the PLAN_CANCELLED domain event emitted by PlanLifecycleService.cancel_plan()
with additional context fields to improve audit trail quality (SEC7 Audit Logging).

Progress context fields added to event details:
- cancelled_phase: the plan phase at the moment of cancellation (e.g. 'strategize')
- cancelled_processing_state: the processing state at cancellation (e.g. 'queued')
- last_completed_step: index of the last successfully completed step (-1 if none)
- subplan_count: number of spawned subplans at cancellation time

Resource cleanup context fields added to event details:
- sandbox_refs: list of active sandbox reference IDs requiring cleanup
- changeset_id: ID of any in-progress changeset that needs cleanup
- resources_pending_cleanup: count of sandbox refs pending cleanup

Existing fields (reason, project_names) are preserved for backward compatibility.
Progress context is captured before the plan state is mutated to CANCELLED so the
event accurately reflects the state at the moment of cancellation.

BDD tests added in features/plan_cancelled_enrichment.feature covering:
- All new progress context fields present in event details
- All new resource cleanup context fields present in event details
- Cancellation reason field (explicit and default empty string)
- Accurate field values (phase, step, sandbox refs count)
- Backward compatibility of existing fields

Closes #717
2026-04-02 09:27:00 +00:00