Skip to content

fix(db): write canonical 'canceled' on all cancel paths + cleanup filter (follow-up to #1277)#1453

Open
cristim wants to merge 1 commit into
mainfrom
fix/1277-followup-canonical-cancel-writes
Open

fix(db): write canonical 'canceled' on all cancel paths + cleanup filter (follow-up to #1277)#1453
cristim wants to merge 1 commit into
mainfrom
fix/1277-followup-canonical-cancel-writes

Conversation

@cristim

@cristim cristim commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

Follow-up to #1277 (expand-contract rename 'cancelled'->'canceled'). Three categories of defects verified on current main and fixed.

Defect 1 (medium, latent deploy trap): Every cancel write path still emitted status='cancelled' and wrote cancelled_by instead of the canonical status='canceled' / canceled_by. If the contract migration #1278 narrows the CHECK to drop 'cancelled' before these writers switch, every session/RI-exchange cancel path fails with check_violation (SQLSTATE 23514).

Paths fixed:

  • store_postgres.go: CancelExecutionAtomic, CancelScheduledExecutionAtomic - now write status=StatusCanceled via $3 param and canceled_by column
  • store_postgres.go: CancelAllPendingExchanges, CancelPendingExchangesByOrigin (both branches) - now write status=StatusCanceled via $1 param
  • handler_ri_exchange.go rejectRIExchange (~line 1372) - uses config.StatusCanceled for TransitionRIExchangeStatus call and response body

Defect 2 (low, silent cleanup miss): CleanupOldExecutions filtered status IN ('completed', 'cancelled') - omitting 'canceled', so rows written by new code after #1277 would never be terminal-cleaned.

Fixed: added 'canceled' to the IN clause; updated godoc comment.

Regression tests added

8 new pgxmock tests in store_postgres_pgxmock_test.go:

  • TestPGXMock_CancelExecutionAtomic_WritesCanonicalStatus - asserts $3=StatusCanceled and canceled_by column
  • TestPGXMock_CancelScheduledExecutionAtomic_WritesCanonicalStatus - same for scheduled path
  • TestPGXMock_CancelAllPendingExchanges_WritesCanonicalStatus - asserts $1=StatusCanceled
  • TestPGXMock_CancelPendingExchangesByOrigin_Standalone_WritesCanonicalStatus
  • TestPGXMock_CancelPendingExchangesByOrigin_Ladder_WritesCanonicalStatus
  • TestPGXMock_CleanupOldExecutions_IncludesCanonicalStatus - regex pins both 'cancelled' and 'canceled' in SQL

4 existing tests updated to reflect the canonical spelling (were asserting "cancelled" as the transition target).

Test plan

  • go build ./... clean
  • go vet ./internal/config/... ./internal/api/... clean
  • go test ./internal/config/... - 650 passed
  • go test ./internal/api/... - 1767 passed
  • go test ./internal/... - 5020 passed in 24 packages
  • CI green
  • @coderabbitai review

@coderabbitai review

@cristim cristim added triaged Item has been triaged priority/p2 Backlog-worthy severity/medium Moderate harm urgency/this-sprint Within the current sprint impact/many Affects most users effort/m Days type/bug Defect labels Jul 17, 2026
@coderabbitai

coderabbitai Bot commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 50 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1bc6fd18-e05f-4344-ad67-9a75653a3ff0

📥 Commits

Reviewing files that changed from the base of the PR and between 1d9f1b8 and fa6ae3f.

📒 Files selected for processing (6)
  • internal/api/coverage_extras_test.go
  • internal/api/handler_ri_exchange.go
  • internal/api/handler_ri_exchange_test.go
  • internal/api/router_handlers_test.go
  • internal/config/store_postgres.go
  • internal/config/store_postgres_pgxmock_test.go
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/1277-followup-canonical-cancel-writes

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

All cancel write paths (CancelExecutionAtomic, CancelScheduledExecutionAtomic,
CancelAllPendingExchanges, CancelPendingExchangesByOrigin) were still emitting
status='cancelled' and the old cancelled_by column after PR #1277 added the
expand-contract rename. TransitionRIExchangeStatus in handler_ri_exchange.go
also used the legacy spelling. If #1278 narrows the CHECK before these writers
switch, every cancel path fails with check_violation (SQLSTATE 23514).

CleanupOldExecutions filtered only 'cancelled', so rows written by new code
with status='canceled' were never terminal-cleaned.

Fixes:
- Switch all cancel SQL writes to StatusCanceled ("canceled") via $N params
- Use canceled_by column in CancelExecutionAtomic + CancelScheduledExecutionAtomic
- Add 'canceled' to CleanupOldExecutions terminal-status IN clause
- Use config.StatusCanceled in rejectRIExchange handler (line ~1372 + response)
- Add 8 pgxmock regression tests asserting canonical spelling per path
- Update 4 test mocks that hard-coded "cancelled" as the reject-transition arg
@cristim
cristim force-pushed the fix/1277-followup-canonical-cancel-writes branch from 97a1378 to fa6ae3f Compare July 17, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/m Days impact/many Affects most users priority/p2 Backlog-worthy severity/medium Moderate 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