Skip to content

feat(api): always announce as Convert SDK via ConvertAgent User-Agent - #41

Merged
abbaseya merged 2 commits into
mainfrom
feat/inject-convert-agent-user-agent
May 23, 2026
Merged

feat(api): always announce as Convert SDK via ConvertAgent User-Agent#41
abbaseya merged 2 commits into
mainfrom
feat/inject-convert-agent-user-agent

Conversation

@abbaseya

@abbaseya abbaseya commented May 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Force User-Agent: ConvertAgent/1.0 on every outbound HTTP request from ApiManager, applied after the per-call and default header merge so it cannot be overridden by config.
  • Matches the metrics-endpoint's isConvertAgentUA bypass — replaces dependence on the source-field bypass for SDK-traffic identification.

Why now

The May 19 metrics-endpoint isbot regression exposed that:

  • ConvertSDK::create() lets customers override network.source via config (packages/Php-sdk/src/Config/DefaultConfig.php:49 default 'php-sdk').
  • A VERSION env-var override hook exists in ConvertSDK.php:70-73 (for CI/release builds). If a future release stamps VERSION=php2.1.0, the wire source becomes php2.1.0 and matches neither of the metrics-endpoint bypass conditions today (endsWith('-sdk') or /^js\d+\.\d+\.\d+/). Silent customer outage.

Baking the UA at the transport layer makes the announcement an SDK invariant — not config-driven, not env-driven, not customer-overridable. Metrics-endpoint code stays untouched (the isConvertAgentUA bypass has been in place since 2026-05-20).

What stays in place

The source-field bypass at the metrics endpoint remains as legacy fallback for already-deployed SDK versions. Customers on older SDKs continue to work via the endsWith('-sdk') path.

Test plan

  • CI green on the existing PHPUnit / PHPStan / php-cs-fixer pipelines
  • Manually verify with a PSR-18 client capable of echoing request headers (e.g., a MockHttpClient test) that User-Agent: ConvertAgent/1.0 is present on outbound requests
  • Smoke against staging metrics endpoint to confirm botCheckSkipped events fire with empty source + userAgent: "ConvertAgent/1.0" (the ConvertAgent UA bypass path)

🤖 Generated with Claude Code


Set the User-Agent header to ConvertAgent/1.0 on every outbound request
from ApiManager, after the header merge so neither $headers nor
$defaultHeaders can override it. This matches the metrics-endpoint's
isConvertAgentUA bypass and removes the fragility of relying on the
source field for legitimate-SDK-traffic identification.

Why this matters: ConvertSDK::create() lets customers override
network.source via config, and a VERSION env var override hook exists
in ConvertSDK.php. Either could break the metrics-endpoint's source-
field bypass silently. The UA is now an SDK invariant: not config-
driven, not env-driven, baked at the HTTP transport layer.

Source-field bypass at the metrics endpoint stays in place as legacy
fallback for already-deployed SDK versions.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@abbaseya abbaseya self-assigned this May 22, 2026
@abbaseya
abbaseya requested a review from DmytroConvert May 22, 2026 23:46
Replaces the hard-coded 'ConvertAgent/1.0' literal in ApiManager
with a private class constant, matching the existing pattern for
DEFAULT_HEADERS and DEFAULT_TRACK_ENDPOINT.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request updates the ApiManager to include a mandatory User-Agent header, ConvertAgent/1.0, in all outgoing requests to ensure the SDK is correctly identified by bot filters. A review comment suggests updating the spelling of 'recognises' to 'recognizes' in the code comments to maintain consistency with the American English conventions used throughout the codebase.

I am having trouble creating individual review comments. Click here to see my feedback.

packages/Api/src/ApiManager.php (220)

medium

The comment uses the British English spelling 'recognises', while the rest of the codebase (e.g., 'Authorization' on line 167, 'transformation' on line 107) follows American English. For consistency with the existing code style, 'recognizes' should be used.

        // bot filter recognizes us via its `isConvertAgentUA` bypass. Set

@abbaseya
abbaseya merged commit 8ce7f36 into main May 23, 2026
10 checks passed
@abbaseya
abbaseya deleted the feat/inject-convert-agent-user-agent branch June 9, 2026 18:47
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