t3code icon indicating copy to clipboard operation
t3code copied to clipboard

[Bug]: t3-code MCP intermittently fails mid-session with "rejected the Authorization header" and flips to needs-auth, then recovers by itself

Open jamesdchen opened this issue 4 weeks ago • 6 comments

Before submitting

  • [x] I searched existing issues and did not find a duplicate. Nearby but different: #14076 (closed; credential expiring after a turn waits over 24 hours), #17633 (closed; env scrub, fails every session from the start), #23710 (Authorization scheme case), #16565 (token scoped to the old provider after a provider switch; fails with parent_not_active, not an auth rejection).
  • [x] I included enough detail to reproduce or investigate the problem.

Area

apps/server (MCP session credentials), possibly its interaction with Claude Code's MCP client

Version

T3 Code (Beta) desktop 0.1.6, Windows 11. claude on PATH is 2.1.316. Claude provider, model claude-opus-5-5.

Steps to reproduce

I don't have a deterministic reproduction. It happened while running:

  1. A long Claude parent thread acting as a coordinator, about 18 hours old, which had been switched between providers earlier.
  2. About nine delegate_task Claude children at once, several of them calling t3-code tools.
  3. Continuing for about two hours.

Expected behavior

t3-code tools stay authorized for the life of the provider session, or fail with an error that says what happened and recovers without the agent or the user acting.

Actual behavior

t3-code tool calls intermittently failed, in the parent and in child threads, with:

MCP server "t3-code" rejected the Authorization header in its config (update it, then run /mcp to reconnect)

Then it recovered by itself. Nobody updated any config or ran /mcp.

Provider event logs, 2026-11-02 UTC.

  • At least 11 failed tool results (is_error: true), from 21:13:16 to 21:56:45. Parent thread: 21:21:52, then 21:55:59, 21:56:17, 21:56:22, 21:56:28. Child threads: 21:13:16, 21:13:29, 21:15:10, 21:31:25, 21:39:24, 21:56:45 (I grouped these logs by a shortened name, so these may be more than one child).
  • system/init events show t3-code changing between connected and needs-auth on the same threads, with source: dynamic. For example, the parent is needs-auth at 21:25:13, connected at 21:33:54, needs-auth at 22:06:25 and connected at 22:58:32. Across the child threads, it changed about 15 times between 21:23 and 23:01 (again, possibly more than one child).
  • Other agents in the same period reported the same error from t3_background_wait, so it isn't specific to one tool.

Server trace, for the part I still have (the rotated logs start at 21:43:52). McpHttpServer.authenticateRequest shows 87 records, all Success, and no failure, including across the 21:55:59-21:56:45 burst. So those rejections either don't produce a failed span or never reached this check. I can't tell which from here. The same trace shows McpSessionRegistry.revokeThread + issue at 21:52:25, and revokeProviderSession from 22:05:48 onward, but I haven't established that they're related.

Effect. During these windows an agent can't start or message delegates, or edit scheduled tasks. The error tells it to update config and run /mcp, which is misleading here, because the condition cleared with no action. Agents relay that to the user as something they must fix.

I haven't verified a cause, so the above is observation only. I can provide more log excerpts if useful.

jamesdchen avatar Nov 02 '26 23:11 jamesdchen

I tried to reproduce this on current main (a036489) with a fresh dev server on Linux, Claude Code as the provider, and Opus 5.5. I could not get a rejection.

  • One Claude thread calling t3_thread_list. t3-code showed connected and the call succeeded.
  • The same thread switched Claude → Codex → Claude, with a t3-code call on each leg. No auth rejection. After the switch back, delegate_task failed with parent_not_active, which is https://git.cafe/pingdotgg/t3code/issues/16565, not this error.
  • A fresh Claude parent starting 4 Claude delegate_task children, each calling t3_thread_list 5 times, then waiting and being woken by them. All 20 child calls and the parent's calls succeeded. Every system/init showed connected and no tool result had is_error.
  • This machine's own server, which runs the same kind of long-lived Claude coordinators with many Claude delegates, logged no MCP credential rejections over the last two days.

The trace you checked can't settle this one way or the other. When the server rejects a token, it returns the 401 from inside a span that still ends in Success and only logs a warning. Those warnings never reach server.trace.ndjson. So "87 Success records" is consistent with server-side rejections.

From the next window where this happens, could you share:

  1. The lines containing rejected MCP request with an unusable credential from server-child.log, which is in the same logs folder as server.trace.ndjson. Include the reason field and timestamps. The token values are not logged.
  2. For one failing thread, the provider event log (logs/provider/events.<thread>.log) from the last system/init before the first failed call through the next connected. Please redact the Authorization header if it appears.
  3. Anything that happened to the parent or those children in that window: a model or provider change, especially by sending a message with a different model selected; archive or settle; a change to agent browser or device access; or the desktop backend restarting.

juliusmarminge avatar Nov 02 '26 23:11 juliusmarminge

Thanks. Answers from the window I still have logs for, 2026-11-02 UTC. The build is v0.1.6 on Windows, not current main, in case that matters for your reproduction.

1. server-child.log. I can't provide it, because it isn't on this machine. %USERPROFILE%\.t3\userdata\logs holds server.trace.ndjson*, desktop.trace.ndjson*, event-loop-stalls.ndjson, renderer-history.ndjson* and provider/. The warning text is in resources/server.asar, so the code is there. Where does that warning go on the packaged Windows desktop build? If there's a setting that writes it to a file, I'll turn it on and send the lines from the next window. And thanks for the correction: my "87 Success records" point doesn't show what I implied.

2. Provider event log, one failing thread. This is a condensed timeline of the parent thread, with event types and timestamps only, since the raw log holds private work. init is the system/init status of t3-code. All of it is one Claude session (session_id d0c883b6...).

UTC Event
20:59:52 init connected, first turn after the provider switch below
21:00:11-21:21:46 t3-code calls in use, including 9 delegate_task at 21:06-21:10, plus schedule_task, t3_thread_read, t3_thread_list, with no rejection recorded
21:19:48 Last init connected before the first failure
21:21:52.855 schedule_task issued
21:21:52.911 is_error: rejected the Authorization header, 56 ms later
21:25:13, 21:26:07, 21:29:05 init needs-auth
21:29:20-21:29:51 delegate_task calls, which worked while init said needs-auth: they started children that ran
21:33:54 init connected, with no action by the user or the agent
21:52:11-21:52:25 delegate_task worked
21:55:11 Last init connected before the second burst
21:55:59-21:56:28 4 calls (delegate_task, t3_thread_send), each rejected within about 15-40 ms of being issued in the log
22:06:25 onward init needs-auth
22:58:32 init connected again (from the status scan in my report)

So init and the tool outcome disagree in both directions: calls worked during needs-auth, and a call was rejected while the latest init said connected. A child thread log shows the same error and status changes, starting earlier, at 21:13:16.

I can send more detail on a specific interval if useful, redacted first.

