Skip to content

fix(xtask): run wrangler again when Cloudflare's API throttles it - #230

Merged
kalaspuff merged 1 commit into
mainfrom
fctl/172-a-ci-workflow-to-deploy-to-cloudflare-fa
Oct 23, 2026
Merged

kalaspuff merged 1 commit into
mainfrom
fctl/172-a-ci-workflow-to-deploy-to-cloudflare-fa

Conversation

@fctl-sh

@fctl-sh fctl-sh Bot commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

The deploy of #228 to app.fctl.sh failed on its first request to Cloudflare's API. wrangler d1 migrations apply got a 429 (Please wait and consider throttling your request speed [code: 971], with a Retry-After of 40 s) and gave up. Rerunning the job 45 minutes later deployed it.

Why it failed

Cloudflare throttles a token, an account or an address once it has made too many requests (the documented limit is 1,200 per 5 minutes per user). It then answers 429 with a Retry-After for up to five minutes, even to a client's first request. That is what happened here, so the requests that used up the limit came from somewhere else: other use of the account's API, or the runner's address. Nothing in a run's logs tells which. fctl.sh's own deploy, about 40 s earlier, made only a dozen or so requests.

Wrangler 4.151.1 retries a 429 only in some of wrangler deploy's requests (retryOnAPIFailure, waits of up to 60 s). Its D1, KV and secret commands send each request once and fail at the first 429. The newest wrangler, 4.152.0, does the same, so upgrading wouldn't help.

What changes

  • util::retry_throttled runs a wrangler command that calls the API, and runs it again when the API throttled it. It gives wrangler a WRANGLER_OUTPUT_FILE_PATH and reads the command-failed entry wrangler writes there ("code": 971, "retry_after_ms": 40000), so wrangler keeps its terminal, its prompts and its colours. It waits what the API asks plus a second (a minute for a 971 without a Retry-After), at most four attempts in all. It gives up at once on a wait over five minutes, and runs any other failure only once.
  • Running a command again from the start is safe: a throttled request never ran, migrations apply applies only the migrations not applied yet, and the deploy, secret and KV writes end the same way when repeated.
  • Every wrangler command xtask runs against the API goes through it: cargo xtask deploy (migrations, deploy, the secret list after it, d1 create), cargo xtask secrets and cargo xtask publish. That last one covers the Release workflow's KV writes to fctl.sh/releases, which had the same exposure.
  • docs/self-hosting.md and docs/development.md (Deploying) say so.

Verification

  • Unit tests in xtask/src/util.rs. They parse the entries wrangler writes, and drive retry_throttled with a stand-in wrangler script: throttled once then done, throttled every time (it gives up after 4 runs), a failure that isn't throttling (1 run) and a wait over five minutes (1 run).
  • End to end against a local stand-in for Cloudflare's API (wrangler's CLOUDFLARE_API_BASE_URL, a dummy token, telemetry off). It answers the first request of each kind with exactly what Cloudflare sent (429, code 971, Retry-After: 2):
    • Without the fix, wrangler d1 migrations apply DB --remote failed with the same output as CI.
    • cargo xtask deploy fctl-sh --skip-build printed Cloudflare's API throttled wrangler: running it again in 3 s (attempt 2 of 4), ran the migrations again and applied the pending one. wrangler deploy then failed because no Worker was built here, and that failure was not retried.
    • cargo xtask secrets fctl-sh (the secret list) and cargo xtask publish (KV puts) each recovered from a throttled first request.
    • Against an API that throttles every request: four runs, then Error: Cloudflare's API throttled wrangler 4 times in a row.
  • cargo xtask check lint and cargo xtask check test pass.

Session: https://app.fctl.sh/s/ses_01M5MEKPMFJDMW1AX89Y9N5G6Q

