Skip to content

feat: add AI Bridge request logs model filter#22230

Merged
jakehwll merged 12 commits intomainfrom
jakehwll/KIWI-39-filter-interceptions-by-model
Feb 25, 2026
Merged

feat: add AI Bridge request logs model filter#22230
jakehwll merged 12 commits intomainfrom
jakehwll/KIWI-39-filter-interceptions-by-model

Conversation

@jakehwll
Copy link
Contributor

This pull-request implements a simple filtering logic so that we're able to pick which model the user actually used when logs were sent to AI Bridge.

  • Add GET /aibridge/models API endpoint that returns distinct model names from AI Bridge interceptions, with pagination and search support
  • New ListAIBridgeModels SQL query using case-sensitive prefix matching (LIKE model || '%') to allow B-tree index usage
  • Hand-written ListAuthorizedAIBridgeModels in modelqueries.go for RBAC authorization filter injection
  • AIBridgeModels search query parser in searchquery/search.go (defaults bare terms to the model field)
  • dbauthz wrappers, dbmetrics, and dbmock implementations for the new query
image

Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a5fb301aba

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +394 to +396
GROUP BY
model
LIMIT COALESCE(NULLIF(@limit_::integer, 0), 100)

Choose a reason for hiding this comment

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

P2 Badge Add ORDER BY before paginating model list

The new GET /aibridge/models query applies LIMIT/OFFSET immediately after GROUP BY without any ORDER BY, so pagination is nondeterministic. In PostgreSQL, grouped rows can be returned in arbitrary order, which means clients using offset pagination can see duplicates or miss models between pages as execution plans/data change. Add a stable ordering (for example by model) before pagination so page boundaries are consistent.

Useful? React with 👍 / 👎.

Comment on lines +24 to +28
if (firstModel) {
return {
label: firstModel,
value: firstModel,
};

Choose a reason for hiding this comment

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

P2 Badge Validate selected model matches filter value

getSelectedOption currently treats the first result from /aibridge/models?q=<value>&limit=1 as the selected model even when it is only a prefix match and not the actual current filter value. If a user lands on a query like model:gpt (or any non-exact value), the dropdown can display a different model as selected, which misrepresents the active filter state and can lead to accidental filter changes. Return a selected option only when the fetched model exactly equals value.

Useful? React with 👍 / 👎.

@jakehwll jakehwll changed the base branch from main to jakehwll/22144-aibridge-client-information February 21, 2026 15:42
@jakehwll jakehwll force-pushed the jakehwll/KIWI-39-filter-interceptions-by-model branch from a5fb301 to 2878930 Compare February 21, 2026 15:44
@coder-tasks
Copy link
Contributor

coder-tasks bot commented Feb 21, 2026

Documentation Check

Updates Needed

  • enterprise/coderd/aibridge.goaiBridgeListModels is missing @Param swagger annotations for its accepted query parameters (q, limit, offset). The auto-generated docs/reference/api/aibridge.md entry will therefore have no "Parameters" section, unlike the interceptions endpoint which documents all its query params. Add annotations matching the interceptions endpoint pattern:

    // @Param q query string false "Search query in the format `key:value`. Available keys are: model."
    // @Param limit query int false "Page limit"
    // @Param offset query int false "Offset pagination"

Automated review via Coder Tasks

Copy link
Contributor Author

jakehwll commented Feb 21, 2026

Base automatically changed from jakehwll/22144-aibridge-client-information to main February 24, 2026 15:39
Copy link
Contributor

@pawbana pawbana left a comment

Choose a reason for hiding this comment

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

I think AI left good review comments. Lack of ORDER BY with LIMIT/OFFSET I agree with.
Not sure If I understand correctly the second one but from my manual testing it seemed impossible to filter by model prefix, which is mentioned in PR description as a feature, fist match from the dropdown was selected instead.

Also it looks like each time a model input field value is changed a request to backend is made (eg. typing "gpt" results in 3 queries):
image

Either get all the models once, remove limit/offset, kind of risky but there should not be that many models in practice, and filter on client side or query back-end only when enter is clicked or after some delay.
Maybe I'm a bit paranoid but this table is big so I'd rather have as little

Copy link
Contributor

@pawbana pawbana left a comment

Choose a reason for hiding this comment

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

Approving with credit that eager endpoint calling on model filter input change will be fixed in a follow up soon : )
(#22230 (review))

@jakehwll jakehwll force-pushed the jakehwll/KIWI-39-filter-interceptions-by-model branch from 3683ce5 to 08fa8ae Compare February 25, 2026 04:17
@jakehwll jakehwll merged commit d2787df into main Feb 25, 2026
32 of 33 checks passed
@jakehwll jakehwll deleted the jakehwll/KIWI-39-filter-interceptions-by-model branch February 25, 2026 15:40
@github-actions github-actions bot locked and limited conversation to collaborators Feb 25, 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