Skip to content

ENG-55: define payment schema tables and align obligations with SPEC 1.5#118

Merged
Connorbelez merged 2 commits intomainfrom
Connorbelez/eng-55-payment-schema
Mar 18, 2026
Merged

ENG-55: define payment schema tables and align obligations with SPEC 1.5#118
Connorbelez merged 2 commits intomainfrom
Connorbelez/eng-55-payment-schema

Conversation

@Connorbelez
Copy link
Copy Markdown
Owner

@Connorbelez Connorbelez commented Mar 18, 2026

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

    • 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

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>
@linear
Copy link
Copy Markdown

linear bot commented Mar 18, 2026

Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @Connorbelez, you have reached your weekly rate limit of 500000 diff characters.

Please try again later or upgrade to continue using Sourcery

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 18, 2026

Warning

Rate limit exceeded

@Connorbelez has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 21 minutes and 52 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4cfc03fc-e356-40c3-8b2e-ffdacabeb594

📥 Commits

Reviewing files that changed from the base of the PR and between adf47d6 and 04558e9.

📒 Files selected for processing (4)
  • convex/engine/effects/obligation.ts
  • convex/engine/reconciliation.ts
  • convex/engine/reconciliationAction.ts
  • convex/machines/__tests__/deal.integration.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch Connorbelez/eng-55-payment-schema
📝 Coding Plan
  • Generate coding plan for human review comments

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.

❤️ Share

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

Copy link
Copy Markdown
Owner Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@Connorbelez Connorbelez marked this pull request as ready for review March 18, 2026 06:25
Copilot AI review requested due to automatic review settings March 18, 2026 06:25
Copy link
Copy Markdown

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Connorbelez has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 obligations schema: add type, amountSettled, timestamp-based dueDate/gracePeriodEnd, new indexes; remove legacy portion/date fields.
  • Add new payment-rails tables (collectionPlanEntries, collectionRules, collectionAttempts) and introduce a placeholder collectionAttempt GT 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.

Comment thread convex/schema.ts
Comment on lines 80 to +84
const lastSettled = await ctx.runQuery(
internal.obligations.queries.getSettledBeforeDate,
{
mortgageId: deal.mortgageId,
beforeDate: closingDateStr,
beforeDate: deal.closingDate,
Comment on lines 93 to 98
const nextObligation = await ctx.runQuery(
internal.obligations.queries.getFirstOnOrAfterDate,
{
mortgageId: deal.mortgageId,
onOrAfterDate: closingDateStr,
onOrAfterDate: deal.closingDate,
}
Comment thread convex/engine/types.ts
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 707bc9c and adf47d6.

📒 Files selected for processing (13)
  • convex/engine/effects/dealClosingProrate.ts
  • convex/engine/effects/obligation.ts
  • convex/engine/machines/collectionAttempt.machine.ts
  • convex/engine/machines/registry.ts
  • convex/engine/types.ts
  • convex/engine/validators.ts
  • convex/obligations/queries.ts
  • convex/schema.ts
  • convex/seed/seedObligation.ts
  • convex/seed/seedObligationStates.ts
  • src/test/convex/engine/crossEntity.test.ts
  • src/test/convex/engine/helpers.ts
  • src/test/convex/engine/obligation-effect.test.ts

Comment thread convex/engine/effects/obligation.ts Outdated
Comment thread convex/engine/types.ts
Comment thread convex/schema.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>
@Connorbelez Connorbelez merged commit 456a1d8 into main Mar 18, 2026
1 of 3 checks passed
Connorbelez added a commit that referenced this pull request Apr 20, 2026
…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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants