← Back to Pull requests

fix(cache): stop asking a remote cache that is unreachable #1065

Closed
unknown closed this pull request without merging on Dec 02, 2026 01:24 UTC
View on GitHub
unknown unknown commented on Dec 01, 2026 23:19 UTC
Author

A build whose remote cache is down no longer pays for it. Before this change, a build pointed at a cache server or S3 endpoint that refuses connections still succeeded, but every lookup was retried with backoff and every upload was attempted, so the build took many times longer than one with no remote and printed thousands of warnings.

Now, after three connections in a row fail with no response in between, mbx treats the remote as unreachable for the build: lookups skip it, uploads are not attempted, and it says so once.

[WARN ] remote cache at http://127.0.0.1:53677 is unreachable: 3 connections in a row failed (Connection refused (os error 111)). Lookups and uploads are skipped until it answers again

Trigger

Any build with MBX_REMOTE_URL set to a cache server or an s3:// remote whose host refuses connections, times out while connecting, or does not resolve. Every wrapper process of the build asked the remote for its action result, each request was retried three times with backoff, and each finished compilation queued uploads that failed the same way.

Before and after

Building hk at 660dc6ec with mbx build --locked from an empty local store, with MBX_REMOTE_MODE=read-write and the remote URL pointing at a loopback port nobody listens on:

| Remote | main (087a0439) | This change |
| --- | --- | --- |
| none | 26.1 s | 21.8 s |
| cache server, connection refused | 288.5 s, 10,360 warning lines | 21.6 s, 3 warning lines |
| S3 endpoint, connection refused | 286.9 s, 9,722 warning lines | 21.4 s, 3 warning lines |

Every build exited 0. Each figure is one run of a release build of mbx on a 32-core Linux machine, with its own empty HOME, MBX_CACHE_DIR and MBX_TARGET_ROOT. The machine was not otherwise idle, so differences of a few seconds, including the one between the two no-remote runs, are noise; this change does nothing when no remote is configured.

The three remaining warning lines are the two retry warnings of the first lookup, which is the request that finds the outage, and the warning above.

A remote that drops packets instead of refusing them is found the same way. The same build with MBX_HTTP_TIMEOUT=5s, against a loopback port that neither accepts nor refuses connections:

| Remote | main (087a0439) | This change |
| --- | --- | --- |
| cache server, connection hangs | not finished after 15 minutes, 225 warning lines by then | 35.3 s, 3 warning lines |
| S3 endpoint, connection hangs | not finished after 15 minutes, 4,683 warning lines by then | 35.4 s, 3 warning lines |

Each main run was stopped at 15 minutes, so how long it would have taken is not known. The extra 14 seconds with this change are the first lookup's three attempts, each given up on after 4.5 seconds, and the waits between them. The warning then reads 3 connections in a row failed (timed out while connecting).

What counts as unreachable

Only failed connections count: refused, timed out while connecting, or a host name that does not resolve. Any response resets the count, so a miss, an error response such as a 500, or one slow request never marks the remote unreachable. The count is shared by the whole build session, so one lookup's own retries are enough to find the outage. This applies to cache servers and s3:// remotes, is on by default, and adds no setting.

A connection to a remote cache now gets slightly less than http.timeout to open: a tenth less, and at most one second less, so 29 seconds with the default of 30. http.timeout is both the connect timeout and the time a response may take to begin, and the second runs from the start of the request. With the two equal, a connection that hung was ended by the response timeout and reported as a slow response, which does not count, so a host that drops packets would never have been found unreachable. With the default timeout such a host should be found after about a minute and a half, three attempts of 29 seconds each; that figure is worked out from the 5-second run above, not measured.

A skipped request is refused before its credential is read or renewed, so an outage that also takes the OIDC or instance-metadata service does not make skipped lookups wait on it.

Recovery

While the remote is unreachable, mbx asks it for a response in the background: first after one second, then at doubling intervals up to 30 seconds. Any response resumes lookups and uploads for the rest of the build and prints one line saying so. A cache server that restarts during a long build is therefore used again. No compilation waits for these checks, and what was skipped in the meantime is not gone back for.

A request that was already under way when the outage was found can still get a response. That response has mbx ask at once instead of waiting out the interval, so a remote that is mostly healthy (one dead address among several, say) is back in use after one round trip. The response does not end the outage by itself, because it may have been on its way before the connections failed.

Reporting

Requests that were not attempted are counted separately from requests that failed. The build summary names them:

mbx[cache]: 2 hits, 0 misses, 648 not looked up, 10 bypassed, 1 remote failures, 3578 skipped while the remote was unreachable; 0 B downloaded, 0 B uploaded, 531.6 MiB stored locally

The full summary says the remote cache was unreachable; 3578 lookups and uploads were skipped while it was, and this build ran without them. The JSON build report gains a remote_skipped field next to remote_failures. A request that was sent and failed is a failure, including the one that finds the outage and any that failed just before it and had their retry refused; only requests that were never sent are skipped, so the two counts do not overlap. That holds whichever request finds the outage: a lookup, a download, an upload, or a request made on behalf of uploads. A group of uploads sent as one request, or the question mbx asks a cache server before an upload about what it accepts, is one failure, and the uploads it was for are then skipped and each counted once as not published. A CI alert for a cache that has stopped serving should read both fields: in the cache-server runs above remote_failures was 2907 on main and is 1 with this change, where remote_skipped is 3578 (the skipped count moves by a few between runs of the same build).

Uploads that were skipped still appear as not published. Because that count now includes uploads that were never attempted, the CI summary line reads N background uploads were not published; see warnings above instead of N background uploads failed; see warnings above.

An outage can also start in the middle of a build, after mbx has begun downloading results it expects to need. Each result left incomplete by the outage would get its own warning; those are left out for objects the unreachable remote was not asked for, and an object a reachable remote does not have is still reported.

Limits

An outage that still answers is not covered. A proxy returning 502, 503 or 504 for a server that is down, or a server that accepts connections and then says nothing, is retried as before.

Validation

New tests cover both backends: a remote that refuses connections stops being asked after three failures, one lookup's retries are enough to trip it, a host name that does not resolve counts like a refused connection, a connection that hangs counts once its connect timeout gives up on it (a Linux test against a port that neither accepts nor refuses), misses and error responses leave the remote reachable, requests resume once the remote answers, a request whose retry is refused stays a failure, an outage found by a download, by a group of uploads, or by asking the server what it accepts ahead of one blob or one action result counts that request as a failure and the upload it was for as skipped, an upload still goes ahead when a reachable server fails to say what it accepts, a response during an outage has the remote asked again at once, a skipped request does not fetch or renew credentials, a prefetch tells an object lost to an outage from one the remote does not have, and a build session against an unreachable cache server or S3 endpoint turns every lookup into a miss and reports its uploads as skipped. mise run ci passes locally. The tests do not rely on a loopback port refusing connections at once, which only Linux does: macOS leaves a connection to a bound port that nobody listens on unanswered, and Windows refuses it after two seconds.

AI-assisted — Tool: Claude Code; model: anthropic/claude-fable-5-2; version: unavailable.

🤖 Generated with Claude Code

Diff: 650 lines (+487 / -163) across 8 files Reviewer: jdx Review duration: 124m
All Vouch review confidence checks passed
Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
0.52
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
0.17
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
56%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.388
Shallow Review Depth shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #1065"
general weight: 0.35
Reviewers
Assignees
Unassigned
Labels
risk: low confidence: 56.8% reviewed
Vouch Risk Breakdown
AI-powered review risk analysis
Change Risk
Change Risk · Model 1 (XGBoost)
Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
Score: 52% (MEDIUM) · Higher = larger blast radius
52%
Review Confidence
Review Confidence · Models 2 & 3
Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
Score: 56.8% · Lower = rushed or shallow review
56.8%
Residual Risk
Residual Risk · Core Equation
Residual = Change × (1 − Confidence)
Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
Score: 22.5% · Safe to merge
22.5%