Skip to content

fix(relay): Telegram + OOM + memory cleanup#531

Merged
koala73 merged 2 commits intomainfrom
fix/relay-telegram-oom
Feb 28, 2026
Merged

fix(relay): Telegram + OOM + memory cleanup#531
koala73 merged 2 commits intomainfrom
fix/relay-telegram-oom

Conversation

@koala73
Copy link
Owner

@koala73 koala73 commented Feb 28, 2026

Summary

  • Telegram never loads on Railwaytelegram and ws added to root dependencies (Railway runs npm install at repo root, not scripts/)
  • OOM crash at 4GB — V8 heap limit logged at startup to verify NODE_OPTIONS=--max-old-space-size=8192 is active; MAX_VESSELS/MAX_VESSEL_HISTORY lowered from 50k→20k (env-configurable)
  • Memory cleanup — threshold raised from 450MB→2GB (env-configurable via RELAY_MEMORY_CLEANUP_GB); emergency cleanup now clears all caches (RSS, Polymarket, WorldBank)
  • Telegram import guard — permanent latch prevents 60s retry spam when package is missing

Railway env vars to set

NODE_OPTIONS=--max-old-space-size=8192 --expose-gc

After 30+ min stability, flip POLYMARKET_ENABLED=true.

Test plan

  • node --check scripts/ais-relay.cjs — syntax OK
  • node -e "require('telegram')" — resolves from root
  • node --test scripts/ais-relay-rss.test.cjs — 5/5 pass
  • tsc --noEmit — clean
  • Deploy to Railway → verify [Relay] Heap limit: 8192MB in logs
  • Monitor 30min for no OOM crashes
  • Verify no Cannot find package 'telegram' errors

… cleanup

- Add `telegram` and `ws` to root dependencies so Railway's `npm install` installs them
- Log V8 heap limit at startup to confirm NODE_OPTIONS is active
- Make MAX_VESSELS/MAX_VESSEL_HISTORY env-configurable (default 20k, down from 50k)
- Add permanent latch to skip Telegram import retries when package is missing
- Raise memory cleanup threshold from 450MB to 2GB (env-configurable)
- Clear all caches (RSS, Polymarket, WorldBank) during emergency cleanup
@vercel
Copy link

vercel bot commented Feb 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

4 Skipped Deployments
Project Deployment Actions Updated (UTC)
worldmonitor Ignored Ignored Preview Feb 28, 2026 0:01am
worldmonitor-finance Ignored Ignored Preview Feb 28, 2026 0:01am
worldmonitor-happy Ignored Ignored Preview Feb 28, 2026 0:01am
worldmonitor-startup Ignored Ignored Preview Feb 28, 2026 0:01am

Request Review

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2494fbfe92

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +48 to +49
const n = Number(envVal);
return Number.isFinite(n) ? Math.max(min, Math.floor(n)) : fallback;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Handle empty AIS cap env vars as unset

The new safeInt parser treats an empty string as a valid number (Number('') === 0), so if AIS_MAX_VESSELS or AIS_MAX_VESSEL_HISTORY is present but blank (a common misconfiguration in managed env UIs), the cap is forced to 1000 instead of using the intended default 20000. That silently shrinks retention by 20x and can cause aggressive eviction/data loss in normal operation; blank values should fall back to defaults rather than being clamped to min.

Useful? React with 👍 / 👎.

Number('') === 0 passes isFinite, silently clamping caps to 1000
instead of using the 20000 default. Guard empty/null before parsing.
@koala73 koala73 merged commit f17860c into main Feb 28, 2026
6 checks passed
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