Skip to content

fix: resolve bigint timestamps and event upsert race conditions#965

Open
chizzy192 wants to merge 1 commit into
LabsCrypt:mainfrom
chizzy192:fix/issues-830-831
Open

fix: resolve bigint timestamps and event upsert race conditions#965
chizzy192 wants to merge 1 commit into
LabsCrypt:mainfrom
chizzy192:fix/issues-830-831

Conversation

@chizzy192

@chizzy192 chizzy192 commented Jun 30, 2026

Copy link
Copy Markdown

closes #830 closes #831

Description

This commit resolves two issues:

  1. Migrates time-valued fields (startTime, lastUpdateTime, endTime, pausedAt, StreamEvent.timestamp) from Int to BigInt to prevent 2038 overflow (and early overflow on long-duration streams).
  2. Prevents unique constraint / write-race collisions between action controllers and the indexer worker on StreamEvent records by using upsert in controllers, and conditional updates in the worker when a placeholder event exists.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • 🧪 Test addition or update

Related Issues

Closes #830
Closes #831

Changes Made

  • Modified backend/prisma/schema.prisma to change time columns to BigInt.
  • Added database migration bigint_timestamps.
  • Added global BigInt JSON serializer to backend/src/app.ts.
  • Updated ClaimableStreamState in claimable.service.ts and updated calculations to support bigint.
  • Modified withdraw, pause, resume controllers to use upsert and pass BigInt values.
  • Updated indexer worker event handlers to conditionally update ledgerSequence/timestamp on existing placeholder records.
  • Updated unit and integration tests to mock and expect upsert.
  • Fixed sunset/deprecated route tests.

Testing

  • Unit tests added/updated
  • Integration tests added/updated

Test Steps

  1. Run DATABASE_URL=postgresql://flowfi:flowfi_dev_password@127.0.0.1:5433/flowfi npm test

Description

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 📚 Documentation update
  • 🔧 Refactoring (no functional changes)
  • ⚡ Performance improvement
  • 🧪 Test addition or update

Related Issues

Closes #

Changes Made

Testing

Test Coverage

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed

Test Steps

Breaking Changes

Breaking Changes:

Migration Guide:

Screenshots/Demo

Checklist

  • My code follows the project's style guidelines
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published
  • I have checked for breaking changes and documented them if applicable

Additional Notes

## Description
This commit resolves two issues:
1. Migrates time-valued fields (startTime, lastUpdateTime, endTime, pausedAt, StreamEvent.timestamp) from Int to BigInt to prevent 2038 overflow (and early overflow on long-duration streams).
2. Prevents unique constraint / write-race collisions between action controllers and the indexer worker on `StreamEvent` records by using `upsert` in controllers, and conditional updates in the worker when a placeholder event exists.

## Type of Change
- [x] 🐛 Bug fix (non-breaking change which fixes an issue)
- [x] 🧪 Test addition or update

## Related Issues
Closes LabsCrypt#830
Closes LabsCrypt#831

## Changes Made
- Modified `backend/prisma/schema.prisma` to change time columns to BigInt.
- Added database migration `bigint_timestamps`.
- Added global BigInt JSON serializer to `backend/src/app.ts`.
- Updated `ClaimableStreamState` in `claimable.service.ts` and updated calculations to support bigint.
- Modified withdraw, pause, resume controllers to use `upsert` and pass BigInt values.
- Updated indexer worker event handlers to conditionally update ledgerSequence/timestamp on existing placeholder records.
- Updated unit and integration tests to mock and expect `upsert`.
- Fixed sunset/deprecated route tests.

## Testing
- [x] Unit tests added/updated
- [x] Integration tests added/updated

### Test Steps
1. Run `DATABASE_URL=postgresql://flowfi:flowfi_dev_password@127.0.0.1:5433/flowfi npm test`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant