Skip to content

Forward coding-agent id into test app for connectedAndroidTest verification#2726

Draft
ctufts wants to merge 1 commit into
mainfrom
agent-tag-connected-test-forwarding
Draft

Forward coding-agent id into test app for connectedAndroidTest verification#2726
ctufts wants to merge 1 commit into
mainfrom
agent-tag-connected-test-forwarding

Conversation

@ctufts

@ctufts ctufts commented Jul 21, 2026

Copy link
Copy Markdown

Summary of changes

Part of a broader effort to measure how much SDK traffic comes from AI coding agents (Claude Code, Codex, Cursor, etc.) rather than human-run apps, the Mapbox Common SDK is adding a way to tag outbound requests with an agent identifier. On Android that identifier has to be resolved at compile time, since there's no OS environment variable to read the way there is on desktop platforms. So it has to come in through a Gradle property and get forwarded into the running process by the app itself.

This PR wires that forwarding path through the sample/test app (app module) used for connectedAndroidTest:

  • app/build.gradle.kts reads an optional -Pmapbox.agent=<id> Gradle property into BuildConfig.MAPBOX_AGENT, following the same project.hasProperty(...) pattern already used for gitVersionCode and APP_KEYSTORE_PASSWORD. Defaults to an empty string when the property isn't supplied, and the value is escaped before being embedded in generated source.
  • MapboxApplication.onCreate() forwards BuildConfig.MAPBOX_AGENT into Common's MapboxAgentContextFactory.getInstance().setMapboxAgentId(...) via a small helper, guarded so it only fires when the value is non-empty.
  • The forward/no-op logic itself lives in a pure, dependency-free function (forwardAgentIdIfPresent in AgentTelemetryForwarding.kt) with a unit test covering: empty id -> no-op, non-empty id -> forwarded, forwarded exactly once.

No agent detection or tagging logic lives in this repo, that all happens in Common. This change only forwards an already-resolved id into the running app process.

Blocked on Common: this depends on an unreleased Mapbox Common SDK change (mapbox-sdk PR #16363) that adds com.mapbox.common.MapboxAgentContext / MapboxAgentContextFactory. Until a Common build with those classes is published and this repo's dependency is bumped, MapboxApplication.kt's import of MapboxAgentContextFactory won't resolve and the app module won't compile. That's why this PR is in draft; it can come out once the dependency lands.

I also wasn't able to verify this end-to-end in my sandbox: building Common from source to work around the above needs the Android NDK and access to Mapbox's private Maven registry, and neither was available there. What I could confirm: the Gradle property to BuildConfig wiring matches this module's existing conventions by inspection, and the forwarding guard has a plain JUnit test with no dependency on the new Common API, so it'll run as soon as the module compiles again.

Verification once Common's change is available

  • ./gradlew :app:testDebugUnitTest --tests "*AgentTelemetryForwardingTest*" for the guard logic (should already pass once the module compiles).
  • ./gradlew connectedAndroidTest -Pmapbox.agent=claude-code on a device/emulator, confirming outbound Mapbox request User-Agents carry agent/claude-code.
  • Running connectedAndroidTest without -Pmapbox.agent (or a normal assembleRelease) should show zero change in behavior.

User impact (optional)

None. This only affects the sample/test app's instrumentation, not the published SDK's public API or behavior.

Pull request checklist:

  • Briefly describe the changes in this PR.
  • Include before/after visuals or gifs if this PR includes visual changes. -- N/A, no visual changes.
  • Write tests for all new functionality. If tests were not written, please explain why. -- unit test added for the forwarding guard; instrumented verification is blocked, see above.
  • Optimize code for java consumption (@JvmOverloads, @file:JvmName, etc). -- N/A, internal to the sample app only.
  • Add example if relevant. -- N/A.
  • Document any changes to public APIs. -- N/A, no public SDK API changes (app module is excluded from API validation).
  • Run make update-api -- N/A, no public API changes.
  • Update CHANGELOG.md or use the label 'skip changelog' -- used the skip changelog label since this only touches the internal sample/test app.

Fixes: N/A -- implements one piece of a larger cross-SDK agent-traffic-measurement effort tracked internally.

Wires an optional `-Pmapbox.agent=<id>` Gradle property into
`BuildConfig.MAPBOX_AGENT` on the sample/test app module, and forwards it
into Common's process-wide MapboxAgentContext during app init, so outbound
Mapbox requests made during a connectedAndroidTest run can be tagged with
the coding agent that triggered them. Defaults to empty (no-op) so normal
builds are unaffected.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@ctufts ctufts added skip changelog locationai-team-skills Work produced by the Location AI team's automation tooling labels Jul 21, 2026
@CLAassistant

CLAassistant commented Jul 21, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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

Labels

locationai-team-skills Work produced by the Location AI team's automation tooling skip changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants