[object Object]

← back to Costa Rica

cycle 17 docs: YOLO_NOTES ledger — pool consolidation + explicit max, crash-on-idle fix

cb24e9d04211d33bebd973e98e37587df41897a6 · 2026-09-24 00:16:38 -0700 · Steve

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

Claude-Session: https://claude.ai/code/session_01TouFkmUGKHtwqpZwgReVic

Files touched

Diff

commit cb24e9d04211d33bebd973e98e37587df41897a6
Author: Steve <steve@designerwallcoverings.com>
Date:   Thu Sep 24 00:16:38 2026 -0700

    cycle 17 docs: YOLO_NOTES ledger — pool consolidation + explicit max, crash-on-idle fix
    
    Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
    
    Claude-Session: https://claude.ai/code/session_01TouFkmUGKHtwqpZwgReVic
---
 YOLO_NOTES.md | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/YOLO_NOTES.md b/YOLO_NOTES.md
index 53f60b9..0a11eb1 100644
--- a/YOLO_NOTES.md
+++ b/YOLO_NOTES.md
@@ -392,3 +392,19 @@ Canonical apply order now: `004_marketplace → 005_apple → 006_contacts → 0
 **Cost:** $0 (local + one Cody pass — which read pm2's source and ran a live fork-mode probe to prove the boot path rather than trust the grep).
 
 **Backlog:** **NEW follow-up (Cody root-cause):** server.js duplicates `lib/db`'s "single shared" pool instead of requiring it — consolidate to one pool (the test-hang was just the first symptom). Plus: approval-enforcement decision on Steve's desk; provider-honored idempotency key + sig-encoding (live-only); processorFee schema prerequisite; per-event webhook auto-reply try/catch. Next cycle: the pool consolidation, more inline-route coverage now that they're testable, or another fresh Cody audit.
+
+## /yoloforever CYCLE 17 (2026-09-24, yf-costa) — pool consolidation (Cody cycle-16 root cause)
+
+**Fixed the root cause Cody flagged in cycle 16:** server.js created its OWN `new Pool(...)` separate from `lib/db.js`'s "single shared" pool — the running server held TWO connection pools against one DB. Now `server.js` does `const { pool } = require('./lib/db')`; dropped the duplicate `new Pool` + the unused `{ Pool } = require('pg')`. All 35 inline `pool.query()` sites unchanged; `app.locals.pool === lib/db.pool` (verified true).
+
+**Strictly better, not just cleanup (Cody verified empirically):** server.js's old private pool had NO `pool.on('error')` handler; lib/db's has one. A node-pg Pool that emits `'error'` (idle-client disconnect / DB restart blip) with no listener throws as an **uncaughtException** — NOT caught by the cycle-10 `unhandledRejection` net (wrong event class) — so the OLD code would crash the whole process on a single idle blip. The shared pool handles it. Cody ran a live EventEmitter probe to confirm.
+
+**Explicit pool max (Cody's "do now"):** added `max: Number(process.env.PG_POOL_MAX) || 20` to lib/db. The old two-pool setup accidentally allowed ~20 connections (2 × node-pg's default 10) — never chosen; consolidating would have silently halved it to 10. 20 makes the ceiling deliberate + env-tunable on the single fork-mode process (Postgres max_connections=100).
+
+**Cody gate — SHIP IT**, verified strictly-better on every axis (read pm2/pg source; grepped every lib/db requirer, every `pool.end`/SIGTERM, every `app.locals.pool` use): require-order safe (dotenv line 3 before the require; lib/db was already required by the route modules); no graceful-shutdown `pool.end()` exists to break; nothing else reads `app.locals.pool` or imported the old pool.
+
+**Tests:** unchanged 190/190 (simplified the server-routes cleanup to one `end()` since both handles are the same object now).
+
+**Cost:** $0 (local + one Cody pass — which read pm2 + pg source and ran live probes to prove the crash-on-idle and default-max claims).
+
+**Backlog / NEW follow-up (Cody, pre-existing not this diff):** `booking-pay-idempotency.test.js` + siblings `require('../lib/db')` without `require('dotenv').config()`, so a bare `npm test` (no exported DATABASE_URL) fails 3 tests — env-dependent. They should load dotenv themselves so CI is env-independent. Plus: approval-enforcement decision on Steve's desk; provider-honored idempotency key + sig-encoding (live-only); processorFee schema prerequisite; per-event webhook auto-reply try/catch. Next cycle: the dotenv-in-tests fix (make `npm test` env-independent — small, real CI-robustness win), or more inline-route coverage, or a fresh Cody audit.

← f45a796 costa-rica: consolidate server.js onto lib/db's shared pool  ·  back to Costa Rica  ·  costa-rica: make the test suite env-independent — load doten 2263da5 →