ENG-55: define payment schema tables and align obligations with SPEC 1.5#118
ENG-55: define payment schema tables and align obligations with SPEC 1.5#118Connorbelez merged 2 commits intomainfrom
Conversation
Add collectionPlanEntries, collectionRules, and collectionAttempts tables. Merge existing obligations table with SPEC 1.5 Section 9: add type union, amountSettled, sourceObligationId; change dueDate/gracePeriodEnd to timestamps; remove principalPortion/interestPortion. Register collectionAttempt as GT entity with placeholder machine (v0.1.0). Fix all downstream references. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Sorry @Connorbelez, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Connorbelez has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
Pull request overview
This PR evolves the obligations domain model to support payment rails work by moving obligation dates to unix timestamps, introducing obligation “type” + cumulative settlement tracking, expanding the Convex schema with collection/payment-rail tables, and wiring a new governed entity (collectionAttempt) into the transition engine.
Changes:
- Update
obligationsschema: addtype,amountSettled, timestamp-baseddueDate/gracePeriodEnd, new indexes; remove legacy portion/date fields. - Add new payment-rails tables (
collectionPlanEntries,collectionRules,collectionAttempts) and introduce a placeholdercollectionAttemptGT machine + engine typing/validation wiring. - Update obligation seeders/tests and deal-closing prorate logic/queries to use the new timestamp/index shape.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/test/convex/engine/obligation-effect.test.ts | Updates obligation test fixtures to new obligation fields (type, timestamp dates, amountSettled). |
| src/test/convex/engine/helpers.ts | Updates test seeding helper to write obligations using timestamp dates and amountSettled. |
| src/test/convex/engine/crossEntity.test.ts | Updates cross-entity test obligation inserts to new obligation shape. |
| convex/seed/seedObligationStates.ts | Updates seeding patch fields and obligation index name used for collection. |
| convex/seed/seedObligation.ts | Updates seeded obligation date handling to timestamps (noon UTC) and writes new obligation fields. |
| convex/schema.ts | Major schema changes: obligations remodel + new payment rails tables and indexes. |
| convex/obligations/queries.ts | Switches obligation boundary queries to numeric timestamps and new index name. |
| convex/engine/validators.ts | Extends entity type validator to include collectionAttempt. |
| convex/engine/types.ts | Extends entity types + governed entity types + table map for collectionAttempt. |
| convex/engine/machines/registry.ts | Registers the new collectionAttempt machine. |
| convex/engine/machines/collectionAttempt.machine.ts | Adds placeholder XState machine definition for collection attempts. |
| convex/engine/effects/obligation.ts | Updates payment-confirmed payload fallback to use amountSettled. |
| convex/engine/effects/dealClosingProrate.ts | Updates prorate logic to call timestamp-based obligation boundary queries and derive YYYY-MM-DD from timestamps. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const lastSettled = await ctx.runQuery( | ||
| internal.obligations.queries.getSettledBeforeDate, | ||
| { | ||
| mortgageId: deal.mortgageId, | ||
| beforeDate: closingDateStr, | ||
| beforeDate: deal.closingDate, |
| const nextObligation = await ctx.runQuery( | ||
| internal.obligations.queries.getFirstOnOrAfterDate, | ||
| { | ||
| mortgageId: deal.mortgageId, | ||
| onOrAfterDate: closingDateStr, | ||
| onOrAfterDate: deal.closingDate, | ||
| } |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@convex/engine/effects/obligation.ts`:
- Around line 55-57: The fallback for calculating amount incorrectly treats 0 as
falsy; update the fallback in the amount assignment so that when
isFiniteNumber(amountFromEvent) is false it uses obligation.amountSettled ??
obligation.amount (use nullish coalescing on obligation.amountSettled) instead
of obligation.amountSettled || obligation.amount to preserve zero values; locate
the assignment around the amount variable near isFiniteNumber(amountFromEvent)
and replace the OR fallback with ??.
In `@convex/engine/types.ts`:
- Around line 26-27: getEntityStatus in reconciliation.ts is missing a case for
the GovernedEntityType "collectionAttempt", causing governed collectionAttempt
rows to be treated as non-governed; add a case for "collectionAttempt" in the
switch inside getEntityStatus (placed after the existing "obligation" case and
before the non-governed entity types block) that applies the same
governed-reconciliation handling logic used for other governed types so
collectionAttempt rows use ENTITY_TABLE_MAP and follow the governed checks.
In `@convex/schema.ts`:
- Around line 520-533: Update the two obligation insert objects in the test that
create rows for the obligations table: remove the deprecated fields
principalPortion, interestPortion, gracePeriodEndDate, settledAmount, and
settledDate; add the required type field (e.g., "regular_interest" for regular
payment obligations); rename gracePeriodEndDate to gracePeriodEnd; and if you
track settlement, replace settledAmount with amountSettled and settledDate with
settledAt so the inserted objects match the obligations schema fields used by
the obligations table inserts in the test.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d3fe94a1-f927-4e77-8551-803c44efdf3a
📒 Files selected for processing (13)
convex/engine/effects/dealClosingProrate.tsconvex/engine/effects/obligation.tsconvex/engine/machines/collectionAttempt.machine.tsconvex/engine/machines/registry.tsconvex/engine/types.tsconvex/engine/validators.tsconvex/obligations/queries.tsconvex/schema.tsconvex/seed/seedObligation.tsconvex/seed/seedObligationStates.tssrc/test/convex/engine/crossEntity.test.tssrc/test/convex/engine/helpers.tssrc/test/convex/engine/obligation-effect.test.ts
- Fix || to ?? for amountSettled fallback in obligation effects (coderabbit) - Add collectionAttempt case to reconciliation.ts and reconciliationAction.ts (copilot + coderabbit) - Update stale obligation inserts in deal.integration.test.ts to new schema (copilot + coderabbit) - Fix getFirstOnOrAfterDate query to use v.number() and by_mortgage_and_date index Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…1.5 (#118) ## Add collection attempt infrastructure and update obligations schema Add collectionPlanEntries, collectionRules, and collectionAttempts tables to support payment collection workflows. Update obligations table to align with SPEC 1.5: add type union for obligation categories, replace settledAmount with amountSettled, add sourceObligationId for late fees, and convert date fields from strings to unix timestamps. Remove principalPortion and interestPortion fields. Register collectionAttempt as governed entity with placeholder state machine (v0.1.0). Update obligation queries to use by_mortgage_and_date index with timestamp parameters. Fix date handling in deal closing proration to properly convert between Date objects and ISO strings. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Added collection attempt tracking system for enhanced payment management * Introduced collection rules and plan entries framework for automated collection workflows * Expanded obligation types to include categorization support (regular interest, arrears cure, late fees, principal repayment) * **Improvements** * Enhanced date handling consistency across obligation tracking for improved calculation accuracy * Restructured obligation data model for better collection attempt linkage and settlement tracking <!-- end of auto-generated comment: release notes by coderabbit.ai -->

Add collection attempt infrastructure and update obligations schema
Add collectionPlanEntries, collectionRules, and collectionAttempts tables to support payment collection workflows. Update obligations table to align with SPEC 1.5: add type union for obligation categories, replace settledAmount with amountSettled, add sourceObligationId for late fees, and convert date fields from strings to unix timestamps. Remove principalPortion and interestPortion fields.
Register collectionAttempt as governed entity with placeholder state machine (v0.1.0). Update obligation queries to use by_mortgage_and_date index with timestamp parameters. Fix date handling in deal closing proration to properly convert between Date objects and ISO strings.
Summary by CodeRabbit
Release Notes
New Features
Improvements