Skip to content

fix(cli): report GitHub API rate limits in difyctl install scripts#38375

Merged
lin-snow merged 1 commit into
mainfrom
fix/difyctl-install-rate-limit-errors
Jul 3, 2026
Merged

fix(cli): report GitHub API rate limits in difyctl install scripts#38375
lin-snow merged 1 commit into
mainfrom
fix/difyctl-install-rate-limit-errors

Conversation

@lin-snow

@lin-snow lin-snow commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

The difyctl install scripts resolve releases through the GitHub REST API with curl -fsSL. -f discards the response body and the X-RateLimit-* headers, so when the API rate limit is hit (60 req/hour per unauthenticated IP — common behind shared NATs, corporate egress, or in CI) the failure was misreported as Dify release <x> not found or failed to query latest Dify release, sending users to debug the wrong thing.

This PR makes the scripts detect and explain rate limiting:

  • fetch_json now reads the HTTP status and rate-limit headers and classifies the failure (rate limit vs. 404 vs. network) instead of collapsing everything into one opaque exit code.
  • On a rate limit it prints an actionable hint: the cause, the reset ETA, and how to proceed.
  • GITHUB_TOKEN / GH_TOKEN, when set, is sent as a bearer token to raise the limit from 60 to 5000 req/hour.
  • Mirrored in install.ps1; unit tests added for both.

The success path is unchanged, and non-rate-limit errors keep their original messages.

Screenshots

N/A — CLI install-script change. Example new output when rate limited:

install-cli: GitHub API rate limit exceeded (unauthenticated requests are capped at 60/hour per IP).
install-cli: The limit resets in ~30 min.
install-cli: To proceed now, authenticate to raise the limit to 5000/hour:
install-cli:   curl -fsSL <install-url> | GITHUB_TOKEN=<token> sh

Checklist

  • This change requires a documentation update, included: Dify Document — the public install page's GITHUB_TOKEN note is a follow-up; cli/README.md is updated here.
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly. (cli/README.md)
  • I ran the cli/ gates instead of the backend/frontend ones (not applicable here): pnpm lint, pnpm type-check, and vitest on the changed suites — all green.

@lin-snow lin-snow requested a review from GareArc as a code owner July 3, 2026 07:19
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 3, 2026
@codecov

codecov Bot commented Jul 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.34%. Comparing base (5622e8f) to head (b2cb47f).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #38375      +/-   ##
==========================================
+ Coverage   85.29%   85.34%   +0.05%     
==========================================
  Files        4992     5147     +155     
  Lines      264162   268493    +4331     
  Branches    50126    51184    +1058     
==========================================
+ Hits       225309   229140    +3831     
- Misses      34434    34934     +500     
  Partials     4419     4419              
Flag Coverage Δ
cli 88.45% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lin-snow lin-snow self-assigned this Jul 3, 2026
@lin-snow lin-snow marked this pull request as draft July 3, 2026 07:24
@lin-snow lin-snow force-pushed the fix/difyctl-install-rate-limit-errors branch from 126e72c to 5088937 Compare July 3, 2026 07:31
The install scripts resolved releases with `curl -fsSL`, which discards the
response body and X-RateLimit-* headers. A rate limit (60 req/hour per
unauthenticated IP) was therefore misreported as "release not found" or
"failed to query".

Classify fetch failures by HTTP status and rate-limit headers, print an
actionable hint (reset ETA + how to authenticate), and send GITHUB_TOKEN /
GH_TOKEN as a bearer to raise the limit to 5000/hour. Mirrored in
install.ps1, with tests for both.
@lin-snow lin-snow force-pushed the fix/difyctl-install-rate-limit-errors branch from 5088937 to b2cb47f Compare July 3, 2026 07:40
@lin-snow lin-snow marked this pull request as ready for review July 3, 2026 07:47

@GareArc GareArc 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.

lgtm

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 3, 2026
@lin-snow lin-snow added this pull request to the merge queue Jul 3, 2026
Merged via the queue into main with commit 262b0b1 Jul 3, 2026
36 checks passed
@lin-snow lin-snow deleted the fix/difyctl-install-rate-limit-errors branch July 3, 2026 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants