Skip to content

fix(referral): wrap LiquidityManagementModule import in forwardRef to break circular dependency#4220

Merged
Danswar merged 1 commit into
developfrom
fix/accounting-module-circular-dependency
Jul 15, 2026
Merged

fix(referral): wrap LiquidityManagementModule import in forwardRef to break circular dependency#4220
Danswar merged 1 commit into
developfrom
fix/accounting-module-circular-dependency

Conversation

@Danswar

@Danswar Danswar commented Jul 15, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • DEV has been crash-looping since PR Add append-only double-entry ledger (monitoring-only) #3880 (AccountingModule) landed: Nest cannot create the ReferralModule instance / The module at index [9] of the ReferralModule "imports" array is undefined, repeating on every restart attempt.
  • AccountingModule is now the first import in core.module.ts, and is the first thing to require LiquidityManagementModule. That require transitively re-enters ReferralModule (via LiquidityManagementModule -> BankModule -> UserModule -> ReferralModule) before LiquidityManagementModule's own file finishes exporting. ReferralModule's existing, unwrapped LiquidityManagementModule import then captures undefined at decorator-evaluation time — a classic CommonJS circular-require hazard, not a runtime bug.
  • Fix: wrap that one import in forwardRef(), matching the pattern ReferralModule already uses for its other circular deps (UserModule, TransactionModule) in the same file.

Verification

  • Reproduced locally: built dist/ off origin/develop unmodified and ran node dist/src/main.js — got the identical ReferralModule crash and scope trace seen in DEV logs.
  • Applied the one-line fix, rebuilt, reran — the DI crash is gone; bootstrap proceeds well past module instantiation (next failure is an unrelated missing local JWT secret, expected without env config).
  • npx jest --testPathPattern="(referral|liquidity-management|accounting)" — 36 suites / 738 tests passed.
  • Full suite via pre-push hook (build + all tests) passed: 237 suites / 4220 tests.

Test plan

  • Merge and confirm DEV's dfx-api container stops crash-looping / all Kuma DEV child monitors recover

… break circular dependency

AccountingModule (#3880) is now the first module in core.module.ts to
require LiquidityManagementModule, which transitively re-enters
ReferralModule (via BankModule -> UserModule) before finishing its own
export. ReferralModule's own unwrapped LiquidityManagementModule import
then captures undefined, crashing Nest bootstrap ("Nest cannot create
the ReferralModule instance") on every restart in DEV.
@Danswar Danswar merged commit 2931730 into develop Jul 15, 2026
7 checks passed
@Danswar Danswar deleted the fix/accounting-module-circular-dependency branch July 15, 2026 14:17
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