Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: add network calls summary to AI session threads API - #27417

Merged
SasSwart merged 5 commits into
mainfrom
aigov-463-network-summary
Jul 30, 2026
Merged

feat: add network calls summary to AI session threads API#27417
SasSwart merged 5 commits into
mainfrom
aigov-463-network-summary

Conversation

@SasSwart

@SasSwart SasSwart commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Backend for the AI session network summary. Exposes total/blocked network calls and top destination domains on the session threads endpoint (GET /api/v2/ai-gateway/sessions/{id}).

Total and blocked reuse the existing Agent Firewall aggregation from the sessions list query, so the numbers match the sessions table. Top domains are a new server-side aggregation (GetAIBridgeSessionTopDomains) over boundary logs, using the same interception-window correlation. There is no network-error state, matching the current data model.

Frontend consuming these fields is in a separate stacked PR.

PR map (merge strictly bottom-up)

This change is a 4-PR stack. Each PR depends on all the ones below it, so merge in this exact order:

  1. feat: add network calls summary to AI session threads API #27417 — backend network summary (base main)
  2. feat: show network request summary on AI session detail card #27418 — frontend summary rows (base feat: add network calls summary to AI session threads API #27417)
  3. feat: add network calls list to AI session threads API #27425 — backend per-call list network_call_logs (base feat: show network request summary on AI session detail card #27418)
  4. feat(site): show network calls list on AI session detail #27426 — frontend network-calls panel (base feat: add network calls list to AI session threads API #27425)

Refs AIGOV-463

🤖 Generated with Claude Code

@linear-code

linear-code Bot commented Jul 22, 2026

Copy link
Copy Markdown

AIGOV-463

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Docs preview

Check off each page once it's been reviewed. If a page changes in a later push, its checkbox clears automatically so it gets a fresh look. Pages not yet wired into the docs navigation aren't listed here.

@SasSwart
SasSwart force-pushed the aigov-463-network-summary branch from a4d26be to 8959a08 Compare July 22, 2026 14:04
@SasSwart SasSwart changed the title feat: add network calls summary to AI session detail feat: add network calls summary to AI session threads API Jul 22, 2026
@SasSwart
SasSwart marked this pull request as ready for review July 28, 2026 13:24
@SasSwart
SasSwart requested a review from a team as a code owner July 28, 2026 13:24

@SasSwart SasSwart left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Self review complete. Mostly explanation but there are a some nits and an rbac change that need to happen.

Comment thread coderd/database/queries/aibridge.sql
Comment thread coderd/database/queries/aibridge.sql Outdated
Comment thread coderd/database/queries/aibridge.sql
Comment on lines +596 to +603
-- Strip an optional scheme, then keep the host up to the first port, path,
-- query, or fragment delimiter. This assumes HTTP egress detail is a plain
-- scheme+host(+port) URL: it does not handle userinfo (user@host, which
-- would be captured into the host) or IPv6 literal hosts ([::1], where the
-- leading '[' is captured and the ':' terminates early). Boundary HTTP logs
-- do not currently emit those forms; revisit this extraction if they do.
SELECT substring(detail from '^(?:[A-Za-z][A-Za-z0-9+.-]*://)?([^/:?#]+)') AS domain
FROM session_boundary_logs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't like this at all. It's brittle and the use of regex here is a crutch for a weak data model. Nevertheless, I'm following @mtojek's advice and accepting that this is good enough for the immediate release and can be improved later.

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.

Add a follow-up issue for later 👍

Comment thread codersdk/aibridge.go
Comment on lines +179 to +182
// NetworkCalls summarizes the Agent Firewall network calls made during the
// session. A nil value means the session did not pass through Agent
// Firewall, so network call monitoring was not active, which the UI
// surfaces as "Disabled".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Overly verbose.

}

func (q *querier) GetAIBridgeSessionTopDomains(ctx context.Context, arg database.GetAIBridgeSessionTopDomainsParams) ([]database.GetAIBridgeSessionTopDomainsRow, error) {
if err := q.authorizeContext(ctx, policy.ActionRead, rbac.ResourceAibridgeInterception); err != nil {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is incorrect. It should use the resources defined for agent firewall instead.

@SasSwart
SasSwart requested a review from johnstcn July 28, 2026 13:36
Comment thread coderd/database/queries/aibridge.sql Outdated
SasSwart and others added 5 commits July 30, 2026 10:16
Expose total and blocked network calls plus top destination domains on
the AI session threads endpoint. Total and blocked reuse the existing
Agent Firewall aggregation from the sessions list query; top domains are
a new GetAIBridgeSessionTopDomains aggregation over boundary logs using
the same interception-window correlation.

Refs AIGOV-463

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…fetch

Add multi-interception and shared-firewall-session tests asserting the
network_calls summary total/blocked and top-domains counts partition
correctly across consecutive windows and do not bleed across AI sessions that
share one firewall session.

Reduce the top-domains fetch to a single row, since the summary card renders
only the most-contacted domain plus a "+N more" count derived from
NetworkDomainCount (a window aggregate independent of the row cap).

Document that the domain-extraction regex assumes scheme+host(+port) detail
without userinfo or IPv6 literal hosts, and add a port-suffixed test row that
pins host stripping.

Refs AIGOV-463

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@SasSwart
SasSwart force-pushed the aigov-463-network-summary branch from 63a4fff to 16d4f5d Compare July 30, 2026 10:16
@SasSwart
SasSwart merged commit 841a176 into main Jul 30, 2026
52 of 54 checks passed
@SasSwart
SasSwart deleted the aigov-463-network-summary branch July 30, 2026 11:09
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 30, 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