Skip to content

feat: add SUNSET_MODE to wind down the bot - #911

Merged
grunch merged 1 commit into
mainfrom
feat/sunset-mode
Aug 10, 2026
Merged

feat: add SUNSET_MODE to wind down the bot#911
grunch merged 1 commit into
mainfrom
feat/sunset-mode

Conversation

@grunch

@grunch grunch commented Aug 10, 2026

Copy link
Copy Markdown
Member

Summary

Adds a SUNSET_MODE environment variable to wind down the bot's service:

  • No LN node connection: skips invoice resubscription, all scheduled jobs, and monitoring; LND_GRPC_HOST is no longer required at startup.
  • Universal sunset notice: every incoming message or command is answered with a service-discontinued message in the user's language (stored user.lang, falling back to the Telegram client language, then English).
  • The notice links the official announcement (Spanish tweet for 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 in tests/bot/sunset.spec.ts covering language resolution (DB lang → client lang → English), no-sender updates, and the locale message contents
  • npm run lint clean
  • Deploy with SUNSET_MODE='true' and empty LND vars; verify the bot replies with the notice to any message/command and never touches the node

Summary by CodeRabbit

  • New Features

    • Added Sunset Mode to discontinue bot services.
    • Users receive localized English or Spanish notices explaining that orders and payments are no longer processed, with links to official announcements and Mostro resources.
    • Sunset Mode prevents Lightning Network connections and scheduled job processing.
  • Documentation

    • Documented the new SUNSET_MODE configuration setting, which defaults to disabled.

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
@coderabbitai

coderabbitai Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Sunset 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.

Changes

Sunset mode

Layer / File(s) Summary
Startup gating and configuration
.env-sample, ln/connect.ts, app.ts
SUNSET_MODE defaults to false. Enabled mode permits a missing LND_GRPC_HOST and skips invoice resubscription and external monitoring.
Localized sunset middleware
bot/start.ts
Sunset mode installs middleware that selects the user language, sends the localized message, and skips normal handlers and scheduled jobs.
Localized messages and validation
locales/en.yaml, locales/es.yaml, tests/bot/sunset.spec.ts
English and Spanish messages describe service discontinuation and provide Mostro links. Tests cover language selection, fallback behavior, replies, and missing senders.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Suggested reviewers: matobi98

Poem

A rabbit sees sunset mode glow,
No Lightning paths remain to go.
In Spanish or English, messages appear,
Mostro links make the next step clear.
Tests hop neatly through the flow.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: adding SUNSET_MODE to wind down the bot.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/sunset-mode

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.

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

Copy link
Copy Markdown

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: 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".

Comment thread ln/connect.ts
Comment on lines +38 to +41
if (
!socket &&
process.env.NODE_ENV !== 'test' &&
process.env.SUNSET_MODE !== 'true'

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge 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 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
tests/bot/sunset.spec.ts (1)

4-5: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Mirror the runtime test path.

tests/bot/sunset.spec.ts tests bot/start.ts. Rename the spec to tests/bot/start.spec.ts, or extract the middleware into bot/sunset.ts and keep a matching tests/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

📥 Commits

Reviewing files that changed from the base of the PR and between 3b140a1 and e2ab6a0.

📒 Files selected for processing (7)
  • .env-sample
  • app.ts
  • bot/start.ts
  • ln/connect.ts
  • locales/en.yaml
  • locales/es.yaml
  • tests/bot/sunset.spec.ts

Comment thread bot/start.ts
Comment thread ln/connect.ts
@grunch

grunch commented Aug 10, 2026

Copy link
Copy Markdown
Member Author

Re: renaming tests/bot/sunset.spec.tsstart.spec.ts: keeping the feature-based name. The spec covers the sunset feature across files (bot/start.ts middleware + both locale files), and the repo already uses feature-named specs that don't mirror source paths (cancelLocale.spec.ts, pending-payments.spec.ts, cancelReleaseTakeSlot.spec.ts).

@grunch
grunch merged commit 0d765f6 into main Aug 10, 2026
7 checks passed
@grunch
grunch deleted the feat/sunset-mode branch August 10, 2026 21:56
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