3. What happened in the window.

  • Provider change: yes. At about 20:59:50, 22 minutes before the parent's first rejection, this thread was changed from Kimi to Claude Opus 5.5 by sending a message with the new model selected. It had earlier run on Claude and then Kimi, so this was a switch back to Claude, close to your #16565 sequence. It didn't produce parent_not_active, though, and the children failed too, even though nobody switched them.
  • Delegates: about nine Claude children started from 21:06. Your 4-child test is similar in shape, but these ran longer and did many long-running shell commands.
  • Scheduled task: a recurring schedule_task bound to this thread, every 20 minutes, was edited several times in the window. The parent's first rejected call was one of those edits.
  • Runtime mode: the change to full-access was at 22:59:57, after both bursts (that's the #16000 path).
  • Backend: the desktop process dates from Nov 1, so it wasn't restarted. I can't speak for the backend child separately.
  • Archive/settle: I have no record of any in this window. No change to browser or device access that I know of.

Next time. I can capture the logs as soon as a rejection appears, if you tell me where the warning is written.

jamesdchen avatar Nov 02 '26 23:11 jamesdchen

It happened again, in the same thread and on the same v0.1.6 Windows build, so here's a newer window (2026-11-02 UTC). Same format: event types and timestamps only.

UTC Thread Event
23:25:28 parent init connected
23:31:57 child init needs-auth
about 23:38 parent 3 delegate_task calls succeeded (they started children that are running)
23:40:02 child init connected
23:44:24 child init needs-auth
23:44:37.925 parent t3_thread_read rejected: "rejected the Authorization header"
23:46:17 parent init needs-auth

Child rows come from logs I grouped by a shortened file name, so they may be more than one child.

For your question 3:

  • Model or provider: the last switch I know of on this parent is still 20:59:50, almost three hours earlier. So a provider switch shortly before isn't needed for it to recur.
  • Runtime mode: the parent went to full-access at 22:59:57. It read auto again by 23:08, so there was at least one more mode change before this window, which I can't time precisely.
  • Delegates: about ten Claude children were active. The parent had started 3 about 6 minutes before the rejection, and those succeeded.
  • Desktop process: same start time as before (Nov 1), so no restart. Free memory was about 2.5 GB at last check, and has been as low as 0.5 GB today.

server-child.log still doesn't exist on this machine, so I still can't give you the reason field. Tell me where that warning goes on this build and I'll capture it next time.

jamesdchen avatar Nov 02 '26 23:11 jamesdchen

Thanks, the timeline helps. I ran more tests on current main (71646e0): a fresh Linux dev server, Claude Code 2.1.304, Opus 5.5.

  • One Claude thread calling t3_thread_list, then a second turn of the same thread. Both calls succeeded.
  • A Claude parent with 3 Claude delegate_task children. Each child ran a background shell command, then called t3_thread_list 3 times. The parent created a 20-minute schedule_task bound to itself, edited it 3 times (calling t3_thread_list after each edit), waited for the children, read them, and deleted the task. Every t3-code call succeeded, and the server logged no rejected credential.
  • Claude Code against a stub MCP server named t3-code that starts returning 401 partway through a session. This produces your exact text: MCP server "t3-code" rejected the Authorization header in its config (update it, then run /mcp to reconnect). So each failed call you saw was a real HTTP 401 for the header that Claude process held. A 401 in one Claude process (using the same Claude config dir) did not affect a T3 thread that was already running, so this isn't Claude Code spreading one failure across sessions.

Your question 1. On the packaged desktop build, that warning isn't written to disk. It goes to the backend's stdout, which the desktop writes to server-child.log only when the backend fails, and it doesn't become an event in server.trace.ndjson. No setting changes that, so please ignore my earlier request for it.

The detail that stands out is delegate_task working at 21:29 while init still said needs-auth. Once T3 revokes a token, it never accepts it again. So either those requests were answered by something other than this backend at the moments they failed, or something else happened. From the server.trace.ndjson you still have (from 21:43:52), could you share the following? Names and timestamps are enough; no ids or content needed.

  1. For each failed call between 21:55:59 and 21:56:45, any McpHttpServer.authenticateRequest span that starts within a second of it, with the names of the spans under it. A rejected request shows up as authenticateRequest with only McpSessionRegistry.resolve (and maybe McpHttpServer.McpClientAuthenticator.authenticate) under it, and no McpServer.* span. If no authenticateRequest span lines up with a failed call, that request never reached this backend.
  2. Every McpSessionRegistry.revokeThread, McpSessionRegistry.issue and McpSessionRegistry.revokeProviderSession span between 21:50 and 21:57, with its parent span's name.
  3. The port your desktop backend listens on (3773 unless it had to pick another), and whether any other server was running on that machine in the window: a T3 dev server, npx t3 or t3 serve (for example one started by the agents' shell commands), or a WSL backend. Next time it happens, the output of netstat -ano | findstr :<port> would show who is listening.

juliusmarminge avatar Nov 02 '26 23:11 juliusmarminge

Found it, and it's my setup, not a T3 credential bug. Your point that those requests might be answered by something other than this backend was right.

Cause. My SSH config has this for the Linux machine, so I can open its T3 in a browser:

Host james-intel
    LocalForward 3773 localhost:3773

The Windows backend listens on 0.0.0.0:3773. Any ssh james-intel, including short commands that agents ran over SSH for other reasons, also binds 127.0.0.1:3773 and [::1]:3773. Windows sends localhost:3773 to those more specific listeners. Claude's MCP URL is http://localhost:3773, so while such a session is up its calls reach the other machine's T3, which correctly returns 401 for a token it never issued.

Direct test (/.well-known/t3/environment, both servers on 0.1.6):

127.0.0.1:3773 PC's LAN IP :3773
No SSH session this PC (c548ff35...) this PC
ssh james-intel running james-intel (acb57edc...) this PC

It fits the timeline.

  • My first ssh james-intel was at 21:12:16, and the first rejection was at 21:13:16.
  • ssh james-intel at 23:44:31, then the rejection at 23:44:37.
  • Agents ran ssh james-intel at 21:55:04 and 21:55:21, just before the 21:55:59 burst. I haven't matched every failure to a session.
  • It explains delegate_task working during needs-auth: the status came from a moment with a forward up, the call from a moment without one.
  • It explains why you couldn't reproduce it, and why the backend shows no failed authenticateRequest span for these calls.
  • The spans missing around 23:38 are a separate question I haven't resolved.

So please ignore my provider-switch and releaseIfStillIdle leads; they were coincidental. I'm fixing this on my side by moving the forward to another port and using -o ClearAllForwardings=yes in scripted sessions.

This can be closed as a local setup issue, unless you'd like to make it easier to diagnose. Two small things would have saved a lot of time, and it's your call whether they're worth doing:

  1. When a provider's t3-code MCP call gets a 401, T3 could check that localhost:<port> still reports its own environmentId and say so if it doesn't. The current message tells the user to update config and run /mcp, which doesn't help here.
  2. The MCP URL could use the backend's unique instance ID as a check, or the provider could connect by a path that a port forward can't shadow.

Thanks for the pointers. "Answered by something other than this backend" is what cracked it.

jamesdchen avatar Nov 03 '26 00:11 jamesdchen

Thanks for tracking this down. That explains every symptom, including why it never reproduced here.

I checked the mechanism on Linux at current main (57cd059): with a listener on 0.0.0.0:<port>, a second bind to 127.0.0.1:<port> fails with EADDRINUSE, so an SSH LocalForward cannot take the port there. Windows allows the more specific loopback bind, which lets the forward answer the provider's MCP calls. On main, the server builds the provider's MCP URL as http://127.0.0.1:<port>/mcp when it listens on all interfaces (McpSessionRegistry.ts), and your table shows 127.0.0.1 is shadowed as well.

Closing this as a local setup issue. Your two ideas (checking environmentId after a 401, or an MCP address a forward can't shadow) are worth considering as an improvement on their own.

juliusmarminge avatar Nov 03 '26 00:11 juliusmarminge