fix(ai-connectors): deduplicate outage bridge DMs per conversation with a cooldown
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- postgresql, redis, typescript
Research direction
Start with apps/api/src/ai-connectors/ai-connectors.service.ts, especially AiConnectorsService and dispatchCompletion, then read apps/api/src/redis/redis.service.ts and the Message model in packages/prisma/schema.prisma. Check how Redis disconnection and existing constructor tests are handled. Done means both outage notifications are suppressed for 15 minutes per conversation, with a database fallback when Redis is unavailable.
Written by the indexing model from the issue text.
Description
Problem Description
In apps/api/src/ai-connectors/ai-connectors.service.ts (dispatchCompletion, lines 546-617), when all AI providers fail and conversationId is present, it unconditionally enqueues a SEND_DM BackgroundJob with bridgeMsg and creates an INTERNAL_NOTE ([AI Outage Alert]) on the conversation with no per-conversation cooldown.
If a customer sends multiple messages while AI providers are down, they receive duplicate bridgeMsg DMs and the conversation gets spammed with duplicate internal notes.
Expected Behavior
- During an AI outage, both
bridgeMsgand the[AI Outage Alert]INTERNAL_NOTEare emitted at most once per conversation within a cooldown window (e.g., 15 minutes). - Works reliably both locally (even without Redis) and in production across multiple API replicas, without breaking existing unit tests.
Where to Look
apps/api/src/ai-connectors/ai-connectors.service.ts(AiConnectorsServiceconstructor line 33,dispatchCompletionlines 546-617)apps/api/src/redis/redis.service.ts(reserveWebhookEventlines 167-197)packages/prisma/schema.prisma(Messagemodel, usessentAt)
Solution / Implementation Guide
- Inject
@Optional() private readonly redisService?: RedisServiceintoAiConnectorsService(RedisModuleis@Global(), and@Optional()preserves existing unit test constructors). - Add a cooldown helper in
RedisService(e.g.,acquireCooldown(key: string, ttlSeconds: number): Promise<boolean>usingSET key '1' EX ttlSeconds NX, returningtrueif acquired or falling back safely if Redis is disconnected). - Gate both
bridgeMsgandINTERNAL_NOTEbehind the 15-minute cooldown indispatchCompletion:- If
this.redisServiceis available: callawait this.redisService.acquireCooldown(\ai:outage_bridge:${conversationId}`, 900)`. - DB fallback (if Redis is unavailable locally): query
prisma.message.findFirstwithwhere: { conversationId, messageType: 'INTERNAL_NOTE', content: { contains: 'AI Outage Alert' }, sentAt: { gte: new Date(Date.now() - 15 * 60 * 1000) } }(note:MessageusessentAt, notcreatedAt). - If the cooldown is active (already sent within 15 minutes), skip both enqueuing the
SEND_DMbridgeMsgjob and creating theINTERNAL_NOTE.
- If
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 1
- Avg merge
- 6m
- Merged PRs (30d)
- 27
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from sumamakhan761/tryinstance
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#65 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
sumamakhan761/tryinstance#64 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
sumamakhan761/tryinstance#63 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#62 ·
Maintainers usually reply within 1 day
-
backend good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
sumamakhan761/tryinstance#60 ·
Maintainers usually reply within 1 day
All issues in sumamakhan761/tryinstance
Similar issues
-
prio:low scope:hud
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OliverRomhagen/vrigstad-joyride#953 ·
Maintainers usually reply within 1 day
-
review-followup
Difficulty 1/5 Under an hour Newbie friendliness 92/100
griffinwork40/agent-afk#5446 ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
kacper-szewczyk/Ticknest#346 ·
Maintainers usually reply within 1 day
-
echarts geo: a GeoJSON URL that returns 200 with a body that is not JSON is fetched on each refreshOpenbug plugin/echarts/geo
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
Yeachan-Heo/gajae-code#8230 ·
Maintainers usually reply within 1 day