FIX: dyno crash on duplicate token insert + hardening from review#332
Merged
Conversation
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…g real db errors Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Overtorment
force-pushed
the
fix-review-findings
branch
from
July 22, 2026 10:26
cf0c416 to
9d667b4
Compare
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes the production crash from Jul 21 (H13, unhandled
ER_DUP_ENTRYon/getTokenConfiguration) plus the issues surfaced by a follow-up review of the surrounding code. Five commits, each self-contained:getTokenConfigurationhit a check-then-insert race on the(token, os)unique index; the rejected promise escaped the route wrapper and killed the dyno. Create path now catchesER_DUP_ENTRYand re-reads the row the concurrent request inserted (same guard in worker-sender). The express route wrapper also gained a.catchso any future rejected handler returns 500 instead of crashing the process.findOneBy, which throws on undefined criteria, and the poison record was never removed: onePOST /enqueuewith{}wedged the worker in a crash-restart loop. Validation now runs first and the record is removed.next(), so the limiter only ever throttled 404s. Now registered before routes. Note: this makes the existing 100 req/15 min/IP limit effective for the first time — worth watching for 429s from clients behind carrier-grade NAT after deploy.level_*/lang/redactedfields (first-ever call withredacted: truestoredredacted: falseand returned 200). Fields are now applied on create too, with the same duplicate-race guard. Blanketcatch {}blocks inmajorTomToGroundControl/unsubscribe/setTokenConfigurationnow only swallow expected duplicates; real DB errors surface as 500 instead of a false success.LAST_PROCESSED_BLOCK, silently dropping every notification in that block; theerror.message.includescheck itself crashed on non-Error throws. Now it logs, sleeps 10s, and retries the block. Trade-off: a deterministically failing block retries forever (loudly) instead of being skipped silently.Test plan
npx vitest run), including 8 new tests: duplicate-race handling for get/set, non-duplicate errors still propagate, settings applied on create, duplicate subscriptions treated as success, unsubscribe skips missing recordstsc --noEmitclean, prettier clean/getTokenConfigurationunder load, watch 429 rates from the now-active rate limiter, confirm worker-sender drains the queueMade with Cursor