Skip to content

feat: add reverse-proxy handler to AI Gateway - #29656

Closed
pawbana wants to merge 8 commits into
mainfrom
pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key
Closed

pawbana wants to merge 8 commits into
mainfrom
pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key

Conversation

@pawbana

@pawbana pawbana commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Implements AIGOV-615 on top of the merged AIGOV-674 router extraction (#29573): allowlisted reverse-proxy forwarding, synchronous interception start and bounded finalization, 32 MiB bridged-body capture with key-failover replay, and an observation seam for later extractors. Passthrough bodies keep streaming unless existing failover or optional API dumping needs replay.

Shared changes harden Coder-sensitive request headers and credential cookies, reject path traversal, bound route/method metric labels, and keep DRPC available while admitted requests drain. In-process response closure cancels upstream work without canceling the caller context. Proxy mode is HTTP-only; client User-Agent is preserved without a gateway suffix/default.

Experimental limitations: no protocol extraction yet. Proxy traffic does not accrue token-based spend or record model/prompt/tool/thought facts, so configured budgets cannot account for this traffic. Existing budget checks still run against other recorded spend. Historical missing facts cannot be backfilled. Bedrock and proxy actor-header injection are unsupported. Breaker correctness is explicitly deferred by the author until extractors land. Startup warnings disclose these limitations. Do not enable this experiment where accounting/enforcement parity is required.

Implementation plan and scope decisions
  1. Build on the immutable provider router; preserve startup mode selection, allowlists, and atomic snapshot replacement. Own transports and close idle connections on replacement/shutdown.
  2. Share client/session/firewall metadata helpers with source-compatible root entry points. Resolve authenticated API key identity per recorder call from trusted context.
  3. Capture bridged request bytes once within 32 MiB; reuse GetBody for retries and preserve the legacy fallback. Keep BYOK bypass and existing key-pool health/rotation behavior.
  4. Use httputil.ReverseProxy for forwarding, preserving raw query/body bytes and explicit encoding. Share Coder/actor/proxy-header and cookie sanitization while retaining trusted actor injection only in legacy SDK interception.
  5. Record start synchronously and fail before upstream if it fails. Install one deferred finalizer for EOF/cancel/read/write/abort paths, with detached bounded end recording and unchanged panic propagation.
  6. Keep a private transparent response observation seam without implementing extractors. Preserve borrowed-buffer ownership, original read results, and Close propagation.
  7. Propagate in-process response closure upstream, distinguish stream abort from a genuine panic, and drain requests before closing the recorder connection. Do not create a new asynchronous recording subsystem.
  8. Validate forwarding, credentials, body limits/replay, bounded metrics, attribution, cancellation, reload, and shutdown through focused tests and consumer suites.

Deferred: extractor/model/error-envelope/accounting parity (AIGOV-616 and subsequent provider work), breaker-correctness changes, new passthrough metric schema, and broader lifecycle/API redesign. The review app requested additional PR decomposition; author authorization is pending and no additional PRs have been created.

Generated by Coder Agents on behalf of @pawbana.

@linear-code

linear-code Bot commented Sep 21, 2026

Copy link
Copy Markdown

AIGOV-615

@pawbana pawbana removed their assignment Sep 21, 2026
@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

Coder Agents is running the automated review loop on behalf of @pawbana. This PR will remain draft and unassigned; no human reviewers will be requested.

@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@coder-agents-review

coder-agents-review Bot commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Chat: Review in progress (28/28 reviewers complete) | View chat
Requested: 2026-09-21 14:33 UTC by @pawbana

deep-review v0.9.0 | Round 4 | c5c7f9d..71af097

Status: Panel review (25 reviewers)

Last posted: Round 3, 73 findings (2 P1, 19 P2, 41 P3, 6 Nit, 5 Note), REQUEST_CHANGES. Review

Finding inventory

Finding inventory, PR #29656

Law analysis

  • Effective LOC: +3370 -1164 across 46 files (1049 production, 2321 test, 68.9% test density).
  • Head SHA analyzed: 1a30fde.
  • Verdict: Split. Horizontal, six PRs (Mode 4).
  • Enforcement: Mandatory.
  • Basis: four independent concerns (C1 helper extraction, C2 clientmeta extraction, C3b intercept header strip, C4 keypool GetBody replay, C5 aibridged served-context lifecycle) are independently mergeable; C3b, C4, and C5 change behavior on the interception path serving production today, while the feature they ship with is behind an experiment that currently 404s. Independence verified empirically by revert-and-test, not asserted.

Findings

# Sev Status Location Summary Round Reviewer Posted
CRF-1 P2 Author fixed (f7cdbcd) aibridge/x/proxy/handler.go:112 Failed interception start returns 500 with the error discarded; no log call anywhere in the handler R1 Netero Yes
CRF-2 P2 Author fixed (f7cdbcd) aibridge/x/proxy/handler.go:165 Passthrough upstream transport errors are neither logged, recorded, nor traced R1 Netero Yes
CRF-3 P2 Author fixed (f7cdbcd) aibridge/x/proxy/handler.go:129 No test constructs the handler with metrics, so all four metric call sites are unexecuted R1 Netero Yes
CRF-4 P2 Author fixed (f7cdbcd) aibridge/x/proxy/handler.go:34 categorizeError and maxRecordedErrorMessageBytes duplicate aibridge/interception_error.go R1 Netero Yes
CRF-5 P2 Author fixed (f7cdbcd) aibridge/clientmeta/client.go:12 The move deleted the comments binding the Client list to public documentation R1 Netero Yes
CRF-6 P3 Author fixed (f7cdbcd) aibridge/clientmeta/session.go:37 Per-client rationale comments deleted; documented no-session clients collapsed into default R1 Netero Yes
CRF-7 P3 Author fixed (f7cdbcd) aibridge/clientmeta/request.go:22 Fail-closed rationale for the firewall headers deleted R1 Netero Yes
CRF-8 P3 Author fixed (f7cdbcd) aibridge/session.go:15 GuessSessionIDFromPayload is a new exported wrapper with zero callers R1 Netero Yes
CRF-9 P3 Author contested; orchestrator closed R2 (AIGOV-616 named as consumer) aibridge/x/proxy/observed_body.go:7 observedBody.onRead is nil at the only production call site R1 Netero Yes
CRF-10 P3 Author fixed (f7cdbcd) aibridge/x/proxy/handler.go:59 WebSocket rejection has no test R1 Netero Yes
CRF-11 P3 Author fixed (f7cdbcd) aibridge/x/proxy/handler.go:64 Invalid-firewall-header rejection has no test R1 Netero Yes
CRF-12 P3 Author fixed (f7cdbcd) aibridge/x/proxy/router.go:44 NewRouter accepts a nil recorder and defers the failure to a per-request 500 R1 Netero Yes
CRF-13 P3 Author fixed (f7cdbcd) aibridge/intercept/credential.go:31 VARCHAR(15) constraint comment now annotates an alias, not the value R1 Netero Yes
CRF-14 Nit Author fixed (f7cdbcd) aibridge/x/proxy/handler.go:228 credentialMetadata builds a second failover config per request with a discarded logger R1 Netero Yes
CRF-15 Nit Author fixed (f7cdbcd) coderd/aibridged/proxy_identity_test.go:173 ctx variable guards nothing; the require.NoError(ctx.Err()) assertion is vacuous R1 Netero Yes
CRF-16 Note Author fixed (f7cdbcd) aibridge/x/proxy/handler.go:279 Proxy mode records and labels model as empty R1 Netero Yes
CRF-17 Note Author accepted R2 (AIGOV-615 specifies no SetXForwarded and no default User-Agent) aibridge/x/proxy/handler.go:210 X-Forwarded-For forwarding and the aibridge User-Agent are both dropped relative to passthrough.go R1 Netero Yes
CRF-18 Note Author fixed (f7cdbcd) aibridge/x/proxy/handler.go:291 Remaining zero-coverage blocks; no test pins a specific error classification R1 Netero Yes
CRF-19 P2 Author fixed (f4310a5) aibridge/x/proxy/handler.go:230 stripProxyHeaders re-implements intercept.IsActorHeader and proxyHeaders with hardcoded literals R2 Netero Yes
CRF-20 P2 Author fixed (f4310a5) aibridge/x/proxy/handler.go:143 route metric label is a client-controlled URL path on subtree passthrough routes, unbounded cardinality R2 Netero P3, orchestrator P2 Yes
CRF-21 P3 Author fixed (f4310a5) aibridge/x/proxy/observed_body.go:19 onRead hands the consumer a caller-owned, reused buffer with no documented lifetime R2 Netero Yes
CRF-22 P3 Author fixed (f4310a5) aibridge/interceptionerror/error.go:15 The error-categorizer extraction dropped every rationale comment it moved R2 Netero Yes
CRF-23 P3 Author fixed (f4310a5) aibridge/intercept/credential.go:32 hintAWSChainKey is now the one hint literal with no VARCHAR(15) constraint documented near it R2 Netero Yes
CRF-24 P3 Author contested; panel closed R3 (6/6 accept) aibridge/client.go:12 The clientmeta extraction left a full re-export shim with zero non-test consumers R2 Netero Yes
CRF-25 P3 Author fixed (f4310a5) aibridge/clientmeta/session.go:19 GuessSessionID hardcodes ClientClaudeCode as the only payload-consuming client R2 Netero Yes
CRF-26 P3 Author fixed (f4310a5) aibridge/x/proxy/router.go:80 Upstream transport tuning is copy-pasted from aibridge/passthrough.go:38 without its comment R2 Netero Yes
CRF-27 P3 Author fixed (f4310a5) aibridge/x/proxy/router.go:93 Circuit-breaker onChange closure is a verbatim copy of aibridge/bridge.go:82-97 R2 Netero Yes
CRF-28 Nit Author fixed (f4310a5) aibridge/x/proxy/handler.go:293 finalize builds an AsyncRecorder for one record and immediately waits; the error is discarded R2 Netero Yes
CRF-29 Nit Author fixed (f4310a5) aibridge/x/proxy/handler_review_test.go:1 File name records the review process rather than its subject R2 Netero Yes
CRF-30 Note Author fixed (f4310a5) aibridge/x/proxy/router.go:97 Breaker-metrics block inside onChange has zero coverage through the proxy router R2 Netero Yes
CRF-31 Note Author fixed (f4310a5) coderd/aibridged/aibridged.go:105 daemon.recorder is constructed on every startup but only reachable in proxy mode R2 Netero Yes
CRF-32 P1 Open aibridge/x/proxy/handler.go:106 Proxy mode records no token, prompt, or tool usage, so AI spend budgets never accrue and IsBudgetExceeded always reports allowed R3 Pariston P1, Luffy P1, Pen Botter P1, Kurapika P2, Kite P2 Yes
CRF-33 P1 Open aibridge/x/proxy/handler.go:78 captureRequestBody buffers every request body before dispatch, including passthrough routes that stream today, with no default concurrency cap R3 Hisoka P1, Netero P2, Kurapika P2, Meruem P2, Killua P2, Knov P2, Ryosuke P2, Kite P2, Luffy P2, Pariston P2 Yes
CRF-34 P2 Open aibridge/x/proxy/handler.go:184 The breaker closure always returns nil and ErrorHandler writes 502, which DefaultIsFailure ignores, so the circuit never trips on transport failures R3 Netero P2, Hisoka P2 Yes
CRF-35 P2 Open aibridge/bridge.go:271 InterceptionCount still passes raw client-controlled r.Method on the interception path serving production today R3 Mafuuu P2, Meruem P2, Melody P2, Ryosuke P2, Mafu-san P2, Robin P2, Zoro P2, Razor P2 Yes
CRF-36 P2 Open aibridge/x/proxy/handler.go:218 Percent-encoded dot segments are forwarded to the upstream verbatim, so the registered route set is not a containment boundary R3 Kurapika Yes
CRF-37 P2 Open aibridge/x/proxy/handler.go:115 Client-controlled session ID reaches client_session_id VARCHAR(256) unclamped, so an over-long value makes every request from that client a 500 R3 Knuckle Yes
CRF-38 P2 Open aibridge/x/proxy/router.go:61 An enabled Bedrock provider is skipped with no log, comment, or sentinel, so every Bedrock request 404s in proxy mode R3 Mafuuu P1, Melody P2, Knov P2, Kite P2, Leorio P2, Gon P2, Pariston P2 Yes
CRF-39 P2 Open aibridge/x/proxy/handler.go:217 Proxy mode strips actor headers and never re-injects them, so the SendActorHeaders deployment option is a silent no-op R3 Ryosuke P2, Razor P2, Netero P3 Yes
CRF-40 P2 Open aibridge/x/proxy/handler.go:233 The Cookie header is forwarded to upstream providers, carrying a live coder_session_token from the Coder origin R3 Knov P2, Kurapika P3 Yes
CRF-41 P2 Open aibridge/x/proxy/handler.go:112 model is persisted as empty into an indexed NOT NULL grouping column and cannot be backfilled, though the payload is already buffered R3 Knuckle P2, Luffy P3, Pen Botter P3 Yes
CRF-42 P2 Open aibridge/x/proxy/handler.go:84 The generic body-read failure discards the error and has no test, and it is the only trace the request leaves R3 Chopper P2, Leorio P2, Bisky P3 Yes
CRF-43 P2 Open aibridge/x/proxy/handler_test.go:251 The only circuit-breaker test passes unchanged with the breaker wiring deleted R3 Bisky Yes
CRF-44 P2 Open aibridge/x/proxy/handler.go:172 Wrapping every response body breaks protocol upgrades that interception mode carries, and the failure aborts the connection after 502 was written R3 Meruem P3, Hisoka P3, Ryosuke P3, Kite P3, Pen Botter P2 Yes
CRF-45 P2 Open coderd/aibridged/transport.go:99 An upstream truncation reaches in-process callers as handler panicked, discarding the real cause R3 Mafuuu P2, Melody P3, Pariston P3 Yes
CRF-46 P3 Open aibridge/x/proxy/handler.go:140 route and the breaker key come from the client URL rather than the registered pattern, so CRF-20's bound is incidental on the record path R3 Mafuuu, Meruem, Killua, Knov, Melody, Kite, Ryosuke, Zoro, Gon, Leorio Yes
CRF-47 P3 Open aibridge/x/proxy/handler.go:95 The route label value differs between modes for OpenAI, so dashboards and alerts break on a mode flip; the metrics reference is not updated R3 Melody, Razor, Robin, Leorio Yes
CRF-48 P3 Open aibridge/intercept/client_headers.go:68 PrepareClientHeaders strips Coder-* but not actor headers, so client-supplied actor metadata reaches upstream on bridged interception routes R3 Melody, Netero Yes
CRF-49 P3 Open aibridge/intercept/client_headers.go:54 Interception-mode passthrough still forwards every Coder-* header; the PR closed the class in two of three upstream paths R3 Netero Yes
CRF-50 P3 Open aibridge/x/proxy/handler.go:170 Upstream response headers including Set-Cookie are relayed to the client on the Coder origin R3 Kurapika Yes
CRF-51 P3 Open aibridge/x/proxy/handler.go:296 The end record runs synchronously on the request goroutine and resolves a DRPC client per call, holding the response up to 5s R3 Takumi, Killua Yes
CRF-52 P3 Open coderd/aibridged/aibridged.go:388 Shutdown cancels the DRPC lifecycle before draining, so every in-flight interception is recorded as started and never ended R3 Takumi Yes
CRF-53 P3 Open coderd/aibridged/aibridged.go:398 Shutdown reads and releases the backend snapshot without backendMu, leaking a concurrently published snapshot's transports R3 Komugi P3, Takumi Note Yes
CRF-54 P3 Open aibridge/x/proxy/handler.go:65 The WebSocket rejection keys on GET while ReverseProxy tunnels an upgrade on any method R3 Kurapika Yes
CRF-55 P3 Open aibridge/routing/routes.go:21 MetricRoute is documented as bounding a label but is the identity function for every reachable input R3 Knov Nit, Meruem Nit, Leorio P2, Luffy P3, Mafu-san P3, Robin Nit, Zoro Nit, Gon P3 Yes
CRF-56 P3 Open aibridge/circuitbreaker/circuitbreaker.go:73 After the extraction NewProviderCircuitBreakers has zero production callers, so the next caller gets breakers with no observability R3 Knov, Zoro Yes
CRF-57 P3 Open aibridge/x/proxy/handler.go:50 record bool duplicates recorder != nil and makes a broken combination representable; the interception lifecycle is implemented twice and has drifted R3 Zoro, Ryosuke, Meruem Yes
CRF-58 P3 Open aibridge/x/proxy/handler.go:244 credentialMetadata treats KeyFailoverConfig.IsBYOK as optional while keypool calls it unguarded, and credential_kind now has two derivations R3 Ryosuke Note, Knuckle P3, Robin P3 Yes
CRF-59 P3 Open aibridge/x/proxy/handler.go:178 Every client-cancelled stream logs WARN reverse proxy error, which is routine user behavior on LLM traffic R3 Chopper Yes
CRF-60 P3 Open aibridge/x/proxy/handler.go:66 Preflight rejection logs carry only path, so a rejected caller cannot be identified at production scale R3 Chopper Yes
CRF-61 P3 Open aibridge/clientmeta/request.go:46 The shared firewall-header extractor embeds raw client values in its errors, so the two callers made opposite logging choices R3 Chopper Yes
CRF-62 P3 Open aibridge/x/proxy/handler.go:144 Passthrough requests have an attempt counter but no outcome signal, so there is no alertable failure rate for most Copilot traffic R3 Chopper Yes
CRF-63 P3 Open aibridge/interceptionerror/error.go:32 In proxy mode the persisted, API-exposed error_message is always HTTP status text, so the provider's explanation is lost R3 Chopper Yes
CRF-64 P3 Open aibridge/x/proxy/handler.go:164 ReverseProxy sets ErrorHandler but not ErrorLog, so body-copy failures bypass slog and print a line saying "in test" R3 Takumi Yes
CRF-65 P3 Open aibridge/x/proxy/handler.go:358 Hijack returns a bespoke error instead of http.ErrNotSupported, so ReverseProxy takes the wrong failure branch R3 Ging-Go Yes
CRF-66 P3 Open aibridge/x/proxy/handler.go:236 The CRF-19 fix shared the actor-header prefix and left proxyHeaders duplicated; the two representations already disagree on X-Forwarded-Server R3 Hisoka, Mafu-san Yes
CRF-67 P3 Open aibridge/utils/http.go:14 The actor header prefix moved to utils, away from the package that owns the wire contract, leaving two exported predicates R3 Ryosuke P3, Knov Nit, Gon P3 Yes
CRF-68 P3 Open aibridge/passthrough.go:29 metricRouteFallback threads a constant through two signatures for a case that cannot occur in production R3 Ryosuke, Zoro, Razor, Gon, Mafu-san Yes
CRF-69 P3 Open aibridge/x/proxy/handler.go:219 Six reachable branches have zero coverage, including the RawPath rewrite and the keypool initial-read failure R3 Bisky, Meruem, Chopper, Netero Yes
CRF-70 P3 Open coderd/aibridged/transport_test.go:625 Two streaming tests assert only that some error type was recorded, and the preflight table cannot tell its own cases apart R3 Chopper, Bisky Yes
CRF-71 P3 Open aibridge/bridge.go:328 Round-3 extractions left doc comments describing behavior their functions no longer have, across six sites R3 Gon, Leorio, Mafuuu, Razor Yes
CRF-72 Nit Open aibridge/x/proxy/handler_test.go:193 require in upstream handler goroutines, and unguarded channel receives that hang the package instead of failing R3 Bisky, Meruem, Komugi Yes
CRF-73 Nit Open aibridge/x/proxy/handler.go:80 errors.As(err, new(*http.MaxBytesError)) where the repository uses errors.AsType R3 Ging-Go, Netero Yes

Contested and acknowledged

CRF-9 (P3, aibridge/x/proxy/observed_body.go:7) - onRead hook dead in production

  • Finding: observedBody.onRead is nil at its only production call site (handler.go), non-nil only in its own unit test. Netero proposed deleting the field and the parameter until a caller exists.
  • Author defense (R2, PRRC_kwDOGkVX1s7yFyp-): The hook is an explicit deliverable of AIGOV-615, which requests a response tee seam for extractors while excluding the extractor implementation; AIGOV-616 supplies the consumer. The approved plan specifies a private optional onRead callback with unchanged Read results and no buffering, I/O, or goroutines. Removing it would remove a deliverable, not accidental dead code.
  • Status: contested, no panel decision yet. The panel judges whether a seam with a named follow-up ticket justifies shipping an unexercised production hook.
  • Orchestrator closure (R2): Keep-argument first, per the drop gate: with no follow-up assumption, AIGOV-616 may never land, leaving an unexercised production hook forever, which is the definition of speculative machinery. Against that: the author names a specific consumer ticket rather than a vague intent, the hook costs one nil function pointer and one nil check per Read, and it changes no Read result. Netero re-examined the code in R2 and declined to re-raise the dead-code claim on consequence. Closed as author-accepted with a named consumer ticket. The actionable residue, the undocumented buffer lifetime on the seam, is raised separately as CRF-21 and remains open.

CRF-17 (Note, aibridge/x/proxy/handler.go:210) - X-Forwarded-For and User-Agent dropped

  • Finding: stripProxyHeaders deletes Forwarded and X-Forwarded-*, rewriteRequest never calls pr.SetXForwarded(), and a missing User-Agent is suppressed with a nil value rather than set to "aibridge". aibridge/passthrough.go:87-91,97 did the opposite deliberately. Netero asked for confirmation against what providers key on.
  • Author accepted (R2, PRRC_kwDOGkVX1s7yFyta): AIGOV-615 specifies no SetXForwarded and no default User-Agent. Proxy routes preserve the client User-Agent unchanged. Coder-header stripping is shared with the interceptor path and BYOK credentials remain preserved.
  • Closure reasoning: The finding was raised as a confirmation request, not a defect claim, and the author confirmed the intent against a named requirement. Closed. Netero re-verified in R2 that the behavior still matches the stated contract and that TestHandlerDoesNotSynthesizeUserAgent pins it.

CRF-24 (P3, aibridge/client.go:12) - clientmeta re-export shim

  • Finding: aibridge/client.go re-exports Client plus 14 Client* constants and wraps GuessClient; aibridge/session.go wraps GuessSessionID. Every reference outside the package is in a _test.go file or a SQL comment. Two constants (ClientCrush, ClientJunie) have no references at all, and the next client added to clientmeta will silently have no alias. Netero proposed deleting the shims and the two compatibility tests.
  • Author defense (R3, PRRC_kwDOGkVX1s7yHa6V): The symbols predate this feature. Repository-local usage cannot establish that external library consumers do not use them. CRF-8 differed because GuessSessionIDFromPayload was a new unused root export introduced by this PR, so removing it broke no existing API. The aliases keep one canonical implementation and value in clientmeta, and this PR does not authorize a breaking cleanup across external callers.
  • Panel closure (R3, 6/6 accept): Netero, Mafuuu, Meruem, Hisoka, Knov, and Kite each reached the defense independently and each declined to re-raise. The reasoning they share: the constants are type and constant aliases over clientmeta, so one value exists at runtime and no divergence in recorded output is possible; every production read path already goes through clientmeta; and aibridge is an importable package path, so deleting exported symbols to satisfy a repository-local grep is the larger risk. The worst consequence of keeping the shim is API-surface drift when a client is added to clientmeta and gets no alias, which surfaces as a missing name rather than wrong data. Closed.
  • Residue the panel agreed on but did not treat as grounds to reopen: nothing marks the shims as a compatibility layer or ties the two lists together, and Hisoka noted that Go cannot enumerate constants of a type so a completeness test is not available. Knov's suggestion of // Deprecated: use clientmeta.X. on each alias is the only mechanically enforceable option.

Law round-1 mandatory split (not a CRF) - unresolved

  • Verdict: Split, horizontal, six PRs, mandatory.
  • Author response (R2, IC_kwDOGkVX1s8AAAABV1MMmg): Item 1's prerequisite chore: move aibridge proxy code and helpers to separate packages #29573 merged to main independently and is now in the merge base. Creating the remaining PRs "requires author approval and is awaiting that decision." No linked ticket.
  • Status: unresolved. The PR still bundles three behavior changes on the production interception path with the experiment-gated feature. This needs a human decision: authorize the split or explicitly accept the bundling.

Round log

Round 3

Churn guard: PROCEED. 11 of 13 round-2 findings addressed in f4310a5318 ("fix: bound AI Gateway metrics and preserve shared contracts", 21 files, +674 -410); CRF-24 contested with no code change. Consecutive pre-panel Netero-only cap reached, so the panel ran this round regardless of first-pass severity; Netero ran alongside the panel as an advisory reviewer rather than a gate. Panel of 24 plus Netero. 42 new findings, CRF-32 to CRF-73: 2 P1, 13 P2, 26 P3, 2 Nit. Law not re-run: effective additions grew 3370 to 3866, a 496 increase, below the 500 threshold. Law's mandatory split remains unresolved with no round-3 response. Reviewed against c5c7f9d..f4310a5.

Cross-check decisions, round 3

  • CRF-32 set at P1 (Pariston, Luffy, Pen Botter said P1; Kurapika and Kite said P2). Downward case, written first: the gap is deliberate sequencing behind AIGOV-615/616 and the mode is experiment-gated. It fails because the consequence is not an absent feature but an enforcement control that reports success while enforcing nothing: IsBudgetExceeded still runs on every request against a spend total that can never grow, and this PR replaced the Warn "reverse proxy routing is not yet functional" with Info "selected reverse proxy routing", removing the only operator-visible signal. Verified: grep -rn "RecordTokenUsage\|RecordPromptUsage\|RecordToolUsage" aibridge/x/proxy excluding tests returns nothing.
  • CRF-33 set at P1 (Hisoka said P1; ten reviewers said P2, several citing experiment gating and the 32 MiB per-request cap). Keep-argument for the higher severity: experiment gating is a probability argument, which the drop gate forbids as a downgrade basis, and "32 MiB is capped" bounds one request, not the process. CODER_AI_GATEWAY_MAX_CONCURRENCY and CODER_AI_GATEWAY_RATE_LIMIT both default to 0 (verified independently by Killua, Kurapika, Hisoka, Knov at codersdk/deployment.go:1973-1989), so resident heap is bounded by client behavior alone and the victim is the whole control plane. Killua measured io.ReadAll at 48 MiB live per 32 MiB body. I could not articulate a bound, so the severity stands at P1.
  • CRF-38 set at P2 (Mafuuu said P1; six reviewers said P2). Keep-argument for P1: a configured, enabled provider loses all traffic with no log line and a 404 indistinguishable from a typo. Against it: the failure is an immediate, total, visible error on the first Bedrock request, not silent data loss or a security hole, and the diagnosability cost is what separates it from CRF-32 and CRF-33. P2 with Mafuuu's dissent recorded.
  • CRF-44 set at P2 (Pen Botter said P2 on the WebSocket half; four reviewers said P3 on the upgrade half). Merged: both are one user-visible class, upgrade traffic that interception mode carries and proxy mode does not. Higher severity wins on the merge.
  • CRF-45 set at P2 (Mafuuu said P2; Melody and Pariston said P3). Higher wins; Mafuuu's evidence is the sharpest, having run the existing truncation test with the error printed.
  • CRF-55 set at P3 (Leorio said P2; seven reviewers said P3 or Nit). Keep-argument for P2: the function's name is the thing a future author will trust instead of checking, and MetricRoute(r.URL.Path) compiles. Against it: there is no runtime consequence today and the remedy is naming, so the majority reading with equal-specificity evidence holds.
  • Consequence chain not visible in any single finding, raised in the review body: CRF-34 and CRF-33 compose. Under a hard upstream outage the breaker never opens, so every request is dispatched and pays the full dial or TLS timeout, and each of those parked requests holds its fully buffered body. A provider outage therefore becomes a coderd memory event rather than shed load. Neither reviewer stated the combination.
  • Dropped, with the keep-argument written first. Mafuuu's Note that an empty-body POST goes upstream chunked: keep-argument is that a provider rejecting chunked would break empty-body requests. Dropped because Knov probed the same path and observed Content-Length: 0 with no Transfer-Encoding, and Mafuuu explicitly reasoned from toolchain source without executing. The empirical result wins.
  • Dropped: Mafuuu's P4 on the interception model label and breaker key being client-controlled. Keep-argument: it is the same attacker-shaped label class as CRF-35 and leaves the label set unbounded even after CRF-35 is fixed. Dropped from posting because it predates this diff and is not touched by it; recorded here so the next round can raise it as its own item rather than losing it. Mafuuu rated it P4 for the same reason.
  • Not re-raised: CRF-24. Netero, Mafuuu, Meruem, Hisoka, Knov, and Kite each independently evaluated the author's compatibility defense and each declined to re-raise. The panel vote is 6/6 accept.
  • Verified by the orchestrator rather than assumed: the unconditional captureRequestBody call above every h.record branch (CRF-33), the breaker closure returning nil together with DefaultIsFailure accepting only 503 and 504 (CRF-34), client_session_id character varying(256) at dump.sql:1669 inserted unclamped at aibridgedserver.go:274 while the neighbouring error_message is truncated at :323 (CRF-37), the absence of any usage-recording call in aibridge/x/proxy (CRF-32), rewriteRequest performing no path normalization (CRF-36), and stripProxyHeaders not covering Cookie (CRF-40).

Round 2

Churn guard: PROCEED. 16 of 18 findings addressed in f7cdbcdada, CRF-17 acknowledged and closed, CRF-9 contested and closed by the orchestrator. Netero re-ran (head changed): 1 P2, 8 P3, 2 Nit, 3 Note new, numbered CRF-19 to CRF-31. Orchestrator upgraded CRF-20 from P3 to P2 (client-controlled unbounded Prometheus label cardinality is a remote resource-exhaustion vector in coderd, not a hygiene issue). Second consecutive pre-panel round: Netero's P2 findings gate panel selection, so no panel ran. Round 3 hits the consecutive Netero-only cap and must run the panel. Orchestrator verified CRF-19 (intercept/actor_headers.go:14 owns the prefix, handler.go:233 hardcodes it), CRF-20 (Copilot PassthroughRoutes returns "/"), CRF-22 (interceptionerror/error.go carries no rationale comments), CRF-23 (hintAWSChainKey has no constraint comment; the moved comment annotates only CredentialHintFailoverKey), CRF-24 (every aibridge.Client* reference outside the package is in a _test.go file or a SQL comment), CRF-25 (GuessSessionID short-circuits on ClientClaudeCode). Base moved to c5c7f9d because prerequisite #29573 (44eb71f922) merged to main and the author merged main in 96b98e77be, which covers Law split item 1. Remaining split items await author authorization with no linked ticket. Law not re-run: effective additions grew 3370 to 3538, below the 500 threshold. Reviewed against c5c7f9d..96b98e7.

Round 1

Netero plus Law (effective additions 3370 > 1000). Law verdict: Split, Mandatory, so no panel ran. Netero: 5 P2, 8 P3, 2 Nit, 3 Note, no P0 or P1. Orchestrator verified CRF-1 (h.logger referenced once, at handler.go:136), CRF-3 (every proxy.NewRouter call site in tests passes nil for metrics), CRF-4 (maxRecordedErrorMessageBytes defined in both aibridge/interception_error.go:15 and aibridge/x/proxy/handler.go:34), CRF-5 (old aibridge/client.go carried the docs-sync and Mux-rename comments; clientmeta/client.go carries neither), CRF-8 (only self-references for the aibridge wrapper), and Law's C3b/C4/C5 independence by reading the diffs. Reviewed against 29ae50d..1a30fde.

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.

The reverse-proxy handler is well built for the shape of the problem. record bool cleanly separates bridged from passthrough behavior, observedBody gives the recorder a real EOF and read-error signal instead of guessing at stream termination, the body-limit path distinguishes a declared oversize Content-Length from a mid-read overflow, and the tests assert observable outcomes (upstream headers received, dump files written, recorder start/end IDs paired, panic propagation) rather than mock returns. TestHandlerBodyLimitBoundaries genuinely allocates MaxRequestBodyBytes and checks the upstream got exactly that many bytes. 68.9% test density on 1049 production lines is not padding.

This round ran the two infrastructure reviewers only. Law returned a mandatory split verdict, so the review panel has not looked at this PR yet and will run once the split lands.

Split request (Law, mandatory). Effective diff is +3370 across 46 files, and four of the nine concerns inside it are independently mergeable. Law verified three of them by revert-and-test rather than by argument: the helper extraction builds standalone at its own commit 09d2561904, reverting aibridge/keypool/failover.go breaks no proxy test, and reverting coderd/aibridged/transport.go fails exactly its own two dedicated tests. Proposed landing order:

  1. refactor(aibridge): hoist mode-independent routing helpers into provider and routing. This is commit 09d2561904 unchanged, +246 -243.
  2. refactor(aibridge/clientmeta): extract client and session identification. Not purely mechanical, GuessSessionID was restructured and rationale comments were dropped (CRF-5, CRF-6, CRF-7, CRF-8).
  3. fix(aibridge/intercept): strip all Coder headers from upstream requests. PrepareClientHeaders now drops every Coder-* and X-Coder-* header instead of the two Agent Firewall headers, on the interception path that serves production today. Its entire dedicated review surface here is two assert.Empty lines.
  4. fix(aibridge/keypool): replay failover bodies via GetBody. Alters retry behavior in interception mode.
  5. fix(coderd/aibridged): scope the in-process served request to its own context. Changes cancellation and stream-termination semantics for every chatd LLM call today.
  6. feat(aibridge/x/proxy): the forwarding handler itself, roughly +560 production.

Law's reason for making this mandatory rather than advisory is not the line count: "A reviewer approving 'add reverse-proxy handler' is being asked to simultaneously approve a change to what headers leave the deployment toward Anthropic and OpenAI, a change to how failed requests are retried, and a change to when chatd's in-process LLM calls are canceled. Those are three different risk domains with three different blast radii, and the one with the largest blast radius has the smallest diff." The compliance cost is low: item 1 is already its own commit, and items 4 and 5 each touch one production file plus one test file with no reference into the feature.

Netero, 18 findings, no P0 or P1: 5 P2, 8 P3, 2 Nit, 3 Note. Build, vet, golangci-lint, and -race tests on the changed trees are all clean.

Two of the P2s compound. CRF-1 and CRF-2 together mean h.logger is referenced exactly once in the whole handler, to build a config, so every rejection (400 no actor, 501 websocket, 400 bad firewall headers, 413, 500 record failure, 502 upstream) is silent, and on passthrough routes the upstream error is not recorded either because finalize returns before touching it. The trace does not name the upstream either, since rewriteRequest dropped the PassthroughUpstreamURL span attribute that aibridge/passthrough.go:94 sets. A 502 in proxy mode is currently undiagnosable from logs, records, or traces at once. The handler this replaces logged both cases.

CRF-3 is the one I would fix first alongside those, because it is the cheapest: no test anywhere constructs the handler with a non-nil *metrics.Metrics, so inflight Inc/Dec balance is unverified and a future label change panics inside the request handler with no CI signal. One test passing metrics.NewMetrics(prometheus.NewRegistry()) closes it.

CRF-5 through CRF-7 and CRF-13 are all the same class: the extraction moved code and left its constraints behind. The docs-sync link, the Mux-rename note, the fail-closed rationale, and the VARCHAR(15) width now sit somewhere other than the definition that has to satisfy them. These are cheap to restore and expensive to rediscover.

Netero on the dead export, verbatim: "Dead export on arrival; delete it."

CRF-17 is a question, not a defect claim. The rewrite drops X-Forwarded-For forwarding and no longer sets the aibridge User-Agent, both of which aibridge/passthrough.go did deliberately. The tests suggest this is intentional, but it is worth confirming against whatever the providers key on.

🤖 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/clientmeta/client.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread coderd/aibridged/proxy_identity_test.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 commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

Coder Agents follow-up on behalf of @pawbana: the logging, metrics, rejection coverage, moved comments, constructor validation, and shared error-classification findings are being addressed. The extractor onRead seam, empty model facts, and header/User-Agent behavior are intentional requirements of AIGOV-615 and its approved plan, not final protocol parity.

The suggested split includes prerequisite #29573, which already merged at 44eb71f before this review. This branch carries the pre-merge version, causing overlap/conflicts; I am reconciling the merged base without rewriting published history. Creating additional PRs requires author approval and is awaiting that decision. This PR remains draft and unassigned.

Restore proxy diagnostics and metadata rationale, share terminal error classification, validate recorder construction, and cover metrics and request rejection paths.

Generated by Coder Agents on behalf of @pawbana.
Reconcile the already-merged AIGOV-674 prerequisite while preserving the reverse-proxy implementation.

Generated by Coder Agents on behalf of @pawbana.
@pawbana

pawbana commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator Author

Coder Agents follow-up on behalf of @pawbana: pushed review fixes in f7cdbcd and merged the already-landed prerequisite/main in 96b98e7 without force-pushing. CRF-1-8, 10-16, and the actionable classification coverage in CRF-18 are addressed. Logging/tracing, metrics/preflight tests, recorder construction validation, shared error categorization, moved rationale comments, and constant documentation are updated. CRF-9 (explicit extractor seam) and CRF-17 (approved header/User-Agent contract) remain intentionally unchanged as explained in-thread.

Validation passed: make fmt; make lint/go; go test ./aibridge/... ./coderd/aibridged/... ./coderd/x/chatd/...; affected-package race tests; TestAIBridgeTransportFactory; enterprise TestIntegration; git diff --check.

#29573 is now part of the merge base, reducing the review to the remaining implementation rather than reviewing the prerequisite twice. Additional PR creation remains pending author authorization. Please re-evaluate the current diff; keep this PR draft and unassigned.

@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@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.

Strong turnaround. 16 of the 18 round-1 findings are fixed in f7cdbcdada, and the fixes are real rather than cosmetic: every rejection path now logs, ErrorHandler logs and sets a span status, rewriteRequest restores the PassthroughUpstreamURL attribute, NewRouter rejects a nil recorder instead of deferring a 500 to request time, the duplicated classifier became aibridge/interceptionerror with a Categorizer interface that restores the provider delegation, and the deleted rationale comments in clientmeta are back with the per-client cases spelled out again. aibridge/x/proxy is at 91.6% statement coverage and TestHandlerRecordsSharedErrorClassifications now pins timeout and rate_limited rather than merely asserting non-empty. CRF-17 is closed on the author's AIGOV-615 answer, and CRF-9 is closed: Netero re-examined the seam and declined to re-raise the dead-code claim, since a nil function pointer and one nil check per Read with a named consumer ticket is a real cost of nearly zero.

This was the second pre-panel round. Netero found a new P2, which gates panel selection again, so the panel still has not reviewed this PR. Round 3 hits the consecutive-first-pass cap and will run the full panel regardless of what Netero finds.

13 new findings: 2 P2, 7 P3, 2 Nit, 2 Note. Build, vet, golangci-lint at the pinned version, make lint/architecture, and -race -count=3 on ./aibridge/x/proxy/ are all clean.

I upgraded one finding. Netero rated the route metric label P3; I am posting it as P2. On subtree passthrough routes the label is the raw client URL path, and Copilot's PassthroughRoutes() returns /, so every distinct path a client invents becomes a permanent Prometheus series in the coderd registry. Netero verified it empirically (50 paths, 50 passthrough_total series). That is client-driven unbounded memory growth with no eviction, reachable by any authenticated gateway user, which is an availability property rather than a hygiene one. The identical class exists at aibridge/passthrough.go:70 today; that does not make it acceptable in the mode meant to replace it, and a fix should cover both.

The other P2 is the same class this PR keeps hitting: stripProxyHeaders re-implements intercept.IsActorHeader with the literal "x-ai-bridge-actor", and the proxyHeaders set with inline string comparisons. Three copies of the actor prefix now exist (the intercept constant, the proxy handler, and a test regex), and if the prefix is ever renamed the proxy silently forwards a client-supplied X-AI-Bridge-Actor-Id upstream. go list -deps ./aibridge/intercept shows no cycle, so intercept.IsActorHeader(name) is available today.

Four of the P3s are duplication that survived the round-1 cleanup: the transport tuning block copied from passthrough.go, the circuit-breaker onChange closure copied verbatim from bridge.go, the clientmeta re-export shim in aibridge/client.go whose only consumers are tests, and GuessSessionID hardcoding ClientClaudeCode as the sole payload-consuming client while the switch below owns that fact. The last one has a consequence beyond tidiness: when a second client gains body-based extraction, the proxy path finds the session ID and the interception path returns nil, with no failing test.

Two round-1 fixes are incomplete rather than wrong. CRF-13's VARCHAR(15) comment moved to recorder/types.go where it annotates only CredentialHintFailoverKey, leaving hintAWSChainKey as the one hint literal in the tree with no length constraint documented anywhere near it. And the class CRF-5 through CRF-7 addressed in clientmeta was not applied to interceptionerror, which dropped all four rationale comments it moved, including the one explaining why key-pool errors must be checked before provider delegation.

Netero on the seam contract, verbatim: "Buffering a response stream is exactly what a response extractor does." onRead receives p[:n] where p is the caller's buffer, and httputil.ReverseProxy reuses one 32 KiB buffer for the whole copy loop. The one existing consumer happens to copy via append; nothing says it must.

Process note on the split. Law's round-1 verdict was mandatory, and it is still unresolved. Item 1's prerequisite #29573 merged to main independently, which removes it from this diff, but the author's response states that creating the remaining PRs "requires author approval and is awaiting that decision," with no linked ticket. Neither I nor the author-agent can accept that bundling as permanent; this needs a human decision. The PR still asks one approval to cover three behavior changes on the interception path that serves production today (the Coder-* header strip in intercept.PrepareClientHeaders, the GetBody replay factory in keypool, and the served-context change in inMemoryRoundTripper) alongside an experiment-gated feature. Worth recording: Netero reviewed all three on their own terms this round and found no defect in the keypool factory or the served-context change, so the split argument is about review surface and revert granularity, not about latent bugs found.

🤖 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/observed_body.go Resolved
Comment thread aibridge/interceptionerror/error.go Resolved
Comment thread aibridge/intercept/credential.go Resolved
Comment thread aibridge/x/proxy/router.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler_review_test.go Resolved
Comment thread aibridge/x/proxy/router.go Resolved
Comment thread coderd/aibridged/aibridged.go Resolved
Use registered passthrough routes for metrics, share header and streaming transport helpers, preserve recorder and session contracts, and update the standalone proxy-mode expectation.

Generated by Coder Agents on behalf of @pawbana.
@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

Coder Agents follow-up on behalf of @pawbana: f4310a5 addresses CRF-19 through CRF-31 except CRF-24, whose pre-existing public compatibility aliases are retained as explained in-thread. Route/method metric labels are bounded in both forwarding modes; legacy routes still share one provider transport. Actor-header predicates, streaming transport construction, and breaker observability are shared without changing the deliberately deferred breaker accounting. End recording uses a direct detached bounded call with error logging. Borrowed-buffer and persistence constraints are documented; session extraction has one payload-needed decision; the review-named tests are merged into handler_test.go.

Also fixed the CI-only standalone test that still expected the pre-handler 404 instead of forwarding/recording success. Full make pre-commit passed, along with gateway/chatd/consumer integration tests, affected race tests, and the standalone experiment test in normal and race modes. Additional PR creation still requires author authorization; this PR remains draft and unassigned.

@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@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.

First panel round, and the code it met is materially better than the code round 1 saw. 29 of the 31 earlier findings are fixed, and the round-3 commit did the harder version of most of them: interceptionerror is a real shared package with a Categorizer interface rather than a copied function, NewProviderCircuitBreakersWithObservability collapsed two duplicated closures into one, sessionIDFromInputs replaced a hardcoded client check with a switch that owns the decision, and utils.NewStreamingTransport carries the rationale comment that was previously lost. The metric-cardinality work is genuinely done where it was aimed: Hisoka went looking to break the bounded passthrough label and could not, and both modes now have a 50-distinct-path test. Several reviewers independently named the same test as the best thing in the diff, TestProxyRecorderUsesAuthenticatedAPIKeyIDPerRequest, which runs three identities concurrently and asserts the negative cases. Kurapika traced the whole recorder identity chain and reported it correct, which is the place cross-request attribution bugs usually live.

42 new findings from a 25-reviewer panel: 2 P1, 13 P2, 25 P3, 2 Nit. Nine reviewers settled claims with throwaway probes rather than reasoning, and every one cleaned up after itself. CRF-24 is closed: six reviewers evaluated your compatibility defense independently and all six declined to re-raise, 6/6 accept.

The two P1s are both about proxy mode being a governance gateway that does not govern yet, without saying so.

CRF-32. There is no RecordTokenUsage, RecordPromptUsage, or RecordToolUsage call anywhere in aibridge/x/proxy, and spend only accrues inside RecordTokenUsage on the coderd side. Server.ServeHTTP still calls IsBudgetExceeded on every request, against a total that can never grow. So a user with a configured monthly cap can spend without bound on the org's centralized keys while the control plane shows the budget check running and passing. I accept that extractors are staged behind AIGOV-615 and AIGOV-616. What is not a sequencing decision is that this PR replaced Warn "reverse proxy routing is not yet functional" with Info "selected reverse proxy routing", which removed the only operator-visible statement that the mode is incomplete. Five reviewers reached this independently from five different angles. Whether to ship a mode that silently disables a documented, entitled control is a human decision, not one a reviewer or a follow-up ticket can make.

CRF-33. captureRequestBody runs above every h.record branch, so passthrough routes that stream today are fully buffered before the upstream is dialed. Copilot is always BYOK with PassthroughRoutes() of {"/"} and a nil key pool, so today every Copilot request streams and buffers nothing; under this handler all of them buffer up to 32 MiB. Hisoka probed it with an open io.Pipe body and confirmed the upstream is not contacted until the client's last byte. Killua measured io.ReadAll holding 48 MiB live per 32 MiB body. CODER_AI_GATEWAY_MAX_CONCURRENCY and CODER_AI_GATEWAY_RATE_LIMIT both default to 0, and the in-memory chatd transport does not pass through that middleware at all, so nothing bounds how many buffers exist at once. Ten reviewers rated this P2, citing the experiment gate and the per-request cap; I am posting P1 because experiment gating is a probability argument and a per-request cap bounds one request, not the process. The fix is four lines and the passthrough path reads none of the bytes.

Those two are not the whole of it, and one compound effect deserves saying because no single reviewer said it. CRF-34 and CRF-33 interact. The breaker's Execute closure always returns nil, ErrorHandler writes 502, and DefaultIsFailure counts only 503 and 504, so the circuit cannot trip on a dial, DNS, or TLS failure. Netero and Hisoka each proved it separately against http://127.0.0.1:1 with a threshold of one: three requests, three 502s, no state change, while the same setup with an upstream 503 opens the circuit on the first failure. So during a hard provider outage proxy mode keeps dispatching at full rate, every request pays the whole dial timeout, and each of those parked requests is holding its buffered body. The one scenario the breaker exists for becomes a coderd memory event instead of shed load. Bisky then found why nothing caught it: the only breaker test asserts a 503 status that an upstream 503 and a breaker-generated 503 both satisfy, and it stays green with the breaker wiring deleted from router.go entirely.

Four findings land on the production interception path rather than behind the experiment, so they need fixing whether or not this PR is split. CRF-35: InterceptionCount still passes raw r.Method, which eight reviewers flagged and two reproduced end to end, minting a permanent series per method token. CRF-37: Knuckle ran inserts against a real migrated schema and found client_session_id is VARCHAR(256) with no clamp on either side, so a client sending a 300-character session ID gets a 500 on every request until it changes, while the neighbouring error_message is truncated. CRF-48 and CRF-49: the PR taught two of three upstream paths to strip Coder headers and left interception-mode passthrough forwarding them, and PrepareClientHeaders strips Coder-* but not the actor headers the proxy path does strip.

Kurapika's CRF-36 is the one I would look at next after the P1s. Encoded dot segments survive rewriteRequest untouched: a request for /copilot/%2e%2e/%2e%2e/admin/keys reached the upstream as /tenant-a/%2e%2e/%2e%2e/admin/keys, because net/http.cleanPath runs on the escaped path so %2e%2e never becomes .. and the subtree pattern matches. On Anthropic and OpenAI the gateway injects the org's pooled key into that request, so the user picks the upstream path and Coder supplies the credential. Kurapika was explicit that the second half is unverified: whether the request lands outside the allow-listed path depends on the upstream normalizing %2e%2e, which edge proxies commonly do but which was not tested against a real provider. The gateway-side break is the half Coder controls and it is confirmed. What would settle the rest is one request to each configured provider with an encoded segment.

Ryosuke's structural read is worth more than any individual P3 and I am relaying it whole rather than as a comment: the record bool is read five times and each read marks a place where the two modes want different code. The unconditional buffer exists because one entry point serves both. The dead metricRoute on bridged handlers and the dead route on passthrough handlers exist because one struct carries both modes' fields. Round 3 extracted the leaves and left the sequencing duplicated in two files, which is exactly why bounded labels landed on one path and not the other. His suggestion is that the next extraction be the recording lifecycle as one component both bridged handlers call, not another helper in utils.

Verbatim, Hisoka opening: "Four probes thrown, four landed. The proxy handler is well-built where it's been looked at. Nobody looked at what it does to a request body, and nobody asked the circuit breaker what it counts."

Two process items. The PR description is still the single word "WIP" on a 45-file, +3866/-992 change, and Leorio and Mafu-san independently noted that the broadest production behavior change in it, widening PrepareClientHeaders to drop every Coder-* header, is described nowhere a reader would look: not the PR body, not the commit that introduced it, not the commit that touched it again. Second, Law's mandatory split from round 1 has now gone two rounds with no linked ticket and no round-3 response. The author-agent's position is that creating the PRs awaits author authorization; that is a reasonable thing for an agent to say and it is also why this needs a human. Three behavior changes on the path serving production today are still bundled with an experiment-gated feature, and four of this round's findings land inside them. Either authorize the split or explicitly accept the bundling; neither I nor the author-agent can accept it as permanent.


aibridge/bridge.go:271

P2 [CRF-35] The CRF-20 fix bounded the method label on the new path and left the same metric unbounded on the interception path that serves production today. (Mafuuu P2, Meruem P2, Melody P2, Ryosuke P2, Mafu-san P2, Robin P2, Zoro P2, Razor P2)

This PR introduced routing.MetricMethod and applied it at passthrough.go:65,106 and x/proxy/handler.go:145,293, but InterceptionCount on the bridged interception path still passes r.Method verbatim at bridge.go:271 (failed) and bridge.go:277 (completed). One unbounded writer poisons the series set for every reader of that metric, so bounding one of the two producers changes nothing. (Ryosuke)

Verified, not reasoned: a request with method FROBNICATE1234567890 to /anthropic/v1/messages returned 200 and produced interceptions_total{...,method="FROBNICATE1234567890",status="completed"} 1. Every distinct token an authenticated user sends creates a new series with initiator_id already in the label set, so one request per series is the cost of growing coderd's registry without bound. (Meruem)

In coderd the handler is mounted under chi, which rejects non-standard method tokens with 405. The standalone gateway mounts it on an http.ServeMux, which matches on path only, so an authenticated client sending FOO /anthropic/v1/messages with a valid body reaches the bridged handler. (Melody)

Eight reviewers found this independently and two reproduced it end to end through aibridge/internal/integrationtest. Melody's mount-point analysis narrows the blast radius to the standalone gateway rather than coderd, which is why this is P2 and not higher, but it is the same remote resource-exhaustion vector the panel rated P2 for the route label and it is not behind the experiment flag. Fix: routing.MetricMethod(r.Method) at both call sites.

🤖

coderd/aibridged/aibridged.go:388

P3 [CRF-52] Graceful shutdown kills the DRPC connection before it drains requests, so every interception still in flight is recorded as started and never ended. (Takumi)

Sequence in Shutdown: s.cancelFn(ErrShutdown), s.wg.Wait(), then s.inflight.Shutdown(ctx) for proxy mode or pool.Shutdown(ctx) for interception mode. s.wg tracks the connect goroutine, which is the only sender on s.clientCh and closes the DRPC connection on its way out. So by the time the drain begins, no sender remains and Server.Client has only <-s.Done() ready.

Verified: with lifecycleCtx canceled, s.Client(ctx) returns ErrShutdown in under a millisecond against a 5s call context.

Every handler that finishes during the drain therefore fails its end record with acquire client: ..., logged at warn and discarded. The interception rows for those requests keep a start and never get an end, on every coderd restart that has gateway traffic. Interception mode has the identical exposure through bridge.go:282.

The ordering fix is local: stop admission and drain first, cancel the lifecycle context after, so the drain still has a client. This interacts with CRF-51: fixing the ordering here also removes the 5s-per-request stall during a restart.

🤖

aibridge/circuitbreaker/circuitbreaker.go:73

P3 [CRF-56] After the CRF-27 extraction, NewProviderCircuitBreakers has zero production callers and exists as an exported hook for tests only. (Knov, Zoro)

Count, not intuition: production callers of NewProviderCircuitBreakersWithObservability are bridge.go:78 and x/proxy/router.go:88, two of two. Production callers of NewProviderCircuitBreakers are zero; the only call sites are the wrapper at line 66 and four in circuitbreaker_test.go.

The wide constructor takes an arbitrary onChange. Every real caller wants exactly one: log the transition and move the metrics. Keeping both exported means the next caller can register breakers with no observability at all, which is the state this refactor was raised to remove, and CI will not notice. This is the shape CRF-27 was about: one behavior, two entry points, drifting independently. (Knov)

The CRF-27 fix is right; this is the residue of it. Unexport the narrow constructor, keep the observable one as the only exported entry point, and rename it back to NewProviderCircuitBreakers since there is no longer an alternative. Gon separately noted the naming consequence: the constructor every production caller must use currently has the longer, mechanism-shaped name.

🤖

🤖 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 Outdated
},
}

