Skip to content

feat(aibridge/x/proxy): integrate key-pool failover - #30400

Merged
pawbana merged 2 commits into
mainfrom
pawel/issue-29726-key-failover
Nov 13, 2026
Merged

pawbana merged 2 commits into
mainfrom
pawel/issue-29726-key-failover

Conversation

@pawbana

@pawbana pawbana commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Route centralized provider requests through the existing key-pool failover transport. Retries replay a consumed request prefix and continue the still-open source, discard rejected attempt responses, and preserve client bytes and headers. BYOK requests do not fall back to pooled credentials.

Generated by Coder Agents on behalf of @pawbana.

@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from 91a8821 to d6b4039 Compare November 2, 2026 09:25
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch 2 times, most recently from 51b2a5a to 130b4d6 Compare November 2, 2026 11:09
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from d6b4039 to 96696d2 Compare November 2, 2026 11:09
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from 96696d2 to 9cc031c Compare November 2, 2026 14:08
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 130b4d6 to 3ff8e29 Compare November 2, 2026 14:08
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from 9cc031c to ee4f79b Compare November 2, 2026 14:18
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch 2 times, most recently from 09b6387 to ac1c059 Compare November 2, 2026 15:26
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from ee4f79b to 265559d Compare November 2, 2026 15:26
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from ac1c059 to 4ba3638 Compare November 2, 2026 15:58
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from 265559d to 3821aa8 Compare November 2, 2026 15:58
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 4ba3638 to d2aa796 Compare November 3, 2026 10:07
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch 2 times, most recently from 0aeb5f3 to 9b66ac7 Compare November 3, 2026 10:32
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch 2 times, most recently from 79fd51e to 954a876 Compare November 3, 2026 10:47
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from 9b66ac7 to 5a06934 Compare November 3, 2026 10:47
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 954a876 to b9607ea Compare November 3, 2026 11:19
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from 5a06934 to a87c0f9 Compare November 3, 2026 11:19
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from b9607ea to 786fb3c Compare November 3, 2026 13:42
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from a87c0f9 to 4af3458 Compare November 3, 2026 13:42
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 786fb3c to 3845123 Compare November 3, 2026 14:11
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from 4af3458 to 530802e Compare November 3, 2026 14:11
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 3845123 to e88bcd6 Compare November 3, 2026 14:47
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch 2 times, most recently from 75e465f to f8c9dff Compare November 3, 2026 15:13
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 16d2763 to 4056e73 Compare November 9, 2026 16:24
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch 3 times, most recently from 1d2e4a9 to b257f3b Compare November 9, 2026 19:00
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch 2 times, most recently from 9072753 to b832964 Compare November 9, 2026 20:05
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from b257f3b to ae29002 Compare November 9, 2026 20:05
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from b832964 to 94fdf97 Compare November 9, 2026 20:32
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from ae29002 to cdf0a37 Compare November 9, 2026 20:32
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch 3 times, most recently from 2ebdb01 to 9c81f2b Compare November 10, 2026 10:33
@pawbana
pawbana marked this pull request as ready for review November 10, 2026 13:14
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 66e9067 to 8e7b20b Compare November 10, 2026 18:41
pr.Out.Header = prepareForwardingHeaders(pr.Out.Header, cred)
},
Transport: h.transport,
Transport: keypool.NewKeyFailoverTransport(h.transport, h.failover),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can reuse this as is for bridged routes. It picks keys with walker.Next() and never updates the request's *CentralizedPool, so cred.Hint() stays <failover key> and the interception won't record which key served the request. That's fine for passthrough because those requests aren't recorded. Could newProxy pass the request's credential to the failover transport, so it records the key it picks?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using the credential would also let newProxy skip key failover for BYOK credentials. Right now the transport checks the auth headers again with IsBYOK, even though we've already resolved the credential 🤔

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recording hint is solved later in stack: https://github.com/coder/coder/pull/29726/changes#diff-fd84ed5f2d4fee4567d1827c1838f33705be295054c9ee169a00b7df4b893ed0R302-R314
It is a bit of a hack so I created followup issue to fix it properly. Checking BYOK again is a bit of a waste but should be working?
I'd rather use transport (with hack for now) then write another custom key loop.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense 👍

@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from cdf0a37 to 7014fc9 Compare November 13, 2026 10:30
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 8e7b20b to ba22df7 Compare November 13, 2026 10:41
Base automatically changed from pawel/issue-29726-wire-forwarding to main November 13, 2026 10:42
@pawbana
pawbana temporarily deployed to main November 13, 2026 10:42 — with GitHub Actions Inactive

@ssncferreira ssncferreira left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

func TestForwardingProviderCredentials(t *testing.T) {
t.Parallel()
// The pool enables failover, which BYOK requests must skip.
pool := newTestPool(t, "pool-secret-key")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: both parallel subtests share this pool and check its state, so anything one subtest does to the pool can make the other fail. Should each subtest create its own pool?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, in theory one test case could break another. Changed so pool is created per test case.

Forwarded requests go through the provider's key failover transport. The
provider transport wrapper is installed beneath key failover, as passthrough
does, so Claude Platform requests carry the required workspace header for
BYOK and pooled credentials.
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from ba22df7 to 2a5c99b Compare November 13, 2026 11:13
@pawbana
pawbana temporarily deployed to main November 13, 2026 11:13 — with GitHub Actions Inactive
@pawbana
pawbana temporarily deployed to main November 13, 2026 11:19 — with GitHub Actions Inactive
@pawbana
pawbana temporarily deployed to main November 13, 2026 11:21 — with GitHub Actions Inactive
@pawbana
pawbana enabled auto-merge (squash) November 13, 2026 11:21
@pawbana
pawbana merged commit ff3de6e into main Nov 13, 2026
33 checks passed

This branch was previously deployed

2 inactive deployments
main — eea0daf5 Deployed Nov 13, 2026 by pawbana via cla #256362
docs-preview — eea0daf5 Deployed Nov 13, 2026 by pawbana via cleanup #33
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants