Skip to content

refactor(aibridge): accept a pre-read payload in GuessSessionID - #29719

Merged
pawbana merged 2 commits into
mainfrom
pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-2
Sep 28, 2026
Merged

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

Conversation

@pawbana

@pawbana pawbana commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

Adds client.GuessSessionIDFromPayload(client, r, payload) for reverse-proxy callers that already buffered the body. It preserves header precedence and never reads, closes, or replaces r.Body, including with nil or empty payloads.

GuessSessionID(client, r) shares the parsing logic, retains read-and-restore behavior when needed, and handles nil bodies safely. Tests cover both paths and body preservation.

Generated by Coder Agents on behalf of @pawbana.

@linear-code

linear-code Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

AIGOV-615

AIGOV-676

@pawbana pawbana removed their assignment Sep 22, 2026
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-1 branch 5 times, most recently from bf128bd to 4d80be1 Compare September 22, 2026 15:53
@pawbana
pawbana added this pull request to stack #29736 September 22, 2026 16:14
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-2 branch 19 times, most recently from e718154 to 7ca2815 Compare September 23, 2026 14:34
@pawbana pawbana changed the title refactor(aibridge): prepare shared helpers for proxy forwarding refactor(aibridge): accept a pre-read payload in GuessSessionID Sep 23, 2026
@pawbana
pawbana marked this pull request as ready for review September 23, 2026 14:40
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-1 branch from d102580 to c48c2bb Compare September 24, 2026 11:53
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-2 branch from 7ca2815 to fdd1bd8 Compare September 24, 2026 11:53
@pawbana
pawbana removed this pull request from stack #29736 September 24, 2026 17:36

@ssncferreira ssncferreira left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM, just a note: IIUC the idea is that we read the body once and then pass it to the functions that need it, right? This is a nice idea 👍 but we need to make sure that the existing proxy logic does not read the body and drains it which I think we are doing in CreateInterceptor. If that ever runs before the session lookup, there's nothing left to read and we silently get no session ID.

Comment thread aibridge/client/session.go Outdated
}
_ = r.Body.Close()
var payload []byte
if len(body) > 0 {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I might be wrong here, but I think that if the function is called as GuessSessionID(client, r, nil) or a variable that is nil, len(body) will be 1.
We can have just a new function GuessSessionIDFromPayload

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.

@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-1 branch 4 times, most recently from 8e5c7c5 to 18de0b0 Compare September 28, 2026 09:37
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-2 branch from fdd1bd8 to 037b358 Compare September 28, 2026 09:47
Base automatically changed from pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-1 to main September 28, 2026 09:49
@pawbana
pawbana force-pushed the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-2 branch from 5f648df to 5810943 Compare September 28, 2026 10:39
@pawbana
pawbana enabled auto-merge (squash) September 28, 2026 10:47
@pawbana
pawbana merged commit 0e8521d into main Sep 28, 2026
52 of 55 checks passed
@pawbana
pawbana deleted the pawel/aigov-615-reverse-proxy-handler-with-recorder-lifecycle-and-key-2 branch September 28, 2026 10:55
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 28, 2026
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