Skip to content

[Fix] Discord recovery can skip events after a session is replaced - #3484

Closed
roomote-roomote[bot] wants to merge 2 commits into
developfrom
fix/discord-checkpoint-session-owner-0f1abghskgt4c
Closed

roomote-roomote[bot] wants to merge 2 commits into
developfrom
fix/discord-checkpoint-session-owner-0f1abghskgt4c

Conversation

@roomote-roomote

@roomote-roomote roomote-roomote Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

​Opened on behalf of @daniel-lxs. Follow up by mentioning @roomote-roomote, in the web UI, or in Telegram.

Related issue

Internal maintainer-requested reliability work; no issue opened.

Why this PR exists

  • A maintainer explicitly invited this PR in the linked issue or discussion
  • I am a maintainer / this is internal Roomote work

A slow checkpoint write from an invalidated Discord gateway session can overwrite its replacement session's recovery position. The new connection may then resume past events it has not durably queued.

What changed

Gateway checkpoint writes now carry their originating session ID, and PostgreSQL updates only the matching session. Flush completion and retry bookkeeping also ignore work whose session has been replaced. Ordinary acknowledged-only checkpoint coalescing, handoff and same-session retry remain intact. This adds one internal write argument and identity comparisons; no schema, dependency or UI changes. The gateway test command now loads .env.test and uses the existing shared database lifecycle so the new persistence regression runs through the normal package command.

How it was tested

  • On current develop 50a58ed4, delayed an old checkpoint at sequence 11, saved a replacement at sequence 0, then released the old write. Both PostgreSQL and the actual gateway store incorrectly reported the replacement at 11.
  • Controlled real-store/SDK/PostgreSQL tests repeat that ordering for stale success and stale failure, read the replacement through a fresh store, verify its own acknowledgements can advance to 1, and remove randomized rows in finally. Also verify a late write cannot repopulate a cleared checkpoint and ordinary same-session retry succeeds.
  • Tested head c9b8f141d58e7e7125f2f2d9b7e41a523ef947cc: normal pnpm --filter @roomote/discord-gateway test --run passes all 91 tests, six SDK persistence DB tests pass, affected typechecks and gateway build pass, and full pre-push gates pass. Test database cleanup readback finds zero fixture rows.
  • Proof boundary: actual gateway resume-store application logic and database persistence with controlled operation ordering. No live Discord websocket, user messages, or provider reconnect parity claimed. Browser proof is not applicable.
  • Additional exact-head proof used independently evaluated Node processes for old writer and replacement connection. The same stimulus fails on develop (expected checkpoint 0, received 11), while c9b8f141 preserves 0 and advances to 1 only after the replacement's own acknowledgement. Scoped cleanup left zero rows.

Checklist

  • The PR title follows the repo convention: [Fix], [Feat], [Improve], [Refactor], [Docs], or [Chore] followed by a user-facing description
  • This PR is small and scoped to one change
  • pnpm lint and pnpm check-types pass locally
    • Normal fast equivalents passed through the complete pre-push suite; changed files formatted.
  • I added tests or included a clear manual validation note above
  • I removed secrets, tokens, private keys, and customer data from code, logs, and screenshots
  • If this change should appear in the changelog, I ran pnpm changeset
    • Narrow persistence fix; no standalone changeset.

Related PRs

@roomote-community

roomote-community Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

No code issues found. See task

Reviewed the checkpoint session fencing and regression tests, plus all newly pushed changes through c9b8f14: test-environment loading and shared database lifecycle setup. Checked setup/teardown locking, package conventions, and CI wiring. Current-head lint, typecheck, and Knip checks passed; tests, Docker build, compatibility checks, and CodeQL analysis were still running when inspected. No local validation suites were run.

Reviewed c9b8f14

@roomote-roomote
roomote-roomote Bot marked this pull request as ready for review October 15, 2026 05:27
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