Repository navigation
fix(api): COALESCE cancel actor across canceled_by/cancelled_by - #1490
Conversation
…ad paths Migration 000089 (PR #1277) and its follow-up (PR #1453) moved cancel attribution writes to the new canonical canceled_by column, but every SELECT path in store_postgres.go still projected the bare legacy cancelled_by column. A cancel actor written only to canceled_by (the CancelExecutionAtomic / CancelScheduledExecutionAtomic paths) scanned back as NULL, silently dropping the actor from the History UI. Fix every read path to project COALESCE(canceled_by, cancelled_by) AS cancelled_by so a row written by either column is attributed correctly, and make SetCancelledBy write both columns so it stays symmetric with the atomic-cancel paths ahead of the planned contract migration (#1278) that drops the legacy column. Adds a pgxmock regression test asserting the projection; confirmed it fails against the pre-fix query (mock returns no rows because the issued SQL lacks the COALESCE expression) and passes post-fix. Relates to #1277, #1453.
|
@coderabbitai review |
✅ Action performedReview finished.
|
|
Important Review skippedNo new commits to review since the last review. ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughCancellation attribution now writes both current and legacy columns, while all purchase-execution readers coalesce those values. Cancellation documentation uses the ChangesCancellation attribution compatibility
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
Suggested labels: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
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/config/store_postgres.go`:
- Around line 1043-1047: Update PostgresStore.SetCancelledBy to append the
cancellation-attribution event instead of directly executing the
purchase_executions UPDATE. Add or reuse the event projection handler to set
both canceled_by and cancelled_by compatibility columns, ensuring the event
stream is the source of truth for this state change.
🪄 Autofix (Beta)
❌ Autofix failed (check again to retry)
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: defaults
Review profile: CHILL
Plan: Pro
Run ID: 04d84b85-0e72-4f1d-ab90-0536b9a33df0
📒 Files selected for processing (4)
internal/api/handler_purchases_revoke.gointernal/config/interfaces.gointernal/config/store_postgres.gointernal/config/store_postgres_pgxmock_test.go
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. The agent ran but didn't make any changes. The issues may already be fixed or require manual intervention. |
Summary
Cancel-actor attribution silently drops from the Purchase History UI whenever the cancelling actor was written to the newer
canceled_bycolumn but not the legacycancelled_byone.PR #1277 (expand-contract migration 000089) and its follow-up #1453 moved cancel-attribution writes to the canonical
canceled_bycolumn, but every SELECT ininternal/config/store_postgres.gostill projected the bare legacycancelled_bycolumn.CancelExecutionAtomic/CancelScheduledExecutionAtomicwrite onlycanceled_by, so any execution cancelled through those paths scanned back withcancelled_by = NULLand the History page lost the actor.Fix
GetExecutionsByStatuses,GetPlannedExecutions,GetStaleApprovedExecutions,ListStuckExecutions,GetPendingExecutions,GetPendingExecutionsTx,GetExecutionByID,GetExecutionByPlanAndDate,GetScheduledExecutionsDue) now projectsCOALESCE(canceled_by, cancelled_by) AS cancelled_by, so a row written by either column round-trips correctly.SetCancelledBynow writes bothcanceled_byand the legacycancelled_bycolumn, keeping it symmetric with the atomic-cancel paths ahead of the planned contract migration (#1278) that drops the legacy column.interfaces.goandhandler_purchases_revoke.goupdate stale'cancelled'references to the canonical'canceled'(US spelling) status value used since fix(db): rename status value cancelled->canceled (expand-contract, US spelling) #1277/fix(db): write canonical 'canceled' on all cancel paths + cleanup filter (follow-up to #1277) #1453.Test plan
go build ./...go vet ./...go test ./internal/api/... ./internal/config/...golangci-lint run(CI-pinned v2.10.1)gocyclo -over 10on changed filesTestPGXMock_GetExecutionByID_ProjectsCoalescedCancelledBy) confirmed to FAIL against the pre-fix query (mock's regexp match onCOALESCE(...)doesn't match the barecancelled_byprojection, so the query returns no rows) and PASS post-fixRelates to #1277, #1453.
Summary by CodeRabbit
Bug Fixes
Tests