Skip to content

feat(runtime): stability foundation - global handlers, pino injection, health/metrics#15

Merged
one-ea merged 1 commit into
mainfrom
260629-feat-stability-foundation
Jun 29, 2026
Merged

feat(runtime): stability foundation - global handlers, pino injection, health/metrics#15
one-ea merged 1 commit into
mainfrom
260629-feat-stability-foundation

Conversation

@one-ea

@one-ea one-ea commented Jun 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • Register unhandledRejection handler with 60s dedup window (suppresses after 5 repeats)
  • Register uncaughtException handler with controlled shutdown + 10s force-exit timeout
  • Add graceful shutdown timeout (10s) for SIGINT/SIGTERM
  • Inject pino Logger into TelegramMessageDeps and sweepExpiredConversations
  • Replace 4 console.error calls in messages.ts, conversation-expiry.ts, updates.ts with structured pino logger calls
  • Add DeliveryService.stats(), ConversationService.conversationStats() + messageStats(), AiDraftService.stats()
  • Add GET /healthz endpoint (public, returns bot/db/uptime status, 503 if degraded)
  • Add GET /metrics endpoint (authenticated, returns message/delivery/conversation/ai_draft counts)
  • Extend WebConsoleOptions with dbHealthCheck and collectMetrics callbacks
  • 6 new test cases covering healthz, metrics auth, and stats aggregation

Problem

The process had no unhandledRejection/uncaughtException handlers, so async errors from timers/workers could silently crash or hang the process. Critical hot paths used console.error instead of pino, losing structured logging. Container orchestration had no health check endpoint, and ops had no metrics visibility.

Verification

  • npm run verify passed (check + 31 tests + audit 0 vulns)

…tion, health/metrics endpoints

- Register unhandledRejection handler with 60s dedup window (threshold 5)
- Register uncaughtException handler with controlled shutdown + 10s timeout
- Add graceful shutdown timeout (10s) for SIGINT/SIGTERM
- Inject pino Logger into TelegramMessageDeps, sweepExpiredConversations
- Replace 4 console.error calls in messages.ts, conversation-expiry.ts,
  updates.ts with structured pino logger calls
- Add DeliveryService.stats(), ConversationService.conversationStats() and
  messageStats(), AiDraftService.stats() - all synchronous GROUP BY queries
- Add GET /healthz endpoint (public, returns bot/db/uptime status, 503 if degraded)
- Add GET /metrics endpoint (authenticated, returns message/delivery/conversation/
  ai_draft counts as JSON)
- Extend WebConsoleOptions with dbHealthCheck and collectMetrics callbacks
- Add 6 new test cases covering healthz, metrics auth, and stats aggregation
Co-authored-by: monkeycode-ai <monkeycode-ai@chaitin.com>
@coderabbitai

coderabbitai Bot commented Jun 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@one-ea, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 1 minute

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 017c8b4b-de74-432d-9375-f67bfc973e9e

📥 Commits

Reviewing files that changed from the base of the PR and between 8969361 and 7b92dbf.

📒 Files selected for processing (10)
  • src/channels/telegram/bot.ts
  • src/channels/telegram/messages.ts
  • src/channels/telegram/updates.ts
  • src/domain/ai-drafts.ts
  • src/domain/conversation-expiry.ts
  • src/domain/conversations.ts
  • src/domain/deliveries.ts
  • src/runtime/main.ts
  • src/runtime/web-console.ts
  • test/core.test.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 260629-feat-stability-foundation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@one-ea one-ea merged commit afd8611 into main Jun 29, 2026
4 checks passed
@one-ea one-ea deleted the 260629-feat-stability-foundation branch June 29, 2026 19:07
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