Fix Alpha Vantage rate-limit failures in the daily alerts worker - #22
Conversation
There was a problem hiding this comment.
Pull request overview
This PR reduces Alpha Vantage free-tier burst rate-limit failures in the apps/alerts scheduled worker by sharing a single AlphaVantageClient per cron run and de-duplicating concurrent identical requests within that client.
Changes:
- Add in-flight request de-duplication to
AlphaVantageClient(no persistent caching; evicts on settle). - Construct one
AlphaVantageClientper scheduled run and pass it to alerts viaAlertContext. - Update/extend tests to cover de-duplication behavior and verify the scheduled handler shares one client instance.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/alpha-vantage/src/alpha-vantage.ts | Add in-flight request de-duplication and shared error handling helper. |
| packages/alpha-vantage/src/alpha-vantage.test.ts | Add unit tests verifying concurrent de-duplication and eviction behavior. |
| apps/alerts/src/scheduled.ts | Build a single Alpha Vantage client per run and pass it into alerts. |
| apps/alerts/src/scheduled.test.ts | Assert the scheduled handler constructs exactly one Alpha Vantage client per run. |
| apps/alerts/src/alerts/types.ts | Extend AlertContext to include a shared alphaVantage client. |
| apps/alerts/src/alerts/sp500-drawdown.ts | Use shared alphaVantage client from context instead of constructing per-alert. |
| apps/alerts/src/alerts/sp500-drawdown.test.ts | Update test harness to provide alphaVantage via context. |
| apps/alerts/src/alerts/sp500-close.ts | Use shared alphaVantage client from context instead of constructing per-alert. |
| apps/alerts/src/alerts/sp500-close.test.ts | Update test harness to provide alphaVantage via context. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 8c1dc31fe8
ℹ️ 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".
What
scheduled.tsnow builds oneAlphaVantageClientper run and passes it to every alert viaAlertContext.AlphaVantageClientde-duplicates concurrent in-flight requests, collapsing those four calls into two. Entries are dropped once a request settles, so a reused client still fetches fresh data and a failure never poisons later calls.How to test
pnpm typecheck
pnpm lint
pnpm test
pnpm build
Security review
No security-impacting changes.