Repository navigation
Enhance Lychee Link Checker (Resiliency & Performance) - #3203
Conversation
|
|
| /.claude/settings.local.json | ||
|
|
||
| # Lychee (link checker) cache | ||
| .lycheecache |
There was a problem hiding this comment.
Lychee supports cache placement only in the root folder.
|
@fegin |
|
@Andrei-Aksionov If we actually fix the transit issue (I noticed that you accept some comment transient errors), should we move the check back to per-PR CI? |
TL;DR: it does exactly that already. This PR doesn’t fix transient network failures, but it makes the link-checking process significantly more resilient to them. In this PR, Lychee checks both internal and external links during pre-commit (local/per-PR CI), but unlike the initial implementation, it only fails on To mitigate this, I modified the nightly link check. It runs with a much higher retry limit to outlast most outages and will fail on 502s. Both the pre-commit (local/PR) and the nightly runs utilize Is this a slight over-complication? Probably 🙂 (I didn't actually create the nightly action (it was added in a previous PR), I just updated it to function correctly within this new architecture.) |
|
Oh, yes, I understand the intention of the PR. I guess I didn't express it clearly. What I meant is that if already make it resilient to these errors, should we just drop the nightly check and restore the per-PR check? |
|
As I wrote above there is a benefit of having a nightly check in the current setup, but overall, for simplicity, we can easily drop the nightly run. @fegin Since there is a significant difference in timezones (I am in UTC+3), you can delete the nightly workflow. Everything else will work without problems. |
|
@fegin I removed the nightly link-checking workflow.
Basically the same as in the original implementation, but now:
For a context: the current code in the main also runs per-PR CI check, but only kept hyperlinks check in CI and hyperlinks/external links check for a local pre-commit run. |
Hey there 👋
As explained in pytorch/torchtitan#3158, this PR refactors the Lychee link-checking logic to eliminate flaky CI failures while significantly improving execution speed.
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.
502(e.g., "GitHub Unicorns") are accepted to prevent transient failures from stalling the workflow.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.2. The Cache Lifecycle: Why
keyandrestore-keysare NecessaryTo understand the necessity of a dynamic
keyand therestore-keysfallback, one must first recognize that GitHub Actions caches are immutable.The Problem with Static Keys
If a static key like
key: lychee-cacheis used without any dynamic parts, the workflow encounters a "Cache Hit" lock:.lycheecachefile and saves it aslychee-cache.lychee-cacheand downloads it. Because GitHub cannot update an existing cache, any new links or status updates discovered during the run are discarded.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 withrestore-keys, the process moves through two distinct phases:Step-by-Step Lifecycle (3-Commit Example)
cache-lychee-SHA1. Falls back torestore-keysto pull the latestmaincache that matchescache-lychee-pattern.SHA2. Pulls the most recent match from the branch scope (SHA1).SHA3. Pulls the latest available version from the branch (SHA2).SHA2baseline, ensuring zero redundant checks.lychee-cache-SHA1.lychee-cache-SHA2.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.
3. Optimization: Parallelism & Output
Previously, the configuration relied on
require_serial: trueandverbose: true.verbose: truewas required to display the "Lychee not found" warning (since the script usesexit 0). However, becausepre-commitspawns a process for every file, this caused the warning to print for every single file checked.require_serial: truewas used to stop the log spam, but caused a 2x-3x slowdown.mkdir /tmp/lychee_lock. Becausemkdiris 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.require_serialandverboseare 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.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.
5. GITHUB_TOKEN
The
GITHUB_TOKENis explicitly passed to the Lychee action and pre-commit steps. This increases the rate limit for GitHub API requests, reducing403 Forbiddenand429 Too Many Requestserrors when checking internal repository links.Summary Overview
404