Skip to content

feat: add resumable WebSocket streams with backfill tokens - #737

Merged
dDevAhmed merged 6 commits into
DigiNodes:mainfrom
Mikewaves7:security/issue-603-prewave-be-008-add-resumable-websocket-streams
Oct 21, 2026
Merged

dDevAhmed merged 6 commits into
DigiNodes:mainfrom
Mikewaves7:security/issue-603-prewave-be-008-add-resumable-websocket-streams

Conversation

@Mikewaves7

Copy link
Copy Markdown
Contributor

Overview

This PR adds versioned, resumable WebSocket stream envelopes with opaque resume tokens and bounded HTTP backfill for blockchain events. It introduces gap/duplicate/expiry/release-rollover detection, binds all chain-derived data to chain ID, release ID, deployment block, and artifact checksum, and requires clients to reconcile against canonical read models. Missing, stale, ambiguous, or wrong-release data fails closed.

Related Issue

Changes

🔁 Resumable Stream Envelopes

  • [MODIFY] src/blockchain/types.ts

    • Adds versioned stream envelope types carrying event ID, cursor, chain/release, block, freshness, and projection version.
    • Adds resume-token and backfill request/response types.
  • [MODIFY] src/blockchain/interfaces/blockchain-event.interface.ts

    • Extends the event interface with the fields required to build versioned envelopes (event ID, cursor, chain/release binding, block, freshness, projection version).
  • [MODIFY] src/blockchain/event-indexing.service.ts

    • Emits versioned envelopes over the stream.
    • Supports reconnect via opaque resume tokens and bounded HTTP backfill.
    • Detects gaps, duplicates, expired tokens, and release changes; fails closed on missing/stale/ambiguous/wrong-release data.
    • Backpressure and slow-consumer handling.
  • [MODIFY] src/blockchain/blockchain.controller.ts

    • Exposes the bounded backfill endpoint and resume-token reconnect path.
  • [MODIFY] src/blockchain/blockchain.module.ts

    • Wires the updated indexing service and controller dependencies.

🗄️ Persistence

  • [MODIFY] prisma/schema.prisma

    • Adds the processed-event model fields needed for cursor/resume-token tracking and duplicate-safe delivery.
  • [MODIFY] src/blockchain/entities/processed-event.entity.ts

    • Mirrors the schema changes on the entity (event ID, cursor, chain/release binding, block, freshness, projection version).

📄 Docs

  • [ADD] docs/FINALIZED_CURSOR.md
    • Documents envelope versioning, resume-token semantics, bounded backfill, duplicate-delivery safety, and the fail-closed canonical resync path.

Verification Results

npx prisma validate
✅ schema valid

npm run build
✅ compiles

npm test -- src/blockchain
✅ stream envelope, reconnect, backfill, gap/duplicate/expiry/rollover, and backpressure suites pass
Acceptance Criteria Status
Reconnect cannot silently lose updates ✅ Resume tokens + bounded backfill; gaps force canonical resync
Duplicate delivery is safe and documented ✅ Duplicate-safe cursor handling; documented in docs/FINALIZED_CURSOR.md
Expired/gapped streams force bounded canonical resync ✅ Expired-token and gap detection trigger bounded resync
Envelopes expose no protected payload ✅ Envelopes carry only event ID, cursor, chain/release, block, freshness, projection version

Closes #603

@Mikewaves7
Mikewaves7 requested a review from dDevAhmed as a code owner October 17, 2026 07:20
@coderabbitai

coderabbitai Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Repository: DigiNodes/truthbounty-api/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 6644f7d2-e0da-46bc-9275-e5a6a5ef0e21
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

@dDevAhmed

Copy link
Copy Markdown
Contributor

resolve conflicts @Mikewaves7

@dDevAhmed
dDevAhmed merged commit 041ccaf into DigiNodes:main Oct 21, 2026
1 check passed
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.

PREWAVE-BE-008 — Add Resumable WebSocket Streams With Backfill Tokens

2 participants