🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

feat: add network calls column to AI sessions table - #27269

Merged
SasSwart merged 7 commits into
mainfrom
aigov-460
Jul 21, 2026
Merged

feat: add network calls column to AI sessions table#27269
SasSwart merged 7 commits into
mainfrom
aigov-460

Conversation

@SasSwart

@SasSwart SasSwart commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Add a "Total/blocked network calls" column to the AIBridge sessions table.

Update ListAIBridgeSessions query to calculate network called made and blocked per session. See query plan here.

@linear-code

linear-code Bot commented Jul 15, 2026

Copy link
Copy Markdown

AIGOV-460

@github-actions

Copy link
Copy Markdown

Docs preview

📖 View docs preview for docs/reference/api/aigateway.md

@SasSwart SasSwart changed the title feat: add total/blocked network calls column to AI sessions table feat: add network calls column to AI sessions table Jul 16, 2026
@SasSwart
SasSwart requested a review from johnstcn July 20, 2026 10:58
@SasSwart
SasSwart marked this pull request as ready for review July 20, 2026 11:00
@SasSwart

Copy link
Copy Markdown
Contributor Author

@johnstcn Would you mind having a look at the backend and API? I'll ask @EhabY for a look at the FE. I have self reviewed the backend. I am still self reviewing the frontend.

@coder-tasks

coder-tasks Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Documentation Check

Updates Needed

  • docs/ai-coder/ai-gateway/audit.md - The Sessions list section enumerates the sessions-table columns and should mention the new Total/blocked network calls column. (No longer needed in this PR: the frontend/UI changes that added the column were removed in 43a0595 "chore: remove frontend changes from backend PR". This is now a backend/API-only PR, so the user-facing sessions-list docs are unaffected. The column docs should be handled by the follow-up frontend PR.)

Note: docs/reference/api/aigateway.md and docs/reference/api/schemas.md are auto-generated and are already correctly updated in this PR; no manual action needed there. The network_calls API field is covered by these generated schema docs.


Automated review via Coder Agents

@johnstcn johnstcn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Was the query plan you shared on the current database state or on a synthetic dataset that includes the new indexes proposed here?

Comment thread codersdk/aibridge.go

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Would it be simpler to inline two nil-able int64s instead of making an embedded struct?

NetworkCallsTotal   *int64 `json:"network_calls_count,omitempty"`
NetworkCallsBlocked *int64 `json:"network_calls_blocked,omitempty"`

Comment thread enterprise/coderd/aibridge_test.go Outdated
Comment on lines +314 to +316
// seq 3, so A's window is (0,3) and B's is (3, +inf). The logs at seq 0
// and 3 are the interceptions' own LLM-provider calls and must be
// excluded by the exclusive lower bound.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Restates the inline comments below.

Suggested change
// seq 3, so A's window is (0,3) and B's is (3, +inf). The logs at seq 0
// and 3 are the interceptions' own LLM-provider calls and must be
// excluded by the exclusive lower bound.
// seq 3, so A's window is (0,3) and B's is (3, +inf).

SasSwart and others added 4 commits July 20, 2026 11:32
Add a "Total/blocked network calls" column to the AIBridge sessions table,
rendering per-session total, blocked, and errored call counts as badges plus
"No activity" and "Disabled" states. Define the NetworkCalls contract on the
codersdk AIBridgeSession type; the DB aggregation and handler population are
left as marked TODO touch points.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The AI Gateway sessions table shipped with the network-calls column
scaffolded but unpopulated, so every session rendered as "Disabled".

Aggregate Agent Firewall egress per session in ListAIBridgeSessions by
correlating boundary_logs to each interception's firewall session and
sequence window (seq, next_seq). The exclusive lower bound drops the
interception's own LLM-provider call; matched_rule IS NULL counts blocked
requests. Sessions that never passed through Agent Firewall report a nil
summary so the UI keeps rendering "Disabled".

Drop the errored counter for now; boundary_logs has no error signal yet.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Move the non-generated frontend changes for network call badges to a
separate branch so this PR is backend only. The generated
typesGenerated.ts additions remain, as they are produced by make gen
alongside the backend changes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@EhabY EhabY left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A few small comments on the FE, but it looks solid!

<TableHead className="text-nowrap">Provider</TableHead>
<TableHead className="text-nowrap">Client</TableHead>
<TableHead className="text-nowrap">In/Out Tokens</TableHead>
<TableHead className="w-40">

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why is this header styled differently, shouldn't it be text-nowrap like above without the width limit?

We could also shorten this to fit in like the other titles to Network Calls since the content it self includes total/blocked

return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe copy the pattern in LastConnectionHead.tsx:13-21 by adding tabIndex={0} to the InfoIcon plus an sr-only "More info" label

Currently there is no way to see why something is disabled using the keyboard (without a mouse)

return (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same here

} from "#/components/Tooltip/Tooltip";

interface NetworkCallBadgesProps {
size?: "xs" | "sm" | "md";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

AFAIK this is never used right? If so then let's remove it for now and only add it when there are other consumers

Comment on lines 514 to 520
-- Fetch only the most recent user prompt across all interceptions
-- in the session.
SELECT up.prompt
FROM aibridge_user_prompts up
WHERE up.interception_id = ANY(sr.interception_ids)
ORDER BY up.created_at DESC, up.id DESC
LIMIT 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Out of scope of this PR: the plan you linked shows the sample query being absolutely hammered by this join. We should probably follow up separately on this.

@SasSwart

Copy link
Copy Markdown
Contributor Author

@johnstcn I've updated the link in the PR description to point to a new query plan. This one is against a seeded DB (2k sessions, 240k log lines). The seeded data is perhaps too uniform, but I believe this is still a good estimate. We are introducing some cost. It's only 25% of the cost that you identified in your comment above though.

I have a fix in mind, but I'm trying to determine whether its worth forcing this now or if this is a rabbit hole of diminishing returns.

@johnstcn johnstcn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's ship and observe the perf on dogfood.

@SasSwart
SasSwart merged commit a9a1dcc into main Jul 21, 2026
32 of 33 checks passed
@SasSwart
SasSwart deleted the aigov-460 branch July 21, 2026 12:34
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 21, 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