Request executor seam: bring your own executor, in all seven SDKs
Every generated operation and every §18 composite now builds a typed request and hands it to a request executor. The default executor is the stack we had before: auth, retry, the ETag cache and hooks, over Transport. An app can supply its own executor. The SDK's retry, auth, cache and redirect policy then step aside, and each call (each page of a walk) is exactly one execute. Hooks still fire. All seven SDKs.
This reworks the earlier per-call request options (8fc7921b) into that seam. Request options are kept: configure still can't change the method or origin (verified, not redone), and it is refused under an app executor.
What's in it
- SPEC §13 "Request Executor" [conformance]. The request and response records, the rule that only one executor is active, the headers being the complete set (set, never append), response mapping, bodies, downloads, and a per-SDK table.
cache_missis a new error code (exit 11, not retryable). A 504 answering anonly-if-cachedrequest becomescache_missand is never retried, under the default stack too (§6).- An executor that sends validators of its own resolves its 304 to the stored 200. A raw 304 is
api_error. - Upload progress is a capability an executor declares (
supportsUploadProgress, false unless declared). The SDK never waits on it. User-Agentmay be replaced by the executor (append the SDK token).AcceptandContent-Typearrive once and unchanged.
- A shipped executor conformance suite in each SDK, with seven cases: sends-as-given, statuses-pass-through, non-idempotent-once, cache-miss, revalidation, streaming-body and cancellation. The default executor passes it in every SDK. Each SDK has tests in which a deliberately broken executor fails only its own case.
- §13 "Cache Policy and Reactive Reads" (Swift, Kotlin, TypeScript).
- The cache-policy key: default, cacheOnly, or networkOnly (RFC 9111
no-cache). It reaches an executor only on a GET. observe/Observed<T>: a cache pass, then a networkOnly pass.observePagesis specced here and implemented after #1139.
- The cache-policy key: default, cacheOnly, or networkOnly (RFC 9111
- The SDK's ETag store (Swift, TypeScript) keys an entry on the URL and the credential headers the strategy set, and keeps
Link,X-Total-Countand the final URL. It steps aside for a call withconfigureor any caller header; such a call under cacheOnly iscache_misswith nothing sent. A 304 is answered only from the entry whose validator went out. Entries are evicted on 401/403/404/410. Go's store (WithCache) still follows its older rule: keyed onAuthorization, stepping aside only for conditional headers, and never evicting. That is an open finding (see the summary comment). - Hooks: operation and request hooks each fire exactly once per call, on both stacks, cancellation included, and each SDK pins this with tests. One exception is open: a TypeScript download cancelled during hop 1's retry backoff is reported to fire
onRequestEndtwice. - §18 rule 7. Composites forward request options to every call. A merge-safe composite's read always revalidates (networkOnly,
Cache-Control: no-cache), so a cache can't feed a stale body into the write. - Redirects (§13 "Redirect Handling").
- A hop that leaves the API origin carries no credential. Every SDK that follows one (Go, Swift, Kotlin, TypeScript) keeps an allowlist on that hop:
User-Agent,Accept, andContent-Typewhen a body goes with it, less any of those the auth strategy set. On the SDK's own stack, a header an app's wrapper orconfigureadded doesn't leave the origin. An injected KtorHttpClientor a custom TypeScriptfetchkeeps its own redirect policy. Python, Ruby and Rust don't follow redirects. - A 3xx on an API request that the stack doesn't follow is
api_errorwith its status. The message names theLocation's origin only. - TypeScript: outside browsers, manual redirects with the same allowlist; in browsers, a request carrying any header the SDK doesn't set itself (or
configure) goes out withredirect: "error", since a browser's opaque redirect can't be inspected.
- A hop that leaves the API origin carries no credential. Every SDK that follows one (Go, Swift, Kotlin, TypeScript) keeps an allowlist on that hop:
- Streaming request bodies (file, stream or bytes) with upload progress, in every SDK. Progress is reported where the stack can do it.
- MIGRATING "Unreleased": the app-executor recipe, with OkHttp and URLSession sketches. AGENTS.md lists the new hand-written infrastructure files.
Review map
- SPEC: §13 "Request Executor", "Cache Policy and Reactive Reads", "Redirect Handling", "Per-Call Request Options"; §6
cache_miss; §18 rule 7. - The seam, per SDK:
go/pkg/basecamp/executor.go,typescript/src/executor.ts(+redirect.ts,client.ts),ruby/lib/basecamp/executor.rbanddefault_executor.rb(+http.rb),swift/Sources/Basecamp/HTTP/RequestExecutor.swift(+HTTPClient.swift,ETagCache.swift),kotlin/sdk/src/commonMain/kotlin/com/basecamp/sdk/Executor.ktandDefaultExecutor.kt(+http/BasecampHttpClient.kt),python/src/basecamp/executor.pyand_executor_http.py,rust/basecamp-sdk/src/executor.rs(+client.rs,hooks.rs). - Shipped conformance suites:
go/pkg/basecamp/executortest/,typescript/src/executor-conformance/,ruby/lib/basecamp/executor_conformance.rb,swift/Sources/BasecampExecutorConformance/,kotlin/.../testing/ExecutorConformance.kt,python/src/basecamp/testing.py,rust/basecamp-sdk/src/executor_conformance.rs. - One generated sample per language (the generator change shows in each):
typescript/src/generated/services/projects.ts,ruby/lib/basecamp/generated/services/projects_service.rb,swift/Sources/Basecamp/Generated/Services/ProjectsService.swift,kotlin/.../generated/services/projects.kt,python/src/basecamp/generated/services/projects.py; Go wrapsgo/pkg/generated/client.gen.gothroughexecutor.go, and Rust's generated services callclient.rs's executor path. - What conformance proves: the default executor passes all seven cases in every SDK, and for each case a deliberately broken executor fails that case alone. The redirect credential rule and the ETag store are unit-tested per SDK (two loopback origins), not conformance-tested.
- Release level: breaking (Swift/Kotlin signatures, new error case). MIGRATING "Unreleased" carries the app-executor recipe.
Departures and per-SDK notes
- Python, Ruby, Go, Rust: no cache-policy key or
observe. The brief scoped those to Swift, Kotlin and TypeScript. - Bodies with no retry: Ruby's and Python's default executors keep their existing rules (GET-only and idempotent-only retry).
retryPolicyreports 1 attempt where the SDK never retries. - Construction refusals: Go panics on a refused construction (an executor beside a transport), as
NewClientalready does. Rust accepts credentials given beside an executor and ignores them, matching Go and Ruby. - Swift: no 401 replay under the default executor, as before.
- TypeScript:
defaultExecutor(when used standalone) has no ETag cache and fires no hooks. A client built without an executor keeps the old wiring.- Streaming bodies work in Chromium only.
- Kotlin: an app wrapping
DefaultExecutorsees hooks fire on the client and per attempt inside the wrapped stack. - Redirect credential rule: pinned by a unit test per SDK over two loopback origins, and marked
[manual]. It becomes a conformance case once #1145's second origin is in this base. - Behaviour changes on redirects:
- Go, Swift, Kotlin and TypeScript now keep only
User-Agent,AcceptandContent-Typeon a cross-origin hop. - Ruby refuses an executor status outside 200–599 (so 1xx too); Python accepts 100–599.
- Python and Ruby raise an unfollowed 3xx as
api_error, where they used to fail decoding an empty body.
- Go, Swift, Kotlin and TypeScript now keep only
What breaks
- Swift and Kotlin: generated method signatures gained a parameter, so code compiled against earlier versions must recompile.
- Exhaustive error matching: Swift
BasecampErrorand KotlinBasecampExceptiongain acacheMiss/CacheMisscase. Exhaustive switches over error codes elsewhere should expectcache_miss. - Redirect behaviour: see the notes above.
Not in this PR
- Page siblings carrying options, and
observePages. These come on a rebase after #1139. - Server-provided action URLs (hypermedia). That is a separate lane, pending a decision.
Landing waits for a person's review of the generators and contracts. This PR changes SPEC, so merging it starts a release.