BCH-1158: Cascade soft-delete to step evidence and workflow execution…#406
Conversation
…s on instance deletion When deleting a WorkflowInstance, the transaction now also soft-deletes: - StepEvidence for open step executions (so orphaned evidence no longer appears in the evidence view) - All WorkflowExecution records belonging to the instance (so the empty execution link is no longer navigable) Open step executions (pending, blocked, in_progress, overdue) are removed. Closed step executions (completed, failed, skipped) and their evidence are preserved to retain the audit trail. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughCascade deletion for WorkflowInstance now runs inside a DB transaction, uses a shared OpenStepStatuses() definition for non-terminal step states, updates step queries to use that definition, and adds tests verifying soft-delete behavior for related records. ChangesWorkflow Instance Cascade Deletion
Sequence DiagramsequenceDiagram
participant Caller as Service.Delete(instance.ID)
participant DB as DB.Transaction
participant Query as WorkflowExecutionQuery
participant StepExec as StepExecution
participant Evidence as StepEvidence
participant WFExec as WorkflowExecution
participant Base as BaseService
Caller->>DB: Begin transaction
DB->>Query: Select WorkflowExecution IDs for instance
DB->>StepExec: Pluck open StepExecution IDs (OpenStepStatuses)
DB->>Evidence: Delete StepEvidence for plucked StepExecution IDs
DB->>StepExec: Delete open StepExecution rows for instance executions
DB->>WFExec: Delete WorkflowExecution rows for instance
DB->>Base: BaseService.DeleteEntity(tx).Delete WorkflowInstance (soft-delete)
DB->>Caller: Commit transaction
🎯 3 (Moderate) | ⏱️ ~20 minutes
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
- Extract OpenStepStatuses package var to constants.go to avoid drift across codebase queries (workflow_instance_service, step_execution_service) - Use NewBaseService(tx).DeleteEntity for instance soft-delete inside the transaction instead of inline result/RowsAffected check Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/service/relational/workflows/constants.go`:
- Around line 147-154: OpenStepStatuses is currently an exported mutable slice;
replace it with an unexported immutable backing slice (e.g., openStepStatuses :=
[]string{string(StepStatusPending), ...}) and expose a function
OpenStepStatuses() []string that returns a copy (e.g., append([]string(nil),
openStepStatuses...)) so callers get a safe copy and cannot mutate package
state; update any usages that treat OpenStepStatuses as a value to call the
function instead.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: ddf79ce4-ae63-43af-a479-46e3122ef740
📒 Files selected for processing (4)
internal/service/relational/workflows/constants.gointernal/service/relational/workflows/step_execution_service.gointernal/service/relational/workflows/workflow_instance_service.gointernal/service/relational/workflows/workflow_instance_service_test.go
Replace exported mutable slice with an unexported backing var and a copy-returning accessor function to prevent callers from accidentally mutating shared query state at runtime. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…s on instance deletion
When deleting a WorkflowInstance, the transaction now also soft-deletes:
Open step executions (pending, blocked, in_progress, overdue) are removed. Closed step executions (completed, failed, skipped) and their evidence are preserved to retain the audit trail.
Summary by CodeRabbit
Bug Fixes
Tests