Skip to content

fix: resolve Sentry issues — JSONC config, ENOENT guard, Node.js port fallback, transient error filtering#443

Merged
BYK merged 1 commit into
mainfrom
fix/sentry-issues
May 21, 2026
Merged

fix: resolve Sentry issues — JSONC config, ENOENT guard, Node.js port fallback, transient error filtering#443
BYK merged 1 commit into
mainfrom
fix/sentry-issues

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 21, 2026

Summary

Triages and resolves all 15 unresolved Sentry issues in LOREAI-GATEWAY. Fixes 3 real bugs and filters transient network noise.

Bug Fixes

GATEWAY-Y: .lore.json parse crash (Critical)

config.ts:260 — bare JSON.parse with no error handling. Users adding // comments to .lore.json (starting with /) crash the process.

Fix: Add inline stripJsonComments() for JSONC support (handles //, /* */, trailing commas) + wrap in try-catch to fall through to defaults on any parse failure.

GATEWAY-K: .lore.md ENOENT on every idle tick (Medium, 6472 events)

agents-file.ts:543exportLoreFile() calls writeFileSync without handling missing directories. When a project dir is deleted/renamed mid-session, the idle worker fires ENOENT every 30 seconds.

Fix: Wrap write+stat in try-catch, silently return on ENOENT. Other FS errors (EACCES, EIO) still propagate.

GATEWAY-6: Node.js EADDRINUSE bypass (Critical, 10 events, regressed)

node-polyfills.ts:88 — the Node.js serve() polyfill calls server.listen() which is async, but returns synchronously. EADDRINUSE is emitted as an 'error' event that nobody catches, completely bypassing the port fallback chain (3207 → 5673 → random).

Fix: Add a ready promise (listening/error events) to the polyfill, propagate through startServer() return type, and await server.ready in startGateway() so the existing catch block handles port conflicts correctly under Node.js. Includes:

  • Unhandled rejection guard (ready.catch(() => {})) for callers that don't await
  • Server cleanup (server.stop()) in the catch block to prevent FD leaks in multi-host configs

Sentry Noise Filtering

Added beforeSend to Sentry.init() to drop transient network errors that are expected in a long-running LLM proxy and not actionable:

  • EPIPE / ECONNRESET / ECONNREFUSED
  • Socket closed unexpectedly
  • ZlibError
  • TimeoutError: The operation timed out
  • Worker upstream exhausted N retries (429, 502)

Each exception in the chain is tested independently so a real bug wrapping a transient cause isn't accidentally silenced.

Files Changed

File Change
packages/core/src/config.ts JSONC support + try-catch
packages/core/src/agents-file.ts Silent ENOENT handling
packages/gateway/script/node-polyfills.ts ready promise on serve() + unhandled rejection guard
packages/gateway/src/server.ts Propagate ready? in return type
packages/gateway/src/cli/start.ts await server.ready + server cleanup in catch
packages/gateway/script/bundle.ts Updated type declarations
packages/gateway/instrument.ts beforeSend transient error filter

Sentry Resolution

All 15 unresolved issues resolved:

  • 3 bugs fixed (Y, K, 6)
  • 8 transient errors now filtered (P, R, M, S, T, W, V, 4)
  • 4 non-bugs resolved (X: test noise, G: caller error, N: user auth, Q: dup)

@BYK BYK self-assigned this May 21, 2026
@BYK BYK force-pushed the fix/sentry-issues branch from e932361 to 13973b3 Compare May 21, 2026 09:42
… fallback, transient error filtering

- Support JSONC (.lore.json with // comments) and add try-catch to
  config parser so malformed configs fall through to defaults (GATEWAY-Y)
- Silently handle ENOENT in exportLoreFile() when project directory is
  deleted mid-session, instead of erroring every 30s (GATEWAY-K)
- Fix Node.js polyfill server.listen() async behavior: add ready promise
  so EADDRINUSE is caught by startGateway() and the port fallback chain
  (3207 → 5673 → random) works correctly under Node.js (GATEWAY-6)
- Add Sentry beforeSend filter to drop transient network errors (EPIPE,
  socket closed, ZlibError, timeout, worker retry exhaustion) that are
  not actionable bugs
@BYK BYK force-pushed the fix/sentry-issues branch from 13973b3 to ebd0fdb Compare May 21, 2026 09:48
@BYK BYK enabled auto-merge (squash) May 21, 2026 09:59
@BYK BYK merged commit 6427ebf into main May 21, 2026
9 of 10 checks passed
@BYK BYK deleted the fix/sentry-issues branch May 21, 2026 09:59
@craft-deployer craft-deployer Bot mentioned this pull request May 21, 2026
6 tasks
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.

1 participant