Skip to content

feat: add per-request reverse proxy for bridged routes - #30399

Merged
pawbana merged 3 commits into
mainfrom
pawel/issue-29726-wire-forwarding
Nov 13, 2026
Merged

pawbana merged 3 commits into
mainfrom
pawel/issue-29726-wire-forwarding

Conversation

@pawbana

@pawbana pawbana commented Oct 6, 2026 •

Copy link
Copy Markdown
Collaborator

Prepare forwardingHandler to forward bridged requests to the provider. Nothing calls it yet.

  • newForwardingHandler parses the provider base URL. NewRouter now fails on a malformed URL. It also builds one transport per provider, with API dump support.
  • newProxy builds an httputil.ReverseProxy for each request. Each proxy shares the handler's transport. The proxy sends the request to the provider base URL, keeps the client's escaped path and raw query, and forwards the client's BYOK key. Key pools will be added in feat(aibridge/x/proxy): integrate key-pool failover #30400.

One change to replaybody

  • replaybody.NewRequest returns a copy of the request instead of changing the caller's.

Generated by Coder Agents on behalf of @pawbana.

@pawbana
pawbana force-pushed the pawel/issue-29726-request-replay branch 5 times, most recently from ed49523 to 1885657 Compare October 7, 2026 10:26
@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-request-replay branch 2 times, most recently from e3e8d44 to b7a42c3 Compare November 2, 2026 11:09
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch 2 times, most recently from 96696d2 to 9cc031c Compare November 2, 2026 14:08
@pawbana
pawbana force-pushed the pawel/issue-29726-request-replay branch from b7a42c3 to 251caf9 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-request-replay branch 2 times, most recently from 8e4a533 to bc7f1aa 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-request-replay branch from bc7f1aa to 8e49622 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-request-replay branch from 8e49622 to 27faaf1 Compare November 3, 2026 10:07
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from 3821aa8 to 0aeb5f3 Compare November 3, 2026 10:07
@pawbana
pawbana force-pushed the pawel/issue-29726-request-replay branch from 27faaf1 to a64f6ec Compare November 3, 2026 10:32
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch 2 times, most recently from 9b66ac7 to 5a06934 Compare November 3, 2026 10:47
@pawbana
pawbana force-pushed the pawel/issue-29726-request-replay branch 2 times, most recently from 432734b to a3ecaaf Compare November 3, 2026 11:19
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch 2 times, most recently from a87c0f9 to 4af3458 Compare November 3, 2026 13:42
@pawbana
pawbana force-pushed the pawel/issue-29726-request-replay branch from a3ecaaf to 3a3adc3 Compare November 3, 2026 13:42
@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-request-replay branch 2 times, most recently from 830e62d to 26b5be9 Compare November 9, 2026 09:29
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from 852c31c to 07dc3bb Compare November 9, 2026 09:29
@linear-code

linear-code Bot commented Nov 9, 2026

Copy link
Copy Markdown

AIGOV-787

@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from 7655635 to 230ef35 Compare November 9, 2026 10:57
Base automatically changed from pawel/issue-29726-request-replay to main November 9, 2026 13:05
@pawbana
pawbana temporarily deployed to main November 9, 2026 13:05 — with GitHub Actions Inactive
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from 230ef35 to c090337 Compare November 9, 2026 13:44
@pawbana
pawbana temporarily deployed to main November 9, 2026 13:44 — with GitHub Actions Inactive
@pawbana
pawbana temporarily deployed to main November 9, 2026 13:58 — with GitHub Actions Inactive
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from bb19f08 to 8f50493 Compare November 9, 2026 16:24
@pawbana pawbana changed the title feat: add provider wire forwarding and transport lifecycle feat(aibridge/x/proxy): add provider wire forwarding Nov 9, 2026
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch 2 times, most recently from 1d2e4a9 to b257f3b Compare November 9, 2026 19:00
@pawbana
pawbana temporarily deployed to main November 9, 2026 19:00 — with GitHub Actions Inactive
@pawbana
pawbana temporarily deployed to main November 9, 2026 19:01 — with GitHub Actions Inactive
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from b257f3b to ae29002 Compare November 9, 2026 20:05
@pawbana
pawbana temporarily deployed to main November 9, 2026 20:05 — with GitHub Actions Inactive
@pawbana
pawbana force-pushed the pawel/issue-29726-wire-forwarding branch from ae29002 to cdf0a37 Compare November 9, 2026 20:32
@pawbana
pawbana temporarily deployed to main November 9, 2026 20:32 — with GitHub Actions Inactive
@pawbana
pawbana marked this pull request as ready for review November 9, 2026 20:37
@pawbana
pawbana requested a review from ssncferreira November 9, 2026 20:38
@pawbana
pawbana temporarily deployed to main November 9, 2026 20:38 — with GitHub Actions Inactive
@pawbana
pawbana requested a review from SasSwart November 9, 2026 20:38
@pawbana
pawbana temporarily deployed to main November 9, 2026 20:44 — 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 👍

Comment thread aibridge/x/proxy/replaybody/buffer.go Outdated
// HTTP/1 handlers must enable full duplex, or the server will drain the body before an early reply.
func NewRequest(r *http.Request) *TeeBuffer {
func NewRequest(in *http.Request) (*http.Request, *TeeBuffer) {
r := *in

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:

Suggested change
r := *in
request := *in

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.

renamed r -> req and resp in NewRequest and NewResponse accordingly.

},
Transport: h.transport,
FlushInterval: -1,
ErrorLog: h.errorLog,

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.

Should this set an ErrorHandler like passthrough?

ErrorHandler: func(rw http.ResponseWriter, req *http.Request, e error) {
if _, ok := errors.AsType[*http.MaxBytesError](e); ok {
routing.WriteRequestBodyTooLarge(req.Context(), rw)
} else {
logger.Warn(req.Context(), "reverse proxy error", slog.Error(e), slog.F("path", req.URL.Path))
http.Error(rw, "upstream proxy error", http.StatusBadGateway)
}
},

AFAIK, the default turns every proxy error into an empty 502 and swallows the error, so finishForwarding never sees it.

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.

This branch was previously deployed

2 inactive deployments
main — 7014fc90 Deployed Nov 13, 2026 by pawbana via cla #256282
docs-preview — 7014fc90 Deployed Nov 13, 2026 by pawbana via cleanup #28
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