feat: add SUNSET_MODE to wind down the bot - #911
Conversation
When SUNSET_MODE='true': - the bot never connects to the LN node (no invoice resubscription, no scheduled jobs, no monitoring, LND_GRPC_HOST no longer required) - every incoming message or command is answered with a service-discontinued notice in the user's language (Spanish for es, English for all other locales) linking the official announcement and pointing users to Mostro as a KYC-free alternative
WalkthroughSunset mode adds an environment setting that disables Lightning Network connections, monitoring, and scheduled jobs. The bot responds with localized service-discontinued messages that direct users to Mostro resources. Tests cover language selection, fallback behavior, replies, and missing senders. ChangesSunset mode
Estimated code review effort: 3 (Moderate) | ~20 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e2ab6a0c22
ℹ️ 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".
| if ( | ||
| !socket && | ||
| process.env.NODE_ENV !== 'test' && | ||
| process.env.SUNSET_MODE !== 'true' |
There was a problem hiding this comment.
Avoid constructing the LND client in sunset mode
When SUNSET_MODE='true' is deployed without LND_GRPC_HOST as advertised, this guard is bypassed, but the module immediately calls authenticatedLndGrpc({ socket: undefined, ... }), which rejects the missing socket/credentials. Because app.ts and bot/start.ts import ../ln before their sunset checks run, the process fails during module loading and never launches the sunset bot; defer importing/constructing the LND client entirely in this mode.
AGENTS.md reference: AGENTS.md:L9-L10
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Verified empirically against the pinned lightning@10.25.0: authenticatedLndGrpc({ cert: undefined, macaroon: undefined, socket: undefined }) does not throw at construction — the gRPC client is lazy and only dials on the first RPC call, which never happens in sunset mode (no jobs scheduled, no trading handlers registered, resubscribeInvoices skipped).
Reproduction:
$ env -i SUNSET_MODE=true node -e "require('./dist/ln/connect.js'); require('./dist/ln/index.js'); console.log('loaded OK')"
loaded OK
The existing test suite already relies on this same behavior: tests import ../ln with cert/macaroon/socket all undefined and pass. No change needed for this version; if the lightning dependency is ever upgraded to a version that validates the socket eagerly, this would need the lazy-import treatment.
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
tests/bot/sunset.spec.ts (1)
4-5: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueMirror the runtime test path.
tests/bot/sunset.spec.tstestsbot/start.ts. Rename the spec totests/bot/start.spec.ts, or extract the middleware intobot/sunset.tsand keep a matchingtests/bot/sunset.spec.ts.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/bot/sunset.spec.ts` around lines 4 - 5, Align the test and runtime paths by renaming tests/bot/sunset.spec.ts to tests/bot/start.spec.ts, since it tests sunsetMiddleware imported from bot/start. Update any references to the renamed spec while preserving its existing test behavior.Source: Coding guidelines
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@bot/start.ts`:
- Around line 214-216: Update the middleware setup in startBot around
isSunsetMode() so sunsetMiddleware is registered after i18n and before limit(),
ensuring rate-limited updates still receive the sunset notice; preserve normal
rate-limiting behavior outside sunset mode. Add an integration test that exceeds
the limit in sunset mode and asserts the notice is sent.
In `@ln/connect.ts`:
- Around line 35-42: Prevent LND client initialization during sunset mode in the
connect flow around the socket validation and authenticatedLndGrpc call. Ensure
app.ts does not eagerly import ./ln before the SUNSET_MODE guard, or
conditionally skip client creation when SUNSET_MODE is 'true', while preserving
normal and test-mode initialization.
---
Nitpick comments:
In `@tests/bot/sunset.spec.ts`:
- Around line 4-5: Align the test and runtime paths by renaming
tests/bot/sunset.spec.ts to tests/bot/start.spec.ts, since it tests
sunsetMiddleware imported from bot/start. Update any references to the renamed
spec while preserving its existing test behavior.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 72f6fa50-e7a1-49a1-95ac-c3b291eacdf3
📒 Files selected for processing (7)
.env-sampleapp.tsbot/start.tsln/connect.tslocales/en.yamllocales/es.yamltests/bot/sunset.spec.ts
|
Re: renaming |
Summary
Adds a
SUNSET_MODEenvironment variable to wind down the bot's service:LND_GRPC_HOSTis no longer required at startup.user.lang, falling back to the Telegram client language, then English).es, English tweet for every other locale via i18n fallback) and invites users to Mostro as a KYC-free alternative, with mostro.community for running a node.Test plan
npm test— 225 passing, including 6 new specs intests/bot/sunset.spec.tscovering language resolution (DB lang → client lang → English), no-sender updates, and the locale message contentsnpm run lintcleanSUNSET_MODE='true'and empty LND vars; verify the bot replies with the notice to any message/command and never touches the nodeSummary by CodeRabbit
New Features
Documentation
SUNSET_MODEconfiguration setting, which defaults to disabled.