fix(alerts): prevent duplicate create retries - #588
Conversation
Disable generic retry for non-idempotent alert creation and bypass the response cache for all Smart Alert mutations. Add focused retry and cache regressions.\n\nFixes nansen-ai#587
pr-reviewer Summary for #bd50a04✅ No issues found The code review completed successfully with no findings. Review effort: 2/5 (Simple) SummaryThis PR is a clean, targeted fix. The production change ( Token usage: 6,872 input, 3,009 output, 290,093 cache read, 34,814 cache write | Usage Guide New pushes are reviewed automatically with a 10-minute cooldown between reviews. To request a review at any time, comment |
There was a problem hiding this comment.
Auto-approved
This PR was automatically approved because:
- Claude recommends approval
- Claude assessed this as a moderate effort change
- The effort level is within the auto-approval threshold of 2
- No high or critical issues were detected
If you have any concerns, please request a manual review.
Follow the existing api.test.js live-test convention so the regression does not access the absent mockFetch fixture when NANSEN_LIVE_TEST=1.
There was a problem hiding this comment.
Auto-approved
This PR was automatically approved because:
- Claude recommends approval
- Claude assessed this as a moderate effort change
- The effort level is within the auto-approval threshold of 2
- No high or critical issues were detected
If you have any concerns, please request a manual review.
Summary
Fixes #587.
Smart Alert mutations inherited the generic response cache, and the non-idempotent create path also inherited generic transport/status retries. A lost response could therefore submit the same create up to four times, while a repeated identical mutation could be satisfied from cache without reaching the API.
Changes
alertsCreate()alertsUpdate(),alertsToggle(), andalertsDelete()Read-only Smart Alert methods are unchanged.
Regression proof
With the new tests applied to current
mainbefore the fix:The failures showed:
alertsCreate()made 4 fetch attempts instead of 1 after an ambiguous network failureWith this fix:
Full suite:
Additional checks:
npm run lint— passedgit diff --check— passednpm pack --ignore-scripts --dry-run— passed; 85 package files, no test artifacts includednpm audit --omit=dev --json— 0 production vulnerabilitiesAll regression tests used a temporary HOME, fake credentials, mocked fetch responses, and no external network access.
Compatibility and risk
Checklist
npm test)src/schema.jsonupdated if new commands or flags were added — no command or flag changesREADME.mdupdated if new top-level commands or categories were added — no command changes.changeset/avoid-duplicate-alert-create.md)