Skip to content

Refactor token ownership and HTTPX request/response adapters - #15

Merged
kdubb merged 6 commits into
mainfrom
codex/token-provider-ownership
Nov 9, 2026
Merged

kdubb merged 6 commits into
mainfrom
codex/token-provider-ownership

Conversation

@kdubb

@kdubb kdubb commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Client settings previously wrapped token providers in a TokenManager, introducing a second cache when an external framework already owned token refresh and invalidation. Transports now use providers directly; applications opt into Sunday caching by supplying a TokenManager.

Changes

  • Add independent RequestAdapter and ResponseAdapter ABCs, asynchronous callable support, and flattened chain_to composition. Each Sunday-managed attempt authorizes and adapts once; request export transfers lifecycle ownership to the caller.
  • Deliver rejected-token feedback to the credential owner independently of response adapters. Preserve effective-credential matching, bounded recovery, and native HTTPX authentication/hook behavior.
  • Add RequestCancellationError as an unconditional stop signal, preserving its identity through retries, SSE reconnects, encoding/decoding, and nullable operations.
  • Consolidate cancellation-safe native I/O and response cleanup, retain bulk buffered reads, and fix SSE early exit, concurrent close, immediate reconnect, retiring-run cleanup, and reentrant transport shutdown. External shutdown callers still wait for cleanup.
  • Support eager and deferred asyncio task factories during token renewal and EventSource startup. Share stream ownership checks for reentrant close and shutdown, and sanitize managed HTTPX request/status errors across request adapters, native hooks, and response processing while preserving response metadata and cancellation identity.
  • Preserve request framing, Host updates, native cookie handling, and redirect/authentication history. Add real TCP regression coverage and document the lifecycle ownership audit.

Compatibility

ClientSettings.token_providers and HttpxTransport(token_providers=...) replace manager-based wiring; TokenManagerFactory is removed. Existing legacy adapters= remain supported. Custom transport integrations should use execute_request for managed execution and retain transport_request for export. README migration guidance covers explicit caching and the new adapter contract. Generator and other-runtime updates are outside this PR.

Validation

  • 1,102 tests passed on each of Python 3.12, 3.13, 3.14, and minimum dependencies, using OAuth replay fixtures.
  • Coverage: 92.92–92.94%; Ruff formatting/lint, mypy across 78 files, and Git diff checks passed.
  • Wheel/sdist build, Twine and wheel-metadata validation, fresh core-only and optional-extra installation smoke tests, installed-wheel redirect behavior, and dependency checks passed.
  • Regression coverage includes real TCP cancellation, EOF/early-exit cleanup, reentrant and concurrent shutdown, retiring EventSource runs, eager/deferred EventSource startup shutdown with concurrent external closers, and upload framing. Managed-error diagnostic tests cover query/header/cookie credentials, request-adapter and send failures, native status errors, response-adapter reads in buffered and streaming execution, buffered collection, status/body/metadata preservation, and cancellation/unmanaged error identity. Token renewal tests cover acquisition and refresh under both task factories, coalescing, cache reuse, cancellation identity, and recovery after cancellation.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T17:46:34.643192Z 2bfe226 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues remain.

Summary

The PR lets applications own token refresh directly and separates request adapters from response adapters. It also separates managed execution from request export and strengthens cancellation and cleanup behavior.

  • HTTPX asks the supplied provider for credentials on each managed attempt.
  • Managed HTTPX requests and responses pass through separate adapter chains.
  • HTTPX and SSE cleanup waits for active work without losing stop signals.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Build request] --> B{Execution owner}
    B -->|Caller| C[Authorize and adapt once]
    C --> D[Export native request]
    B -->|Sunday| E[Authorize and adapt attempt]
    E --> F[Send through HTTPX]
    F --> G[Notify credential owner]
    G --> H[Adapt response]
    H --> I{Retry or redirect allowed?}
    I -->|Yes| J[Finish response cleanup]
    J --> E
    I -->|No| K[Return or decode response]
Loading

Reviews (2) · Last reviewed commit: "Sanitize managed response execution erro..." · Reviewed by Greptile

Comment thread src/sunday/httpx/_response_cleanup.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 02826952fb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/sunday/httpx/_transport.py Resolved
Comment thread src/sunday/httpx/_requests.py Resolved

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f4c48dd246

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/sunday/httpx/_transport.py Resolved
@kdubb
kdubb merged commit b8519c9 into main Nov 9, 2026
5 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.

1 participant