Repository navigation
Re-read ui/index.html when its mtime changes (#777) - #778
Conversation
tj serve cached index.html at startup, so UI edits served stale markup until a restart. Re-read the file when its mtime changes; the api-key and write-token meta injection still applies to the re-read HTML. Add tests and update .claude/rules/web-ui.md.
|
|
Thanks @ardaylmz30, and welcome. Good first PR. You took option (a) from #777, left the production read-once default intact rather than deleting the cache, and the tests are load-bearing: I reverted What I verified
One change I want before this merges
A blank page behind a 200 with nothing in the console is the most expensive failure mode this UI has (Critical Rule 50 in _ui_cache["html"] = index_path.read_text(encoding="utf-8")That also makes your Two optional notes, neither blocking
One process note, not on youCI has not actually run on this PR. Fork PRs need a maintainer to approve the workflow run, so the checklist in your description reflects your local run rather than our CI. We will start it. I want Add the |
read_text() with no encoding= resolves to the LOCALE default, and ui/index.html holds ~3KB of non-ASCII. Under LC_ALL=C -- a bare container, a systemd unit with no locale -- the read raises UnicodeDecodeError. Before this PR that was a loud crash at create_app() naming the file. With the new cache and its `except (OSError, UnicodeDecodeError)` it becomes silent: the empty initial cache survives and `GET /` returns HTTP 200 with a zero-length body. A blank dashboard, nothing in the console. That is exactly the failure Critical Rule 50 exists for, and the catch is right for the mid-write truncation it was written for -- it just also swallowed this. Two tests. The first asserts the call passes encoding="utf-8" and fails against the unfixed line; a behavioural version would have to mutate the process-wide locale, which is unsafe under -n auto and resolves differently across 3.10/3.11/3.12, so it would prove less while breaking more. The second round-trips the dash, bullet, arrow and tick characters the real file uses, so the pin has a companion that tests content rather than call shape. Side effect worth noting: this also makes the existing undecodable-file test deterministic. It writes a truncated UTF-8 sequence and expects a decode failure, which a latin-1 locale would have decoded happily. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Co-Authored-By: ardaylmz30 <[email protected]>
|
Thanks @ardaylmz30 — CI is green across all six jobs now that I've approved the fork run, and the repair-and-retry commit handles the mid-write case cleanly. I've pushed the one-keyword encoding fix to your branch myself (89c0c95) rather than make you do another round-trip on a first contribution. Nothing else changed, and the commit credits you as co-author. For the record of why it mattered: That is not a criticism of the catch — it is the right fix for the truncation case it was written for, and the bot was right to ask for it. It just also swallowed something that used to be loud, which is the kind of thing only a second pair of eyes catches. Two tests came with it: one asserts the call passes Your two non-blocking nits from the review are worth doing but not here: gating the re-read on a trailing Merging once CI comes back green. Nice first contribution — the mtime approach was the right one of the two the issue offered, and the rules file update was accurate, including the point about |
anilmurty
left a comment
There was a problem hiding this comment.
Approving. CI is 6/6 green on 89c0c95, the branch is up to date with main, and all four of issue #777's acceptance criteria are met with no scope creep.
Verified locally rather than taken on CI's word: the encoding pin fails against the unfixed line and passes with it, 191 tests across the reload, UI-offline, module-parse and API-integration files pass, ruff check tokenjam/ is clean and mypy tokenjam/ is clean across 288 files. The rendered UI was also exercised against a real server, not just TestClient — edit the file, next request serves it, byte-identical to disk with both <meta> injections intact.
One process note for the record: Greptile reviewed the earlier head and returned 5/5 with nothing actionable, and has not re-reviewed since the encoding commit roughly twenty minutes ago. I am merging on the strength of the verification above rather than waiting indefinitely, since the delta since its pass is one keyword and two tests that I wrote and checked myself.
Thanks again @ardaylmz30.
|
Correcting something I wrote in the approval above: I said Greptile had not re-reviewed after the encoding commit. It had. It re-reviewed 89c0c95 at 17:30, sixteen minutes before the merge, and returned 5/5 with nothing actionable. I had it wrong because Greptile edits its existing summary comment in place rather than posting a new review, so a poll that counts reviews or looks at So the merge was not made over a missing bot review, and the §5c process note I attached to it was based on a false premise. Nothing about the change itself is affected. |
Summary
tj servecachedui/index.htmlat startup, so UI edits served stale markup until a restart._serve_uinow re-readsindex.htmlwhen its mtime changes (onestat()per request); the cached string is otherwise reused.tj-api-key/tj-write-tokenmeta injection still applies to the re-read HTML..claude/rules/web-ui.mdto describe the new behaviour.tests/unit/test_ui_index_reload.py(edit → reload shows new content; meta injection on re-read HTML; missing file keeps last good copy).Related issue
Closes #777
Checklist
pytest tests/unit/test_ui_index_reload.py tests/unit/test_ui_offline.py tests/unit/test_budget_route.py)ruff check tokenjam/)mypy tokenjam/api/app.py)tests/factories.py(n/a, no spans in these tests)@anilmurtyas reviewer