Skip to content

fix: send stable user-agent from the Python SDK#4

Merged
ryanmcmillan merged 1 commit intomainfrom
fix/python-sdk-user-agent
Mar 27, 2026
Merged

fix: send stable user-agent from the Python SDK#4
ryanmcmillan merged 1 commit intomainfrom
fix/python-sdk-user-agent

Conversation

@ryanmcmillan
Copy link
Copy Markdown
Member

Summary

  • centralize the SDK version/user-agent metadata
  • send an explicit User-Agent from both the sync urllib client and async httpx client
  • add coverage for sync and async header propagation

Why

Hosted SDK calls from a fresh controller were getting blocked by Cloudflare with error 1010 because the stdlib urllib client was not sending an explicit user agent.

Validation

  • cd /Users/openclaw/projects/delega-python && PYTHONPATH=src python3 -m unittest
  • installed this branch on the fresh controller CT and reran /root/work/delega-tests/sdk/sdk-hosted.sh -> 14/14 pass

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 27, 2026

Greptile Summary

This PR fixes a Cloudflare 1010 error that was blocking Python SDK calls from fresh controllers by centralizing version metadata into a new _version.py module and explicitly setting a User-Agent header on both the synchronous urllib-based client and the async httpx client. The fix is minimal, well-targeted, and adds test coverage for header propagation in both transport layers.\n\nKey changes:\n- New src/delega/_version.py establishes a single source of truth for __version__ and the USER_AGENT string (delega-python/0.1.2).\n- __init__.py now re-exports __version__ from _version.py rather than defining it inline — backwards compatible with from delega import __version__.\n- _http.py and async_client.py both import USER_AGENT and inject it into their respective header dicts.\n- tests/test_client.py adds test_auth_header assertion for the sync User-agent and a new test_async_client_sets_user_agent test that mocks _require_httpx to verify the httpx.AsyncClient is constructed with the correct User-Agent kwarg.

Confidence Score: 5/5

Safe to merge — fixes a concrete production outage with a small, well-tested, backwards-compatible change.

The change is minimal and surgical: one new module, two one-line header additions, and two new tests that directly verify the fix. No public API surface changes, version is consistent, and the root cause (missing User-Agent blocked by Cloudflare 1010) is directly addressed. End-to-end validation was reported as 14/14 passing.

No files require special attention.

Important Files Changed

Filename Overview
src/delega/_version.py New file centralizing __version__ and USER_AGENT; clean and correct single source of truth.
src/delega/init.py Replaces inline __version__ assignment with import from _version.py; backwards-compatible re-export.
src/delega/_http.py Adds User-Agent: delega-python/0.1.2 to sync urllib request headers; straightforward and correct.
src/delega/async_client.py Adds User-Agent to the httpx.AsyncClient header dict; correctly placed so all async requests inherit it.
tests/test_client.py Extends existing header test for sync User-agent and adds new async test via _require_httpx mock; both tests are well-structured.

Reviews (1): Last reviewed commit: "fix: send stable user agent from python ..." | Re-trigger Greptile

@ryanmcmillan ryanmcmillan merged commit c8c77d0 into main Mar 27, 2026
5 checks passed
@ryanmcmillan ryanmcmillan deleted the fix/python-sdk-user-agent branch March 27, 2026 02:40
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