Revalidate static UI assets on every load (Cache-Control: no-cache) - #53
Merged
Merged
Conversation
The static mount sent ETag and Last-Modified but no Cache-Control, so browsers applied heuristic freshness and kept running a cached app.js (and style.css, console.js, ...) after DaveLLM was updated. An open browser or Electron tab could then run stale JS against a newer API. Serve static/ through RevalidatedStaticFiles, which adds Cache-Control: no-cache to every file response and 304. Browsers keep their cached copy but revalidate each load, so an unchanged asset costs a 304 on loopback and a changed one is fetched. API routes are unchanged; the agent events stream keeps no-store. Tests pin the header on /, the fixed-URL assets, and their 304s, assert /health and /nodes carry no Cache-Control, and pin no-store on the SSE events route.
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
app.mount("/", StaticFiles(...))sentETagandLast-Modifiedbut noCache-Control.static/index.htmlloadsapp.js,style.css,console.js,prompt-contract.js,anticipation.js, and vendored GSAP by fixed URLs, so browsers applied heuristic freshness and kept a cachedapp.jsafter DaveLLM was updated. While testing PR #48 (claude/notion-adapter-v1), the page kept running the oldapp.js(transferSize: 0, 173,254 bytes vs 175,326 live) through a plain reload and a direct navigation, untilfetch('/app.js', {cache: 'reload'}). An open browser or Electron tab can therefore run stale JS against a newer API.Change
app.py: a smallRevalidatedStaticFiles(StaticFiles)subclass overridesfile_responseand setsCache-Control: no-cacheon every static file response, including 304s. Browsers still cache, but they revalidate each load: an unchanged asset costs a 304 on loopback and a changed one is fetched. It also covers edits that keep the same version, which versioned URLs fromVERSIONwould miss. The class sits beside the mount at the bottom ofapp.py, below the pinned tool handlers./tools/agent/runs/{id}/events?stream=truekeepsno-store.CLAUDE.mdandREADME.mdeach get one line describing the header.Tests
tests/test_api_contracts.py::test_static_bundle_revalidates_and_api_headers_are_unchanged:/,/index.html,/app.js,/style.css,/console.js,/prompt-contract.js,/anticipation.js,/vendor/gsap/gsap.min.js, and/monitoring.htmlreturnno-cachewith an ETag and Last-Modified. A conditionalIf-None-Matchrequest returns a 304 withno-cacheand an empty body./health,/nodes(authenticated and 401), and a 404 for/app.pycarry noCache-Control.tests/test_agent_lifecycle_api.py: pinsno-storeon the SSE events stream.mainand passes on this branch.Verification (local, macOS, Python 3.14 venv, Node 22)
py_compile(CI's file list),compileall daveharness, andmypy daveharness: clean.pytest -q: 758 passed, 1 skipped.node --checkon all static and desktop JS, plusnode --testfor the run ledger, approval preview, and console suites (5/5): clean.bash -non the deploy and launcher scripts,npm ci,npm ls --depth=0(electron@44.0.0),npm audit --audit-level=high(0 vulnerabilities), andgit diff --check: clean.desktop/main.js,DAVE_ELECTRON_SMOKE_EXIT_MS, CDP on a spare port, static mtimes backdated so heuristic freshness applies,app.jsedited on disk after the first load):main: after the edit, both the navigation and the reload kept running the oldapp.js. The backend log shows the assets were never requested again after the first load (only/revalidated once).app.js(200, edited body confirmed through CDP) and the other assets returned 304. The next reload returned 304 for everything. The UI rendered (titleDaveLLM, composer present) with no page exceptions in both runs.