Skip to content

Fix Alpha Vantage rate-limit failures in the daily alerts worker - #22

Merged
valuecodes merged 3 commits into
mainfrom
feat/alpha-vantage-dedupe
Jul 18, 2026
Merged

Fix Alpha Vantage rate-limit failures in the daily alerts worker#22
valuecodes merged 3 commits into
mainfrom
feat/alpha-vantage-dedupe

Conversation

@valuecodes

Copy link
Copy Markdown
Owner

What

  • The daily alerts worker was failing with Alpha Vantage's 1-request-per-second rate-limit error. Both SP500 alerts run on the same 08:00 cron and each built its own client, so four identical requests (2 alerts × daily+weekly) fired at once and tripped the free-tier burst limit.
  • scheduled.ts now builds one AlphaVantageClient per run and passes it to every alert via AlertContext.
  • AlphaVantageClient de-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.

Copilot AI review requested due to automatic review settings July 18, 2026 09:59

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 AlphaVantageClient per scheduled run and pass it to alerts via AlertContext.
  • 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.

Comment thread packages/alpha-vantage/src/alpha-vantage.ts Outdated
Comment thread packages/alpha-vantage/src/alpha-vantage.ts Outdated
Comment thread apps/alerts/src/scheduled.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread packages/alpha-vantage/src/alpha-vantage.ts Outdated
@valuecodes
valuecodes merged commit 4efd1e8 into main Jul 18, 2026
7 checks passed
@valuecodes
valuecodes deleted the feat/alpha-vantage-dedupe branch July 18, 2026 10:14
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.

2 participants