Skip to content

feat: forward bridged routes in AI Gateway proxy mode - #30226

Merged
pawbana merged 2 commits into
mainfrom
pawel/issue-29726-forwarding
Nov 17, 2026
Merged

pawbana merged 2 commits into
mainfrom
pawel/issue-29726-forwarding

Conversation

@pawbana

@pawbana pawbana commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Enable bridged request forwarding in AI Gateway proxy mode. Responses are captured through TeeBuffer.
Proxies are created per-request reusing transports.

Handle http.ErrAbortHandler inside the circuit-breaker wrapper so aborted responses are classified by HTTP status before the panic is propagated.

Generated by Coder Agents on behalf of @pawbana.

@pawbana

pawbana commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review

coder-agents-review Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Chat: Review in progress (15/15 reviewers complete) | View chat
Requested: 2026-10-01 08:14 UTC by @pawbana

deep-review v0.13.0 | Round 1 | 4f25ef8..860b9c7

Status: Panel review (13 reviewers)

About deep-review

CRF = Coder Review Finding (P0-P4, Nit, Note)

Reviewer Focus
Bisky tests
Chopper ops/errors
Churn-guard change verification
Ging language modernization
Gon naming
Hisoka edge cases
Killua perf
Kite change integrity
Knov contracts
Knuckle SQL
Komugi flake/determinism
Kurapika security
Law decomposition
Leorio docs
Luffy product
Mafu-san process
Mafuuu contracts
Melody dispatch/pairing
Meruem structural
Nami frontend
Netero mechanical checks
Pariston premise testing
Pen-botter product gaps
Razor verification
Robin duplication
Ryosuke Go arch
Takumi concurrency
Zoro shape

🤖 Managed by Coder Agents.

@coder-agents-review coder-agents-review Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR adds the bridged-route forwarding engine (request replay, key failover, circuit breaker, response observation) behind an unexported method. Findings: 3 P1, 3 P2, 16 P3, 7 P4, 4 Nit. The P1s are breaker accounting of client aborts and two headers the interception path sets that forwarding does not (custom actor headers, Claude Platform workspace ID); each fails once #29726 connects this method.

Out of scope (needs a ticket or explicit acceptance by a human):

  • aibridge/circuitbreaker/circuitbreaker.go:132: statusCapturingWriter records a 1xx as the final status and its Flush drops errors, so every wrapper that needs either must route around it.
  • aibridge/circuitbreaker/circuitbreaker.go:184: Execute ignores handlerErr, so dial errors (written as 502) never open the breaker in either mode.
  • aibridge/circuitbreaker/circuitbreaker.go:96: Get does not initialize the state gauge, so a recreated breaker keeps the previous gauge value.
  • aibridge/headers/headers.go:195: PrepareClientHeaders keeps Cookie and Coder-Session-Token; the SDK path, passthrough (aibridge/passthrough.go:52), and the entrypoint (coderd/aibridged/http.go:103) forward Coder session credentials upstream.
  • aibridge/passthrough.go:83: passthrough routes neither strip nor inject custom ActorHeaderNames, so client-supplied values reach upstream.
  • aibridge/passthrough.go:38: the passthrough transport is not in router.transports, so retired routers keep its idle connections for 90s.
  • aibridge/passthrough.go:63: client cancellation before upstream headers is logged at Warn as a reverse proxy error.
  • coderd/aibridged/transport.go:188: pipeResponseWriter.WriteHeader treats a 1xx as final, so in-process callers lose the real status when an upstream sends 100 or 103.
  • aibridge/x/proxy/router.go:120: requestMux builds a new ServeMux per request; cost grows with route count (not measured).
  • aibridge/utils/http.go:16: MaxIdleConnsPerHost stays at 2, so HTTP/1.1 upstreams re-dial with TLS after each concurrent burst.

Notes:

  • handler.go:179: prepareForwarding, forward, and observedBody.onRead have no production caller until #29726; tests reach forward through startForwarding, a copy of serve's setup that must be kept in sync by hand.
  • handler.go:379: errorCapturingWriter sends 1xx and flushes to client and everything else to the breaker writer; any method added later must choose the right one.
  • router.go:132: CloseIdleConnections at retirement does not close connections held by in-flight streams; they go idle afterwards and stay open until IdleConnTimeout (90s).
  • handler.go:96: with the client's Accept-Encoding preserved and DisableCompression set, onRead receives gzip bytes; the #29726 observer must decode Content-Encoding.
  • handler.go:194: the whole request body (up to 32 MiB) stays in requestBuffer for the request lifetime, and bytes() makes a second copy.

🤖 This review was automatically generated with Coder Agents.

Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
@pawbana
pawbana force-pushed the pawel/issue-29726-validation branch from 95b40d6 to 6417449 Compare October 2, 2026 11:59
@pawbana
pawbana force-pushed the pawel/issue-29726-validation branch from 6417449 to 027f798 Compare October 2, 2026 14:50
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from e76a1f9 to 8469a1a Compare October 2, 2026 20:07
@pawbana pawbana changed the title feat(aibridge/x/proxy): implement forwarding and request replay feat: implement AI Gateway forwarding and request replay Oct 2, 2026
@pawbana
pawbana force-pushed the pawel/issue-29726-validation branch 2 times, most recently from c2fb367 to 1a6b56c Compare October 5, 2026 09:15
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from 8469a1a to 91da7d1 Compare October 5, 2026 09:15
@pawbana
pawbana force-pushed the pawel/issue-29726-validation branch from 1a6b56c to 053d24e Compare October 5, 2026 11:07
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from 91da7d1 to 493dbba Compare October 5, 2026 20:03
@pawbana
pawbana force-pushed the pawel/issue-29726-validation branch from 053d24e to 6e9ddda Compare October 5, 2026 20:03
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from 493dbba to 623e0f6 Compare October 6, 2026 09:22
@pawbana pawbana changed the title feat: implement AI Gateway forwarding and request replay feat(aibridge/x/proxy): observe terminal forwarding outcomes Oct 6, 2026
@pawbana
pawbana changed the base branch from pawel/issue-29726-validation to pawel/issue-29726-key-failover October 6, 2026 09:23
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 69d5489 to 51b2a5a Compare November 2, 2026 09:25
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch 2 times, most recently from 2d4de83 to 6cde609 Compare November 2, 2026 11:09
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 51b2a5a to 130b4d6 Compare November 2, 2026 11:09
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch 2 times, most recently from bfa7e06 to 516011c Compare November 4, 2026 14:01
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch 2 times, most recently from 1709e41 to 6c0b3f8 Compare November 4, 2026 14:08
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 516011c to 3795d4d Compare November 4, 2026 14:08
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from 6c0b3f8 to 4cebde4 Compare November 6, 2026 12:47
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 3795d4d to 48d8bfd Compare November 6, 2026 12:47
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from 4cebde4 to 20a6229 Compare November 6, 2026 12:52
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 48d8bfd to fe6e3c1 Compare November 9, 2026 09:29
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from 20a6229 to 0f1cb56 Compare November 9, 2026 09:29
@linear-code

linear-code Bot commented Nov 9, 2026

Copy link
Copy Markdown

AIGOV-789

@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from fe6e3c1 to fc49002 Compare November 9, 2026 10:57
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch 2 times, most recently from ae7c67c to ac99ab1 Compare November 9, 2026 13:44
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch 2 times, most recently from 16d2763 to 4056e73 Compare November 9, 2026 16:24
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch 2 times, most recently from a3c87f4 to cba3dfe Compare November 9, 2026 19:00
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 4056e73 to 9072753 Compare November 9, 2026 19:00
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from cba3dfe to 71384bd Compare November 9, 2026 20:05
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch from 9072753 to b832964 Compare November 9, 2026 20:05
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from 71384bd to e7effff Compare November 9, 2026 20:32
@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-forwarding branch from e7effff to 0942dd0 Compare November 9, 2026 21:36
@pawbana
pawbana force-pushed the pawel/issue-29726-key-failover branch 2 times, most recently from bb02faf to 2ebdb01 Compare November 10, 2026 10:19

@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, just some suggestions to make the code easier to read

Comment thread aibridge/x/proxy/handler.go Resolved
Bridged routes now forward requests through the reverse proxy with key
failover and the circuit breaker, and capture request and response bodies
in TeeBuffers. Proxy errors are written by ErrorHandler, as in passthrough.

ReverseProxy aborts a broken response stream by panicking with
http.ErrAbortHandler, and the circuit breaker counts any panic as an
upstream failure. forward recovers the abort and ServeHTTP re-panics after
the breaker, so client disconnects no longer open the circuit.

Interception recording is not connected yet.

Generated by Coder Agents.

This branch had an error being deployed

1 failed and 1 inactive deployments
main — 410eb6ee Deployed Nov 17, 2026 by pawbana via cla #258865
docs-preview — 410eb6ee Deployed Nov 17, 2026 by pawbana via cleanup #175
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