OpenAI OAuth refresh lacks an explicit end-to-end HTTP deadline; preserve rotation commit safety
Source-level follow-up
While reviewing cancellation safety for #1756, a separate authentication wait boundary was found in upstream a61c38ee9:
crates/jcode-base/src/auth/oauth.rs,refresh_openai_tokens_inner: refresh awaits HTTPsend, then error text or success JSON, before synchronously persisting the rotated credentials for a stored account.crates/jcode-provider-core/src/lib.rs,shared_http_client: configures a 15-second connection timeout and transport keepalive, but does not configure an overall request or body-read timeout.crates/jcode-provider-openai-runtime/src/openai_stream_runtime.rs,force_refresh_openai_token: subsequently commits the returned credentials to the in-memory credential lock.
A connection timeout bounds establishment, not a server that accepts the connection and never returns headers or finishes the response body. Thus the refresh phase does not have an explicit end-to-end deadline in this path. This is source inspection, not attribution of any specific incident or a live-account reproduction.
Why this should be separate from stream cancellation
Blindly canceling the entire refresh future is unsafe: a remote rotation may have succeeded while local persistence and in-memory commit are unfinished. Likewise, spawning an unbounded detached refresh task hides rather than resolves the waiting problem.
The focused #1756 stream fix should preserve the existing inline rotation/persistence transaction. This follow-up should separately design bounded network waiting together with correct rotation, persistence, account-scoped coordination, and error/recovery semantics. Do not impose a timeout that simply drops the post-rotation persistence or commit phase.
Acceptance and synthetic verification
- Define and document a finite policy for refresh network header/body waiting. Verify it against loopback servers that accept a request but withhold headers, or provide an incomplete body.
- Preserve existing account-scoped refresh coordination and rotated-token persistence semantics. A waiting caller's cancellation must not corrupt another account's or another transaction's credentials.
- Use gated synthetic transaction tests for cancellation before rotation, after a synthetic successful rotation, during persistence, and before in-memory commit. Distinguish safely canceled work from an already-started shared transaction.
- Cover normal success, error responses, malformed JSON, persistence failure, concurrent refresh, and the case where transport failure leaves remote rotation outcome uncertain. Do not automatically reset credentials or repeatedly reuse a known-invalid refresh token.
- Surface bounded, privacy-safe failure states without logging tokens, authorization headers, account identifiers, response credential bodies, or local credential paths.
- Use dummy credentials and isolated test storage only. No live authentication endpoint calls, customer transcripts, or real credential stores are required for regression tests.
No timeout or cancellation-policy change is claimed here. This report contains no incident logs, session identifiers, user prompts, credential values, private filesystem paths, or account information.
Thanks. This needs a design decision (refresh deadline policy that preserves rotation and persistence safety), so I've flagged it for the maintainer. #1758 keeps the existing transaction intact, as you suggested.
--- — Jcode agent (automated triage), on behalf of @1jehuang