Skip to content

fix: resolve undefined prisma.eventOutbox in outbox relayer - #1497

Merged
Junirezz merged 2 commits into
Junirezz:mainfrom
taiwo722-blip:fix/issue-1370-outbox-relayer-references-undefined-prisma
Oct 3, 2026
Merged

Junirezz merged 2 commits into
Junirezz:mainfrom
taiwo722-blip:fix/issue-1370-outbox-relayer-references-undefined-prisma

Conversation

@taiwo722-blip

Copy link
Copy Markdown
Contributor

Overview

This PR fixes a runtime fragility where prisma.eventOutbox resolved to undefined in certain execution paths of the outbox relayer, causing Cannot read properties of undefined (reading 'create') errors during governance test runs. The root cause was inconsistent Prisma client initialization/import paths across the backend modules, which allowed the relayer to reference an uninitialized or differently-instantiated client under load. This change consolidates client initialization and ensures eventOutbox.ts always resolves the shared, initialized Prisma client.

Related Issue

Changes

🔧 Prisma Client Initialization

  • [MODIFY] backend/src/prisma.ts

    • Ensures the Prisma client is instantiated once and exported as a stable singleton, so all consumers (including the outbox relayer) resolve the same initialized instance.
  • [MODIFY] backend/src/prismaClient.ts

    • Aligns the client accessor with the singleton in prisma.ts, removing the divergent initialization path that could yield an undefined eventOutbox delegate.
  • [MODIFY] backend/src/database.ts

    • Routes database access through the shared client so no module constructs or imports a separate/uninitialized Prisma instance.

📤 Outbox Relayer

  • [MODIFY] backend/src/eventOutbox.ts
    • References the shared, initialized Prisma client instead of a path that could resolve eventOutbox to undefined, so prisma.eventOutbox.create is always defined when writing events.

Verification Results

npm test -- eventOutbox.test.ts
✅ eventOutbox.test.ts passes

The governance test path that previously logged "Failed to write event to outbox" with Cannot read properties of undefined (reading 'create') now resolves prisma.eventOutbox.create correctly, since all modules share the same initialized client.

Acceptance Criteria Status
prisma.eventOutbox.create is defined in all runtime paths ✅ Shared initialized client used across prisma.ts, prismaClient.ts, database.ts, and eventOutbox.ts
Outbox relayer no longer throws Cannot read properties of undefined (reading 'create') ✅ Relayer references the consolidated client
eventOutbox.test.ts continues to pass ✅ Existing test suite passes
Prisma client initialization is consistent under load ✅ Single singleton client, no divergent import paths

Closes #1370

@drips-wave

drips-wave Bot commented Sep 29, 2026

Copy link
Copy Markdown

@taiwo722-blip 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

@Junirezz
Junirezz merged commit 13c656a into Junirezz:main Oct 3, 2026
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.

Outbox relayer references undefined prisma.eventOutbox under certain runtime paths

2 participants