Repository navigation
fix(xtask): run wrangler again when Cloudflare's API throttles it - #230
Merged
kalaspuff merged 1 commit intoOct 23, 2026
Merged
Conversation
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.
kalaspuff
approved these changes
Oct 23, 2026
kalaspuff
deleted the
fctl/172-a-ci-workflow-to-deploy-to-cloudflare-fa
branch
October 23, 2026 13:37
This was referenced Oct 23, 2026
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 | |---|---| |  |  | **On a phone** (390 px): | Before | After | |---|---| |  |  | **Dark:**  **Three findings**, most severe first: one on lines the pull request deletes ("old version"), and one in the review's summary:  **What fctl told the agent**, opened:  **A findings message sent before this change**, which has no review in it:  Session: https://app.fctl.sh/s/ses_01M5MFGRENHK8PHRFQXJ53360Z --------- Co-authored-by: fctl-sh[bot] <343971779+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.
The deploy of #228 to app.fctl.sh failed on its first request to Cloudflare's API.
wrangler d1 migrations applygot a 429 (Please wait and consider throttling your request speed [code: 971], with aRetry-Afterof 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-Afterfor 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_throttledruns a wrangler command that calls the API, and runs it again when the API throttled it. It gives wrangler aWRANGLER_OUTPUT_FILE_PATHand reads thecommand-failedentry 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 aRetry-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.migrations applyapplies only the migrations not applied yet, and the deploy, secret and KV writes end the same way when repeated.cargo xtask deploy(migrations, deploy, the secret list after it,d1 create),cargo xtask secretsandcargo xtask publish. That last one covers the Release workflow's KV writes to fctl.sh/releases, which had the same exposure.Verification
xtask/src/util.rs. They parse the entries wrangler writes, and driveretry_throttledwith a stand-inwranglerscript: 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).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):wrangler d1 migrations apply DB --remotefailed with the same output as CI.cargo xtask deploy fctl-sh --skip-buildprintedCloudflare's API throttled wrangler: running it again in 3 s (attempt 2 of 4), ran the migrations again and applied the pending one.wrangler deploythen failed because no Worker was built here, and that failure was not retried.cargo xtask secrets fctl-sh(the secret list) andcargo xtask publish(KV puts) each recovered from a throttled first request.Error: Cloudflare's API throttled wrangler 4 times in a row.cargo xtask check lintandcargo xtask check testpass.Session: https://app.fctl.sh/s/ses_01M5MEKPMFJDMW1AX89Y9N5G6Q