Skip to content

feat(agent-proxy): add adoption telemetry for agent proxy commands - #341

Merged
saifsmailbox98 merged 5 commits into
mainfrom
saif/agent-proxy-telemetry
Jul 31, 2026
Merged

feat(agent-proxy): add adoption telemetry for agent proxy commands#341
saifsmailbox98 merged 5 commits into
mainfrom
saif/agent-proxy-telemetry

Conversation

@saifsmailbox98

@saifsmailbox98 saifsmailbox98 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Description 📣

Agent proxy commands emit no telemetry today, and on a proxy host nothing identifies the caller either: start and connect authenticate with a client id/secret, and UniversalAuthLogin holds that token in memory rather than exporting it, so GetDistinctId finds nothing in the environment and falls through to anonymous_cli_<machineid>. Standalone proxy usage was unattributable.

Events: one per command, cli-command:agent-proxy start, connect and run, captured before the long-running work so an attempt is still recorded when the command later dies. Properties describe the deployment shape rather than its contents: unmatchedHost, credentialSource, logFormat/logFileSet, pollInterval for start; sandboxEnabled plus sandboxSource (flag, env or default) and the --allow-read/--allow-write/--allow-host/--pass-env/--set-env counts for run; allowReadableBrokeredSecrets for connect. The sandbox escape-hatch counts are the useful ones: if most runs re-open three paths, the sandbox defaults are wrong.

Attribution: AttachTokenIdentity records the identity and organization claims from a token the command has already resolved, so events are attributed even when nothing is exported in the environment. Events are grouped under $groups.organization, matching the organization group type the backend sets, which is what makes usage attributable to a company rather than a machine. Both claim spellings are read: orgId on machine identity tokens, organizationId on user session JWTs.

Agent name: the basename of the first word after --, and nothing else. argv past the first word routinely carries credentials (-- python train.py --hf-token=hf_...), so the executable name is the only part reported.

Companion backend PR: Infisical/infisical#7491

Not in this PR: failure events with a reason enum, since every failure path exits through util.HandleErroros.Exit and instrumenting them means touching every call site. Session duration and per-request decision rollups are also left out; both need the defer t.posthogClient.Close() in CaptureEvent fixed first, because today the second capture in a process is silently dropped. Both are follow-ups.

Type ✨

  • Bug fix
  • New feature
  • Improvement
  • Breaking change
  • Documentation

Tests 🛠️

# Here's some code block to paste some code snippets

Capture start, connect and run as PostHog events with their deployment
shape (sandbox state, unmatched-host policy, sandbox escape-hatch counts,
agent executable name). Group CLI events under the organization so usage
is attributable, including for commands that authenticate with a client
id/secret and therefore have no token in the environment to read.
@infisical-review-police

Copy link
Copy Markdown

💬 Discussion in Slack: #pr-review-cli-341-feat-agent-proxy-add-adoption-telemetry-for-agent-proxy-comman

Posted by Review Police — reviews, comments, new commits, and CI failures will stream into this channel.

Comment thread packages/telemetry/telemetry.go Outdated
Comment thread packages/cmd/agent_proxy.go Outdated
@greptile-apps

greptile-apps Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

Adds adoption telemetry for agent-proxy commands.

  • Captures deployment, sandbox, credential-source, and executable metadata for start, connect, and run.
  • Derives telemetry identity and organization grouping from the token already selected by each command.
  • Gives an attached machine identity precedence over persisted or environment-derived identities.

Confidence Score: 4/5

The PR should not merge until mixed-source universal-auth invocations report their credential source accurately.

The reply states that token-path reporting was fixed by returning the authentication branch, but the residual mixed-source case remains: client ID and client secret are resolved independently while universalAuthCredentialSource inspects only the client-ID flag, so valid invocations using an environment client ID with a flag-provided secret, or the inverse, emit incorrect adoption metadata.

Files Needing Attention: packages/cmd/agent_proxy.go, packages/cmd/agent_proxy_start.go

Important Files Changed

Filename Overview
packages/cmd/agent_proxy.go Adds connect telemetry and token-source reporting, but mixed flag/environment universal-auth credentials remain mislabeled.
packages/cmd/agent_proxy_run.go Adds run telemetry describing the sandbox, network fallback, agent executable, and escape-hatch counts.
packages/cmd/agent_proxy_start.go Adds start telemetry while consuming the credential-source classification that remains inaccurate for mixed inputs.
packages/telemetry/telemetry.go Adds attached token identity and organization grouping, with the previously reported precedence defects corrected.

Reviews (4): Last reviewed commit: "fix(agent-proxy): prefer attached identi..." | Re-trigger Greptile

@saifsmailbox98
saifsmailbox98 requested a review from akhilmhdh July 30, 2026 18:31
@saifsmailbox98

Copy link
Copy Markdown
Contributor Author

@greptile review

Comment thread packages/telemetry/telemetry.go Outdated
…ent properties

The attached machine identity now outranks a persisted human login, so a
machine-identity run on a developer host no longer files the event against
the human's person record while grouping it under the machine's org. A user
session JWT carries no identityId, so login-backed runs still resolve to the
email.

Also drops port, logFormat and logFileSet, moves the run capture below the
sandbox preflight, and reports netDowngraded so a fence that fell back to
shared networking is visible.
@saifsmailbox98

Copy link
Copy Markdown
Contributor Author

@greptile review

1 similar comment
@saifsmailbox98

Copy link
Copy Markdown
Contributor Author

@greptile review

Comment thread packages/telemetry/telemetry.go Outdated
…comments

SetActor takes the identity and org ids instead of an access token, so nothing
token-shaped crosses into telemetry. Also removes a duplicated comment block and
cuts the added comments back.
akhilmhdh
akhilmhdh previously approved these changes Jul 30, 2026
@saifsmailbox98
saifsmailbox98 merged commit 841c3e1 into main Jul 31, 2026
30 checks passed
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.

2 participants