GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(recon): replace stub with claims and payout reconciliation engine by Ranjeet2063 · Pull Request #995 · Predictify-org/predictify-backend

Conversation

@Ranjeet2063

@Ranjeet2063 Ranjeet2063 commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

Replaced the stub reconciliation implementation with a production-ready Claims and Payout Reconciliation engine that compares on-chain Soroban contract claim events against database payout and prediction records.

Key Capabilities

  1. 6 Discrepancy Rules:

    • claimed_on_chain_missing_in_db: Event recorded on-chain but payout record missing from DB.
    • db_paid_missing_on_chain: DB records payout as settled but no corresponding on-chain claim exists.
    • amount_mismatch: Exact Stroop-level difference between on-chain claim amount and DB recorded payout amount.
    • claim_for_losing_prediction: Claim event references a prediction row whose resolved outcome is 'lost'.
    • duplicate_on_chain_claim: Multiple on-chain claim events emitted for the same prediction ID.
    • stale_unclaimed: Winning prediction unclaimed past configured grace period.
  2. Exact Stroop Arithmetic:

    • Implemented parseExactStroops and formatExactStroops using 7-decimal BigInt scaling to prevent floating-point inaccuracies.
  3. Database Persistence & Migrations:

    • Added tables reconciliation_reports and reconciliation_discrepancies with migration drizzle/0027_add_reconciliation_reports.sql.
    • Fingerprint deduplication (SHA-256) prevents redundant duplicate discrepancy records.
    • Keyset-paginated retrieval support for high throughput queries.
  4. Admin Endpoints & OpenAPI Contract:

    • GET /api/admin/reports (keyset pagination cursor, status filter, limit).
    • GET /api/admin/reports/:id (report metadata with joined discrepancies array).
    • Guarded by requireScopedAdmin(ADMIN_SCOPES.REPORT_READ).
    • OpenAPI schemas and contract invariants validated via npm run openapi:check.
  5. Worker & Observability Integration:

    • BullMQ reconciliationWorker updates Prometheus metrics: reconciliation_discrepancies_total{kind}.
    • Audit log emitted on discrepancy detection with context headers (x-request-id, x-correlation-id).
  6. Documentation:

    • Comprehensive operator runbook added to docs/runbook-reconciliation.md detailing severity classifications and step-by-step triage actions.

Verification & Test Evidence

  • Unit & Integration Tests: 49/49 tests passing across 4 suites:
    • tests/reconciliationPayouts.test.ts (26 tests covering all 11 issue scenarios + DB mock tests)
    • tests/reconciliationWorker.test.ts (6 tests)
    • tests/reconciliationService.test.ts
    • tests/adminReconciliation.test.ts (17 tests)
  • Memory Benchmark: Scenario 10 benchmark verified memory growth < 100 MB for 50,000 keys.
  • OpenAPI Validation: npm run openapi:check -> PASS.
  • DB Drift Validation: npm run db:check-drift -> PASS (0 schema drift).
  • TypeScript: Clean compilation with 0 errors.

Closes #980

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Copilot AI balanced review requested due to automatic review settings October 19, 2026 11:23
@drips-wave

drips-wave Bot commented Oct 19, 2026

Copy link
Copy Markdown

@Ranjeet2063 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Copilot AI reviewed Oct 19, 2026

Copilot AI left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Ranjeet2063
fix(recon): replace stub with claims and payout reconciliation engine
be2b5af
Implement full claims and payout reconciliation against Soroban smart contract events and database records.

- Implements 6 discrepancy rules: claimed_on_chain_missing_in_db, db_paid_missing_on_chain, amount_mismatch, claim_for_losing_prediction, duplicate_on_chain_claim, and stale_unclaimed
- Uses exact BigInt Stroop arithmetic (7 decimal places) avoiding float inaccuracies
- Adds reconciliation_reports and reconciliation_discrepancies tables with migration 0027
- Exposes keyset-paginated admin routes GET /api/admin/reports and GET /api/admin/reports/:id with OpenAPI registry & tests
- Updates reconciliationWorker with Prometheus metrics and audit logs
- Includes operator runbook and comprehensive unit test suite

Closes #980
@Ranjeet2063
Ranjeet2063 force-pushed the fix/payout-reconciliation branch from 8c34ad8 to be2b5af Compare October 22, 2026 06:08
@greatest0fallt1me
greatest0fallt1me merged commit d114e50 into Predictify-org:main Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

Copilot code review Copilot
Copilot review effort
Applies to this pull request for everyone.Learn more about Copilot code review.
Copilot left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Replace the always-green reconciliation stub with a claims and payout reconciliation that reports real discrepancies

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@Ranjeet2063 @greatest0fallt1me
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.