Repository navigation
ci: run the checks in parallel jobs and deploy main sooner - #170
Merged
kalaspuff merged 13 commits intoOct 21, 2026
Merged
Conversation
cargo run gives xtask CARGO_MANIFEST_DIR, CARGO_PKG_VERSION and the rest of its package's variables, and every command xtask ran inherited them. ring's build script reads several (rerun-if-env-changed), so cargo built ring, rustls, tungstenite and everything on them again whenever it ran with and without xtask in turn, and in CI on every run after a release: rust-cache's keys leave the workspace version out, so the cache kept the values of the version it was saved with. util::run, output and run_with_stdin, and the processes cargo xtask dev starts, now run without them. util also gets beside/join, which run a closure on a thread of its own with the output of its commands prefixed with a name, for builds that run at once.
cargo xtask dev built the CLI, host and agent, then installed the Node dependencies, built the web app, applied the D1 migrations, and only then started wrangler dev, which built the Worker: a minute and a half of CI's smoke test, one thing after another on four cores. Now the CLI, host and agent build on one thread, the Worker (worker-build --dev) on another, and the Node dependencies, the web app and the migrations on a third; the last two's output comes prefixed with worker and web. The Worker builds in target/worker, a target directory of its own, so that neither cargo waits for the other's lock, and wrangler dev builds there too: as it starts, its worker-build only binds the Worker again.
The check job ran cargo xtask check from start to end: formatting, the generated types, Biome and TypeScript, Clippy twice, the tests, Vitest and the web app's build, one after another, two and a half minutes on every pull request. cargo xtask check now takes parts (lint, test, web; all of them without one, in the same order as before), and CI runs each in a job of its own. A job named cargo xtask check passes once they all have, so main's ruleset requires the same checks as before; a test checks that ci.yml runs every part. .github/actions/rust sets up Rust the same way for every job: the toolchain from a cache, the runner image's own toolchains removed (rust-cache's keys hashed them, so every image update, and every second image in use during a rollout, started the caches over), and rust-cache saved from main only, so that pull requests stop pushing main's caches out of the repository's 10 GB (it was at 11.6 GB). Dev and test builds leave out debug info (CARGO_PROFILE_DEV_DEBUG=0), which halves their build and link times and the caches. On main, what the deploy ships (the web app, the release Worker and xtask) builds beside the checks, and the deploy only waits for them. The Worker's release build is cached by what it is built from, so a push that leaves its crates, the manifests, the toolchain and ci.yml as they were deploys the Worker built before.
…, to measure them
Every job spent nine seconds building xtask, from files that most pull requests don't change. .github/actions/xtask puts the binary on PATH from a cache keyed by what it is built from (its crate, fctl-proto, the manifests, the lockfile, the toolchain), building it only when they changed; jobs run xtask check, xtask dev and xtask lint-commit with it, and the web and Commits jobs need no Rust at all when it hits. On main the deploy takes xtask the same way and builds the web app (two seconds) itself, so the only build beside the checks is the Worker's, whose job skips Rust when its cache hits.
…and try the deploy
3 tasks done
kalaspuff
approved these changes
Oct 21, 2026
kalaspuff
deleted the
fctl/106-what-kind-of-optimisations-can-we-do-to
branch
October 21, 2026 16:55
kalaspuff
pushed a commit
that referenced
this pull request
Oct 21, 2026
A release waits for the standalone image: its Build and run a session job took 6.5 to 10 minutes in the last two releases, and its Publish job another 2.5. Most of that time went to work that didn't have to happen: - **The Rust image moved under the cache.** The Worker's stage built on `rust:1-slim-bookworm`, which Docker Hub rebuilds with every Rust and Debian release (it moved again this morning, after v0.14.1). Each move started every later layer over: `cargo install worker-build` ran again (2:03 in v0.14.1's run), and so did the download of the image's newer Rust, on top of which `rustup toolchain install` then put the pinned one. The stage now builds on `rust:1.99.0-slim-bookworm`, the Rust that `rust-toolchain.toml` pins, whose tag last changed on October 6. `rustup toolchain install` only adds the wasm32 target and the components. A test in `xtask/src/serve.rs` fails when the two versions differ, so a toolchain bump moves both. - **The Worker's layer held a gigabyte.** With the target directory and the fetched sources in it, every build exported it to the GitHub Actions cache: in v0.14.0's run, "preparing build cache for export" took 29 s and writing that layer 16 s, and Publish imported it again. The build's `RUN` now removes them and keeps only the Worker. worker-build's layer drops the sources cargo fetched for it, which every build that rebuilds the Worker imported too (18 s). - **Publish built arm64 from scratch under QEMU.** Its apt-get and npm ci took 90 s in v0.14.1's run, the same work in every release. Publish now writes its layers to a cache scope of its own (`standalone-publish`, the image's final layers only) and reads it back, so those steps run again only when the Node image or the lockfile changes. - **The session through the image** builds the CLI, host and agent without debug info (`CARGO_PROFILE_DEV_DEBUG=0`), as #170 does in `ci.yml`. In v0.14.0's run that build took 49 s. The Worker itself still builds from scratch in every image build, dependencies included (about two minutes). Caching its dependencies in a layer of their own, as cargo-chef does, would need their build to copy worker-build's environment exactly: wasm-bindgen's macros read `WASM_BINDGEN_USE_JS_SYS` at expansion time, a variable cargo doesn't track, so a mismatch would give a wrong Worker, not a slow one. ## How I verified it This pull request's Standalone image run builds the image from the new Dockerfile, starts it, runs `cargo xtask dev --smoke --server` through it and checks that it stops cleanly. The xtask tests pass, the new one included. Publish runs only for a release, so its cache shows its effect from the second release after the merge on: the first one fills it. Refs #170, which makes the checks on pull requests and the deploy from main faster. Session: https://app.fctl.sh/s/ses_01M5FGG04ZQGCABWSN2Z0NDSJE Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
kalaspuff
pushed a commit
that referenced
this pull request
Oct 21, 2026
…176) Sessions learned what became of their pull requests only from their agents, which look each one up when a turn ends, until it merges. A pull request merged or closed after the session's last turn, as most are, stayed "open" in the lists and on the session page for good, and nothing said whether its checks passed. Now GitHub tells the control plane, through the GitHub App's webhook, and session lists, the session page and `fctl show` show each pull request's current state and whether its checks are green ([ADR 0032](docs/adr/0032-githubs-webhook-keeps-sessions-pull-requests-current.md)). ## How it works - **The webhook**, `POST /api/v1/github/webhook`, takes deliveries signed with `GITHUB_WEBHOOK_SECRET` (HMAC-SHA256, constant time; 401 otherwise, 501 without the secret) for the events Pull request, Check run, Check suite and Status (`fctl_domain::webhooks`). - **A delivery is a cue, a lookup the answer.** D1's new `pull_request_sessions` (migration 0019, backfilled from every session's list) says which sessions list which pull request, with its head commit, which commit statuses name. For each listed pull request a delivery concerns, the control plane asks GitHub with one GraphQL query (title, state, draft, merge queue entry, times, and the head commit's checks counted by state), with a token of the installation that sent it, cached per isolate while valid. When the lookup fails, a `pull_request` delivery's payload gives the state. - **The sessions** get it at SessionDO's new `/pull-requests`, which keeps what is newer (`fctl_domain::pulls::update`): GitHub's `updatedAt` orders what GitHub and agents say, so an agent's stale state file can't reopen a merged pull request; an agent's `open` leaves a queued one queued (`gh` can't see merge queues); checks go by when the control plane asked. Viewers and dashboards see the change at once, D1 within seconds. - **Queued** is the webhook's action `enqueued` (or `queued`), a merge queue entry, or `mergeStateStatus` (else `mergeable_state`) of `queued` or `in_merge_queue`. - **When the state changed** (`state_changed_at`): when GitHub says it merged, closed or joined the queue, or else when fctl saw it change. Agents now ask `gh pr view` for `updatedAt`, `createdAt`, `mergedAt` and `closedAt` too (older `gh` falls back as before). - **Lookups without a delivery:** pull requests are looked up as sessions find them, and the hourly job looks up to 30 that aren't merged or closed and that nobody asked about for six hours. That catches missed deliveries and brings sessions from before the webhook up to date. - Instances without `GITHUB_WEBHOOK_SECRET` look nothing up and behave as before. `PullRequestRef` gains optional `state_changed_at`, `updated_at` and `checks` (`PullRequestChecks`: passed, failed, pending, sha, at), and `state` may be `queued`: older hosts, agents and CLIs ignore them. ## What people see Each pull request gets GitHub's octicon for its state in GitHub's color (open, draft, queued, merged, closed, or unknown until someone looked it up), and while it is open a mark for its checks: all passed ✓, some pending ●, one failed ✕. Tooltips and screen readers say it in words ("fctl#171, open, 1 of 4 checks failed"). The Pull requests section says when it merged, closed or joined the queue, and how many checks passed. `fctl show` prints `app#12 open, 1 of 4 checks failed`. The colors are the new `pr-*` and `checks-*` tokens of @hyperstructure/design v0.6.0 (hyperstructure/design#16); the table's last row, unknown, was cut off in the request, so its colors (`#59636e` light, `#9198a1` dark) and icon (git-pull-request) are my pick. ## Before merging - [x] Merge hyperstructure/design#16, which released v0.6.0, then pin `github:hyperstructure/design#v0.6.0` in `web/package.json` in place of the branch commit `c2c2094`: daa2e12. - [ ] On app.fctl.sh's GitHub App (fctl-sh): under General, make the webhook Active with the URL `https://app.fctl.sh/api/v1/github/webhook` and a new secret (`openssl rand -hex 32`); under Permissions & events, subscribe to Pull request, Check run, Check suite and Status (no new permissions). Then `echo "$SECRET" | cargo xtask secrets fctl-sh --set GITHUB_WEBHOOK_SECRET`. Until then, nothing changes. - [ ] Merge hyperstructure/fctl-site#36, the privacy policy, once this is deployed with the webhook on. ## How I verified it - Unit tests: the merge rules, merge queue signs, state times, check counting and GitHub's time format (`fctl_domain::pulls`); signatures against GitHub's published example, event parsing and the lookup's answer (`fctl_domain::webhooks`); the agent's `gh pr view` times; `fctl show`; the web app's names, labels and colors (`lib/pulls.test.ts`, `row.test.tsx`). `cargo xtask check` passes. - The GraphQL query and the exact request the Worker sends (installation token, headers, body), replayed with curl against #170 while its checks ran: GitHub answers it, and counts a cancelled run as a failure, as the parser does. - The migration's backfill on SQLite with all earlier migrations, both list formats, run twice. - End to end on `cargo xtask dev`, with dev sessions whose pull requests I seeded in their storage (dev projects have no repository), a throwaway app config so the endpoint is on, and deliveries signed as GitHub signs them: unsigned and forged ones get 401, `ping` 200, one about an unlisted pull request reaches no session. A `closed` (merged) delivery turned the open session page and the project's list to "merged just now" without a reload, and D1 followed; `ready_for_review` and `enqueued` moved a draft to open and queued. With the app's credentials refused by GitHub, lookups failed and payloads stood in, as intended; check deliveries changed nothing then. The hourly job looked up only the pull request nobody had asked about. ## Screenshots On the dev stack with seeded pull requests, at e1c7383 (v0.6.0, pinned since, has the same colors). The project's sessions, light, 1440 px: | Before | After | |---|---| |  |  | The same, dark:  A session's header and Pull requests section, light: | Before | After | |---|---| |  |  | Dark, a merged and a closed pull request, and the details sheet on a phone (390 px):  <img alt="After, dark, phone: the details sheet lists the pull requests with their state and checks first" src="https://app.fctl.sh/api/v1/published/ejBGb92yb2ZDCB0igk5MoSigifNUcrcfm3rXYTjtgzB/after-phone-dark.png" width="390"> Refs #8: the same deliveries can wake agents when CI fails or a review comes in. Made in the fctl session https://app.fctl.sh/s/ses_01M5FGTZXMEJVX5CD3MRXQ6XPB --------- Co-authored-by: fctl-sh[bot] <343971779+fctl-sh[bot]@users.noreply.github.com> Co-authored-by: fctl-sh[bot] <fctl-sh[bot]@users.noreply.github.com>
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.
CI took about 2 min 45 s to check a pull request: one job ran all of
cargo xtask checkin sequence (formatting, generated types, Biome and TypeScript, Clippy twice, the tests, Vitest, the web build), and the smoke job built the host, then the web app, then the migrations, then the Worker, one after another. A merge took 5 to 11 minutes to reach app.fctl.sh, because the deploy only started its two-minute release build of the Worker once both checks had passed. On top of that, every run rebuilt work its caches should have saved.What changed
The checks run in parallel.
cargo xtask checknow takes parts:lint(rustfmt,web/src/gen, Clippy for the host and the Worker),test(cargo test) andweb(Biome, TypeScript, Vitest,node --test, the web build). With no part it runs everything, in the same order as before. CI runs each part in a job of its own. A job namedcargo xtask checkpasses once all three have, so main's ruleset requires the same checks as before. A test inxtask/src/check.rsfails ifci.ymlstops running one of the parts.cargo xtask devbuilds in parallel. The CLI, host and agent build on one thread; the Worker (worker-build --dev) builds on a second, intarget/workerso the two cargo builds don't wait for each other's lock; npm ci, the web build and the D1 migrations run on a third. The last two prefix their lines withworker │andweb │.wrangler devbuilds intarget/workertoo, so as it starts it only binds the Worker again. This speeds up localcargo xtask devas well as CI's smoke job.ring and the TLS stack stopped rebuilding on every run.
cargo rungives xtaskCARGO_MANIFEST_DIRandCARGO_PKG_VERSION_*, and every cargo that xtask started inherited them. ring's build script tracks those variables, and rust-cache's keys leave out the workspace version. So after each release, every job on every run rebuilt ring, rustls, tungstenite and everything that depends on them, twice in the check job. Locally, alternatingcargo buildandcargo xtaskrebuilt them each time too. xtask now strips those variables from the commands it runs.Caches that hit, and stay within the quota.
.github/actions/rustsets up Rust the same way in every job:7543b454andb771e0dfon main today).CARGO_PROFILE_DEV_DEBUG=0). Locally that took the test build from 50 s to 15 s with warm dependencies, and the caches shrank: the smoke's from 405 to 263 MB, lint and test 188 and 216 MB against the old check job's 552 MB.xtask comes from a cache. Every job spent 9 s building xtask.
.github/actions/xtaskputs the binary on PATH from a cache keyed by what it is built from (its crate, fctl-proto, the manifests, the lockfile, the toolchain), and builds it only when one of those changed. The jobs runxtask check lintand the like, and the web and Commits jobs need no Rust at all when the cache hits.main deploys sooner. The Worker's release build runs in its own job, beside the checks, and the deploy waits for the checks and that build. The build is cached by the files it is built from (its three crates, the manifests, the lockfile, the toolchain,
ci.yml, worker-build's version). A push that leaves those as they were, such as web, docs, host or agent changes, skips it (9 s). The deploy takes xtask from its cache, builds the web app itself (2 s), downloads the Worker and runsxtask deploy fctl-sh --skip-build.Measured on this pull request
cargo xtask checkcheckcargo xtask dev --smokecheckThe smoke job is now the critical path: its builds run side by side for about 25 s, and the session itself takes 17 s (12 s of watched checks and a 3 s background task, which are what it tests). With every cache cold, the first run on this pull request still had
cargo xtask checkgreen after 2:18.How I verified it
cargo xtask check(all parts) and each part on its own pass locally, as doescargo xtask dev --smoke. Under the same conditions (warm dependencies, workspace crates rebuilt, fresh state), the smoke took 57 s before this change and 47 s after.xtask deploy fctl-sh --skip-build --dry-runandwrangler deploy --dry-run) were exercised through temporary commits, removed in the last one. The dry run caught a real bug: the first version unpacked xtask's binary into the checkout, wherextask/is the crate.cargo xtask checkcheck, while the other jobs passed; a revert followed it.After the merge
The first run on main starts every cache over (the keys changed), so it takes about five minutes, building worker-build too. The ones after it are warm. The old caches (
v0-rust-check-*,v0-rust-deploy-*,v0-rust-dev-*-7543b454-*and-b771e0df-*) are no longer used and expire within a week; deleting them frees about 2 GB sooner.The Release workflow and the standalone image are unchanged here: #175 makes the image's build and publish faster.
Session: https://app.fctl.sh/s/ses_01M5FGG04ZQGCABWSN2Z0NDSJE