Skip to content

Enhance GitHub GraphQL Rate Limit Handling and Token Security - #8273

Open
pisum-sativum wants to merge 11 commits into
JhaSourav07:mainfrom
pisum-sativum:fix-github-graphql-rate-limit
Open

Enhance GitHub GraphQL Rate Limit Handling and Token Security#8273
pisum-sativum wants to merge 11 commits into
JhaSourav07:mainfrom
pisum-sativum:fix-github-graphql-rate-limit

Conversation

@pisum-sativum

Copy link
Copy Markdown
Contributor

Description

Fixes #6239

This PR resolves critical issues related to GitHub GraphQL rate limit exhaustion and token exposure vulnerabilities.

Specific changes include:

  • Request Deduplication: Fixed a bug in lib/github.ts where request deduplication was bypassed for requests providing an options.signal. The background cache-populating fetch is now properly decoupled from individual request abort signals, preventing duplicate GraphQL calls for concurrent same-user requests.
  • Token Security & Log Sanitization: Safely caught network-level fetch errors (TypeError) and converted them into generic errors. This guarantees that Request objects, which contain the Authorization header with the Personal Access Token (PAT), are stripped and never logged to serverless dashboards or exposed to clients.

Pillar

  • 🎨 Pillar 1 — New Theme Design
  • 📐 Pillar 2 — Geometric SVG Improvement
  • 🕐 Pillar 3 — Timezone Logic Optimization
  • 🛠️ Other (Bug fix, refactoring, docs)

Visual Preview

No visual changes. This PR strictly improves backend API resilience, rate limit handling, and token security.

Checklist before requesting a review:

  • I have read the CONTRIBUTING.md file.
  • I have tested these changes locally (localhost:3000/api/streak?user=YOUR_USERNAME).
  • I have run npm run format and npm run lint locally and resolved all errors (CI will fail otherwise).
  • My commits follow the Conventional Commits format (e.g., feat(themes): ..., fix(calculate): ...).
  • I have updated README.md if I added a new theme or URL parameter.
  • I have started the repo.
  • I have made sure that i have only one commit to merge in this PR.
  • The SVG output matches the CommitPulse "premium quality" aesthetic standard (no raw elements, smooth animations, correct fonts).
  • (Recommended) I joined the CommitPulse Discord community for contributor discussions, mentorship, and faster PR support.

Copilot AI review requested due to automatic review settings July 22, 2026 17:24
@vercel

vercel Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

@pisum-sativum is attempting to deploy a commit to the jhasourav07's projects Team on Vercel.

A member of the Team first needs to authorize it.

@retenta-bot

retenta-bot Bot commented Jul 22, 2026

Copy link
Copy Markdown

This pull request effectively resolves critical issues related to GitHub GraphQL rate limits and enhances token security. The changes made, such as request deduplication and error handling, are crucial for maintaining the integrity of our API interactions. It's worth noting that similar past decisions focused on improving user experience through visually themed error responses, which highlights our commitment to both functionality and user experience. Thank you for your contributions, and I look forward to your feedback!

@retenta-bot retenta-bot Bot changed the title Fix GitHub graphql rate limit Enhance GitHub GraphQL Rate Limit Handling and Token Security Jul 22, 2026
@pisum-sativum

Copy link
Copy Markdown
Contributor Author

@JhaSourav07 I have done the necessary changes kindly check and merge with appropriate labels.

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

Improves GitHub API resiliency by adjusting retry/abort behavior and contribution-request coalescing to reduce duplicated calls and avoid leaking sensitive request details, while also tweaking CI analytics paging and reordering the socials registry.

Changes:

  • Updates fetchWithRetry error/abort handling and adjusts contribution-fetch coalescing so abort signals don’t bypass deduplication.
  • Reduces CI Actions pagination depth for CI analytics fetches.
  • Sorts the socials registry alphabetically at module initialization.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
services/github/ci-analytics.ts Reduces Actions pagination (likely to lower API usage).
lib/github.ts Changes abort/error behavior in retry logic and contribution request coalescing for better dedup + safer error surfaces.
app/generator/data/socials.ts Sorts socials registry by display name (user-visible ordering change).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/github.ts
Comment on lines 289 to +290
if (didThrow) {
if (options.signal?.aborted) throw fetchError;
if (options.signal?.aborted) throw new Error('AbortError');
Comment thread lib/github.ts
Comment on lines +957 to +962
return new Promise<ExtendedContributionData>((resolve, reject) => {
if (options.signal?.aborted) return reject(new Error('AbortError'));

const onAbort = () => reject(new Error('AbortError'));
options.signal?.addEventListener('abort', onAbort, { once: true });

Comment thread app/generator/data/socials.ts Outdated
Comment on lines +594 to +597
placeholder: 'e.g. https://huggingface.co/yourname',
},
] as Social[]
).sort((a, b) => a.name.localeCompare(b.name));
@github-actions

Copy link
Copy Markdown
Contributor

📦 Next.js Bundle Size Report (Gzipped Sizes)

✨ No significant bundle size changes detected.

📊 Summary of Totals

Category PR Size Base Size Difference
Total JS 3984.87 KB 3984.83 KB +0.04 KB (+0.00%)
Total CSS 331.41 KB 331.41 KB 0 B

@Aamod007 Aamod007 added level:advanced Complex contributions involving architecture, optimization, or significant feature work type:bug Something isn't working as expected type:security Security fixes, dependency updates, or hardening mentor:Aamod007 labels Jul 23, 2026

@Aamod007 Aamod007 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is a solid improvement to our GraphQL rate limit handling and request cancellation logic! The way you're handling \AbortError\ and coalescing requests is very robust.

However, similar to PR #8274, it looks like this branch contains unrelated changes that were accidentally committed. Specifically, the changes to \�pp/generator/data/socials.ts\ and \services/github/ci-analytics.ts\ do not belong in this PR.

To fix this, please revert the changes to those files using \git restore\ or \git checkout\ so that this PR is focused entirely on the GitHub API rate limit and token handling.

Looking forward to getting this merged once the branch is cleaned up!

Label Justification:

  • \level:advanced: Implementing complex request coalescing, abort controller logic, and rate-limit backoff across the API layer is an advanced task.
  • \ ype:bug\ & \ ype:security: Prevents token exhaustion and handles API edge cases securely.
  • \mentor:Aamod007: Assigned as required.

@github-actions github-actions Bot added the status:blocked This PR is blocked due to a failing CI check. label Jul 23, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🚨 Hey @pisum-sativum, the CI Pipeline is failing on this PR and it has been marked as status:blocked.

Please fix the issues before this can be reviewed. Here's how:

1. Run checks locally before pushing:

npm run format:check   # Check Prettier formatting
npm run lint           # Run ESLint
npm run typecheck      # TypeScript type check
npm run test           # Run unit tests (Vitest)
npm run build          # Verify production build passes

2. Auto-fix common issues:

npm run format         # Auto-fix formatting with Prettier
npm run lint -- --fix  # Auto-fix lint errors where possible

3. Check the full failure log here:
👉 View CI Run

Once you push a fix and the CI passes, the status:blocked label will be removed automatically. 💪

@pisum-sativum

Copy link
Copy Markdown
Contributor Author

This is a solid improvement to our GraphQL rate limit handling and request cancellation logic! The way you're handling \AbortError\ and coalescing requests is very robust.

However, similar to PR #8274, it looks like this branch contains unrelated changes that were accidentally committed. Specifically, the changes to \�pp/generator/data/socials.ts\ and \services/github/ci-analytics.ts\ do not belong in this PR.

To fix this, please revert the changes to those files using \git restore\ or \git checkout\ so that this PR is focused entirely on the GitHub API rate limit and token handling.

Looking forward to getting this merged once the branch is cleaned up!

Label Justification:

  • \level:advanced: Implementing complex request coalescing, abort controller logic, and rate-limit backoff across the API layer is an advanced task.
  • \ ype:bug\ & \ ype:security: Prevents token exhaustion and handles API edge cases securely.
  • \mentor:Aamod007: Assigned as required.

@Aamod007 I have done the necessary changes required but the CI is failing again and again I tried to fix it but I don't think so I can. Maybe after sometime will try ;(

@Aamod007 Aamod007 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

New commits address some of the previous concerns. The signal/abort refactoring in fetchGitHubContributions looks notably better — properly propagating abort signals through the coalesced promise pattern rather than ignoring them. The error message extraction (fetchError instanceof Error ? fetchError.message : String(fetchError)) is a good improvement too.

CI is still failing though. Please check the logs and fix whatever is causing the failures before we can approve.

Label justification:

  • level:advanced — the async signal propagation + coalesced promise pattern is non-trivial, spans 4 files including github.ts which has complex retry/abort logic
  • quality:clean — well-structured changes
  • type:bug, type:security — rate limit error handling + token security
  • mentor:Aamod007 — assigned

