Skip to content

Fix six small bugs: bot.json reapply, stale gateway.pid, send ID reuse, migrations, crash files, claim lines - #128

Merged
Crokily merged 12 commits into
mainfrom
fix/small-bugs
Dec 4, 2026
Merged

Crokily merged 12 commits into
mainfrom
fix/small-bugs

Conversation

@Crokily

@Crokily Crokily commented Dec 4, 2026 •

Copy link
Copy Markdown
Owner

Six small bugs from a code review, each fixed in its own commit, each with a test that fails before its fix.

  1. A bot.json whose apply failed part way was not applied again. The model or a channel could already be changed, but the remembered text stayed the old one, so putting the old file back did nothing until a restart. Now the bot compares with what runs (its model and each channel's settings), and the gateway forgets the remembered text after a failed apply. Old channels still stop before their new adapters are made, so a stateful adapter (Feishu, Teams) reads the state the old one saved as it stopped. Test: test/definition.test.ts.
  2. A stale gateway.pid. After a crash, a PID reused by another program counted as a running gateway: pots start refused, and on Windows pots service stop could taskkill that program. Now the process's arguments must run pots start: the Pots entry point (the pots bin, pots.js, pots.ts or the Windows shim) and then start as its first argument that is not an option, so pots --log-level debug start counts. /proc/<pid>/cmdline gives the arguments on Linux; on macOS (ps) and Windows (Win32_Process) the line is split at spaces outside double quotes. A command line that cannot be read still counts as a gateway. pots service restart reads each PID's command line once while it polls, and the Windows stop checks afresh right before a forced stop. Test: test/cli.test.ts.
  3. A reused send ID sent the new caller's text. When an unfinished send ID came again, the outbox posted the new text to the old destination, and it waited in the new caller's line. Now a send ID is bound to its first call: the stored text and destination, in that place's line. spec/Outbox.tla already assumed one place per send ID; its comment now says so. Test: test/gateway.test.ts.
  4. Migrations outside a transaction. bot.ts, timers.ts and pages/store.ts checked the columns and then added them outside a transaction, so two processes could fail with "duplicate column". They now use addMissingColumns (src/core/sql.ts), which does it in one transaction, as log.ts does. Test: test/sql.parts.test.ts, with two real processes that open the pages store of an old schema; it fails on origin/main with "duplicate column name".
  5. Crash and hold files worked in production. A file such as crash-after-send in a bot folder killed the whole gateway. Now they work only with POTS_TEST_CRASH_FILES=1, which test/support/gateway.ts sets. Test: test/gateway.behavior.test.ts. The crash tests in gateway.behavior, children, nesting, memory and pages still pass.
  6. A password page's receipt could be lost. writeSecrets removed every earlier claim line, so a second link that wrote the same file before the first link was marked used made the first link open again after a crash. Now a write keeps the other claim lines, and each submission removes only its own line once its link is marked used, then clears its claim in the table. At the start, a used link whose claim is still in the table has its line removed too (a crash before the line went, or a receipt from an earlier release). Test: test/pages.parts.test.ts.

Not taken from the review: a retry of a send ID with another destination can be overtaken by a later send to the first destination (needs a script that reuses an ID for another destination, with overlapping sends).

Tested: npm run check, and only the touched test files, one at a time: definition, cli, gateway, properties, timers, sql.parts, pages, pages.parts, service, nesting, and the crash cases of gateway.behavior, children and memory. TLC was not run here. The outbox change touches spec/Outbox.tla (comment only).

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-12-04T01:32:19.696969Z 529d949 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@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: 529d94971b

ℹ️ 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 src/bot/bot.ts Outdated
const made: [ChannelAdapter, string][] = [];
for (const channel of next.channels) {
const config = liveChannel(channel, next.name);
if (live.channels.get(channel.id) !== config) made.push([await this.#loadChannel(channel, next.name), config]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reload persisted adapter state after stopping the old channel

When a Feishu/Lark channel is reconfigured while it has unflushed state, constructing its replacement before removing the old adapter loads an outdated snapshot. FeishuChannel reads its state file in its constructor, but batches state writes for one second and flushes outstanding changes in stop(). The replacement therefore misses that final flush and subsequently overwrites it with its stale snapshot, losing recently learned message mappings and other channel state. For example, #storeOwn can then silently skip logging a card edit because its message-to-chat mapping is gone. Validate the new configuration first if needed, but load or refresh the replacement's persisted state after the old adapter has stopped.

Useful? React with 👍 / 👎.

@Crokily
Crokily merged commit f36c6cf into main Dec 4, 2026
6 checks passed
@Crokily
Crokily deleted the fix/small-bugs branch December 4, 2026 02:40
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