t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: Codex instance with managed ChatGPT auth sends remote compaction without Authorization header (401 Missing bearer)

Open 017pixel opened this issue 2 weeks ago • 2 comments

Summary

On a Codex provider instance that was added with the managed ChatGPT setup (setupMode: "managed", token sharing), a thread whose native Codex conversation is large enough to trigger context compaction can no longer run. Every turn fails with:

unexpected status 401 Unauthorized: Missing bearer or basic authentication in header,
url: https://api.openai.com/v1/responses

The request that fails is Codex's own remote compaction (responses_compaction_v2), not a normal turn. Normal turns on the same instance work fine, so the instance is authenticated correctly.

Environment

  • T3 Code 0.1.11-nightly.20261117.4814 (Nightly), macOS 27.0.1, arm64
  • Codex CLI 0.169.0 (codex app-server)
  • Two Codex provider instances:
    • built-in codex (ChatGPT sign-in through ~/.codex/auth.json)
    • an added instance with setupMode: "managed" (ChatGPT token sharing)
  • Thread context at the time of failure: ~218k of a 475k effective window (gpt-6.1-sol, context_window 500000, effective_context_window_percent 95)

Steps to reproduce

  1. Add a second Codex provider instance in the managed ChatGPT setup and sign in with a ChatGPT account.
  2. Confirm it works: a short thread on that instance answers normally, and orchestrator_capabilities lists its models as ready.
  3. Take a thread that already holds a large native Codex conversation (>200k tokens) — for example a thread that was started on the default Codex instance and then switched to the managed instance.
  4. Send any message.

Expected: the turn runs; compaction uses the same credentials as the normal requests.

Actual: the turn starts, a native compaction turn item appears, the compaction request is sent without an Authorization header and fails with 401 after retries. The thread stays failed until it is forked.

Evidence

Codex app-server argv for the managed instance (sanitized) — credentials are only available through the writable auth command of the custom provider:

codex app-server \
  -c thread_unload_delay_secs=0 \
  -c model_provider="openai_token_sharing" \
  -c model_providers.openai_token_sharing={
       name="OpenAI Token Sharing",
       base_url="https://api.openai.com/v1",
       model_catalog_url="https://api.openai.com/v1/models",
       wire_api="responses",
       requires_openai_auth=false,
       supports_websockets=false,
       auth={command="/Applications/T3 Code (Nightly).app/Contents/MacOS/T3 Code (Nightly)",
             args=[".../apps/server/dist/bin.mjs","__managed-chatgpt-token","<tmp>","<instanceId>","<profileId>","<hash>"],
             timeout_ms=80000, refresh_interval_ms=0}
     } \
  -c features.api_key_model_discovery=true \
  -c features.multi_agent=false \
  -c features.multi_agent_v2=false

Provider event log (~/.t3/userdata/logs/provider/events.<thread>.log), trimmed:

{"method":"turn/start","params":{"threadId":"<native-thread>","model":"gpt-6.1-sol","input":[{"type":"text","text":"weiter"}]}}
{"method":"item/started","params":{"item":{"type":"compaction","status":"in_progress"}}}
{"method":"error","params":{"error":{"message":"Error running remote compact task: unexpected status 401 Unauthorized: Missing bearer or basic authentication in header, url: https://api.openai.com/v1/responses"}}}