@Aamod007 Aamod007 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewing: the only CI failure was Vercel authorization (not code-related). All code checks pass. The Vercel deploy auth is a repo-level config issue. Approving.

@pisum-sativum

Copy link
Copy Markdown
Contributor Author

@Aamod007 @JhaSourav07 Kindly check and merge if possible with correct labels.

@pisum-sativum

Copy link
Copy Markdown
Contributor Author

New commits address some of the previous concerns. The signal/abort refactoring in fetchGitHubContributions looks notably better — properly propagating abort signals through the coalesced promise pattern rather than ignoring them. The error message extraction (fetchError instanceof Error ? fetchError.message : String(fetchError)) is a good improvement too.

CI is still failing though. Please check the logs and fix whatever is causing the failures before we can approve.

Label justification:

  • level:advanced — the async signal propagation + coalesced promise pattern is non-trivial, spans 4 files including github.ts which has complex retry/abort logic
  • quality:clean — well-structured changes
  • type:bug, type:security — rate limit error handling + token security
  • mentor:Aamod007 — assigned

@Aamod007 Do I need to make any changes which you stated ?

@pisum-sativum

Copy link
Copy Markdown
Contributor Author

@Aamod007 @JhaSourav07 Kindly merge this pr so that i can take up new issues since the bots is not allowing me to take up any more new issues .
image

@pisum-sativum

Copy link
Copy Markdown
Contributor Author

@Aamod007 @JhaSourav07 If no change is required then kindly check and merge.

@pisum-sativum

Copy link
Copy Markdown
Contributor Author

@Aamod007 @JhaSourav07 pls check and merge.
image

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

⚠️ Hey @pisum-sativum, this pull request has been inactive for 3 days. It will be automatically closed in 2 days if no further activity occurs.

If you are still working on this, please push your latest changes or leave a comment to keep it active.

@Aamod007 Aamod007 added level:beginner Small changes Usually isolated fixes or simple UI/text updates. quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. type:refactor Code changes that neither fix a bug nor add a feature labels Aug 6, 2026

@Aamod007 Aamod007 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice improvement! Alphabetically sorting the socials dropdown makes the UI much more intuitive and user-friendly for people trying to find a specific platform. Approved!

@pisum-sativum

Copy link
Copy Markdown
Contributor Author

@Aamod007 @JhaSourav07 Caan u pls merge this pr asap

@pisum-sativum

Copy link
Copy Markdown
Contributor Author

@Aamod007 @JhaSourav07 pls merge this pr asap
image

@pisum-sativum

Copy link
Copy Markdown
Contributor Author

@JhaSourav07 could you please merge all the PRs I've worked on? I've been requesting this for several days now but they are still pending. I would really appreciate it if you could review and merge them as soon as possible. Thank you!

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @pisum-sativum, this pull request has been inactive for 3 days. It will be automatically closed in 2 days if no further activity occurs.

If you are still working on this, please push your latest changes or leave a comment to keep it active.

@pisum-sativum

Copy link
Copy Markdown
Contributor Author

@JhaSourav07 pls merge

@pisum-sativum

Copy link
Copy Markdown
Contributor Author

@JhaSourav07 Any update?

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @pisum-sativum, this pull request has been inactive for 3 days. It will be automatically closed in 2 days if no further activity occurs.

If you are still working on this, please push your latest changes or leave a comment to keep it active.

2 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @pisum-sativum, this pull request has been inactive for 3 days. It will be automatically closed in 2 days if no further activity occurs.

If you are still working on this, please push your latest changes or leave a comment to keep it active.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @pisum-sativum, this pull request has been inactive for 3 days. It will be automatically closed in 2 days if no further activity occurs.

If you are still working on this, please push your latest changes or leave a comment to keep it active.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Hey @pisum-sativum, this pull request has been inactive for 4 days. It will be automatically closed in 1 days if no further activity occurs.

If you are still working on this, please push your latest changes or leave a comment to keep it active.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:advanced Complex contributions involving architecture, optimization, or significant feature work level:beginner Small changes Usually isolated fixes or simple UI/text updates. mentor:Aamod007 quality:clean PR follows clean coding practices, proper formatting, documentation, and maintainability standards. status:blocked This PR is blocked due to a failing CI check. type:bug Something isn't working as expected type:refactor Code changes that neither fix a bug nor add a feature type:security Security fixes, dependency updates, or hardening

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix GitHub GraphQL Rate Limit + Token Security Vulnerability

3 participants