Skip to content

fix(api): COALESCE cancel actor across canceled_by/cancelled_by - #1490

Merged
cristim merged 1 commit into
mainfrom
fix/1277-coalesce-cancelled-by-readside
Jul 22, 2026
Merged

cristim merged 1 commit into
mainfrom
fix/1277-coalesce-cancelled-by-readside

Conversation

@cristim

@cristim cristim commented Jul 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Cancel-actor attribution silently drops from the Purchase History UI whenever the cancelling actor was written to the newer canceled_by column but not the legacy cancelled_by one.

PR #1277 (expand-contract migration 000089) and its follow-up #1453 moved cancel-attribution writes to the canonical canceled_by column, but every SELECT in internal/config/store_postgres.go still projected the bare legacy cancelled_by column. CancelExecutionAtomic / CancelScheduledExecutionAtomic write only canceled_by, so any execution cancelled through those paths scanned back with cancelled_by = NULL and the History page lost the actor.

Fix

Test plan

  • go build ./...
  • go vet ./...
  • go test ./internal/api/... ./internal/config/...
  • golangci-lint run (CI-pinned v2.10.1)
  • gocyclo -over 10 on changed files
  • New pgxmock regression test (TestPGXMock_GetExecutionByID_ProjectsCoalescedCancelledBy) confirmed to FAIL against the pre-fix query (mock's regexp match on COALESCE(...) doesn't match the bare cancelled_by projection, so the query returns no rows) and PASS post-fix

Relates to #1277, #1453.

Summary by CodeRabbit

  • Bug Fixes

    • Cancellation attribution is now saved and displayed consistently across current and legacy records.
    • Execution history and scheduled execution views correctly show who canceled an execution.
    • Cancellation status documentation now accurately reflects the transition to “canceled.”
  • Tests

    • Added coverage to verify cancellation details are returned correctly when stored in the current cancellation field.

…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.
@cristim cristim added triaged Item has been triaged priority/p1 Next up; this sprint severity/high Significant harm urgency/this-sprint Within the current sprint impact/many Affects most users type/bug Defect labels Jul 22, 2026
@cristim

cristim commented Jul 22, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

No new commits to review since the last review.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 9fe53bdf-14a1-4f5c-82f5-1fe7cdef039a

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Cancellation attribution now writes both current and legacy columns, while all purchase-execution readers coalesce those values. Cancellation documentation uses the canceled status spelling, and a pgxmock test covers direct execution lookup.

Changes

Cancellation attribution compatibility

Layer / File(s) Summary
Cancellation status and attribution contracts
internal/api/handler_purchases_revoke.go, internal/config/interfaces.go
Documentation now uses canceled for cancellation transitions and describes stamping both attribution columns.
Cancellation attribution storage and reads
internal/config/store_postgres.go, internal/config/store_postgres_pgxmock_test.go
SetCancelledBy updates both columns, readers use COALESCE(canceled_by, cancelled_by), and a pgxmock test verifies populated attribution.

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

  • LeanerCloud/CUDly#1255: Both modify SQL projections for planned execution reads and related pgxmock coverage.
  • LeanerCloud/CUDly#1277: Both align cancellation spelling and support current/legacy cancellation attribution fields.

Suggested labels: effort/m

🚥 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 clearly summarizes the main change: coalescing cancel-actor attribution across the canonical and legacy columns.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1277-coalesce-cancelled-by-readside

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

@coderabbitai coderabbitai Bot left a comment •

Copy link
Copy Markdown
Contributor

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/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

📥 Commits

Reviewing files that changed from the base of the PR and between 1cc33d3 and 662472a.

📒 Files selected for processing (4)
  • internal/api/handler_purchases_revoke.go
  • internal/config/interfaces.go
  • internal/config/store_postgres.go
  • internal/config/store_postgres_pgxmock_test.go

Comment thread internal/config/store_postgres.go
@coderabbitai

coderabbitai Bot commented Jul 22, 2026 •

Copy link
Copy Markdown
Contributor

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.

@cristim
cristim merged commit 70c9a7b into main Jul 22, 2026
19 checks passed
@cristim
cristim deleted the fix/1277-coalesce-cancelled-by-readside branch July 27, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact/many Affects most users priority/p1 Next up; this sprint severity/high Significant harm triaged Item has been triaged type/bug Defect urgency/this-sprint Within the current sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant