Skip to content

ADFA-5254 | Tag AI network sockets with TrafficStats - #85

Open
jatezzz wants to merge 1 commit into
mainfrom
fix/ADFA-5254-tag-ai-network-sockets
Open

ADFA-5254 | Tag AI network sockets with TrafficStats#85
jatezzz wants to merge 1 commit into
mainfrom
fix/ADFA-5254-tag-ai-network-sockets

Conversation

@jatezzz

@jatezzz jatezzz commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Description

Tag OpenAI and Gemini network operations using Android TrafficStats so AI traffic can be attributed to inference and model catalog requests.

The changes add shared traffic-tag helpers that set the appropriate thread stats tag before socket creation and always clear it in a finally block. OpenAI POST requests are tagged as inference and GET requests as catalog traffic, while Gemini tags inference requests, SSE streaming, and the full paginated model catalog flow.

This prevents StrictMode untagged socket violations and enables Android network statistics tools to distinguish AI inference usage from routine catalog requests.

Details

  • Added dedicated inference and catalog traffic tags for both AI agent modules.
  • Wrapped OpenAI POST and GET request lifecycles with the appropriate traffic tags.
  • Tagged Gemini standard inference and SSE streaming requests as inference traffic.
  • Tagged the complete Gemini paginated model catalog loop as catalog traffic.
  • Added unit tests verifying that tags are applied, cleared after successful execution, cleared after exceptions, and remain distinct and non-zero.
  • Supports validation through StrictMode and dumpsys netstats network usage reporting.
Screenshot 2026-09-01 at 10 46 01 AM

Ticket

ADFA-5254
Parent: ADFA-5251

Observation

Traffic tags are thread-local and are explicitly cleared to prevent tags from leaking into reused Dispatchers.IO threads. Network accounting can remain approximate when persistent or pooled sockets retain the tag assigned when the socket was originally created.

Untagged sockets trip the host's process-wide StrictMode detectUntaggedSockets() and leave AI traffic unattributable; tag inference and catalog in both backends.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review for a one-time review, or @claude review always to subscribe this PR to a review on every future push.

Tip: disable this comment in your organization's Code Review settings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant