Skip to content

feat: add client column to aibridge_interceptions table#21839

Merged
pawbana merged 9 commits intomainfrom
pb/aibridge-user-agent-db
Feb 17, 2026
Merged

feat: add client column to aibridge_interceptions table#21839
pawbana merged 9 commits intomainfrom
pb/aibridge-user-agent-db

Conversation

@pawbana
Copy link
Contributor

@pawbana pawbana commented Feb 2, 2026

Depends on: coder/aibridge#158

Copy link
Contributor Author

pawbana commented Feb 2, 2026

@pawbana pawbana force-pushed the pb/aibridge-user-agent-db branch from 9286dc9 to d52be35 Compare February 3, 2026 17:13
@pawbana pawbana changed the title tmp-commit feat: add client column to aibridge_interceptions table Feb 3, 2026
@pawbana pawbana force-pushed the pb/aibridge-user-agent-db branch 3 times, most recently from f287ce3 to b6f4775 Compare February 3, 2026 17:38
@pawbana pawbana marked this pull request as ready for review February 3, 2026 17:56
Copy link
Contributor

@coder-tasks coder-tasks bot left a comment

Choose a reason for hiding this comment

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

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 Client field in filter
  • All database call sites updated to include the new parameter
  • Test data properly includes the new Client field with sql.NullString type

Implementation Details Verified

  1. Migration: Clean up/down migration pair that properly adds/removes the VARCHAR(64) column
  2. Database queries: All queries that filter or return interceptions updated:
    • InsertAIBridgeInterception - includes client in insert
    • ListAIBridgeInterceptions - filters by client using COALESCE
    • CountAIBridgeInterceptions - counts with client filter
    • ListAIBridgeInterceptionsTelemetrySummaries - updated to use actual client column
    • CalculateAIBridgeInterceptionsTelemetrySummary - updated to use actual client column
  3. API integration: Enterprise handler properly passes Client from filter to database queries
  4. 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

@pawbana pawbana force-pushed the pb/aibridge-user-agent-db branch from b6f4775 to e7fa5ea Compare February 3, 2026 18:04
@coder-tasks
Copy link
Contributor

coder-tasks bot commented Feb 3, 2026

Documentation Check

Updates Needed

  • docs/ai-coder/ai-bridge/monitoring.md - Add client to the list of available query filters (line 26-32)
  • docs/reference/api/aibridge.md - Add client to the search query keys documentation (line 20)

Details

This 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 client parameter.

Suggested changes:

In docs/ai-coder/ai-bridge/monitoring.md line 26-32, add:

- `client` - Filter by client name (e.g., `claude-code`, `cursor`, `unknown`)

In docs/reference/api/aibridge.md line 20, update the description to include client in the list of available keys.


Automated review via Coder Tasks

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

LGTM!

Provider: "two",
Model: "two",
StartedAt: now.Add(-time.Hour),
Client: sql.NullString{String: "cursor", Valid: true},
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: use the same values as in coder/aibridge#158

Suggested change
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);
Copy link
Contributor

Choose a reason for hiding this comment

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

This means that all previous interceptions will have client as NULL, no? Should we maybe use a default value like 'unknown'?

Suggested change
ADD COLUMN client VARCHAR(64);
ADD COLUMN client VARCHAR(64) DEFAULT 'unknown';

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
Copy link
Contributor

Choose a reason for hiding this comment

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

What if the client is an empty string? Should we validate for that case?

Copy link
Contributor Author

@pawbana pawbana Feb 5, 2026

Choose a reason for hiding this comment

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

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.

@pawbana pawbana force-pushed the pb/aibridge-user-agent-db branch from e7fa5ea to 4c30f20 Compare February 5, 2026 16:06
@coder-tasks
Copy link
Contributor

coder-tasks bot commented Feb 5, 2026

Documentation Check

Updates Needed

  • enterprise/cli/aibridge.go - Add --client flag to aibridgeInterceptionsList() command (lines 45-54: add client variable; lines 78-89: add flag option similar to provider/model; lines 137-148: add Client field to filter struct)
  • enterprise/cli/testdata/coder_aibridge_interceptions_list_--help.golden - Add --client flag documentation in help output
  • docs/ai-coder/ai-bridge/monitoring.md - Add client to the "Available query filters" list (after line 30) and CLI filter examples (after line 50)

Context

This 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 --client flag should follow the same pattern as --provider and --model flags already implemented.


Automated review via Coder Tasks

@github-actions github-actions bot added the stale This issue is like stale bread. label Feb 13, 2026
@pawbana pawbana force-pushed the pb/aibridge-user-agent-db branch from 4c30f20 to 6778eb9 Compare February 16, 2026 15:58
@coder-tasks
Copy link
Contributor

coder-tasks bot commented Feb 16, 2026

Documentation Check

Updates Needed

  • docs/ai-coder/ai-bridge/monitoring.md - Add client to the list of available query filters

    • Added with comprehensive list of client values in collapsible section (lines 28-46)
  • docs/reference/api/aibridge.md - Add client to the search query keys documentation (line 20)

    • Current: Available keys are: initiator, provider, model, started_after, started_before.
    • Needed: Add client to the list
    • Schema examples already show client field (auto-generated), but parameter description needs manual update
  • enterprise/cli/aibridge.go - Add --client flag to CLI command

    • Variable added at line 52
    • Flag option added at lines 92-96
    • Field added to filter struct at line 150
  • docs/reference/cli/aibridge_interceptions_list.md - Document --client flag

    • Auto-generated documentation updated (lines 54-60)

Context

This 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:

  • CLI implementation with --client flag
  • Auto-generated CLI reference docs
  • Monitoring guide with client filter and comprehensive list of supported clients
  • API schemas (auto-generated)

⚠️ Still Needed:

  • Manual update to docs/reference/api/aibridge.md line 20 to add client to the query keys list

Automated review via Coder Tasks

@pawbana pawbana force-pushed the pb/aibridge-user-agent-db branch from 6778eb9 to 1a7d40b Compare February 16, 2026 16:04
@github-actions github-actions bot removed the stale This issue is like stale bread. label Feb 17, 2026
@pawbana pawbana force-pushed the pb/aibridge-user-agent-db branch from 8206db2 to 42b467a Compare February 17, 2026 10:03
@pawbana pawbana force-pushed the pb/aibridge-user-agent-db branch from d15a6be to 875b56a Compare February 17, 2026 13:52
@pawbana pawbana merged commit 90c11f3 into main Feb 17, 2026
33 of 36 checks passed
@pawbana pawbana deleted the pb/aibridge-user-agent-db branch February 17, 2026 14:43
@github-actions github-actions bot locked and limited conversation to collaborators Feb 17, 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.

3 participants