Skip to content

feat: check for newer remote configuration files and add --reload[=config|plugins] flag - #1328

Merged
dsherret merged 7 commits into
mainfrom
remote-config-cache-revalidation
Oct 10, 2026
Merged

dsherret merged 7 commits into
mainfrom
remote-config-cache-revalidation

Conversation

@dsherret

@dsherret dsherret commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Closes #774

Remote configuration files (--config <url> and extends) were cached forever under a hash of the url, so an updated file was never picked up without dprint clear-cache or a new url.

Changes

  • The cached response is used while it's fresh according to its caching headers (Cache-Control: max-age, Expires/Date, Age), or for a day when it has none. no-cache/no-store and entries written by older versions (no timestamp) are always checked.
  • Once stale, the server is asked for a newer version with If-None-Match/If-Modified-Since. A 304 keeps the cached content and refreshes its headers and timestamp; a 200 replaces it (and the "includes ignored" note is shown again for changed content).
  • When the server can't be reached, the stale cached copy is used with a warning. The check is a single attempt with a 5 second timeout so an unreachable server can't stall formatting, and the cached response's time is refreshed so it's checked again once stale again rather than on every run while offline. A 404 still errors.
  • A redirect chain is only served from the cache when every hop is fresh. Otherwise it's requested again from the original url, so short-lived redirect targets (ex. signed urls) are never requested directly. A fresh target behind a stale redirect isn't re-requested.
  • New global --reload[=config|plugins] flag. Plain --reload checks the server for newer remote configuration files (a cheap conditional request) and downloads remote plugins again, since plugin urls aren't always versioned. --reload=config and --reload=plugins do one kind only. Each remote plugin is reloaded at most once per process, so dprint lsp --reload doesn't re-download plugins on every config change. Plumbed through fmt/check/etc., descendant configs, init, and dprint lsp.
  • Repeated response header lines are now joined with , instead of keeping only the last one.
  • Docs: new sections in cli.md, config.md, and a note in lsp.md.

Adds the httpdate crate (pinned) for parsing Expires/Date.

Tests

Unit tests for the freshness math, resolver tests for fresh hits, 304 revalidation, default expiry, stale fallback, 404, reload, older cache entries without a time, Age handling after a 304, and redirect chains. Parser tests for the flag's forms, a CLI test that dprint fmt --reload picks up an updated remote extends file, a CLI test that --reload=plugins re-downloads a remote wasm plugin while --reload=config doesn't, a plugin resolver test that a reload happens once per process, and tests that a failed check falls back to the cached copy, defers the next check, and makes a single attempt.

Note: extract_tarball_preserves_exec_bits_via_env_set_permissions fails locally before and after this change (umask dependent), unrelated to this PR.

Remote configuration files (`--config <url>` and `extends`) were cached
forever under a hash of the url, so an updated file was never picked up
without `dprint clear-cache` or a new url.

The cached response is now used while it's fresh according to its caching
headers (`Cache-Control: max-age`, `Expires`, `Age`), or for a day when it
has none. After that the server is asked for a newer version with
`If-None-Match`/`If-Modified-Since` so it can answer 304 Not Modified, and
the stale cached copy is used with a warning when the server can't be
reached. A redirect chain is only used from the cache when every hop is
fresh, otherwise it's requested again from the original url so short-lived
redirect targets aren't requested directly.

The new global `--reload` flag checks the server right away instead of
waiting for the cached copy to expire.

Closes #774
@dsherret
dsherret force-pushed the remote-config-cache-revalidation branch from c13be51 to 614f09f Compare October 10, 2026 21:27
A plain `--reload` now reloads both remote configuration files and remote
plugins, since plugin urls aren't always versioned. `--reload=config` or
`--reload=plugins` reloads only one kind, which avoids downloading and
setting up every plugin again when only the configuration changed.

Each remote plugin is downloaded again at most once per process, so the
language server doesn't re-download them every time a config file changes.
@dsherret dsherret changed the title feat: check for newer remote configuration files and add --reload flag feat: check for newer remote configuration files and add --reload[=config|plugins] flag Oct 10, 2026
…config

Checking for a newer version of a cached remote configuration file now
makes a single attempt with a 5 second timeout instead of three attempts
with 30 second connect timeouts, since the cached copy is used when it
fails. A network that drops packets could otherwise stall formatting for
up to 90 seconds.

After a failed check the cached response's time is refreshed, so the
server is asked again once the response is stale again rather than on
every run while offline. Responses marked no-cache are still checked on
every run.
…alues

The merged completions change tests that every sub command lists the
global options last and that the shells can complete the values of flags
whose parsers accept any text, so `--reload` joins both.
@dsherret
dsherret merged commit 5c1d34a into main Oct 10, 2026
23 checks passed
@dsherret
dsherret deleted the remote-config-cache-revalidation branch October 10, 2026 22:30
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.

Consider a better method to invalidate remote config URL cache

1 participant