Commit 474f188
fix(audit): bundling-safe CLI guard in apply-triggers (stop worker crash-loop) (#469)
`require.main === module` is unreliable once apply-triggers.ts is bundled: esbuild inlines
it into dist/workers/auditLogWorker.js, where `require.main === module` evaluates TRUE for the
bundle entry. That ran the apply-triggers CLI main() inside the audit-log worker, which connected
to the worker's placeholder DATABASE_URL (localhost:5432), hit ECONNREFUSED, and process.exit(1) —
crash-looping the worker so the audit-logs queue stopped draining and Loop B materialization
stalled. (The Next/webpack web build was unaffected, so the web canary passed.)
Gate the CLI on the process entry-script path instead: argv[1] contains "apply-triggers" only when
invoked directly (tsx scripts/apply-triggers.ts), never when bundled into the worker or the Next
server. applyAuditTriggers() remains a side-effect-free import for the boot hooks.
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>1 parent 33b0dab commit 474f188
1 file changed
Lines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
358 | | - | |
359 | | - | |
360 | | - | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
361 | 366 | | |
362 | 367 | | |
363 | 368 | | |
| |||
0 commit comments