The deploy of #228 failed on its first request to Cloudflare's API:
wrangler d1 migrations apply got a 429 (code 971) with a Retry-After of
40 seconds, and wrangler gives up at once in its D1, KV and secret
commands. xtask now gives each wrangler command that calls the API a
WRANGLER_OUTPUT_FILE_PATH, reads the command-failed entry wrangler writes
there, and runs a throttled command again once the wait is over, up to
four times and for waits of up to five minutes. deploy, secrets and
publish (the release's KV puts) all go through it.
@fctl-sh
fctl-sh Bot requested a review from kalaspuff as a code owner October 23, 2026 13:33
@kalaspuff
kalaspuff merged commit 03f8d79 into main Oct 23, 2026
10 checks passed
@kalaspuff
kalaspuff deleted the fctl/172-a-ci-workflow-to-deploy-to-cloudflare-fa branch October 23, 2026 13:37
kalaspuff pushed a commit that referenced this pull request Oct 23, 2026
When fctl's review agent posts findings on a pull request that one of
fctl's agents opened, fctl passes them on to that agent in a message
(#225). The session's transcript showed that message whole: each
finding's explanation, then the instructions for the agent and the `gh
api` command it answers with. A single finding took most of a page, and
several took more. People rarely need to read all of that, so the
transcript now shows the review in a few lines, with the whole message a
click away.

## What changed

- **The message carries the review it is about** (`UserMessage.review`,
a new `PassedOnReview`), as follow-ups carry theirs
(`UserMessage.follow_up`, #228). It holds the pull request, the commit,
the review's summary and session, and for each finding its severity,
title, file and lines, and its comment on GitHub.
`fctl_domain::reviews::passed_on_review` builds it from the same `Found`
as the message's text, in the same order (most severe first, through a
shared `order`). The agent gets the same text as before.
- **The transcript shows it in a few lines**, styled like a follow-up's
failed checks: "fctl's review agent found 2 issues in web#12 at
3f2a1c9", then one line per finding (its title, then its severity and
`path:lines`). Each finding's title opens its comment on GitHub, or the
review's summary for a finding on lines the diff doesn't show. **What
fctl told the agent** opens the whole message. The agent's name opens
the review's session, the pull request opens the review's summary, and
the commit opens the commit.
- **Findings messages sent before this change** have no review in them.
They show their first five lines with a **Show all** button. Only these
get cut: they are recognized by the words `passed_on` starts them with.
Other messages from fctl stay whole, including a scheduled run's task
(#229, which sends it as a message from fctl), and so do people's
messages.

## Compatibility

All additive, no migration. `UserMessage.review` is optional, and
clients without it show the message's text as before. The internal
`/review-findings` body's new `shown` field defaults to nothing. Neither
hosts nor agents read the field.

## How I verified it

- **Unit tests** cover the proto wire format, including a message
without a review. In the domain, they check that `passed_on_review`
lists findings in the message's order and links each by where it is on
GitHub: its comment, the summary, or nothing known. Web tests check the
findings view (lines, links, one issue, no summary, the message a click
away), the transcript (a review goes to the new view, old findings
messages get cut, and a short task, a long scheduled task and people's
long messages stay whole), and that the builder keeps the review on its
item.
- `cargo xtask check` passes. One run failed in xtask's
`runs_a_throttled_command_again`, an intermittent race in tests from
#230 that this branch doesn't touch (#232); the rerun passed.
- **End to end in `cargo xtask dev`**, through a temporary route I
didn't commit. It hands made-up findings to SessionObject's
`/review-findings` as `pass_on` does: the real `passed_on`, `held_back`
and `passed_on_review`, the internal call, and the stored event. A
session got the finding from the screenshot in the request, and the
message's text came out identical to it. fake-claude answered it, and
the page showed the review in a few lines. The stored event carried the
review (`GET …/events`). An `fctl` binary built from main printed the
same event with `fctl logs --json`, without the field, so older clients
read it as before. A message sent without the review, like one from
before this change, showed its first lines and opened with Show all. I
didn't run posting on GitHub, `spots` or `pass_on`'s choice of session
against a GitHub stand-in. This change leaves them as they were, and
their tests cover them.

## Screenshots

From `cargo xtask dev` at 444dfee (the views haven't changed since),
with fake-claude's answer after each message. The pull request and
finding are the ones from the screenshot in the request.

**The message from the request**, light, 1440 px wide:

| Before | After |
|---|---|
| ![Before: fctl's findings message in full, taking most of the
page](https://app.fctl.sh/api/v1/published/hj84xS95c5bvmd2utgEMY1qGp14QCmlXFJobpNa4dDQ/before-light.png)
| ![After: one header line, one line for the finding, and What fctl told
the
agent](https://app.fctl.sh/api/v1/published/Sv7KaTlWWLrrhz4G976yvEcixZECIG8ndKWSCGrPtR0/after-light.png)
|

**On a phone** (390 px):

| Before | After |
|---|---|
| ![Before: the message runs over several screens on a
phone](https://app.fctl.sh/api/v1/published/QwKoh1y4GzNuWodKc1DapBit9LSGjcV3KFbCcL0XM6j/before-light-390.png)
| ![After: the review in a few lines on a
phone](https://app.fctl.sh/api/v1/published/x95nhqGSdlfia0sjaxY7yRVoAGLXnkSSp3j7Fip5h6k/after-light-390.png)
|

**Dark:**

![After, dark: the review in a few
lines](https://app.fctl.sh/api/v1/published/NXNIRQW3qFYiiyykOl45CcB0c6O2zBpiauPCQ3PRQRv/after-dark.png)

**Three findings**, most severe first: one on lines the pull request
deletes ("old version"), and one in the review's summary:

![A review with three findings, one line each, on the session
page](https://app.fctl.sh/api/v1/published/Wpu8NTZ1NEUmdbBgC2gBQYUgJR9o3QNvLrHneAoBbZJ/three-light.png)

**What fctl told the agent**, opened:

![What fctl told the agent opened under the review, showing the whole
message](https://app.fctl.sh/api/v1/published/MKyPEc1MV1SonBnMLzskBYoG4UpvnQ0vxw9otdMncZR/one-told-dark.png)

**A findings message sent before this change**, which has no review in
it:

![The older message's first five lines, ending at the first finding's
title, with Show
all](https://app.fctl.sh/api/v1/published/cXussMeSJ3b0XIILwM3Ktg3cxyEkG9rxs7gKiWjc8vP/older-light.png)

Session: https://app.fctl.sh/s/ses_01M5MFGRENHK8PHRFQXJ53360Z

---------

Co-authored-by: fctl-sh[bot] <343971779+fctl-sh[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant