Decide whether the bot's timers should keep the database compute awake continuously
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 12/100
- issue の種類
- リファクタリング
- 明瞭さ
- 説明が足りない
- 活発さ
- 活発
- 技術スタック
- postgresql, typescript
調査の方向性
This is a design decision, not a code change. Start in bot/index.ts by reading the timer constants (LISTEN_HEARTBEAT_INTERVAL_MS, the 5-minute sweeps) and in lib/slack/poller.ts the Slack poll interval, then check railway.bot.toml for deployment settings. Done means a written decision on the four options, coordinated with #128 / PR #130 for the dashboard heartbeat, and any follow-up code is agreed with maintainers first.
索引モデルが issue の本文から書いたものです。
説明
Copied from DeadantCo/answerLoops#30 · originally opened by sethr07 on 2026-11-20
Copied from https://github.com/answerLoops/answerLoops/issues/131 — originally opened by
@FaithTarberton 2026-09-08
Background
The bot is a long-running process, not a webhook receiver: it holds a Discord Gateway connection (discord.js Client with GatewayIntentBits), is started as tsx bot/index.ts, and is deployed by railway.bot.toml with restartPolicyType = "on_failure". It must stay up to ingest Discord messages — app/api/discord/* is OAuth and channel listing only, with no HTTP ingestion path.
While it runs, several of its timers query the database often enough that a serverless compute can never reach its idle window (Neon's default is 5 minutes):
Timer (constant in bot/index.ts) |
Interval | What it does |
|---|---|---|
LISTEN_HEARTBEAT_INTERVAL_MS |
4 min | SELECT 1 on the dedicated LISTEN connection; a failure triggers reconnect and re-LISTEN. Database work every beat. |
STUCK_TICKET_SWEEP_INTERVAL_MS |
5 min | getStuckPendingTickets(), then forwards each stuck ticket to /api/ingest/retry-stuck. Skipped entirely when BOT_SECRET is unset. |
EMBEDDING_MIGRATION_SWEEP_INTERVAL_MS |
5 min | Calls the app route that finds and re-embeds workspaces whose vectors are not on their target model (the request itself is bounded by EMBEDDING_MIGRATION_REQUEST_TIMEOUT_MS). Skipped without BOT_SECRET. |
KB_SYNC_SAFETY_SWEEP_INTERVAL_MS |
5 min | Safety net for the knowledge-base sync queue: reclaims jobs stuck in running (KB_SYNC_STUCK_THRESHOLD_MS) and claims queued ones. The queue is normally driven by a kb_sync_job_queued notification, so this only matters when a notification is dropped. |
KB_RETENTION_SWEEP_INTERVAL_MS |
24 hours | Blanks visitor text on old review items and prunes expired article-usage rows. Also runs once at startup. |
ORG_PURGE_SWEEP_INTERVAL_MS |
6 hours | Hard-purges workspaces whose deletion grace period has elapsed. One indexed query when nothing is due. Also runs once at startup. |
Slack poller (DEFAULT_INTERVAL_MS in lib/slack/poller.ts, from SLACK_POLL_INTERVAL_SECONDS) |
60 sec | No work on cloud unless a workspace has the slack_force_polling flag, because the bot only hands it the flagged orgs. Does database and network work when self-hosted. |
The three 5-minute sweeps and the 4-minute heartbeat all sit at or under a 5-minute idle window, so each one on its own is enough to keep a serverless compute awake. The 6-hour and 24-hour sweeps are negligible.
The effect is that the compute runs continuously whenever the bot is up, rather than suspending when nothing is happening. Because this is a single database with row-level tenancy (org_id), that is one shared compute for every tenant — there is no per-customer endpoint to suspend independently, so this is a fixed floor rather than something that scales with usage.
Why this is worth a decision
The 4-minute heartbeat interval appears chosen to sit under a 5-minute autosuspend window, i.e. it prevents suspension as much as it detects a dead connection. That was a reasonable trade when it was written — #71 / #77 exist because a postgres.js LISTEN goes silently stale on a suspending compute, with nothing logged and config hot-reload quietly dead until the process restarted.
But the cost of that choice is now the dominant term in idle database spend, and it is worth being deliberate about rather than inheriting. Note that lengthening the interval alone does not recover suspension: any periodic query restarts the idle countdown, so a 10-minute beat keeps the compute up roughly half the time rather than all of it. The 5-minute sweeps have the same property and would all have to move too.
Options
- Accept it. Config changes reach the bot within seconds and a dead LISTEN is caught within four minutes. Simplest, and defensible if compute cost is not a real constraint.
- Lengthen the heartbeat and all of the 5-minute sweeps together, accepting slower config propagation and slower stuck-ticket recovery in exchange for partial suspension. Only meaningful if both move past the idle window.
- Drop the periodic heartbeat and re-check config lazily. The bot only needs current config when it processes a message — and processing a message already queries the database, which wakes the compute anyway. A config version check at message time (with LISTEN kept as a fast path rather than the source of truth) would let the compute suspend while genuinely idle, at the cost of a config change not reaching an idle bot until its next message. Needs care: this is the failure #71 / #77 were about, so it should be correct-by-construction rather than relying on the LISTEN staying alive.
- Make the stuck-ticket sweep (and the embedding migration sweep) event-driven rather than 5-minute polls, the way the KB sync worker already is, independently of whichever heartbeat option is chosen.
Interaction with #128
Decide together with #128 / PR #130 (dashboard heartbeat).
PR #130 adds a 4-minute heartbeat to the dashboard's own SSE LISTEN connection. That was justified partly on the grounds that it costs nothing extra in compute-hours because the bot already holds the compute awake. If this issue is resolved by letting the compute suspend, that reasoning no longer holds and the dashboard heartbeat becomes the thing preventing suspension whenever a tab is open. The two should be decided together.
The dashboard case is less severe — its stream exists only while a tab is open, and closes when the tab is backgrounded — but it would need revisiting.
Acceptance
Decide and document. If the decision is to change behaviour, the bot should still detect and recover from a dead LISTEN connection without relying on a process restart, and a config change should still reach the bot before it acts on the next message.
Start here: new to the project? Read CONTRIBUTING.md first. It covers the ground rules, running answerLoops locally, and how to open a pull request.
- 主要言語
- TypeScript
- スター
- 0
- フォーク
- 0
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
- Dockerfile または Docker Compose ファイルあり
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
DeadantCo/answerLoopsdev のほかの issue
-
Widget: match the chat bubble color to the rest of the widget対応中かも @sethr07 が今日担当しました。 オープンenhancement frontend help wanted
難易度 2/5 半日 初心者へのやさしさ 75/100
DeadantCo/answerLoopsdev#68 · コメント 3 件 ·
-
Widget: make the chat window fit on small phones対応中かも @sethr07 が今日担当しました。 オープンenhancement frontend good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
DeadantCo/answerLoopsdev#67 · コメント 9 件 ·
-
Add 'select all' option to Slack channel picker in Settings対応中かも @sethr07 が今日担当しました。 オープンfrontend good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
DeadantCo/answerLoopsdev#22 · コメント 5 件 ·
-
enhancement frontend help wanted
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
DeadantCo/answerLoopsdev#141 ·
-
backend enhancement frontend help wanted
難易度 4/5 3〜5日 初心者へのやさしさ 45/100
DeadantCo/answerLoopsdev#140 ·
DeadantCo/answerLoopsdev の issue をすべて見る
似ている issue
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
lingdojo/kana-dojo#34545 · コメント 1 件 · リアクション 5 件 ·
メンテナーはふだん 1 日以内に返信
-
blocklist addition
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
MetaMask/eth-phishing-detect#315455 ·
メンテナーはふだん 1 日以内に返信
-
area: telegram bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
griffinwork40/agent-afk#5275 ·
メンテナーはふだん 1 日以内に返信
-
macOS: the Save Diagnostics panel goes behind the editor after an app switch and can't be reachedオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
getopenscreen/openscreen#1667 ·
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
erkamyaman/rust-anything#371 ·
メンテナーはふだん 1 日以内に返信