feat: add client column to aibridge_interceptions table#21839
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
9286dc9 to
d52be35
Compare
f287ce3 to
b6f4775
Compare
There was a problem hiding this comment.
Code Review
Reviewed the addition of a client column to the aibridge_interceptions table. The implementation is well-structured and complete.
Summary
✅ Strengths:
- Proper database migration with both up and down migrations following the project's migration pattern
- Comprehensive query updates across all affected queries in
aibridge.sql - All generated code properly updated via
make gen(queries.sql.go, models.go, modelqueries.go) - Good test coverage including filtering tests for client field (unknown, exact match, no match)
- Consistent use of
COALESCE(client, 'unknown')pattern for handling nullable client field - Properly integrated into search query parser in
searchquery/search.go - SDK types updated with the new
Clientfield in filter - All database call sites updated to include the new parameter
- Test data properly includes the new Client field with
sql.NullStringtype
Implementation Details Verified
- Migration: Clean up/down migration pair that properly adds/removes the VARCHAR(64) column
- Database queries: All queries that filter or return interceptions updated:
InsertAIBridgeInterception- includes client in insertListAIBridgeInterceptions- filters by client using COALESCECountAIBridgeInterceptions- counts with client filterListAIBridgeInterceptionsTelemetrySummaries- updated to use actual client columnCalculateAIBridgeInterceptionsTelemetrySummary- updated to use actual client column
- API integration: Enterprise handler properly passes
Clientfrom filter to database queries - Tests: New test cases cover the client filtering scenarios comprehensively
This PR properly implements the client tracking feature and removes the TODO comments that referenced the upstream aibridge issue.
Approved ✅
b6f4775 to
e7fa5ea
Compare
Documentation CheckUpdates Needed
DetailsThis PR adds client tracking to AI Bridge interceptions, allowing filtering by which AI client made the request (Claude Code, Cursor, VS Code, etc.). The monitoring documentation shows available filters but is missing the new Suggested changes: In - `client` - Filter by client name (e.g., `claude-code`, `cursor`, `unknown`)In Automated review via Coder Tasks |
enterprise/coderd/aibridge_test.go
Outdated
| Provider: "two", | ||
| Model: "two", | ||
| StartedAt: now.Add(-time.Hour), | ||
| Client: sql.NullString{String: "cursor", Valid: true}, |
There was a problem hiding this comment.
nit: use the same values as in coder/aibridge#158
| Client: sql.NullString{String: "cursor", Valid: true}, | |
| Client: sql.NullString{String: "Cursor", Valid: true}, |
| @@ -0,0 +1,4 @@ | |||
| ALTER TABLE aibridge_interceptions | |||
| ADD COLUMN client VARCHAR(64); | |||
There was a problem hiding this comment.
This means that all previous interceptions will have client as NULL, no? Should we maybe use a default value like 'unknown'?
| ADD COLUMN client VARCHAR(64); | |
| ADD COLUMN client VARCHAR(64) DEFAULT 'unknown'; |
coderd/database/queries/aibridge.sql
Outdated
| model, | ||
| -- TODO: use the client value once we have it (see https://github.com/coder/aibridge/issues/31) | ||
| 'unknown' AS client | ||
| COALESCE(client, 'unknown') AS client |
There was a problem hiding this comment.
What if the client is an empty string? Should we validate for that case?
There was a problem hiding this comment.
If client is an empty string then it will be saved as null in DB: https://github.com/coder/coder/pull/21769/changes#diff-fb7aa3352ed36e6ce93c9b4e0ec0717885b726476a07617471bc5e1cf627174dR165
As far as I know there is no way to distinguish between empty and not set in proto3: golang/protobuf#15 (comment)
It could be set to Unknown in such case.
e7fa5ea to
4c30f20
Compare
Documentation CheckUpdates Needed
ContextThis PR adds database-level support for tracking which AI client initiated each interception (Cursor, Claude Code, VS Code, etc.). The backend filtering is complete, but the CLI and documentation need to expose this new capability to users. The Automated review via Coder Tasks |
4c30f20 to
6778eb9
Compare
Documentation CheckUpdates Needed
ContextThis PR adds database-level support for tracking which AI client initiated each interception (Cursor, Claude Code, VS Code, etc.). Most documentation has been addressed: ✅ Completed:
Automated review via Coder Tasks |
6778eb9 to
1a7d40b
Compare
8206db2 to
42b467a
Compare
d15a6be to
875b56a
Compare

Depends on: coder/aibridge#158