Skip to content

feat: record AI Gateway interception start and end - #29726

Merged
pawbana merged 3 commits into
mainfrom
pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-9
Nov 18, 2026
Merged

pawbana merged 3 commits into
mainfrom
pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-9

Conversation

@pawbana

@pawbana pawbana commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Persist interception starts before forwarding. If start recording fails, return 500 without contacting upstream.

Record the final outcome asynchronously with a five-second timeout. The end record carries the categorized error (for upstream error statuses, the response body truncated to 1024 bytes, or the status text when empty) and the last pooled key used. Response completion does not wait for recording. Graceful shutdown waits for inflight recordings.

Model, session ID, and token accounting remain unset.

Generated by Coder Agents on behalf of @pawbana.

@linear-code

linear-code Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

AIGOV-615

AIGOV-790

@pawbana pawbana removed their assignment Sep 22, 2026
@pawbana
pawbana added this pull request to stack #29736 September 22, 2026 16:14
@pawbana
pawbana removed this pull request from stack #29736 September 24, 2026 17:36
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-8 branch 9 times, most recently from b62dd7e to 09ec334 Compare September 29, 2026 22:46
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-9 branch from f421249 to 8406598 Compare September 30, 2026 08:53
@pawbana pawbana changed the title feat(aibridge/x/proxy): record the complete request lifecycle feat: AI Gateway proxy - common layers Sep 30, 2026
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-9 branch from 8406598 to 16539ac Compare September 30, 2026 09:14
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-8 branch from 09ec334 to 5341ac5 Compare September 30, 2026 09:18
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-9 branch 5 times, most recently from fd534b6 to a5d87a9 Compare October 1, 2026 07:07
@pawbana pawbana changed the title feat: AI Gateway proxy - common layers feat: connect AI Gateway forwarding with lifecycle recording Oct 1, 2026
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from f46556c to caef5d9 Compare November 2, 2026 15:26
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-9 branch from 8b1502c to aba43ac Compare November 2, 2026 15:26
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from caef5d9 to 670f139 Compare November 2, 2026 15:58
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-9 branch 2 times, most recently from 104c3bb to c80231e Compare November 3, 2026 10:07
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from 670f139 to 2a1d514 Compare November 3, 2026 10:07
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-9 branch from c80231e to 998377f Compare November 3, 2026 10:32
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from 2a1d514 to 8329a86 Compare November 3, 2026 10:32
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-9 branch from 998377f to fdb903b Compare November 3, 2026 10:47
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch 2 times, most recently from 5a267cc to d1599a5 Compare November 3, 2026 11:19
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-9 branch from fdb903b to c6f166c Compare November 3, 2026 11:19
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from d1599a5 to 77bcf5f Compare November 3, 2026 13:42
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-9 branch 2 times, most recently from 1e82141 to f646a8e Compare November 3, 2026 14:11
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch 2 times, most recently from ac92712 to f2c474f Compare November 3, 2026 14:47
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-9 branch 2 times, most recently from e7a7633 to e2dae58 Compare November 3, 2026 15:13
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch 2 times, most recently from 77da38a to 5937625 Compare November 3, 2026 15:56
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-9 branch from e2dae58 to 00195a8 Compare November 3, 2026 15:56
@pawbana
pawbana force-pushed the pawel/issue-29726-forwarding branch from 5937625 to f12f7bd Compare November 4, 2026 13:04
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-9 branch 2 times, most recently from cabb446 to 3d1ec95 Compare November 4, 2026 14:01

@ssncferreira ssncferreira left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Overall LGTM 👍 not sure if some comments will be addressed on a follow-up, so approving to non-block

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
Record the interception start synchronously before the circuit breaker and
return 500 without forwarding when it fails. After the breaker, record the
end with the categorized error, the upstream error status, and the last
pooled key used, then wait for the record before releasing the request.

Model, session ID, and token accounting remain unset.

Generated by Coder Agents.
added sentinel error for aborted forwarding
changed error parsing
removed theoretical hang, .Wait call in endRecord.
added test cases + error message check.

@ssncferreira ssncferreira left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM 🌟 thanks for addressing the comments

err := fr.err

// Prioritize context cancellation over the errForwardingAborted sentinel.
if canceled := context.Cause(ctx); canceled != nil && errors.Is(err, errForwardingAborted) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Are we testing this? Would it be possible to add a test where the client cancels mid-stream and assert ErrorMessage is context canceled?


// TruncateMessage caps msg at the size persisted on the interception record,
// dropping any multi-byte character split by the cut.
func TruncateMessage(msg string) string {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: Should we also add a test for TruncateMessage?

This branch had an error being deployed

1 failed and 1 inactive deployments
main — d64706c0 Deployed Nov 18, 2026 by pawbana via cla #259572
docs-preview — d64706c0 Deployed Nov 18, 2026 by pawbana via cleanup #208
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants