Skip to content

refactor(config): share plan writes with caller transactions - #888

Merged
cristim merged 1 commit into
mainfrom
refactor/631-plan-storage-tx
Oct 15, 2026
Merged

cristim merged 1 commit into
mainfrom
refactor/631-plan-storage-tx

Conversation

@cristim

@cristim cristim commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Plan creation and account replacement keep their existing wrapper behavior while sharing private SQL bodies that can use a caller's transaction. This lets the command store compose those writes without nesting transactions or escaping to the pool.

The change preserves the Create insert's 13 arguments, UUID and timestamp mutation, JSON encoding and errors. Account replacement retains its Begin/rollback/Commit boundaries, validation order, duplicate handling and errors. No exported transaction API, StoreInterface change, migration, route or atomic Save endpoint is included.

Validation at b71d7c1 (tree aa3e7b41274cd023e15a596dceb851ce1346d069):

  • Two independent source passes and exact staged-tree binding found no actionable issues. A fresh independent gpt-6.1-sol medium review of the committed SHA also found none, under the standing review-model decision.
  • Native PostgreSQL 17.11 with production migrations through 120: actual storage writes compose in one outer transaction, roll back together, and commit together. Duplicate plan insert returns 23505; account validation, empty replacement, frozen baseline, raw JSON and progress compatibility pass. These are real database tests with synthetic records, without provider purchases.
  • The parent wrapper adapter and a scratch mutation replacing only the supplied Create executor with the pool both fail the intended rollback assertion. The cold reviewer independently reproduced the mutation and restored all 1708 committed files byte-for-byte.
  • Full backend build, config race tests, repository-pinned golangci-lint 2.10.1 built with Go 1.26.9, and all applicable normal commit hooks pass.

Refs #631. This leaf does not complete or close the graph editor work. The next consumer is the creator-owned command store composing plan, associations, roots, cancellations, clock and receipt in one transaction.

Summary by CodeRabbit

  • Refactor
    • Purchase plan creation and account updates continue to support existing validation, duplicate handling, and transaction behavior.
    • Updating account associations preserves plan details and progress data. No user-facing behavior changes are expected.

@cristim cristim added priority/p2 Backlog-worthy urgency/this-sprint Within the current sprint impact/internal Team-internal only type/chore Maintenance / non-user-visible triaged Item has been triaged severity/low Minor harm effort/s Hours labels Oct 15, 2026
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: LeanerCloud/cloud-commitments-platform/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Essentials
  • Run ID: 0b3434b1-fddc-4e71-8255-c0374a678b7a
📥 Commits

Reviewing files that changed from the base of the PR and between 842ec35 and b71d7c1.

📒 Files selected for processing: 3
  • internal/config/store_postgres.go
  • internal/config/store_postgres_plan_writes.go
  • internal/config/store_postgres_plan_writes_integration_test.go

Included review availability: This review used your included allowance. 0 included reviews remain after this review. Your included PR review attempts over the past 7 days set your current allowance at 1 review per hour.

📝 Walkthrough

Plan creation and account association writes now use PostgreSQL helper functions. Integration tests cover transaction outcomes, duplicate plans, association validation, and preservation of plan data.

Changes: PostgreSQL Purchase Plan Writes

Layer / File(s) Summary
Plan creation
internal/config/store_postgres.go, internal/config/store_postgres_plan_writes.go, internal/config/store_postgres_plan_writes_integration_test.go
CreatePurchasePlan delegates ID assignment, timestamp handling, serialization, and insertion to createPurchasePlan. Integration tests check commit and rollback behavior and duplicate-plan errors.
Account association replacement
internal/config/store_postgres.go, internal/config/store_postgres_plan_writes.go, internal/config/store_postgres_plan_writes_integration_test.go
SetPlanAccounts delegates provider validation and association replacement to setPlanAccountsTx. Integration tests check deduplication, error handling, clearing associations, and preservation of plan data.

Priority: ⬇️ Low

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

Change: Refactor

Merge Risk: ⚪ Minimal · up to b71d7

No actionable issue remains identified for these plan and account-association writes; they are mergeable after normal checks.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: refactoring plan writes to support caller-managed transactions while retaining wrapper behavior.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
📝 Generate docstrings: 💡
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@cristim

cristim commented Oct 15, 2026

Copy link
Copy Markdown
Member Author

Merge verification: head remains b71d7c1, the independently reviewed tree aa3e7b41274cd023e15a596dceb851ce1346d069. Both workflow runs completed successfully, all reported checks are green, and GitHub reports CLEAN/MERGEABLE. CodeRabbit's actual review of this head reported no actionable comments; the inline comment list is empty.

Current main is 282c7e1. Its changes since the reviewed base touch separate tooling and ladder-provenance paths. The original plan wrappers, WithTx, provider validation, baseline code and shared native fixtures are byte-identical between those bases; the types.go delta only adds LadderTrancheDB provenance fields. The three PR files do not overlap those changes. The existing independent committed-SHA verification and scope limits in the PR description remain applicable. Normal squash merge uses the expected reviewed head and all active required checks.

@cristim
cristim merged commit 8386d48 into main Oct 15, 2026
25 checks passed
@cristim
cristim deleted the refactor/631-plan-storage-tx branch October 15, 2026 12:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/s Hours impact/internal Team-internal only priority/p2 Backlog-worthy severity/low Minor harm triaged Item has been triaged type/chore Maintenance / non-user-visible urgency/this-sprint Within the current sprint

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant