Skip to content

feat(events): offer a reload for renders and fragments from another release, and check rolling deploys at release - #714

Merged
JuroOravec merged 9 commits into
mainfrom
test/rolling-deploy
Nov 15, 2026
Merged

JuroOravec merged 9 commits into
mainfrom
test/rolling-deploy

Conversation

@JuroOravec

@JuroOravec JuroOravec commented Nov 15, 2026 •

Copy link
Copy Markdown
Member

Part of the 1.0.0 work (#624, C6; decision 10 and the C6 scope additions). One PR, because the script's judgement of a render with other helpers depends on the browser change.

What changes

  1. The page reports that it is out of date instead of failing with a plain error when it gets something another Citry release wrote and it cannot read:

    • a vue-prepared/1 render whose definitions name another helper contract (checked first in preflight, then again where a definition asset or script is registered);
    • a Vue fragment whose protocol is not citry-vue-fragment/1, or that has a top-level field other than vue.

    The runtime fails these with an error whose code is stale_state and status is 0. The Events bridge sends every stale_state failure, from the server or from the browser, through one reportFailure path: the cancelable citry:events:stale (reason version), then Citry's own once-per-page report, then citry:events:error. That path now covers queued calls, wait: false actions, and the public Citry.events.applyActions (including its preflight). A refused fragment fires the new citry:fragments:stale event instead (see below).

Production behaviour change (maintainer decision)

Citry's own report on an out-of-date page, from an expired State token (#706) or from a deploy:

  • Development mode (configuration.development === true): the built-in confirm("This page is out of date. Reload to continue?"), once per page.
  • Production: no prompt and no automatic reload. The call still rejects with stale_state, Citry still fires citry:events:stale (reason version) and citry:events:error, and it writes one console.warn per page that names the cause and links https://citry.dev/reference/browser-apis/#out-of-date-pages.
  • Cancelling the stale event replaces the report in both modes. The once-per-page flag is shared by every app on the page and by fragments, so the first report decides.
  • serialization.py now writes development into the page configuration, so a fragment knows which mode its server ran in. The page's own mode (from the first app startDocument starts) decides how a refused fragment is reported; the fragment's flag counts only on a page with no Citry app of its own. That way a fragment block injected into a production page without a nonce cannot make it ask the question.

Why a separate citry:fragments:stale event. A fragment comes from no event call. Every citry:events:stale detail promises instance, class and event, and a fragment has none of them, so reusing that event would break its documented shape. citry:fragments:stale bubbles, is cancelable (cancelling replaces Citry's report, as for citry:events:stale), has detail {reason: "version", error}, and fires on the fragment's data <script> while it is in the page, otherwise on document. A listener on document always hears it.

Docs: browser APIs has a new section "Handle out-of-date pages" with a banner-and-reload-button example, a warning not to reload from the listener (a cached page with an expired token would loop), and the fragment event. It says an expired token is the common production case. The Versioning page, web frameworks, State, cache backends, security, development mode, troubleshooting (a row for the warning), HTML fragments, the spec, the upgrade guide, the blog post, the design docs and the CHANGELOG are updated to match. The CHANGELOG has an "Upgrading from 0.9.x" entry for the production change and an "Added" entry for the fragment event.
2. scripts/rolling_deploy/: check.py installs the previous published citry (from PyPI) and the candidate (wheel or checkout) in two uv environments. scenario.py runs the same app on both. In each direction (old page to new server, then new page to old server) it renders pages with signed and server-stored State into a shared DiskCache, sends their event calls to the other release through the WSGI app, fetches their runtime and definition files (compared by SHA-256), and renders a cached component again. An answer must be a success or stale_state.

  • What a success must mean (maintainer request): the counters start at 41, away from State's default of 0, so a server that ignored the page's State would show another count. A successful bump must render 42. The count is read from the answer's render as the whole text rolling-count-<n>, which scenario.py builds in template_data, so it reaches the render as one string in any form (the text of an HTML render, or a value in a Vue render's data) without depending on a field name the release's browser code chose. A render showing no count, another count, or two counts fails.
  • Second click: the page's next bump goes to the same serving release with the State token, render ID and app revision the first answer returned, and must render 43. For signed State this proves the new token carries the new count. For server-stored State the answer returns a new pointer on every write (each write stores State under a new key and leaves the old entry), so the check sends the returned pointer, not the original one: the original would rightly still show 42. A separate scenario.py answer process with a fresh engine reads the new pointer, so 43 can only come from the shared store. After an answer that leaves the page out of date (stale_state, or a render with other helpers), the second call is reported as SKIP, not failed.
  • Not checked: the token the serving release returns is not sent back to the rendering release; the second click goes to the same release.
  • How it knows what is promised: from the two version numbers alone. Only a deploy within one major version, 1 or later, can fail the run. For any other pair (0.9.0 to 1.0.0 today) every result, including a stage that crashes, is reported and the exit code is 0. The one exception: if the script cannot find the previous release on PyPI, it fails before it can decide.
  1. Release qualification only (decision 10): a rolling-deploy job in py--citry--publish.yml, run for qualify, beside smoke-python, and required by verify-distributions. It is not run on PRs. Plus one line in the release section of docs/codebase.md.

The script's check is now named page_reports_out_of_date and its status stale.

Adding a verification step (CLAUDE.md checklist)

  • Contract protected: a page rendered by one 1.x release keeps working, or reports that it is out of date as documented, when its requests reach a worker on another 1.x release (event calls with signed and server-stored State, runtime and definition files, cached renders), in both directions.
  • Cheapest boundary: two real installed releases, run as separate processes against one shared store, answered through the real WSGI adapter. No browser and no network server. The browser's half (the out-of-date report) is proven once by node and e2e tests in this PR, not again in the script.
  • When it runs: once per citry qualification run. Never on PRs or pushes.
  • Measured cost: the script took 10 s locally with a cold uv cache (UV_NO_CACHE=1, 0.9.0 to the built candidate wheel, both directions). With checkout, setup-python, uv install and two artifact downloads, the job should take well under 1 minute. I could not time it in CI, because a qualify run needs a release candidate on main. It runs in parallel with the smoke-python matrix, whose five jobs took 01:38:24 to 01:43:15 (about 5 minutes, mostly runner queueing) in the last qualify run, 43663453455. So I expect no addition to the release critical path. Worst case, if it is the last job to get a runner, it adds under 1 minute.
  • Reused evidence: the raw-citry-distributions wheel and, when selected, the candidate-citry-core-wheel from build. Nothing is rebuilt.
  • Concurrency: independent of smoke-python; both gate verify-distributions.
  • Disk: two environments of about 0.1 to 0.3 GB, in a temporary directory that is deleted afterwards.

Smoke run against 0.9.0

python scripts/rolling_deploy/check.py --previous 0.9.0, with the candidate built from this branch's checkout (its version still reads 0.9.0 because main has not been bumped; the different runtime hashes show the two installs differ). The run is report-only, because 0.9.0 to 0.9.0 is not a 1.x deploy. Output on 2d220e1:

Rolling deploy from citry 0.9.0 to 0.9.0 (5 s)
  OK      old page, new server: event call, signed State: the call succeeded, its render shows 42, and it uses the page's render helpers
  OK      old page, new server: event call, stored State: the call succeeded, its render shows 42, and it uses the page's render helpers
  OK      old page, new server: second event call, signed State: the call succeeded, its render shows 43, and it uses the page's render helpers
  OK      old page, new server: second event call, stored State: the call succeeded, its render shows 43, and it uses the page's render helpers
  OK      old page, new server: runtime /citry/citry.fa9d3c244db272262b258532d316f0c595f64ed6bd5948838bf9de82ef26f2bc.js: served with the SHA-256 the page expects
  OK      old page, new server: definition /citry/ext/events/definitions/6ebe7df7a4039d350faef6cfe56123a639905cefd394ac59984b26b21a34cf16.js: served with the SHA-256 the page expects
  OK      old page, new server: cached render: rendered again; the output matches a render without the entry
  OK      new page, old server: event call, signed State: the call succeeded, its render shows 42, and it uses the page's render helpers
  OK      new page, old server: event call, stored State: the call succeeded, its render shows 42, and it uses the page's render helpers
  OK      new page, old server: second event call, signed State: the call succeeded, its render shows 43, and it uses the page's render helpers
  OK      new page, old server: second event call, stored State: the call succeeded, its render shows 43, and it uses the page's render helpers
  OK      new page, old server: runtime /citry/citry.fe718b6db2db50188b4fcd54df7a3e434539ca6eb8ad31c272de801654ac088d.js: served with the SHA-256 the page expects
  OK      new page, old server: definition /citry/ext/events/definitions/6ebe7df7a4039d350faef6cfe56123a639905cefd394ac59984b26b21a34cf16.js: served with the SHA-256 the page expects
  OK      new page, old server: cached render: rendered again; the output matches a render without the entry
Only deploys between two releases of the same major version, 1 or later, are promised. These results are reported only; a failed check does not fail the run.

Checks

  • pnpm --dir packages/js/citry-client run check: 334 pass. Generated runtime.js, events.js and fragments.js were rebuilt with pnpm run build.
  • New node tests:
    • the bridge reports stale_state failures on every path: a waited action, a wait: false action, and public applyActions refused in preflight;
    • a fragment with another protocol, or an unknown top-level field, fires citry:fragments:stale (on the block, or on document once the block is gone) and reports once: a question in development, a warning in production, nothing when cancelled; one refused for its nonce does not;
    • registerDefinition treats another helper contract as stale_state.
  • E2E plus the script, token and dev-check tests: 742 passed (4 skips: the private venv has no django or uvicorn). The stale-token and helper-contract tests run in both modes: development checks a single question, production checks no question and one warning that links the docs section.
  • packages/py/citry/tests/test_rolling_deploy_script.py (20 tests): which pairs are promised, the previous-release pick from a synthetic PyPI payload, how answers are classified, the page reader, the digest check, and the exit rule when a stage cannot run.
  • Citry non-browser pytest passed, apart from failures caused by my private venv: no yaml or citry_ui, pydantic 2.14.3 against the locked 2.14.1, and no tzdata. They are in unrelated files.
  • scripts/validate.py passed; test_ci_workflows.py passed, with the --core-wheel consumer count updated to 3; ruff and mypy are clean, including --platform linux. I did not run the full gate, because its cargo phase needs a Rust build, which this lane must not run.

Review (Mechanism 6, 7, 8)

An independent reviewer (technical, security, advisory survey, prose) and the docs-cold-reader agent both read the change. Fixed during the review:

  • public applyActions gave no out-of-date report, because its preflight ran outside the reporting path. It is now reported, and the test makes the failure happen in preflight;
  • other preflight checks could fail a newer-release render with a plain error first. The helper contract is now checked first;
  • the script judged only one direction. It now runs both;
  • a crash failed even report-only runs. Stages that cannot run are now reported as failures and fail only a promised deploy;
  • file checks only looked at HTTP 200. They now compare SHA-256, and a page with no definition file fails;
  • the cached-render result now says whether the other release's entry was reused or rendered again;
  • the error text and docs now say "another Citry release", not "a newer one" or "a different version of the app";
  • the changelog said pages from the older release now offer a reload. That is wrong for an upgrade from 0.9.0, and now reads "a page rendered by this release";
  • the spec clashed with its own 409 pairing for stale_state. It now says the error is made in the browser and never travels on the wire;
  • documented what a visitor who declines sees;
  • fixed the stale wording on the Versioning page ("reloads once") and in the audit doc.
  • after the production change, a second docs-cold-reader pass found: the cause list missed dropped server-stored State and unknown token versions; "the page stays unusable" overstated it (only calls from that component fail); the example did not cancel the events, so development showed both the dialog and the banner; a refused fragment's visible effect was not described; cache.py and settings.py docstrings still mentioned the old reload offer. All fixed.
  • a later independent review of the production change found no security hole and confirmed production never asks. Fixed from it in 1796113:
    • the docs no longer mention Citry.fragments.load, which is not public;
    • the upgrade guide has a checklist step and its own section for the out-of-date listener, moved out of the _max_age fix;
    • a refused fragment follows the page's own mode (see above), with node tests for an injected block on a production page and for a development page;
    • a server test checks that the development flag reaches a fragment's prepared, and the fragment e2e fails if any dialog opens in production;
    • stale reload wording in tokens.py, docs/codebase.md, the CHANGELOG (the snippet now cancels and listens for both events), the spec, settings.py, development mode and troubleshooting;
    • prose in the browser APIs section and a rewrap in cache.py.
  • an independent reviewer checked the count check (f047b93). Fixed in 2d220e1:
    • the counters started at State's default of 0, so a server that ignored the page's State would also have shown 1. They now start at 41;
    • the skip reason said stale_state also when the page refused a render with other helpers; it now says "left the page out of date";
    • a token refreshed by a protocol state action (instead of the render's Events record) is now accepted;
    • comments now explain why the returned pointer is used for stored State, plus prose fixes;
    • tests for each of these: 31 tests in test_rolling_deploy_script.py, including a success with the wrong count (1, 41, 43, none, two counts), a wrong count with other helpers, and the skip reasons.

Not changed:

  • Script judges renders by helper contract only. Any other change to the render format is not detected. Running the old runtime's preflight on the new answer would need node or a browser in the job. Its OK message now says only what it checks.

Security (Mechanism 7). Places touched: Events responses, navigation (location.reload), fragment data blocks, and the CSP nonce path. The question and warning texts are constants, the question appears only on a development page, and the navigation is always a reload of the same URL after the visitor agrees. Routes the reviewer classified:

  • safe: the server's own answers (same-origin), and a fragment block under a nonce-based CSP (refused before the new check; tested);
  • author-only by design: a custom transport or public applyActions;
  • low nuisance, not a hole: on a page without CSP, or with a CSP that uses hashes instead of a nonce, injected markup can raise the report (a console warning in production) and use up the once-per-page report. Without CSP the same injection can already run script.

The reviewer also noted, for the maintainer, existing behaviour that this PR did not add: under a CSP without nonces, an injected fragment block can start a fragment with definition URLs it chooses.

Mechanism 8. The reviewer read the advisory survey and checked hydration, trusted-shape, script-load, open-redirect, xss-url, dom-clobber, proto, ci and cache-key. This change introduces none of them.

🤖 Generated with Claude Code

JuroOravec and others added 6 commits November 15, 2026 18:08
…lease, and check rolling deploys at release

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… and add citry:fragments:stale

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ocument the fragment event

Rename the docs section to Handle out-of-date pages, lead it with the
production case, add a banner example and the citry:fragments:stale
event, and update every page, guide, design doc and changelog entry that
described a reload question in production.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
List every cause of stale_state, cancel the events in the example, say
which calls keep failing, explain what a refused fragment looks like,
and fix the stale reload wording in two docstrings.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ported

A fragment's development flag now counts only on a page with no Citry app
of its own, so an injected fragment block cannot make a production page
ask the reload question. Add tests for that case and for the flag
reaching a fragment, add an upgrade step for the out-of-date listener,
and fix the remaining reload wording.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
JuroOravec and others added 2 commits November 15, 2026 19:56
… count

Each successful bump must render the count 1, and a second bump sent with
the State the first answer returned must render 2, for signed and
server-stored State in both directions. After stale_state the second call
is reported as skipped.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t count

A server that ignored the page's State would also render 1 after one
click, so the pages now start at 41 and the check expects 42 and 43. Also
accept a token refreshed by a state action, and word the skip reason so it
fits a render the page cannot read.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@JuroOravec
JuroOravec merged commit 0cc86a3 into main Nov 15, 2026
33 checks passed
@JuroOravec
JuroOravec deleted the test/rolling-deploy branch November 15, 2026 19:48
JuroOravec added a commit that referenced this pull request Nov 16, 2026
JuroOravec added a commit that referenced this pull request Nov 16, 2026
* docs: record the security reviews of #713, #714, #718 and #722

Adds the Mechanism 7 step 7 records for four merged pull requests:
GHSA-x773 (#713, reserved attribute names as c-bind keys), #714
(out-of-date pages and the rolling-deploy check), #718 (one Rust URL
scheme reader), and GHSA-7fjh (#722, reserved data-* names in Citry UI
attribute maps). The two advisory records name the advisory and the
affected and fixed versions; the facts come from the pull requests.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

* docs: link the #720 follow-up from the #714 review record

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Sonnet 5.5 <[email protected]>
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.

1 participant