Skip to content

fix(webui): stop browsers serving a stale embedded UI after the binary is upgraded - #112

Merged
jasonxu114514 merged 1 commit into
jasonxu114514:mainfrom
WengeLiu101:fix/webui-asset-cache-revalidation
Oct 23, 2026
Merged

jasonxu114514 merged 1 commit into
jasonxu114514:mainfrom
WengeLiu101:fix/webui-asset-cache-revalidation

Conversation

@WengeLiu101

Copy link
Copy Markdown
Contributor

Problem

The management UI is embedded in the binary (//go:embed) and served through http.FileServerFS.

Those responses carry no Cache-Control, and the embed FS reports a zero modification time, so there is
no Last-Modified and no ETag either. With nothing to go on, browsers are free to apply heuristic caching and
keep an old index.html / js/*.js / css/*.css for hours.

That stays invisible until the operator upgrades the binary. Then the new backend serves requests the cached old
frontend does not know about — newly added pages simply never appear, and a renamed asset or changed API shape
breaks the page outright — until the cache happens to expire or the user hard-refreshes.

Concretely: after adding a new page to the WebUI and restarting the binary, the nav entry and page were missing
in the browser while curl against the same server returned them, and only Ctrl+Shift+R fixed it.

Fix

 	if r.URL.Path != "/" && r.URL.Path != "/index.html" {
 		if _, err := fs.Stat(assets, strings.TrimPrefix(r.URL.Path, "/")); err != nil {
 			r.URL.Path = "/"
 		}
 	}
+	w.Header().Set("Cache-Control", "no-cache")
 	files.ServeHTTP(w, r)

no-cache means "revalidate before reuse", not "don't store" — the browser keeps the asset but must check with
the server first. Against a local management server that check is free, and it makes the UI version follow the
binary version, which is the invariant //go:embed already implies.

Verification

|

  • curl -I http://127.0.0.1:8791/ → Cache-Control: no-cache (was: header absent).
  • After upgrading the binary, a page reload picks up the new asset without a hard refresh.

Notes / alternatives

A content-based ETag (e.g. keyed on the build version) would additionally make revalidation answer 304 instead
of re-sending the asset. That is more code and needs care for dev builds; no-cache alone already fixes the
staleness, so this PR keeps the change to one line. Happy to follow up with the ETag version if preferred.

The management UI is embedded in the binary (//go:embed) and served through
http.FileServerFS. Those responses carry no Cache-Control, and the embed FS
reports a zero modification time, so there is no Last-Modified or ETag either.
Browsers are therefore free to apply heuristic caching and keep an old
index.html/app.js/styles.css for hours.

That is invisible until the operator upgrades the binary: the new backend then
serves requests that the cached old frontend does not know about, so newly
added pages never appear (or the UI breaks) until the cache expires or the user
hard-refreshes.

Set Cache-Control: no-cache on the embedded assets so the browser always
revalidates. Revalidation is cheap against a local server, and it makes the UI
version follow the binary version, which is the invariant the embed implies.
@jasonxu114514
jasonxu114514 merged commit 05874a5 into jasonxu114514:main Oct 23, 2026
5 checks passed
WengeLiu101 pushed a commit to WengeLiu101/opencode2api that referenced this pull request Oct 24, 2026
TiaraBasori added a commit to TiaraBasori/opencode2api-1 that referenced this pull request Oct 25, 2026
…breaker)

Pick up origin/main (19 commits since v1.4.3):

- 2.1.1 client shape: version bump, /inference/openai|anthropic family
  routes, max_completion_tokens 32000, strict:false tools, client key
  order, no HTML escaping, runtime-owned Accept/Content-Length (jasonxu114514#141-jasonxu114514#143)
- anonymous-lane abuse handling: IP-block detection, per-exit block TTL,
  circuit breaker (models.anonymous_backoff), max_anonymous_exits cap,
  deterministic 4xx stops the walk instead of replaying every exit
- placeholder key dropping, probe failure classification (jasonxu114514#111),
  WebUI Cache-Control (jasonxu114514#112), reasoning disable preserved end to end
  (jasonxu114514#150), Italian README/WebUI

Conflict resolutions:
- internal/config/config.go, README.md, README.zh-CN.md: kept both sides —
  the alias fields (aliases/strip_free_suffix) and the new
  anonymous_backoff block sit side by side in ModelsConfig and the README
  tables.

Local adaptation for this deployment's #pool exit (not upstream):
- a #pool transport dials a fresh upstream address on every attempt, so an
  IP-scoped abuse block cannot be parked on the transport: blocked() and
  markBlocked() ignore pool transports and the anonymous walk keeps
  rotating instead of freezing every exit behind one flagged address.
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.

2 participants