execErr := h.breaker.Execute(route, "", w, func(rw http.ResponseWriter) error {

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.

P2 [CRF-34] The breaker closure always returns nil, so upstream transport failures never count as circuit-breaker failures. (Netero P2, Hisoka P2, both reproduced)

h.breaker.Execute(route, "", w, func(rw) error { ...; proxy.ServeHTTP(writer, r); return nil }) swallows every failure. The ErrorHandler writes 502, and circuitbreaker.DefaultIsFailure counts only 503 and 504, so a dial failure, TLS failure, or DNS failure is invisible to gobreaker. The interception path does the opposite: bridge.go:261-263 returns interceptor.ProcessRequest's error, which gobreaker counts. (Netero)

Bridged route, FailureThreshold: 1, base URL http://127.0.0.1:1, three requests: 502 502 502, no state change logged. Same provider, same threshold, upstream answering 503 instead: circuit breaker state change provider=openai endpoint=/v1/chat from=closed to=open, second request {"error":"circuit breaker is open"}. So the breaker works, and refuses the one case that matters. (Hisoka)

Two reviewers reproduced this separately with the same setup and the same result. Verified independently: the closure returns a bare nil, and DefaultIsFailure accepts only StatusServiceUnavailable and StatusGatewayTimeout.

This compounds with CRF-33. During a hard provider outage the circuit never opens, so every request is dispatched, pays the full dial or TLS timeout, and holds its fully buffered body while it waits. The scenario the breaker exists for becomes a coderd memory event instead of shed load.

Fix is one line: return state.transportErr from the closure. ErrorHandler has already written the 502 so the client response does not change, and terminalError already prefers execErr over transportErr, so the recorded error type does not change either.

🤖

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 coderd/aibridged/transport_test.go Resolved
Comment thread aibridge/bridge.go Resolved
Comment thread aibridge/x/proxy/handler_test.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved

@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.

First panel round, and the code it met is materially better than the code round 1 saw. 29 of the 31 earlier findings are fixed, and the round-3 commit did the harder version of most of them: interceptionerror is a real shared package with a Categorizer interface rather than a copied function, NewProviderCircuitBreakersWithObservability collapsed two duplicated closures into one, sessionIDFromInputs replaced a hardcoded client check with a switch that owns the decision, and utils.NewStreamingTransport carries the rationale comment that was previously lost. The metric-cardinality work is genuinely done where it was aimed: Hisoka went looking to break the bounded passthrough label and could not, and both modes now have a 50-distinct-path test. Several reviewers independently named the same test as the best thing in the diff, TestProxyRecorderUsesAuthenticatedAPIKeyIDPerRequest, which runs three identities concurrently and asserts the negative cases. Kurapika traced the whole recorder identity chain and reported it correct, which is the place cross-request attribution bugs usually live.

42 new findings from a 25-reviewer panel: 2 P1, 13 P2, 25 P3, 2 Nit. Nine reviewers settled claims with throwaway probes rather than reasoning, and every one cleaned up after itself. CRF-24 is closed: six reviewers evaluated your compatibility defense independently and all six declined to re-raise, 6/6 accept.

The two P1s are both about proxy mode being a governance gateway that does not govern yet, without saying so.

CRF-32. There is no RecordTokenUsage, RecordPromptUsage, or RecordToolUsage call anywhere in aibridge/x/proxy, and spend only accrues inside RecordTokenUsage on the coderd side. Server.ServeHTTP still calls IsBudgetExceeded on every request, against a total that can never grow. So a user with a configured monthly cap can spend without bound on the org's centralized keys while the control plane shows the budget check running and passing. I accept that extractors are staged behind AIGOV-615 and AIGOV-616. What is not a sequencing decision is that this PR replaced Warn "reverse proxy routing is not yet functional" with Info "selected reverse proxy routing", which removed the only operator-visible statement that the mode is incomplete. Five reviewers reached this independently from five different angles. Whether to ship a mode that silently disables a documented, entitled control is a human decision, not one a reviewer or a follow-up ticket can make.

CRF-33. captureRequestBody runs above every h.record branch, so passthrough routes that stream today are fully buffered before the upstream is dialed. Copilot is always BYOK with PassthroughRoutes() of {"/"} and a nil key pool, so today every Copilot request streams and buffers nothing; under this handler all of them buffer up to 32 MiB. Hisoka probed it with an open io.Pipe body and confirmed the upstream is not contacted until the client's last byte. Killua measured io.ReadAll holding 48 MiB live per 32 MiB body. CODER_AI_GATEWAY_MAX_CONCURRENCY and CODER_AI_GATEWAY_RATE_LIMIT both default to 0, and the in-memory chatd transport does not pass through that middleware at all, so nothing bounds how many buffers exist at once. Ten reviewers rated this P2, citing the experiment gate and the per-request cap; I am posting P1 because experiment gating is a probability argument and a per-request cap bounds one request, not the process. The fix is four lines and the passthrough path reads none of the bytes.

Those two are not the whole of it, and one compound effect deserves saying because no single reviewer said it. CRF-34 and CRF-33 interact. The breaker's Execute closure always returns nil, ErrorHandler writes 502, and DefaultIsFailure counts only 503 and 504, so the circuit cannot trip on a dial, DNS, or TLS failure. Netero and Hisoka each proved it separately against http://127.0.0.1:1 with a threshold of one: three requests, three 502s, no state change, while the same setup with an upstream 503 opens the circuit on the first failure. So during a hard provider outage proxy mode keeps dispatching at full rate, every request pays the whole dial timeout, and each of those parked requests is holding its buffered body. The one scenario the breaker exists for becomes a coderd memory event instead of shed load. Bisky then found why nothing caught it: the only breaker test asserts a 503 status that an upstream 503 and a breaker-generated 503 both satisfy, and it stays green with the breaker wiring deleted from router.go entirely.

Four findings land on the production interception path rather than behind the experiment, so they need fixing whether or not this PR is split. CRF-35: InterceptionCount still passes raw r.Method, which eight reviewers flagged and two reproduced end to end, minting a permanent series per method token. CRF-37: Knuckle ran inserts against a real migrated schema and found client_session_id is VARCHAR(256) with no clamp on either side, so a client sending a 300-character session ID gets a 500 on every request until it changes, while the neighbouring error_message is truncated. CRF-48 and CRF-49: the PR taught two of three upstream paths to strip Coder headers and left interception-mode passthrough forwarding them, and PrepareClientHeaders strips Coder-* but not the actor headers the proxy path does strip.

Kurapika's CRF-36 is the one I would look at next after the P1s. Encoded dot segments survive rewriteRequest untouched: a request for /copilot/%2e%2e/%2e%2e/admin/keys reached the upstream as /tenant-a/%2e%2e/%2e%2e/admin/keys, because net/http.cleanPath runs on the escaped path so %2e%2e never becomes .. and the subtree pattern matches. On Anthropic and OpenAI the gateway injects the org's pooled key into that request, so the user picks the upstream path and Coder supplies the credential. Kurapika was explicit that the second half is unverified: whether the request lands outside the allow-listed path depends on the upstream normalizing %2e%2e, which edge proxies commonly do but which was not tested against a real provider. The gateway-side break is the half Coder controls and it is confirmed. What would settle the rest is one request to each configured provider with an encoded segment.

Ryosuke's structural read is worth more than any individual P3 and I am relaying it whole rather than as a comment: the record bool is read five times and each read marks a place where the two modes want different code. The unconditional buffer exists because one entry point serves both. The dead metricRoute on bridged handlers and the dead route on passthrough handlers exist because one struct carries both modes' fields. Round 3 extracted the leaves and left the sequencing duplicated in two files, which is exactly why bounded labels landed on one path and not the other. His suggestion is that the next extraction be the recording lifecycle as one component both bridged handlers call, not another helper in utils.

Verbatim, Hisoka opening: "Four probes thrown, four landed. The proxy handler is well-built where it's been looked at. Nobody looked at what it does to a request body, and nobody asked the circuit breaker what it counts."

Two process items. The PR description is still the single word "WIP" on a 45-file, +3866/-992 change, and Leorio and Mafu-san independently noted that the broadest production behavior change in it, widening PrepareClientHeaders to drop every Coder-* header, is described nowhere a reader would look: not the PR body, not the commit that introduced it, not the commit that touched it again. Second, Law's mandatory split from round 1 has now gone two rounds with no linked ticket and no round-3 response. The author-agent's position is that creating the PRs awaits author authorization; that is a reasonable thing for an agent to say and it is also why this needs a human. Three behavior changes on the path serving production today are still bundled with an experiment-gated feature, and four of this round's findings land inside them. Either authorize the split or explicitly accept the bundling; neither I nor the author-agent can accept it as permanent.


aibridge/bridge.go:271

P2 [CRF-35] The CRF-20 fix bounded the method label on the new path and left the same metric unbounded on the interception path that serves production today. (Mafuuu P2, Meruem P2, Melody P2, Ryosuke P2, Mafu-san P2, Robin P2, Zoro P2, Razor P2)

This PR introduced routing.MetricMethod and applied it at passthrough.go:65,106 and x/proxy/handler.go:145,293, but InterceptionCount on the bridged interception path still passes r.Method verbatim at bridge.go:271 (failed) and bridge.go:277 (completed). One unbounded writer poisons the series set for every reader of that metric, so bounding one of the two producers changes nothing. (Ryosuke)

Verified, not reasoned: a request with method FROBNICATE1234567890 to /anthropic/v1/messages returned 200 and produced interceptions_total{...,method="FROBNICATE1234567890",status="completed"} 1. Every distinct token an authenticated user sends creates a new series with initiator_id already in the label set, so one request per series is the cost of growing coderd's registry without bound. (Meruem)

In coderd the handler is mounted under chi, which rejects non-standard method tokens with 405. The standalone gateway mounts it on an http.ServeMux, which matches on path only, so an authenticated client sending FOO /anthropic/v1/messages with a valid body reaches the bridged handler. (Melody)

Eight reviewers found this independently and two reproduced it end to end through aibridge/internal/integrationtest. Melody's mount-point analysis narrows the blast radius to the standalone gateway rather than coderd, which is why this is P2 and not higher, but it is the same remote resource-exhaustion vector the panel rated P2 for the route label and it is not behind the experiment flag. Fix: routing.MetricMethod(r.Method) at both call sites.

🤖

coderd/aibridged/aibridged.go:388

P3 [CRF-52] Graceful shutdown kills the DRPC connection before it drains requests, so every interception still in flight is recorded as started and never ended. (Takumi)

Sequence in Shutdown: s.cancelFn(ErrShutdown), s.wg.Wait(), then s.inflight.Shutdown(ctx) for proxy mode or pool.Shutdown(ctx) for interception mode. s.wg tracks the connect goroutine, which is the only sender on s.clientCh and closes the DRPC connection on its way out. So by the time the drain begins, no sender remains and Server.Client has only <-s.Done() ready.

Verified: with lifecycleCtx canceled, s.Client(ctx) returns ErrShutdown in under a millisecond against a 5s call context.

Every handler that finishes during the drain therefore fails its end record with acquire client: ..., logged at warn and discarded. The interception rows for those requests keep a start and never get an end, on every coderd restart that has gateway traffic. Interception mode has the identical exposure through bridge.go:282.

The ordering fix is local: stop admission and drain first, cancel the lifecycle context after, so the drain still has a client. This interacts with CRF-51: fixing the ordering here also removes the 5s-per-request stall during a restart.

🤖

aibridge/circuitbreaker/circuitbreaker.go:73

P3 [CRF-56] After the CRF-27 extraction, NewProviderCircuitBreakers has zero production callers and exists as an exported hook for tests only. (Knov, Zoro)

Count, not intuition: production callers of NewProviderCircuitBreakersWithObservability are bridge.go:78 and x/proxy/router.go:88, two of two. Production callers of NewProviderCircuitBreakers are zero; the only call sites are the wrapper at line 66 and four in circuitbreaker_test.go.

The wide constructor takes an arbitrary onChange. Every real caller wants exactly one: log the transition and move the metrics. Keeping both exported means the next caller can register breakers with no observability at all, which is the state this refactor was raised to remove, and CI will not notice. This is the shape CRF-27 was about: one behavior, two entry points, drifting independently. (Knov)

The CRF-27 fix is right; this is the residue of it. Unexport the narrow constructor, keep the observable one as the only exported entry point, and rename it back to NewProviderCircuitBreakers since there is no longer an alternative. Gon separately noted the naming consequence: the constructor every production caller must use currently has the longer, mechanism-shaped name.

🤖

🤖 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 Outdated
},
}

execErr := h.breaker.Execute(route, "", w, func(rw http.ResponseWriter) error {

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.

P2 [CRF-34] The breaker closure always returns nil, so upstream transport failures never count as circuit-breaker failures. (Netero P2, Hisoka P2, both reproduced)

h.breaker.Execute(route, "", w, func(rw) error { ...; proxy.ServeHTTP(writer, r); return nil }) swallows every failure. The ErrorHandler writes 502, and circuitbreaker.DefaultIsFailure counts only 503 and 504, so a dial failure, TLS failure, or DNS failure is invisible to gobreaker. The interception path does the opposite: bridge.go:261-263 returns interceptor.ProcessRequest's error, which gobreaker counts. (Netero)

Bridged route, FailureThreshold: 1, base URL http://127.0.0.1:1, three requests: 502 502 502, no state change logged. Same provider, same threshold, upstream answering 503 instead: circuit breaker state change provider=openai endpoint=/v1/chat from=closed to=open, second request {"error":"circuit breaker is open"}. So the breaker works, and refuses the one case that matters. (Hisoka)

Two reviewers reproduced this separately with the same setup and the same result. Verified independently: the closure returns a bare nil, and DefaultIsFailure accepts only StatusServiceUnavailable and StatusGatewayTimeout.

This compounds with CRF-33. During a hard provider outage the circuit never opens, so every request is dispatched, pays the full dial or TLS timeout, and holds its fully buffered body while it waits. The scenario the breaker exists for becomes a coderd memory event instead of shed load.

Fix is one line: return state.transportErr from the closure. ErrorHandler has already written the 502 so the client response does not change, and terminalError already prefers execErr over transportErr, so the recorded error type does not change either.

🤖

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 coderd/aibridged/transport_test.go Resolved
Comment thread aibridge/bridge.go Resolved
Comment thread aibridge/x/proxy/handler_test.go Resolved
Comment thread aibridge/x/proxy/handler.go Resolved
@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

Coder Agents scope reconciliation on behalf of @pawbana:

The demonstrated passthrough buffering regression, cookie/path/upgrade boundaries, method-label cardinality, diagnostics, and shutdown/stream-abort issues are being addressed. Startup warnings and the PR description will explicitly disclose incomplete usage/spend accounting, unknown model facts, unsupported Bedrock, and missing proxy actor injection.

Several panel recommendations conflict with the agreed implementation contract and are not being silently converted into new features:

  • CRF-34: the author explicitly deferred breaker correctness until extractors land. Existing breaker behavior remains, including its limitations; the circuit-open test will still prove the wrapper is wired.
  • CRF-41 and CRF-63: AIGOV-615 explicitly excludes protocol facts and extractors; AIGOV-616 owns model/tool/usage/error-payload extraction. These are acknowledged, non-backfilled gaps, not claims of parity.
  • CRF-51: bounded finalization before handler completion is the approved lifecycle contract and preserves legacy wait behavior. A shared asynchronous recording lifecycle is a separate architectural change, not a safe automatic follow-up to CRF-28.
  • CRF-56: keep the pre-existing exported breaker constructor for source compatibility; the observable constructor delegates to it. Repository-local callers do not prove absence of external consumers, as already accepted for CRF-24.
  • CRF-57 and CRF-62: no new cross-mode lifecycle framework or passthrough metric schema in this ticket. The buffering defect and bounded-label omissions will be fixed directly.
  • CRF-67: keep the canonical lightweight actor-header definition shared by both paths, consistent with the approved package separation. A transitive dependency does not require adding a direct proxy-to-interceptor dependency.

These dispositions do not claim app approval. The mandatory split still needs a human decision; no additional PRs have been created. #29656 remains draft and unassigned.

Stream passthrough bodies, reject unsafe upstream paths and upgrades, sanitize credential cookies across forwarding modes, preserve recorder access during graceful shutdown, and disclose staged proxy limitations.

Generated by Coder Agents on behalf of @pawbana.
@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

Coder Agents follow-up on behalf of @pawbana: pushed 71af097 with the bounded panel fixes. Passthrough requests stream again; encoded traversal and unsupported upgrades fail closed; cookies and untrusted identity/proxy headers are sanitized across forwarding modes; method/route labels are bounded; overlong optional session IDs no longer block traffic; logging and exact error tests are improved. Graceful shutdown stops publication/admission and drains requests before closing DRPC; in-process stream aborts no longer masquerade as handler panics. Duplicate app threads for addressed findings are resolved.

CRF-32/38/39 are addressed through explicit startup warnings and the expanded PR description, not through unsupported claims of parity. No extractor/spend/model facts or breaker-correctness feature was added. The remaining scoped deferrals in the prior reconciliation comment still stand (CRF-34, 41, 51, 56, 57, 62, 63, 67). Existing public compatibility entry points remain.

Validation: full make pre-commit passed; aibridge/aibridged/chatd and consumer integration tests passed; affected-package race tests passed. One broader integration race run failed two breaker-transition assertions; the exact tests passed on rerun, so it is reported rather than claimed proven pre-existing.

Please review the current work against these explicit scope decisions. Additional PR creation remains awaiting human authorization. PR remains draft and unassigned.

@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

Coder Agents follow-up on behalf of @pawbana: pushed 71af097 with the bounded panel fixes. Passthrough requests stream again; encoded traversal and unsupported upgrades fail closed; cookies and untrusted identity/proxy headers are sanitized across forwarding modes; method/route labels are bounded; overlong optional session IDs no longer block traffic; logging and exact error tests are improved. Graceful shutdown stops publication/admission and drains requests before closing DRPC; in-process stream aborts no longer masquerade as handler panics. Duplicate app threads for addressed findings are resolved.

CRF-32/38/39 are addressed through explicit startup warnings and the expanded PR description, not through unsupported claims of parity. No extractor/spend/model facts or breaker-correctness feature was added. The remaining scoped deferrals in the prior reconciliation comment still stand (CRF-34, 41, 51, 56, 57, 62, 63, 67). Existing public compatibility entry points remain.

Validation: full make pre-commit passed; aibridge/aibridged/chatd and consumer integration tests passed; affected-package race tests passed. One broader integration race run failed two breaker-transition assertions; the exact tests passed on rerun, so it is reported rather than claimed proven pre-existing.

Please review the current work against these explicit scope decisions. Additional PR creation remains awaiting human authorization. PR remains draft and unassigned.

@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@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.

Round 4, against 71af09733f, and the first time the panel has seen this head.

The hardening commit is substantial and mostly right. Request-body capture moved inside if h.record with a MaxBytesError arm, so passthrough streams again and unknown-length oversize bodies get 413. ValidateForwardPath rejects encoded traversal on both forwarding paths, and Kurapika and Razor each probed it: %2e%2e%2fadmin, ..%2f../admin, and ./chat are rejected, a%2Fb survives, and double encoding is not a traversal at the provider. StripSensitiveRequestHeaders is one matcher covering Cookie, actor headers, coder-*, x-coder-*, forwarded, and x-forwarded-*, called from all three upstream paths. Shutdown drains before cancelFn. The breaker test now counts upstream calls and asserts the open-circuit body, so CRF-43's "green with the wiring deleted" property is gone. Netero measured 96.7% coverage on aibridge/x/proxy and Komugi ran the new shutdown and streaming tests at GOMAXPROCS=1 -race -count=30 green. Bisky, who is not generous about tests, called the drain tests honest.

Process note, because it changed what this round did. Law returned Split/Mandatory a second time, which under this review process skips the panel. deep-review post refused that payload: it requires panel reviewers once the panel has reviewed the PR. The tool is right and the process rule was wrong here, because 71af09733f claimed 34 panel findings closed and no panel member had checked any of them. So the panel ran. It found ten P2s, a P1 re-raise with nine reviewers behind it, and five independent reproductions of one defect.

The one that five reviewers reproduced separately

CRF-81: an enabled circuit breaker turns a user pressing Escape into a route-wide outage. requestProxy.ServeHTTP runs inside h.breaker.Execute, httputil.ReverseProxy panics http.ErrAbortHandler when the copy to the client fails, and gobreaker.Execute books any panic as a failure before re-panicking. Hisoka, Mafuuu, Takumi, Meruem, and Komugi each drove it to an open circuit and then watched a healthy client get 503. Set at P2 rather than P1 because the breaker is opt-in, which three of the five cited explicitly.

Read it together with CRF-34, which is posted again this round. The breaker cannot trip on dial, DNS, or TLS failure, and it does trip on client behaviour the upstream never saw. The signal is inverted in both directions, and neither half depends on extractors. Enabling the breaker today is worse than leaving it off. If breaker correctness stays deferred, the honest form is to not register it in proxy mode and not export CircuitBreakerTrips and CircuitBreakerState for it, so nothing claims a protection that does not exist.

CRF-32, re-raised at P1 by nine reviewers

The round-4 answer was a startup Warn plus a PR-description sentence. Nine reviewers reached P1 independently, and Kite withdrew its own round-3 P2 to do so: "a missing metric is P2, a live enforcement check that answers incorrectly is P1."

What is new, and why this is not a restatement. Every surface an operator or user actually reads still presents proxy traffic as accounted, and none of them is in this 48-file diff. I read each one.

  • docs/ai-coder/ai-gateway/cost-controls.md:11: "Enforcement stops a user's requests routed via AI Gateway once their spend reaches their budget." Unqualified.
  • docs/ai-coder/agents/platform-controls/spend-management.md:9: budgets "cap all AI Gateway usage".
  • docs/ai-coder/ai-gateway/monitoring.md:9: "AI Gateway records the last user prompt, token usage, model reasoning, and every tool invocation for each intercepted request."
  • The experiment description, which is the text at the point of decision, is codersdk/deployment.go:5244: "Uses stateless reverse proxy routing when MCP injection is not configured." Nothing about accounting. grep -rn "ai-gateway-reverse-proxy" docs/ matches only the generated schema enum.
  • aibridgedserver.go:293-296 still records the billable AI seat event on every RecordInterception. The charge is kept and the cap is dropped.
  • The sessions page renders 0 input and 0 output tokens for proxy sessions, which is the same rendering a genuinely free request gets.
  • IsBudgetExceeded evaluates the current budget period only, so after one rollover a proxy-mode deployment's period total can only be 0 and the limit is unreachable by construction, while every request still pays a DRPC round trip to ask.

A startup Warn in the aibridged process log reaches none of that. Two fixes are available and neither needs extractors: put the accounting gap in the experiment description and in cost-controls.md in the same release, or refuse proxy mode when a spend limit is configured. Pariston noted the request path already holds what it needs: IsBudgetExceeded returns SpendLimitMicros as an optional, nil exactly when no budget exists, and coderd/aibridged/http.go:189 already reads it.

Four reviewers converged on the same shape without coordinating: CRF-32, CRF-38, and CRF-39 are each "proxy mode silently voids something the operator configured", and the remedy chosen each time was a log line. Two of the three have a cheap honest fix in the same file as the problem.

Split request, Law's second mandatory verdict

Effective diff +5051 -1073, 48 files, 1334 production, 3717 test. Law re-ran because additions grew 3370 to 5051 and found the growth is not feature code. Two new independently-mergeable production behavior changes arrived since round 1: header sanitization plus traversal rejection plus metric relabeling on the interception passthrough path, and a shutdown and admission rework in coderd/aibridged. That moved the recommended cut from horizontal to mostly vertical.

Six PRs, H1 then V1 to V6:

  1. H1, mechanical extractions. clientmeta, interceptionerror, the breaker observability constructor. ~360 production / 700 test. It delivers no user-visible behavior by construction, which is why it wants its own review: the GuessSessionID restructure and the new Categorize status parameter are where an extraction quietly became a design decision, and CRF-86 is what that second one cost.
  2. V1, credentials stop leaking upstream. The utils header helpers plus both consumers. ~60 / 130.
  3. V2, unsafe upstream paths are rejected. ~30 / 30.
  4. V3, metric labels are bounded. ~35 / 40.
  5. V4, failover retries replay the original body. ~37 / 255.
  6. V5, in-process calls cancel and terminate correctly. transport.go plus the aibridged.go shutdown rework. ~160 / 560.
  7. V6, the gateway forwards and records proxy traffic. The feature, atomic, last. 536 / ~1850.

V2 and V3 may fold into V1 if four PRs is preferred. They must not fold into V6.

Independence is measured: git checkout <base> -- <file> then build and go test ./aibridge/x/proxy/... left the tree green for passthrough.go, intercept/client_headers.go, keypool/failover.go, and aibridged/transport.go. The aibridged.go shutdown separation is read at hunk level, not executed, and Law labelled it so.

This round is the argument for the split, not just a repeat of it. V1 and V5 are where the panel found the most, and they are the two smallest slices. V1's territory produced CRF-91 (trailers bypass the header strip that was the whole point of the CRF-40 fix) and CRF-92 (SetXForwarded deletes X-Forwarded-For outright on the coderd-hosted path). V5's territory produced CRF-84, CRF-95, CRF-96, CRF-97, and CRF-98. Both slices were previously described as having roughly one dedicated subtest of review surface each. That is what a bundle costs: 73.6% test density lowers how hard the diff is to read and does nothing about how many independent merge decisions hide behind one approval.

The mandatory verdict has now been open for four rounds, answered each round with "awaiting human authorization" and no ticket, so it is unresolved rather than deferred. Authorize the split, or explicitly accept a single approval covering six production behavior changes plus an experiment-gated feature. Mafu-san's observation is the reason this keeps coming back: additions went 3370, 3866, 5051, and the growth is review response. The answer to "too large to review as one unit" has three times been more production code in the same unit.

Contested findings, resolved this round

Four close on code rather than on deference.

  • CRF-56 closes because the claim is now false: NewProviderCircuitBreakersWithObservability ends return NewProviderCircuitBreakers(...) at circuitbreaker.go:66.
  • CRF-57 closes on reachability: NewRouter is the only constructor and rejects record=true, recorder=nil at startup.
  • CRF-62 closes on parity: interception passthrough increments its counter with no outcome label at passthrough.go:69,113.
  • CRF-67 closes on impossibility of divergence: one implementation behind a one-line delegation.
  • CRF-38 closes on its own basis. Round 3 rated it on diagnosability and the per-provider Warn addresses that. Chopper, Pariston, and Meruem each argued for closing it. The client-facing half is now CRF-90 rather than a reopening, because five reviewers found the fix idiom already sitting six lines away in the same file.
  • CRF-51 holds, on evidence rather than on the author's framing. Meruem, Knuckle, Kite, Takumi, Knov, and Luffy each traced it: aibridge/bridge.go:284-291 already blocks the interception request goroutine on asyncRecorder.Wait() with the same 5s budget, so proxy mode is parity, not a regression. Knov also ruled out the memory scenario: Server.ServeHTTP calls s.Client(ctx) before IsAuthorized, so during a DRPC outage new requests park at the entry gate before buffering anything. Takumi's residue is CRF-84, which is about the shutdown budget rather than the contract.

Contested findings still open

CRF-34 is posted again with the corrected mechanism. CRF-41 is re-raised at P2 with evidence the AIGOV-616 scope defense does not cover, chiefly that cost.go:128 keys the price lookup on intc.Model, so proxy rows resolve to no price and store cost_micros NULL, and no query in the tree updates model or cost_micros. Extraction fixes rows written after it ships; it cannot repair these. CRF-39 is re-raised at P2 because the flag description and two generated docs pages still promise headers the mode does not send.

CRF-63 holds, narrowed. Kite established the loss is confined to upstream HTTP error responses, since transport, pool, cancellation, and breaker errors all persist their real message, and Nami established no UI renders the field. Chopper and Knuckle both argue the upstream body is available at ModifyResponse with no extraction needed, and Knuckle found the sharper consequence, now CRF-86: for Anthropic's 529, http.StatusText is empty and the row is written with no message at all.

AIGOV-616

Three dispositions now rest on it: CRF-9 was closed in round 2 because AIGOV-616 was named as the consumer, and CRF-41 and CRF-63 are assigned to it. None of the three can be checked, because the PR description names AIGOV-615, AIGOV-616, and AIGOV-674 as bare IDs with no links. A reviewer cannot confirm the ticket exists or that it covers what is claimed, and this process treats an unverifiable follow-up as a drop rather than a deferral. Please link all three.

Findings not anchorable to a diff line

[CRF-102] P3, docs/ai-coder/ai-gateway/monitoring.md. No docs/ file changed. Four things in that table are now wrong or incomplete, and it is the only place a proxy-mode operator would look. interceptions_total, _inflight, and _duration_seconds are documented with a model label that proxy mode always emits empty. circuit_breaker_state and _trips_total have exactly one writer, the onChange callback, so in proxy mode no child series is ever created: an alert on == 1 matches nothing and an alert on absent() fires for every provider (Razor). MetricMethod introduces a new OTHER value in a table that spells out every other bounded label's value set. The passthrough route label is now the registered pattern rather than the request path, a live label-value change on the interception path. Two cardinality notes in aibridge/metrics/metrics.go are also stale: line 79 says "3 methods" against nine plus OTHER, and line 55 says "5 models" against an unbounded client string (CRF-83). docs/admin/integrations/prometheus.md:135 lists the same metric.

[CRF-114] P3, the PR description. Three things. The Validation paragraph ends "CI was green on the previous head and is running for the latest fixes", which is the last thing a reviewer reads before approving, while test-go-pg (windows-2022) is red at this head. Because this repository squash-merges, that sentence becomes the permanent commit body. Replace it with the current state: name the failing job, say the log needs admin rights, say what was checked instead. Second, the suite enumeration is a test plan, which .claude/docs/PR_STYLE_GUIDE.md:142 lists under "Never Include". Third, the three AIGOV IDs are unlinked, per the section above.

CI, disclosed rather than cleared

test-go-pg (windows-2022) (job 106373880225) failed at step 21, "Test with PostgreSQL Database (Windows)". I could not read the log: the job-log endpoint returns 403 Must have admin rights to Repository and gh returns 401 Bad credentials in every worktree, so the failing test name is unavailable to this review.

The standing hypothesis got weaker rather than stronger. Netero offered ProxyModeWithoutMCP flipping 404 to 200 as the most plausible slow-runner candidate. Kite checked it and weakened it: /readyz gates on s.daemon.Ready() && s.providersLoaded.Load(), so the test cannot race the provider snapshot, and requireAIGatewaySessions polls with require.Eventuallyf rather than asserting once. Mafu-san could not reproduce the author's two breaker-transition failures under -race -count=3, and noted that circuit_breaker_internal_test.go drives every transition with a real-clock time.Sleep(Timeout + 10ms) at four sites, untouched by this PR but the most mechanically plausible slow-runner mechanism. What was ruled out across reviewers: no build tag, no runtime.GOOS branch, no exec.Command, no OS-dependent path handling, no new test matching on a dial-error string, go vet clean, both changed-package suites green on linux including -race.

Nobody has a confirmed cause. Please post the failing test name. Law's related point is a decomposition argument rather than a CI one: six of the eight concerns touch shutdown, cancellation, or body lifecycle, so landing V5 alone would attribute this in one CI run, where the bundled diff attributes nothing.

Round 4 finding inventory

Churn guard: PROCEED. 34 of 42 round-3 findings addressed in 71af09733f (29 files, +1341 -237); 8 contested with no code change, none silent.

Law: Split, Mandatory, second verdict. Additions 3866 to 5051, growth 1185 above the 500 threshold.

Panel of 25 plus Netero: Bisky, Chopper, Ging-Go, Gon, Hisoka, Killua, Kite, Knov, Knuckle, Komugi, Kurapika, Leorio, Mafu-san, Mafuuu, Melody, Meruem, Pariston, Pen Botter, Razor, Robin, Ryosuke, Takumi, Zoro, plus wildcards Luffy and Nami.

New: CRF-74 to CRF-80 (Netero) and CRF-81 to CRF-131 (panel). 10 P2, 33 P3, 3 P4, 12 Nit.
Re-raised: CRF-32 (P1), CRF-34 (P2), CRF-39 (P2), CRF-41 (P2).
Closed this round: CRF-38, CRF-56, CRF-57, CRF-62, CRF-67.
Holding as defended: CRF-51, CRF-63 (narrowed).
Still closed from earlier rounds, not re-raised: CRF-9, CRF-17, CRF-24.

Severity notes where reviewers disagreed. CRF-81 P2 against two P1s, on the opt-in breaker default. CRF-84 P2, taking Ryosuke's higher rating over two P3s because interception mode inherits it. CRF-86 P2, taking Knuckle over Melody's P3. CRF-90 P2, three P2s against two P3s. CRF-103 P3 against Gon's P2, because the code is correct and only the comment is wrong.

Wildcard value worth recording: Nami's triggers did not match a Go-only diff, and Nami produced CRF-88, which no trigger-matched reviewer found.

Reviewed against c5c7f9d8b2727b1430a55716728b023b389ede34..71af09733ff9909d1f8f7e27ae990f5c642e7109.

Generated by Coder Agents.


docs/ai-coder/ai-gateway/monitoring.md:35

P3 [CRF-102] This PR changes label values and label domains on metrics that serve production today, and no docs/ file changed. (Razor P3, Leorio P3, Zoro Nit, Mafuuu Nit)

Four reviewers found four separate defects in this one table, which is the only place a proxy-mode operator would look. grep -rn "ai-gateway-reverse-proxy" docs/ matches only the generated schema enum.

coder_ai_gateway_interceptions_total, _inflight, and _duration_seconds are documented with a model label. In proxy mode every one is emitted with unknownModel = "", so any dashboard grouping by model silently collapses proxy traffic into one blank series. (Razor)

circuit_breaker_trips_total is documented as "Times a circuit breaker transitioned to the open state" and circuit_breaker_state as the current state. Those two families have exactly one writer, the onChange callback, so with no state change WithLabelValues is never called and no child series is created at all for a proxy-mode provider. An alert written as == 1 matches nothing; an alert written on absent(...) fires for every proxy provider from the moment the experiment is enabled. Either way the operator learns nothing, which is worse than a gauge pinned at 0. (Razor)

routing.MetricMethod now collapses any nonstandard method to the literal OTHER on interceptions_total and passthrough_total, and the passthrough route label became the registered pattern instead of r.URL.Path. Interception mode serves real traffic, so both are live label-value changes, not experiment-gated ones. This is not a doc that ignores value domains: it spells out that status is enabled/disabled/error, type is mitm/tunneled, state is valid/temporary/permanent, and it carries a full > [!IMPORTANT] block with migration guidance for the last metric rename. The one new sentinel this PR introduces gets nothing. (Leorio, Zoro)

Two cardinality notes in the code are now false in opposite directions, which is worth fixing in the same pass because they are what a future author will trust. aibridge/metrics/metrics.go:79-80 reads "N provider names, 10 routes, 3 methods = up to 30N" against nine methods plus OTHER, so the real bound is about 100N (Mafuuu). Line 55 reads "5 models" against an unbounded client-supplied string, which is CRF-83.

Fix is documentation plus two comments, no behavior change. State in the table which labels and series proxy mode cannot populate, add one sentence that method is the HTTP method or OTHER outside the standard set, say that passthrough route is the registered pattern rather than the request path, and correct the two cardinality notes. docs/admin/integrations/prometheus.md:135 lists the same metric and needs the same treatment.

🤖

🤖 This review was automatically generated with Coder Agents.

Comment thread aibridge/x/proxy/handler.go Resolved
Comment thread aibridge/x/proxy/handler.go Outdated
ErrorLog: slog.Stdlib(ctx, log, slog.LevelWarn),
}

execErr := h.breaker.Execute(route, "", w, func(rw http.ResponseWriter) error {

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.

P2 [CRF-34, re-raised] The circuit breaker cannot trip on transport failures, so CircuitBreakerTrips and CircuitBreakerState stay silent through a dead upstream. (Netero rounds 3 and 4; mechanism confirmed independently by Pariston, Takumi, Komugi, and the orchestrator)

The author's response is that breaker correctness is deferred until extractors land, which is a scheduling statement rather than a counter-argument. The round-3 mechanism was also imprecise, so here is the verified one.

ProviderCircuitBreakers.Execute derives failure from the captured status code, not from the handler error: circuitbreaker.go:190-196 returns an error to gobreaker only when p.isFailure(sw.statusCode) holds, and DefaultIsFailure (:28-37) accepts only 503 and 504. The proxy ErrorHandler writes 502 (handler.go:219). The only configured override, anthropicIsFailure, adds 529 and delegates otherwise. (Netero)

Consequence: during a dial, DNS, or TLS failure the breaker records no failure and never opens, so every request keeps dialing the dead upstream, bounded only by the client context because utils.NewStreamingTransport sets no dial timeout either (CRF-77). Razor sharpened the observability half: CircuitBreakerState and CircuitBreakerTrips have exactly one writer, the onChange callback, so no state change means no child series is ever created. The gauges are not pinned at zero, they are absent, so an alert on == 1 matches nothing and an alert on absent() fires for every proxy provider.

Read with CRF-81, which is the same call site and the opposite defect. Together the failure signal is inverted: the breaker ignores the outages it exists for and trips on client hangups. Neither half depends on extractors, so "deferred until extractors land" does not describe a dependency here. The minimum fix is returning an error from the Execute closure when state.transportErr != nil. If the deferral stands, do not register the breaker in proxy mode and do not export its metrics, so nothing claims a protection that does not exist.

🤖

Comment thread aibridge/x/proxy/handler.go Resolved
Metadata: actor.Metadata,
Provider: h.provider.Type(),
ProviderName: h.provider.Name(),
Model: unknownModel,

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.

P2 [CRF-41, re-raised] The empty model is the price key, a public API value, and an admin filter dimension, and nothing in the tree can ever rewrite it. (Knuckle P2, Pen Botter P2, Luffy P2, Meruem P2, Nami P3, Kite, Pariston)

Contested with "AIGOV-616 owns extraction". That is a true statement about scope and it does not reach the consequence. Round 3 said "indexed NOT NULL grouping column, cannot be backfilled". Here is what that means, read out of the schema and query files.

Price lookup. coderd/aibridgedserver/cost.go:128 keys GetAIModelPriceByProviderModel on intc.Model, read from the interception row, at token-usage write time, and ai_model_prices is unique on (provider, model, source). A row with model = '' resolves to no price, takes the sql.ErrNoRows branch, and stores cost_micros NULL while incrementing UnpricedTokenUsageRecords with an empty model label. (Knuckle)

No recompute path. No statement in coderd/database/queries/ updates aibridge_interceptions.model or aibridge_token_usages.cost_micros; cost is snapshotted at insert. "Cannot be backfilled" is structural, not stylistic: every proxy interception recorded while this experiment is enabled is permanently unpriceable, and GetUnpricedTokenUsage will report them forever under a name an admin cannot price without inserting a price row keyed on the empty string. Extraction only fixes rows written after it ships. (Knuckle)

Public API and admin UI. ListAIBridgeModels is GROUP BY model ORDER BY model ASC with no non-empty filter, served by GET /api/v2/ai-gateway/models, so one proxy interception makes "" the first returned model. ModelFilter.tsx maps every returned value to {label: model, value: model} and SelectFilter renders it with no empty guard, so the dropdown gains a top row with a question-mark icon and no text. Meanwhile the sessions filter is WHEN @model::text != '' THEN ai.model = @model, so the empty value means "all models" and no value of the documented model filter ever returns a proxy-mode session. (Pen Botter, Nami, Luffy)

ListAIBridgeSessions aggregates ARRAY_AGG(DISTINCT ai.model), so a mixed session reports {"", "claude-sonnet-4"}; telemetry grouping is DISTINCT ON (provider, model, client), so a blank model dimension leaves the deployment; the seat audit reason is built as "provider=" + Provider + ", model=" + Model, landing as provider=openai, model=; and idx_aibridge_interceptions_model pays write cost on one constant key. (Knuckle, Luffy)

Two fixes, neither waiting on AIGOV-616. The model is one gjson.GetBytes(payload, "model") away: the bridged payload is already buffered at handler.go:110 and the handler already runs gjson over those same bytes through clientmeta.GuessSessionIDFromPayload (Meruem, Knuckle, Luffy, Kite each reached this independently). If parsing is off the table, Luffy found the repository already chose the other sentinel for the same problem in the same subsystem: coderd/aibridgedserver/cost.go:42 is const unknownProviderType = "unknown", documented as unknown in monitoring.md:67. Make this one "unknown" so the rows are distinguishable, filterable, and priceable, and open a real backfill ticket for the sentinel rows. Either beats shipping the empty string.

The panel is not asking to close the extraction gap here. It is asking that the defense be read as what it is: accept permanently unpriceable rows and a broken filter dimension, deliberately, rather than call it deferred.

🤖

Comment thread aibridge/intercept/client_headers.go Resolved
Comment thread aibridge/x/proxy/handler_test.go Resolved
Comment thread aibridge/x/proxy/handler.go Outdated
ErrorLog: slog.Stdlib(ctx, log, slog.LevelWarn),
}

execErr := h.breaker.Execute(route, "", w, func(rw http.ResponseWriter) error {

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.

Nit [CRF-128] Three naming slips in this file, grouped because they are the same edit. (Gon, Leorio)

A bare "" for the model at this call. unknownModel exists at handler.go:39 with a comment explaining why the model is empty in proxy mode, and lines 137, 165, 305, 307, and 317 all use it. This one site spells the same concept as an anonymous empty string, so the reader cannot tell whether it means "unknown model" or "no model dimension", and a later real model value has two places to change. (Gon, Leorio)

state.status >= 400 at handler.go:312 is the only bare numeric HTTP status in the new code. Everything else in the file uses http.Status*, and interceptionerror.Categorize writes the same comparison as status < http.StatusBadRequest. (Gon)

unknownModel names a sentinel that does not exist; the value is the empty string. ClientUnknown = "Unknown" in the same subsystem sets the reader's expectation that an "unknown" constant holds a marker, so a reader seeing Model: unknownModel will assume the record and the metric label carry one. Either name it emptyModel or give it a real value. (Gon)

The third one is where this touches something substantive: whether the persisted value should be empty is CRF-41, and Luffy found the repository already answered the same question the other way in the same subsystem with const unknownProviderType = "unknown". If CRF-41 is fixed by adopting a sentinel, this naming resolves itself; if it is not, the name should stop implying one.

🤖

Comment thread aibridge/utils/http.go Resolved
continue
}
if prov.Type() == config.ProviderBedrock {
// Bedrock signing is implemented only by interception mode. Keep the

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.

Nit [CRF-130] "Proxy" already names a different shipped component, and this mode reuses the word in package names, comments, and log text. (Razor)

enterprise/aibridgeproxyd is the AI Gateway Proxy: a CONNECT/MITM proxy with its own documented metric namespace coder_ai_gateway_proxy_*, including coder_ai_gateway_proxy_mitm_requests_total and a documented proxy_excluded status. This PR's mode is a reverse-proxy forwarder inside aibridge/x/proxy, and its comments and dispositions say "proxy mode" throughout. (Razor)

The user-facing strings mostly escape the collision, since the experiment is ai-gateway-reverse-proxy and the startup line says "reverse proxy routing", which is why this is a nit. The collision is internal: a reader who greps "proxy" in this codebase now gets two unrelated subsystems, and this review has had to write "proxy mode" and "AI Gateway Proxy" in the same paragraph to keep them apart.

Worth noting the two are not merely similarly named, they meet: Pen Botter traced that AI Gateway Proxy forwards to aibridged via Options.GatewayURL, so traffic from the clients its docs list lands on this handler. That makes the name overlap slightly more than cosmetic for anyone debugging across both. A name like x/forward with "forwarding mode" in the prose would keep "proxy" meaning one thing.

🤖

Comment thread aibridge/x/proxy/handler.go Resolved
@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

Coder Agents clarification on behalf of @pawbana: CI failure is confirmed from accessible job logs, not guessed. All platform/database test jobs at 71af097 fail cli TestNewAIBridgeDaemonBackend/Interception, cli/aibridged_backend_internal_test.go:48: expected concrete *aibridge.RequestBridge, actual admission-wrapped handler. The test is corrected locally to assert mode selection; normal/race targeted runs and full make pre-commit pass. The next push includes it.

The PR description now links AIGOV-615, AIGOV-616, and AIGOV-674 directly and states the current CI failure. Operator-facing experiment, actor-header, cost-control, and metric documentation is being updated. CRF-82 embedded Recover swallowing ErrAbortHandler and CRF-91 trailer sanitization are being fixed.

CRF-81/34/93 remain subject to the author’s explicit breaker-correctness deferral. Re-enabling that scope or splitting the PR requires a human decision, not an app instruction. No claim of approval is made.

Propagate embedded HTTP aborts, sanitize trailers, preserve provider status classifications, clarify bounded shutdown semantics, and update operator-facing experiment and actor-header documentation.

Generated by Coder Agents on behalf of @pawbana.
@github-actions

Copy link
Copy Markdown
Contributor

Docs preview

Check off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here.

@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

Generated by Coder Agents on behalf of @pawbana: 32c1808 fixes embedded HTTP abort propagation, drops sensitive trailers, restores provider-specific HTTP status classification with nonempty fallback messages, improves failure diagnostics, and tightens shutdown/admission behavior. Operator documentation, experiment/config descriptions, and generated outputs now explicitly disclose missing usage/spend accounting and actor-header support; the embedded backend CI assertion is corrected. Full local pre-commit and the targeted normal/race checks passed. CI for this head is running; the two broad-run breaker-transition failures previously reported passed on focused rerun, not claimed to be proven pre-existing.

I am reconciling fixed threads against this head. Breaker correctness and extractor/model/provider-body/accounting implementation remain explicitly deferred by the author; the disclosure fixes do not claim those capabilities. The requested multi-PR split still lacks author authorization. Please distinguish remaining concrete in-scope defects from those scope/authorization blockers. This PR remains draft, unassigned, and without human review requests.

@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

Generated by Coder Agents on behalf of @pawbana: pushed 914fbba with the narrow CRF-92 trusted bare-IP fix and CRF-75 real HTTP truncated-stream regression. Full make pre-commit and race tests for both affected packages pass. CI for 32c1808 completed with 22 passing and 9 skipped checks; the new head is being checked. Addressed threads are resolved; deferred and partially addressed design requests remain open. No additional PRs or breaker/extractor changes were made.

@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

/coder-agents-review

@pawbana

pawbana commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator Author

Generated by Coder Agents on behalf of @pawbana, remaining review disposition:

  • CRF-34/81/93 and breaker-dependent CRF-105: explicitly deferred breaker correctness, not claimed fixed.
  • CRF-41/63/88: protocol/model/provider-body/session facts need AIGOV-616 or follow-up product work. Accounting and historical-data limitations are now public, not merely a startup log (CRF-32/39/102/114/115 disclosure work).
  • CRF-51/84/89/96/98: retain synchronous bounded finalization, caller-bounded shutdown, and fixed startup mode. Shutdown after its deadline is best-effort, not a guarantee that records persisted or a stuck dialer joined. Acquisition is not serving admission; an unserved acquired handler may be refused after shutdown. Existing tests pin these contracts.
  • CRF-85: hint correctness and tests are fixed; proxy metadata describes the BYOK credential actually forwarded, rather than importing SDK credential substitution policy.
  • CRF-90: Bedrock remains unregistered per the approved plan, with operator disclosure. CRF-94/83/101/121 ask for additional metric/cardinality/allocation/metadata policies, outside this bounded feature.
  • CRF-104: exact EOF handling follows the io.Reader contract; a wrapped EOF is not a clean EOF and must not hide stream truncation.
  • Remaining facade, signature, naming, and package-structure recommendations are not prerequisites for the approved behavior. Partial cleanups are not being called fully fixed.

The app-requested PR split still requires author authorization. No extra PRs, reviewer assignments, or broader redesigns have been created. Please assess the final head against these explicit boundaries; deferred findings remain open.

@pawbana

pawbana commented Sep 22, 2026

Copy link
Copy Markdown
Collaborator Author

Generated by Coder Agents on behalf of @pawbana: split this reference implementation into ten draft, unassigned PRs, each with one commit and a dedicated GPT 5.6 Sol concision review. This original PR remains unchanged as the reference; it has not been closed or marked ready.

  1. chore: move to be shared gateway types and helpers #29718: mechanical helper moves
  2. refactor(aibridge): accept a pre-read payload in GuessSessionID #29719: new and modified helpers
  3. refactor(aibridge): share client request header stripping #29720: forwarding security integration
  4. fix(aibridge/keypool): reuse request bodies during key failover #29721: key-failover body replay
  5. fix: bound AI Gateway method and route metric labels #29722: bounded metric labels
  6. fix: propagate cancellation and aborts in the in-memory transport #29723: in-process cancellation and HTTP aborts
  7. fix: drain proxy requests before closing DRPC #29724: admission and graceful shutdown
  8. feat: wire AI Gateway proxy routing and recorder dependencies #29725: dormant forwarding engine
  9. feat: record AI Gateway interception start and end #29726: complete dormant recorder lifecycle
  10. docs: disclose AI Gateway reverse proxy accounting limits #29727: activation, trusted identity, and disclosures

The PRs form a numbered publication stack with incremental diffs. No new extractor or breaker-correctness scope was added. Local checks passed for each slice; CI is running for the published stack.

@github-actions github-actions Bot added the stale This issue is like stale bread. label Oct 23, 2026
@github-actions github-actions Bot closed this Oct 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale This issue is like stale bread.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant