Skip to content

BCH-1158: Cascade soft-delete to step evidence and workflow execution…#406

Merged
saltpy-cs merged 4 commits into
mainfrom
fix/BCH-1158
May 27, 2026
Merged

BCH-1158: Cascade soft-delete to step evidence and workflow execution…#406
saltpy-cs merged 4 commits into
mainfrom
fix/BCH-1158

Conversation

@saltpy-cs
Copy link
Copy Markdown
Contributor

@saltpy-cs saltpy-cs commented May 27, 2026

…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.

Summary by CodeRabbit

  • Bug Fixes

    • Workflow instance deletion now runs as a single transaction that reliably soft-deletes only open step executions and their evidence while preserving closed step data; all related workflow executions are also soft-deleted.
    • Assigned-step queries now consistently use the centralized definition of "open" step statuses.
  • Tests

    • Added tests verifying soft-delete behavior for open step executions, their evidence, and workflow executions.

Review Change Stack

…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>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: c7ed9cd8-50f1-4f74-ab42-96b2275ba27a

📥 Commits

Reviewing files that changed from the base of the PR and between ea97701 and 7e651b0.

📒 Files selected for processing (3)
  • internal/service/relational/workflows/constants.go
  • internal/service/relational/workflows/step_execution_service.go
  • internal/service/relational/workflows/workflow_instance_service.go

📝 Walkthrough

Walkthrough

Cascade 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.

Changes

Workflow Instance Cascade Deletion

Layer / File(s) Summary
Define open step statuses constant
internal/service/relational/workflows/constants.go
New unexported openStepStatuses and exported OpenStepStatuses() returning a defensive copy of non-terminal statuses: pending, blocked, in_progress, overdue.
Apply constant to step queries
internal/service/relational/workflows/step_execution_service.go
GetAssignedSteps now filters by status IN OpenStepStatuses() instead of a hard-coded status list.
Implement cascade delete in Delete method
internal/service/relational/workflows/workflow_instance_service.go
WorkflowInstanceService.Delete now runs in a DB transaction: selects workflow execution IDs, plucks open step execution IDs (using OpenStepStatuses()), deletes step evidence for those IDs, deletes open step executions, deletes workflow executions for the instance, then soft-deletes the WorkflowInstance via a transaction-scoped BaseService.
Test cascade delete behavior
internal/service/relational/workflows/workflow_instance_service_test.go
Three tests added asserting: open step executions are soft-deleted while closed remain, all workflow executions for the instance are soft-deleted, and evidence for open steps is soft-deleted while evidence for closed steps is preserved.

Sequence Diagram

sequenceDiagram
  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
Loading

🎯 3 (Moderate) | ⏱️ ~20 minutes

A rabbit hops through the cascade,
Deleting steps both swift and vast,
Open states are put to rest,
Transactions hold the past,
Soft-deletes settle at last. 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: cascading soft-delete behavior to step evidence and workflow executions when deleting a WorkflowInstance, which is the primary objective of the PR.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

Comment thread internal/service/relational/workflows/workflow_instance_service.go Outdated
Comment thread internal/service/relational/workflows/workflow_instance_service.go Outdated
- 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>
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between e2da7ff and ea97701.

📒 Files selected for processing (4)
  • internal/service/relational/workflows/constants.go
  • internal/service/relational/workflows/step_execution_service.go
  • internal/service/relational/workflows/workflow_instance_service.go
  • internal/service/relational/workflows/workflow_instance_service_test.go

Comment thread internal/service/relational/workflows/constants.go Outdated
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>
@saltpy-cs saltpy-cs merged commit d1e9687 into main May 27, 2026
5 checks passed
@saltpy-cs saltpy-cs deleted the fix/BCH-1158 branch May 27, 2026 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants