Skip to content

Harden the widget release: pin wrangler, enforce host agreement, probe the routes - #443

Merged
neuromechanist merged 5 commits into
developfrom
fix/release-hardening
Sep 22, 2026
Merged

neuromechanist merged 5 commits into
developfrom
fix/release-hardening

Conversation

@neuromechanist

Copy link
Copy Markdown
Member

Addresses every finding from the two release reviews of #442, plus the production route pre-attach. All five are things this rollout has already been bitten by once.

1. The deploy wrangler was unpinned

sync-worker-cors.yml ran npm install -g wrangler with no version, so every CI run used whatever was newest on npm that day.

That matters here specifically: once a [[routes]] table is present, wrangler flips workers_dev to false, and that already took the workers.dev hostname down once during #437, with clean deploy output. A floating installer reintroduces that class of silent regression on a future date with no code change at all.

JS lockfiles are gitignored here by design, so package.json is the only real pin: the caret is now exactly 4.136.2. Both steps also move from npm to bun, matching the tooling rule and the setup-bun pattern already in test.yml and tests.yml.

2. MOUNTED_HOSTS and the route patterns could drift silently

index.js's MOUNTED_HOSTS and wrangler.toml's [[routes]] have to agree and nothing enforced it. The two drift directions are not equally visible:

Drift What happens Visible?
Host in a route, not in MOUNTED_HOSTS Strip is a no-op, every path keeps its prefix, all requests 404 Loud, and the fall-through logs both paths
Host in MOUNTED_HOSTS, not in a route Cloudflare never invokes the worker at all Silent. No worker code runs, so no log can ever catch it

test-mounted-hosts.js catches both, and also asserts each route mounts at MOUNT_PREFIX, since matching hostnames with a mismatched path would pass a hostname-only check and still be wrong. Wired into both workflows.

Mutation-verified: an extra MOUNTED_HOSTS entry fails 2 of 11 and names the silent direction; a route moved to /chat/* fails the prefix assertion alone.

3. The 404 diagnostic log was unreachable

No [observability] block existed, so console.warn was visible only to someone running wrangler tail at the exact moment a request arrived. The log added in #438 satisfied "we added logging" in review while behaving as silent in production: it could not explain an outage after the fact, which is the only time anyone looks. Workers Logs now enabled for both environments.

4. Nothing watched the routes

The status dashboard resolves straight to api.osc.earth/osa, so it never traverses the worker and stays green through a total route outage. Now that nemar.org's Content-Security-Policy points at widget.osc.earth (that repo's ADR 0017), a host other people have pinned needs something watching it.

widget-route-health.yml probes every 15 minutes: both mounted hosts, the legacy workers.dev name that cached SRI-pinned builds still call, and the host gate itself, where a 200 instead of a 404 would mean the strip went host-blind again. Files a labeled issue on failure, comments rather than duplicating, closes on recovery.

5. release.yml has been dead since February 2026

Its only trigger was push: tags, and tag-release.yml pushes the tag under the default GITHUB_TOKEN, from which GitHub deliberately does not start workflow runs. Zero runs for v0.8.9 through v0.8.12; the last was v0.6.2, back when a real token pushed tags.

The symptom: published release notes carried the plain commit log and never the Widget Embedding section, which is the only place the SRI hash for a version-pinned embed is published. Consumers were pointed at a section that did not exist, which matters most for a release that changes the widget's hostname.

Fixed with release: types: [published], the same escape publish.yml already uses. Takes effect on the release after this one, since GitHub reads triggers from the default branch.

Also: rollback is documented

The rollback section covered the Docker backend only. It now records what a release actually does and what cannot be undone. The tag and the PyPI upload are immediate and permanent, so the way back is a revert PR that cuts the next patch, not deleting a version. A revert must also verify the Cloudflare route detached, and /health is not sufficient evidence because it answers from the worker even when the deployed widget points elsewhere.

Production route is already attached

Separately, widget.osc.earth/osa/* was registered ahead of the merge so the frontend flip does not race the route registration, which was the blocker finding. Verified live: /osa/health, /osa/communities and /osa/hed/ all 200 against the production backend; both workers.dev names still 200; osa-worker…workers.dev/osa/health correctly 404, confirming the host gate.

Gates

93 routing, 10 mounted-hosts, 13 endpoint, 69 streaming, 10 citation, both syntax checks, ruff check clean, all five workflows YAML-validated. The seven files ruff format would reformat are Markdown with embedded Python, pre-existing on develop and untouched here.

Related: #437, #438, #439, #442.

The deploy steps ran a bare global npm install of wrangler, so every CI
run used whatever was newest on npm that day, while the worker declared
a caret range locally.

That matters here specifically. wrangler's defaults are version
dependent: once a [[routes]] table is present it flips workers_dev to
false, and that already took the workers.dev hostname down once during
#437, with clean deploy output either way. A floating installer can
reintroduce that class of silent regression on a future date with no
code change at all.

JS lockfiles are gitignored in this repository by design, so package.json
is the only place a version can actually be fixed; the caret is now an
exact 4.136.2. The steps also move from npm to bun, matching the
repository's tooling rule and the setup-bun pattern already in test.yml
and tests.yml.

Verified: bun install resolves wrangler 4.136.2 and bunx wrangler
--version reports it.
index.js's MOUNTED_HOSTS and wrangler.toml's [[routes]] patterns have to
say the same thing, and nothing enforced it. Both drift directions are
bad and one is completely silent:

A host in a route but not in MOUNTED_HOSTS means the worker runs, the
strip is a no-op, every path keeps its prefix and every request 404s.
Loud, and the 404 fall-through logs both paths, so it is diagnosable.

A host in MOUNTED_HOSTS but not in a route means Cloudflare never invokes
the worker at all. No worker code runs, so no console.warn can fire and
no application log can ever catch it. The only symptom is an external
request failing. That is the direction this test exists for: invisible at
runtime, so it has to be caught at build time.

Also asserts each route mounts at MOUNT_PREFIX, since matching hostnames
with a mismatched path would pass a hostname-only check and still be
wrong.

Mutation-verified both ways: an extra MOUNTED_HOSTS entry fails 2 of 11,
naming the silent direction explicitly; a route moved to a different
prefix fails the prefix assertion alone.
console.warn and console.error in the worker were visible only to someone
running wrangler tail at the exact moment a request arrived. That makes
the 404 fall-through log added in #438 satisfy "we added logging" in
review while behaving as silent in production: it cannot explain an
outage after the fact, which is the only time anyone looks.

head_sampling_rate stays at 1.0 because this worker serves chat requests
and health probes rather than high-volume edge traffic.
Nothing watched the worker's public mounted hosts. The status dashboard
resolves straight to api.osc.earth/osa, the FastAPI backend, so it never
traverses the Cloudflare Worker or widget.osc.earth and stays green
through a total route outage.

That gap matters now that a third party's Content-Security-Policy points
at widget.osc.earth (nemarOrg/website ADR 0017). A host other people have
pinned needs something watching it.

Probes every 15 minutes: both mounted hosts, the legacy workers.dev name
that cached SRI-pinned builds still call, and the host gate itself, where
a 200 rather than a 404 would mean the strip went host-blind again and is
silently swallowing a community named osa.

Files a labeled issue on failure, comments on it rather than filing
duplicates, and closes it on recovery. The probe report goes through env
rather than being interpolated into the github-script body: the values
are hardcoded URLs and status codes today, but interpolation is the wrong
habit in a workflow holding issues:write.
release.yml has not run since February 2026. Its only trigger was
push: tags, and tag-release.yml pushes the tag under the default
GITHUB_TOKEN, from which GitHub deliberately does not start workflow
runs. Zero runs for v0.8.9 through v0.8.12; the last was v0.6.2, back
when a real token pushed tags.

The symptom was that published release notes carried tag-release.yml's
plain commit log and never the Widget Embedding section, which is the
only place the SRI hash for a version-pinned embed is published.
Consumers were being pointed at a section that did not exist, which
matters most for a release that changes the widget's hostname.

Adds release: types: [published], the same escape publish.yml already
uses, plus a manual dispatch. Takes effect on the release after the one
that merges it, since GitHub reads triggers from the default branch.

The rollback section covered the Docker backend only. It now records
what a release actually does and what cannot be undone: the tag and the
PyPI upload are immediate and permanent, so the way back is a revert PR
that cuts the next patch rather than deleting a version. Also notes that
a revert must verify the Cloudflare route detached, and that checking
/health is not enough because it answers from the worker even when the
deployed widget points elsewhere; only a real chat round trip on
demo.osc.earth shows that.
@neuromechanist
neuromechanist merged commit 1e2ae59 into develop Sep 22, 2026
9 checks passed
@neuromechanist
neuromechanist deleted the fix/release-hardening branch September 22, 2026 15:07
neuromechanist added a commit that referenced this pull request Sep 22, 2026
Brings the widget-hostname work (#437, #438, #440, #441) and the release
hardening (#443) onto the epic branch. Two conflicts, both real rather
than textual.

workers/osa-worker/index.js: phase 1 matched its routes against the raw
url.pathname, which predates develop's host-gated stripMountPrefix. Left
as merged, every phase 1 route would have 404'd on widget.osc.earth
while ordinary chat worked, so the two-run continuation would have been
broken on the mounted host only. Both communityAction and
communityChatResume now match the stripped pathname; the named
ROUTE_PATTERNS constants from phase 1 are kept.

workers/osa-worker/test-routing.js: both branches created this file
independently. Develop's version drives the real exported fetch handler,
phase 1's asserted against the regex constants in isolation. Kept
develop's, because a test that matches a pattern by hand cannot catch a
route wired to the wrong variable, which is exactly the bug above. Phase
1's resume coverage is re-added in that style, driving the real handler
prefixed and unprefixed.

The workflow conflicts were duplicate steps; develop already runs the
routing test in the same job.

Tested: 102 routing, 10 mounted-hosts, 13 endpoint, ruff clean, 2483
pytest passed. Note that a fresh worktree resolves Python 3.14, where
langfuse's pydantic.v1 usage fails at collection; pin 3.12 to match CI.
neuromechanist added a commit that referenced this pull request Sep 30, 2026
The file had sections for 0.8.10, 0.8.12, 0.8.14 and 0.8.15 only. The
three missing releases are written from the pull requests between their
tags (0.8.13: #438, #440, #441, #443; 0.8.11: #418; 0.8.9: #351 to #355
and #359 and #367), so the last seven releases are now all present.

Tested: docs only; each entry checked against its pull request's body.
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