Notable details:

  • T3 never sends a compaction RPC. The log only contains turn/start, item/* and error, so Codex decides to compact by itself and the failing request originates inside the app-server.
  • The first attempt goes to wss://api.openai.com/v1/responses; Codex logs Falling back from WebSockets to HTTPS transport. unexpected status 401 ... and then fails identically on HTTPS.
  • features.responses_websockets = false in ~/.codex/config.toml does not change the outcome (401 on HTTPS).
  • model_auto_compact_token_limit = 450000 does not prevent the compaction, so it cannot be avoided client-side. model_post_turn_compact_threshold_percent = 90 does not either. Both were reverted.
  • Disabling T3's "Compact idle threads" for the instance changes nothing (T3 is not the one compacting).
  • The same managed instance answers normally on a fresh thread and reports auth.status: authenticated, so this is not a credential problem in general — only the compaction request has no bearer.
  • Forking the thread creates a fresh native Codex conversation and the thread runs again, which confirms the failure is tied to resuming a large native conversation that needs compaction.

Hypothesis

The managed instance only receives credentials through the custom provider's auth command (and requires_openai_auth=false, because there is no auth.json in the instance's shadow home). Remote compaction v2 appears to use a different auth path than regular turns, so the request leaves T3/Codex without any Authorization header and OpenAI answers Missing bearer or basic authentication in header.

If that is intended, compaction should either request a token through the same auth command or the managed instance should get usable credentials for it.

Impact

Any large thread on a managed ChatGPT Codex instance becomes unusable as soon as it crosses the compaction threshold. The only workarounds are forking the thread (new native conversation, losing thread identity) or not using the managed instance for long threads.

Related

  • #5817 (Codex shadow-home handling for managed instances)
  • #25943 (automatic compaction after provider switches)

017pixel avatar Nov 17 '26 07:11 017pixel

I tried to reproduce this on the current build and could not.

Not run in the T3 app: a managed Codex instance needs a real ChatGPT OAuth sign-in, which no VM has. Reproduced the reporter's exact error one layer down, with Codex CLI 0.169.0 (the reporter's version), against a local mock Responses server that logs headers and returns 401 when no Authorization header is sent. On origin/main a2bace5cf4. (1) Plain codex exec on the built-in openai provider (openai_base_url pointed at the mock, API-key auth.json, model_auto_compact_token_limit=1000) created a rollout. (2) Removed auth.json, as in a managed shadow home. (3) Started codex app-server with T3's managed launch args (-c model_provider="openai_token_sharing", model_providers.openai_token_sharing={name="OpenAI Token Sharing",...,requires_openai_auth=false,auth={command=<token script>}}, features.api_key_model_discovery=true, thread_unload_delay_secs=0). Then thread/resume of that rollout followed by turn/start. Result: thread/resume returned modelProvider: "openai". The turn emitted a contextCompaction item, then 'Reconnecting... unexpected status 401 Unauthorized: Missing bearer or basic authentication in header, url: wss://api.openai.com/v1/responses', then the same over HTTPS, then 'Error running remote compact task: unexpected status 401 ... Missing bearer ...', and turn/completed failed. Only the models-catalog GET went through the token-sharing provider; the compaction requests went to api.openai.com without the managed token. Controls: a conversation created on openai_token_sharing compacted locally with 'Bearer ', and codex exec resume <id> with an explicit provider change is refused ('Cannot change this thread's model provider from openai to openai_token_sharing on resume'). T3 reaches this path because CodexManagedProvider and CodexDriver both derive continuationKey codex:home:<sharedHome>, so decideProviderSessionTransition returns restart_and_resume for a default-to-managed switch and T3 resumes the same native thread. Failing test on factory/repro-37979: 4/4 cases of the existing CodexManagedRuntime.test.ts case fail on the new assertion only.

Closing as not planned. If it still happens for you, reply with the exact steps and the version you are on and it will be looked at again.

juliusmarminge avatar Nov 17 '26 07:11 juliusmarminge

I can still reproduce this on T3 Code 0.1.10 (desktop, macOS). It also isn't limited to compaction. After switching a thread from the default Codex instance to a managed ChatGPT instance, every turn fails with 401 Unauthorized: Missing bearer or basic authentication in header, url: https://api.openai.com/v1/responses. The managed instance worked normally in other threads at the same time.

From the provider event log, after the switch:

  • T3 sends thread/resume for the existing native thread to the managed instance's app-server.
  • The result reports "modelProvider":"openai", and the rollout records "model_provider":"openai".
  • Every turn/start after that ends in the 401.

This is the cause found in the repro comment above: CodexDriver and CodexManagedProvider both derive codex:home:<sharedHome>, so the switch resumes the thread instead of handing it off.

#38435 fixes it by adding the managed model provider to the managed continuation key. Default ↔ managed switches then hand off to a new native thread, and managed ↔ managed switches still resume. The PR includes the assertion from factory/repro-37979: it fails on main and passes with the fix.

Noah-mh avatar Nov 18 '26 04:11 Noah-mh