Skip to content

fix: stop health probes from tearing down caller-derived upstreams - #66

Merged
blakebauman merged 1 commit into
mainfrom
fix/health-skip-caller-derived
Aug 14, 2026
Merged

blakebauman merged 1 commit into
mainfrom
fix/health-skip-caller-derived

Conversation

@blakebauman

Copy link
Copy Markdown
Member

The bug

A health probe runs on nobody's behalf. An upstream using passthrough or token-exchange has no credential outside a request, so creds.Apply fails (auth/upstream.go:109-127), the connect fails, and guardedDo charges that failure to the upstream:

  • u.limiter.Allow consumes the upstream's rate budget
  • u.breaker.Record(ctx, false) — five polls open the circuit for the clients it serves perfectly well
  • once a real session exists, chargeBudgets bills the upstream and server budgets for traffic no caller asked for
  • healthy == 0 → /health answers 503 (gateway.go:1750)

The chart wires readiness to /health, so a gateway whose federation is entirely caller-derived never becomes Ready while serving every authenticated caller correctly.

healthCheck.intervalMs had the same defect and worse: probeEndpoints runs on context.Background() (gateway/upstream.go:591), so it ejected every endpoint on its first round and never restored them.

The fix

  • Such an upstream is reported "unprobed": true and counted as neither healthy nor unhealthy.
  • collectUpstreamHealth returns a probeable count alongside healthy; the 503 is judged against what the gateway can actually reach, and status: "ok" means healthy == probeable.
  • startHealthProbes skips them with a warning rather than a validation error, so an existing config keeps serving.

Unprobed is omitempty, so a federation without caller-derived credentials keeps the exact response shape it had.

This also makes UpstreamCredentials.PerRequest() load-bearing. It was dead code — nothing in the tree called it — which is why the session question it names was never wired up anywhere.

Tests

  • TestHealthDoesNotProbeCallerDerivedUpstreams — ten collections (well past the threshold of 5), asserting unprobed, healthy=0/probeable=0, /health 200 with status: ok, and then that a real authenticated tools/call still succeeds. That last assertion is the point: on the previous code the circuit is open by then.
  • TestHealthStillReportsProbeableUpstreamsDown — the carve-out is not a blanket amnesty; one reachable-but-dead upstream still yields 503.
  • TestActiveProbesSkipCallerDerivedUpstreams — no probe loop, no ejected endpoints.

Docs

docs/operations.md endpoint table and a new paragraph in docs/deploy.md's Probes section explaining why this is a correctness fix rather than a cosmetic one.

Gate

gofmt, go mod tidy -diff, go vet, go build, go test -race ./..., golangci-lint run (0 issues) all pass locally.

🤖 Generated with Claude Code

A health probe runs on nobody's behalf, so an upstream using passthrough or
token-exchange has no credential to present: creds.Apply fails, the connect
fails, and guardedDo charges that failure to the upstream. Every poll then
consumed its rate budget, recorded a circuit-breaker failure — five polls
open the circuit for the clients it serves perfectly well — and, once a real
session existed, charged the upstream and server budgets for traffic no
caller asked for. /health reported healthy == 0 and answered 503, so a
gateway whose federation is entirely caller-derived never became Ready while
serving every authenticated caller correctly. The active probe loop had the
same defect and worse: probeEndpoints runs on context.Background(), so it
ejected every endpoint on its first round.

Report such an upstream "unprobed" rather than down, count it as neither
healthy nor unhealthy, and judge the 503 against what the gateway can
actually reach. healthCheck is likewise ignored for them, with a warning at
startup rather than a validation error so an existing config keeps serving.

The unprobed flag is omitempty, so a federation without caller-derived
credentials keeps the exact response shape it had. This also makes
UpstreamCredentials.PerRequest — until now dead code — load-bearing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@blakebauman
blakebauman merged commit 0c2c37d into main Aug 14, 2026
7 checks passed
@blakebauman
blakebauman deleted the fix/health-skip-caller-derived branch August 14, 2026 01:06
blakebauman added a commit that referenced this pull request Aug 14, 2026
#66 landed as a squash, so its commits are not ancestors of this branch and
git sees both sides editing the lines it introduced. This branch already
contains main's content in full — verified by diffing the trees — plus this
PR's changes, so the merge keeps the branch tree as-is.
blakebauman added a commit that referenced this pull request Aug 14, 2026
Covers #65, #66 and #68. Filed under "Unreleased" rather than a dated
version: entries here are written as part of a release and land in the
release commit, so a dated heading on main before the tag is the exact
drift the release runbook warns about. It becomes the version heading when
these ship.

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
blakebauman added a commit that referenced this pull request Aug 14, 2026
Dates the changelog entry for the three caller-derived credential fixes
(#65, #66, #68) and bumps the chart: appVersion to v1.12.1, which is what a
default helm install deploys, and the chart's own version to 0.2.2, since a
published OCI tag is immutable.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant