Skip to content

[CI] Move lychee link checker to nightly workflow - #3158

Merged
fegin merged 5 commits into
mainfrom
gh/fegin/116/head
Apr 30, 2026
Merged

fegin merged 5 commits into
mainfrom
gh/fegin/116/head

Conversation

@fegin

@fegin fegin commented Apr 29, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move it out of per-PR lint into a dedicated nightly workflow so flakes no longer block PRs but broken links still get surfaced.

fegin added 2 commits April 29, 2026 11:28
[ghstack-poisoned]
[ghstack-poisoned]
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 29, 2026
@fegin
fegin changed the base branch from gh/fegin/116/base to main April 29, 2026 18:28
@fegin fegin changed the title [ci] Move lychee link checker to nightly workflow [CI] Move lychee link checker to nightly workflow Apr 29, 2026
Comment thread .github/workflows/lint.yaml Resolved
Comment thread .github/workflows/link_check.yaml Resolved

@fegin fegin left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think the main issue is that lychee is quite flaky due to external network issues. I'm not sure how much signals lychee can give us for per-PR run if we only run on the modified files, which 99% of the time don't contain links.

Comment thread .github/workflows/link_check.yaml Resolved
Comment thread .github/workflows/lint.yaml Resolved
[ghstack-poisoned]
fegin added a commit that referenced this pull request Apr 29, 2026
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced.

Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness.

ghstack-source-id: 8cba300
Pull-Request: #3158
Comment on lines +15 to +56
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10']
steps:
- name: Check out repo
uses: actions/checkout@v6

- name: Setup python
uses: actions/setup-python@v6
with:
python-version: ${{ matrix.python-version }}

- name: Update pip
run: python -m pip install --upgrade pip

- name: Install Lychee (Latest Release)
run: |
# Query GitHub API for the latest release tag
LATEST_TAG=$(curl -s https://api.github.com/repos/lycheeverse/lychee/releases/latest | jq -r .tag_name)
echo "Installing Lychee version: $LATEST_TAG"

URL="https://github.com/lycheeverse/lychee/releases/download/${LATEST_TAG}/lychee-x86_64-unknown-linux-gnu.tar.gz"

# Load the archive, extract into temp folder, move the binary, delete the rest
mkdir -p lychee_install
curl -sLO "$URL"
tar -xzf "lychee-x86_64-unknown-linux-gnu.tar.gz" -C lychee_install --strip-components=1
sudo mv lychee_install/lychee /usr/local/bin/
rm -rf lychee_install "lychee-x86_64-unknown-linux-gnu.tar.gz"

# Verify installation
lychee --version

- name: Install pre-commit
run: |
python -m pip install -r requirements-dev.txt
pre-commit install-hooks

- name: Check links with Lychee
run: |
pre-commit run lychee-link-checker --all-files
fegin added a commit that referenced this pull request Apr 29, 2026
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced.

Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness.

ghstack-source-id: 8cba300
Pull-Request: #3158
fegin added a commit that referenced this pull request Apr 29, 2026
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced.

Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness.

ghstack-source-id: 8cba300
Pull-Request: #3158
fegin added a commit that referenced this pull request Apr 29, 2026
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced.

Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness.

ghstack-source-id: 8cba300
Pull-Request: #3158
fegin added a commit that referenced this pull request Apr 29, 2026
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced.

Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness.

ghstack-source-id: 8cba300
Pull-Request: #3158
@tianyu-l

Copy link
Copy Markdown
Contributor

@Andrei-Aksionov wdyt?

[ghstack-poisoned]
fegin added a commit that referenced this pull request Apr 30, 2026
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced.

Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness.

ghstack-source-id: f51a303
Pull-Request: #3158
@fegin
fegin changed the base branch from main to gh/fegin/116/base April 30, 2026 00:36
fegin added a commit that referenced this pull request Apr 30, 2026
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced.

Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness.

ghstack-source-id: f51a303
Pull-Request: #3158
[ghstack-poisoned]
fegin added a commit that referenced this pull request Apr 30, 2026
The lychee link checker is flaky due to transient external network failures, causing spurious PR CI failures. Move external link checking to a dedicated nightly workflow so flakes no longer block PRs but broken external links still get surfaced.

Per-PR lint continues to validate in-repo links by running lychee in --offline mode on changed markdown/python files, so file-path/anchor breakage is caught at PR time without network flakiness.

ghstack-source-id: a0a848b
Pull-Request: #3158
@fegin

fegin commented Apr 30, 2026

Copy link
Copy Markdown
Contributor Author

I update the per-PR lychee to run only the local links. I still keep the full run nightly check. Let me know if you want to delete it.

@tianyu-l tianyu-l 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.

can give it a try

@fegin
fegin changed the base branch from gh/fegin/116/base to main April 30, 2026 05:54
@fegin
fegin merged commit 47d3045 into main Apr 30, 2026
9 of 11 checks passed
@tianyu-l
tianyu-l deleted the gh/fegin/116/head branch April 30, 2026 06:18
saforem2 pushed a commit to saforem2/torchtitan that referenced this pull request Apr 30, 2026
Stack from [ghstack](https://github.com/ezyang/ghstack/tree/0.14.0)
(oldest at bottom):
* __->__ pytorch#3158

The lychee link checker is flaky due to transient external network
failures, causing spurious PR CI failures. Move it out of per-PR lint
into a dedicated nightly workflow so flakes no longer block PRs but
broken links still get surfaced.
@andrei-aksionau

Copy link
Copy Markdown
Contributor

Oh, I see.
It looks like we're hitting transient GitHub availability issues.
I’ve experienced this myself: sometimes when opening a GitHub link, I get a "Unicorn" error page instead of code 🙃.

To ensure consistent behavior between local environments and CI, and to prevent transient network failures from blocking the workflows, I suggest the following options:

1. Fail only on 404 (Not Found)

We can configure Lychee to accept most HTTP error codes except for 404. This ensures that if an external resource is temporarily offline (e.g., a 502 or 503 error), it won't fail the pre-commit check. The downside is that a legitimate 404 could theoretically be masked by a 502 during a check, but I believe the trade-off for CI stability is worth it.

2. Implement Lychee Caching

Lychee supports caching results in a simple CSV-formatted file (URL, Status_Code, Timestamp). This provides several benefits:

  • Resilience: If a URL was reachable previously but is currently down, Lychee can rely on the cached status.
  • Self-Healing: If a real 404 is hidden behind a 502, Lychee will eventually reach the URL once it's back online and update the cache accordingly.
  • Performance: It significantly speeds up link checking by skipping recently verified URLs.
  • CI Integration: We can configure GitHub Actions to share and update a "global" cache across all PRs and runs.

3. Maintain a "Nightly" Action

Even if we decide to fail only on 404 for standard PRs, we should still monitor other errors like 502 or 503. A nightly action is perfect for this:

  • We can set a much higher number of retries (e.g., retrying for up to 30 minutes) to account for longer outages.
  • Once the nightly run successfully verifies all links, it will refresh the Lychee cache, which all other workflows can then reuse for the next day.

fegin pushed a commit that referenced this pull request May 12, 2026
Hey there 👋 

As explained in
[#3158](#3158 (comment)),
this PR refactors the Lychee link-checking logic to eliminate flaky CI
failures while significantly improving execution speed.

<br>

## 1. Multi-Tier Check Strategy
The "Commit-time" experience is now separated from "Infrastructure
monitoring" to ensure the development flow is not blocked by external
outages.

* **Pre-commit (Local & PR CI):** Configured to **fail only on 404**.
Codes like `502` (e.g., "GitHub Unicorns") are accepted to prevent
transient failures from stalling the workflow.
* **Nightly CI:** Performs a strict check (accepting only `200`, `403`,
`429`, `503`) with high persistence. It retries for up to **30
minutes**, outlasting most service outages. This run populates the cache
with verified statuses that later can be reused in other workflow runs.

<br>

## 2. The Cache Lifecycle: Why `key` and `restore-keys` are Necessary
To understand the necessity of a dynamic `key` and the `restore-keys`
fallback, one must first recognize that **GitHub Actions caches are
immutable**.

### The Problem with Static Keys
If a static key like `key: lychee-cache` is used without any dynamic
parts, the workflow encounters a "Cache Hit" lock:
1. **The First Run:** GitHub creates the `.lycheecache` file and saves
it as `lychee-cache`.
2. **Subsequent Runs:** GitHub finds an exact match for `lychee-cache`
and downloads it. Because GitHub cannot update an existing cache, any
new links or status updates discovered during the run are **discarded**.
3. **The "Stale Cache" Effect:** Over time, the cache becomes frozen in
the state of the first run. Fixed links remain marked as "broken," and
new links are re-checked every single time, slowing down CI.

### The Solution: Dynamic Keys & Branch Isolation
GitHub restricts cache access based on branches: the **Default Branch**
(`main`) is accessible by all, while **Feature Branches** can only
access their own caches or the default branch's cache.

By using a dynamic key (e.g., `cache-lychee-${{ github.sha }}`) combined
with `restore-keys`, the process moves through two distinct phases:
- **Restore** (start of job)
- **Save** (end of job).

#### Step-by-Step Lifecycle (3-Commit Example)
| Phase | Commit 1: The "Inheritance" | Commit 2: The "Update" | Commit
3: The "Iteration" |
| :--- | :--- | :--- | :--- |
| **Restore** | Misses `cache-lychee-SHA1`. Falls back to `restore-keys`
to pull the latest `main` cache that matches `cache-lychee-` pattern. |
Misses `SHA2`. Pulls the most recent match from the branch scope
(**SHA1**). | Misses `SHA3`. Pulls the latest available version from the
branch (**SHA2**). |
| **Action** | Lychee runs, checks only new links, and uses the
inherited cache for the rest. | Lychee updates results with any new
findings. | Lychee uses the `SHA2` baseline, ensuring zero redundant
checks. |
| **Save** | GitHub saves a **new** cache entry: `lychee-cache-SHA1`. |
GitHub saves a new immutable entry: `lychee-cache-SHA2`. | GitHub saves
the final state: `lychee-cache-SHA3`. |

> [!NOTE]
> This "chaining" effect ensures every commit builds upon the previous
one, while keeping PR runs fast and the nightly "source of truth"
accessible.

<br>

## 3. Optimization: Parallelism & Output
Previously, the configuration relied on `require_serial: true` and
`verbose: true`.

* **The Problem:** `verbose: true` was required to display the "Lychee
not found" warning (since the script uses `exit 0`). However, because
`pre-commit` spawns a process for every file, this caused the warning to
print for every single file checked. `require_serial: true` was used to
stop the log spam, but caused a **2x-3x slowdown**.
* **The Fix:** An **Atomic Sentinel** is now used via `mkdir
/tmp/lychee_lock`. Because `mkdir` is an atomic operation, only the
first process successfully creates the directory and prints the warning.
All other parallel processes fail to create the directory and remain
silent.
* **The Result:** `require_serial` and `verbose` are now **false**. The
check runs in parallel (fast), and the warning prints exactly once
(clean) by redirecting directly to the user's terminal screen via `>
/dev/tty`.

<br>

## 4. Fix Lychee version to install
In **Lychee v0.24.1**, a change in the release archive structure broke
dynamic installation scripts that fetched the "Latest" release.
* **Change:** The installation now uses a **fixed, verified version** to
prevent upstream changes from breaking the CI pipeline.

<br>

## 5. GITHUB_TOKEN
The `GITHUB_TOKEN` is explicitly passed to the Lychee action and
pre-commit steps. This increases the rate limit for GitHub API requests,
reducing `403 Forbidden` and `429 Too Many Requests` errors when
checking internal repository links.

<br>

## Summary Overview
| Feature | Local / PR CI | Nightly CI |
| :--- | :--- | :--- |
| **Failure Condition** | Only `404` | Most non-200 codes |
| **Duration/Retries** | Fast (5 retries / 15 secs) | Patient (30
retries / 30 mins) |
| **Execution** | Parallel (via Sentinel) | Standard Action |
| **Cache Goal** | Consume & Increment | Refresh & Validate |
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/8gpu CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants