# The page renderer out of the instance (design note)

Status: rev 4, built on this branch. Rev 2 was approved by the
coordinating session (2026-11-30). Rev 3 adds the host probe's findings and
the SOURCES record. Rev 4 folds in Astra's build round 1 (below). Branch
`renderer-out-of-instance` off main dd66ff0c. Rev 1 had one Astra review
(NOT READY, 4 Important, 2 Minor). Its findings are folded in below and
listed at the end. It was not reviewed again.

## Problem

dd66ff0c's instance artifact is 374 MB. `scripts/build-instance-release.sh`
copies the Linux runner's `renderer.tar.gz` (230,650,088 bytes) into
`internal/release/bundled`, which `//go:embed bundled/*` links into the
instance so it can serve `/releases/<version>/renderer.tar.gz`. CARLOS caps
one ship at 256 MiB (carlos/platform `internal/console/apicli.go:1827`), so
`carlos deploy` answers 413. Ruling (a): the renderer stops riding inside
the instance binary, and the runner gets it separately, verified as install
verifies it today. No chunked deploys, no split binary.

## Who reads the instance's copy today

Only the self-serve install: `install-v1.sh` runs the runner's
`setup.installUser` (`internal/runner/setup/install.go`). It fetches
`<origin>/releases/<v>/renderer.tar.gz` when no verified tree for the
linked pin is on disk, and requires the archive's MANIFEST digest to equal
both the pin linked into the runner (`release.rendererSHA256`) and the
install manifest's `targets.linux.renderer_sha256`.

The operator paths never touch it. `scripts/upgrade-thin.sh`,
`cutover-thin.sh`, `cutover-finish-thin.sh` and `staging-thin.py` run
the runner's `install-renderer <kit>/renderer.tar.gz` from the release
kit, after `renderer_linked` checks the MANIFEST digest against the runner.
The Mac updater (`thin/mac.go`) fetches only darwin assets, and a Mac has no
renderer. `verify-installed` reads the tree on disk and renders the fixture.

So the change is confined to where the self-serve install gets the archive,
and to what the instance embeds and serves.

## Decision: a release asset on the forge, addressed by the archive

Each renderer archive is published once as a release on the amadan forge,
in oficina/equipo, and the runner knows exactly which one:

- The archive digest `rendererArchiveSHA256` is linked into the Linux
  runner beside the tree pin (`rendererSHA256`), from the same kit file
  (Makefile `release-runner`).
- So is a release tag `rendererTag`: `renderer-<first 12 of the archive
  digest>`, or `renderer-<12>-r<n>` if an earlier publication of the same
  bytes was withdrawn (see below).
- The forge origin and repository path are constants in the runner
  (`https://amadan.net/oficina/equipo/-/releases/`), not data. The runner
  builds the URL itself: origin + tag + `/renderer.tar.gz`. Nothing the
  instance or the install manifest says can point it elsewhere.

The asset is the kit's `renderer.tar.gz`, byte for byte. The forge says
"anyone who can see the repo can download a file", and the repo is public.

The addressing is by archive bytes, not by tree pin. A builder or
compression change can keep the MANIFEST and change the archive. It then
gets its own tag rather than colliding with the published one. Most
releases change neither, link the same tag and publish nothing.

### What the install manifest records

`targets.linux` gains `renderer_archive_sha256` and
`renderer_archive_size` beside `renderer_sha256` (the tree pin,
unchanged). They are informational for the instance and for operators. The
runner checks them against its own linked values and refuses a
disagreement (`runner.install.checksum`). No URL is recorded.

### Trust does not move

The runner checks, in order, before anything of the runner is written:

1. the download is exactly `renderer_archive_size` bytes (bounded by
   `RendererArchiveMax`, 384 MiB) and its SHA-256 is the linked archive
   digest
2. the archive's MANIFEST digest is the linked tree pin
   (`RendererArchivePin`, as today)
3. the unpacked tree verifies in full before it is renamed into place
   (`InstallRenderer` and `VerifyRenderer`, as today). The MANIFEST check
   alone does not cover payload bytes.

Redirects: the forge answers the asset URL with `302` to a presigned S3
URL (host probe, 2026-11-30: `s3.eu-west-1.amazonaws.com`, five-minute
expiry). So the runner follows exactly one redirect, only from the fixed
forge URL, and only to an `https` URL with no credentials in it. A second
redirect, a non-https target or any other status is
`runner.install.release`. The target host is not pinned: the bytes are
checked by size and digest, and the presigned host is the forge's storage
detail. A HEAD, or a ranged GET, is never sent. The forge counts a
redirect it issues as a download (the probe's HEAD made the release
impossible to undo).

### The download

One private scratch file (`O_TMPFILE`, or a 0600 file in the install's own
scratch directory) keeps a single descriptor throughout. The response body
is copied through a hash, bounded at size + 1. A short read, an overlong
read, a cancelled context or a failed check deletes the scratch and stops.
After step 1 the descriptor is rewound for step 2, then again for
unpacking. The deadline is per transfer, with a long overall bound (for
example 20 minutes) and a stall timeout, not `fetchRelease`'s 2 minutes. No
230 MB buffer stays in memory, as one does today.

## What changes, by path

**Instance.** `build-instance-release.sh` stops copying `renderer.tar.gz`
into the bundle. `install_assets.go` stops requiring it, checking its pin
and serving it, so `/releases/<v>/renderer.tar.gz` is a 404, as any unknown
name is. `TestBundledInstallAssets` and the bundle tests drop it. Expected
artifact size is back near 152 MB. A test bounds the bundle (for example
the sum of embedded files under 200 MiB) so this cannot regress silently.

**Self-serve install** (`setup/install.go`):

- A tree already verified for the pin is kept and nothing is fetched (as
  today).
- Otherwise, if the previous release directory beside it has a tree that
  verifies for the same pin, it is copied (not hardlinked:
  `VerifyRenderer` refuses files with more than one link) into a scratch
  directory, verified and renamed into place. Nothing is fetched.
- Otherwise the runner fetches its own URL (above), streams to scratch and
  checks 1-3.
- Failure keys stay as they are, with no new copy: unreachable means
  `runner.install.release`, a wrong digest, size or pin means
  `runner.install.checksum`, and nothing of the runner is written (the
  order today: renderer unpacked and verified before any runner file).

**Upgrade, cutover, staging** (operator, agent-run): no change. They
already install from the kit's `renderer.tar.gz` and verify it against the
runner.

**verify-installed:** no change. The tree is beside the runner, as today.

**Mac:** no change.

## Offline, outage, mismatch

- A runner that already has the tree for its pin needs nothing. Its
  restarts and Design work never fetch.
- A new install, or a new pin, while amadan.net is unreachable fails
  closed, as an install fails today when the instance is unreachable
  (`runner.install.release`). The old tree and the old release stay.
- A mismatch at any of 1-3 refuses (`runner.install.checksum`), writes
  nothing, and the scratch is removed.
- A runner whose tree is missing or wrong still runs Engineering. Its
  renderer health says so, and Design waits (`design_renderer`, the
  existing copy), as today.
- A withdrawn asset (forge `release withdraw`) makes new installs of that
  pin fail closed. The fix is a new renderer pin and release, as for any
  bad build.

## The release kit and the release step

- `make release-runner` keeps building `renderer.tar.gz` into the kit (the
  operator scripts need it). It links the tree pin, the archive digest and
  `rendererTag` into the Linux runner.
- Provenance: `scripts/staged-artifacts.py` records the hashes of
  `renderer.tar.gz` and of `install-manifest.json` in its `artifacts()`
  when the kit is staged, and verifies them on every later use. Then the
  kit's archive and manifest cannot both be swapped after staging while
  the instance embeds the originals.
- New step `scripts/publish-renderer.sh <kit>`. It reads the tag linked
  into the kit's runner. If that release exists, it downloads the asset
  unauthenticated and requires its SHA-256 to equal the kit's. Otherwise it
  tags the current commit, runs `amadan release create <tag>
  <kit>/renderer.tar.gz` and checks the upload the same way. It needs
  writer access (an agent account's token, or a PAT in CI).
- Ordering: `staging-thin.py` runs the same check, a full unauthenticated
  GET of the published asset and its digest against the staged provenance,
  never a HEAD, as a prerequisite before it installs anything. Staging installs from the kit, so without this an unpublished
  asset would only show at a user's install. Production promotion goes
  through staging, so it cannot ship before the asset exists.
- Withdrawal: if a published asset must be withdrawn, the same bytes are
  republished as `renderer-<12>-r<n+1>`. A new runner build links that tag,
  and an Equipo release follows. Runners already installed keep their
  verified trees.

## Alternatives considered

- **Build the tree on the runner from the pinned debs** (98 packages,
  171 MB, from snapshot.debian.org by sha256). It needs no new hosting,
  and `ulikunitz/xz` is already a dependency. But it means a Go port of
  `build-renderer-tree.py` whose MANIFEST must match byte for byte (or
  replacing the Python with it). It also means 98 requests per install to
  a service that asks not to be used as a mirror, and regular mirrors drop
  pinned Chromium builds within weeks. Kept as a possible later fallback.
- **A separate CARLOS ship for the archive.** 230.6 MB is 90% of the
  256 MiB cap, so a Chromium update could cross it. That is the same limit
  again.
- **Object storage outside CARLOS** (an S3 bucket, like the platform's CI
  mirror). New infrastructure, and it steps around the platform.

## Host probe (done 2026-11-30)

The forge accepted a 251,658,240-byte (240 MiB) random blob as release
`probe-size-20261130` in 1 min 49 s, and reported the same SHA-256. An
unauthenticated HEAD answered `302` to presigned S3. That HEAD counted as a
download, so the release could not be undone: an owner withdraws it. The
full anonymous transfer is proven when staging installs from the published
asset (below).

## SOURCES: what we distribute

Publishing the archive makes us a public distributor of the Debian
packages in it and of Chromium. The renderer release therefore carries a
second asset, `SOURCES`, and its notes say so in one line ("The page
renderer: Debian packages and Chromium headless shell <version>. Where
each one's source is: SOURCES.").

`SOURCES` is generated from `internal/release/renderer.json`, the same
pinned list the archive is built from, by
`scripts/renderer-sources.py <renderer.json> <SOURCES>`, so it cannot
drift. It is deterministic text:

- a header: the Chromium headless-shell version (`renderer.json`
  `version`), and its source package on snapshot.debian.org
  (`https://snapshot.debian.org/package/chromium/<version>/`, which links
  the `.dsc` and upstream tarballs)
- one line per amd64 package, in the pin's order: package, exact version,
  architecture, the snapshot URL of the binary it was built from, and its
  source package page
  (`https://snapshot.debian.org/package/<source>/<source version>/`)

A package's source name and version are not in `renderer.json` today
(its `package` is the binary). The generator reads them from each `.deb`'s
`control` (`Source:` field, which defaults to the binary's name and
version), which the archive build already fetches and checks by sha256.
So `build-renderer-tree.py` writes `SOURCES` beside `renderer.tar.gz` in
the same run, and `scripts/renderer-sources.py` is the function it calls.
A test checks `SOURCES` lists exactly the pinned packages.
`publish-renderer.sh` uploads both assets. Its check (full GET, digest)
covers `SOURCES` too, against the kit's copy.

## Astra rev 1 findings and what changed

- Important, URL policy: an https URL from data permits any destination.
  Now the URL is built from a runner constant and a linked tag, and
  only one redirect, from the forge to https, is followed (rev 3).
- Important, provenance: staged artifacts did not record the archive or
  the manifest. Both are now recorded and re-verified.
- Important, identity: a tree pin does not identify the compressed bytes.
  Now addressed by the archive digest, with a revision suffix after a
  withdrawal.
- Important, ordering and hosting: now a full-size upload is proven first,
  and staging requires the published asset as a prerequisite.
- Minor, download lifecycle: specified (one descriptor, bounded, rewound,
  scratch removed on any failure), and the full-tree check is kept.
- Minor, hardlinks: tree reuse copies.

## Tests the build would add

- install builds the URL from the linked tag only, follows one redirect to
  https and refuses a second, a non-https target or a credentialed URL, and
  refuses a wrong size, archive digest or tree pin, and a truncated or
  cancelled download, with nothing written and the scratch gone. It keeps
  a verified tree without fetching, and copies one from the previous
  release.
- the instance bundle has no renderer and stays under its bound; the
  instance answers 404 for it.
- manifest validation requires the archive digest and size on Linux, and
  install refuses a manifest that disagrees with the linked values.
- `staged-artifacts.py` refuses a kit whose archive or manifest changed
  after staging.
- `publish-renderer.sh` refuses a published asset that differs from the
  kit.

## Astra build round 1 (on rev 3) and what changed

- Important, provenance: adding the archive and the install manifest to
  `artifacts()` would send them through the Go build-information check.
  Now every artifact is hashed, and only binaries are asked for build
  information (`NOT_BINARIES`). The exact Linux-target comparison
  includes the archive's digest and size.
- Important, SOURCES lacked provenance. It is now one of the staged
  artifacts, hashed and re-verified like the archive.
- Minor, tagging: `publish-renderer.sh` tags the kit's `COMMIT`, never the
  checkout, and refuses a forge tag on another commit.
- Minor, size: the archive size is linked into the runner
  (`rendererArchiveSize`) from the same file, and `RendererAsset.Valid`
  requires `0 < size <= RendererArchiveMax`.

