Skip to content
Source
Sign inSign up
pingdotgg/t3code

[Bug]: Delegated Codex child threads keep their MCP server processes for ~60 min after the task completes #21905

ClosedKrarilotus(GitHub profile, opens in a new tab) opened this issue 1 comment

Before submitting

  • I searched existing issues and did not find a duplicate.
  • I included enough detail to reproduce or investigate the problem.

Area

apps/server

Steps to reproduce

  1. Configure a stdio MCP server in ~/.codex/config.toml. Any idle server works; a minimal stub is included below. Leave thread_unload_delay_secs unset for the default-delay case.
  2. In a T3 conversation, call delegate_task to a Codex model with a trivial task such as "reply READY". Wait for the delegated task to complete; leave the child idle, with no pending runs or background work.
  3. Watch descendants of the shared codex app-server and thread/unsubscribe / thread/closed in T3's provider protocol logs (<T3 home>/userdata/logs/provider/*.log). Repeat short delegated tasks to observe accumulation.

Related reports describe different paths: #15979 / #16917 introduced idle unloading; #21354 / #20048 concern Codex-native subagents and threads that never unsubscribe; #20348 concerns a parent-settle/subscription race. Here app-owned delegated tasks complete successfully and unsubscribe, but retain their MCP processes for about an hour. Also related: #20717 reports orphaned Claude grandchildren; #18485 reports memory growth with an unproven cause. Neither is evidence of this specific retention path.

Minimal stdio MCP stub

Save as dummy-mcp.mjs and configure [mcp_servers.dummy] with command = "node" and args containing its absolute path (use forward slashes on Windows). The stub owns one child so process-tree cleanup can be observed.

// Minimal stdio MCP server that also owns one long-lived grandchild process,
// so the test can see whether a whole MCP process tree is ended.
import { spawn } from 'node:child_process';
import { createInterface } from 'node:readline';

spawn(process.execPath, ['-e', 'setInterval(() => {}, 1 << 30)'], { stdio: 'ignore' });

const send = (msg) => process.stdout.write(JSON.stringify({ jsonrpc: '2.0', ...msg }) + '\n');
createInterface({ input: process.stdin }).on('line', (line) => {
  let req;
  try { req = JSON.parse(line); } catch { return; }
  if (req.id === undefined) return;
  if (req.method === 'initialize') {
    send({ id: req.id, result: { protocolVersion: req.params?.protocolVersion ?? '2025-06-18', capabilities: { tools: {} }, serverInfo: { name: 'dummy', version: '0.0.1' } } });
  } else if (req.method === 'tools/list') {
    send({ id: req.id, result: { tools: [] } });
  } else {
    send({ id: req.id, error: { code: -32601, message: 'not implemented' } });
  }
});

Expected behavior

After a delegated task's result is published and the child has no pending work, release its provider thread promptly, preserving history and later follow-ups through resume. Keep active turns and background work protected.

Actual behavior

In the observed default configuration, T3 sends thread/unsubscribe 30 minutes after completion. Codex retains the unsubscribed idle thread for another 30 minutes before thread/closed; its MCP processes exit then. This is delayed reclamation, rather than orphaned processes in these cases.

Source inspection of main at f740a97947cc701859040e530e7fe07b96d02ae5 (2026-10-19), not a fresh runtime reproduction of that commit:

  • ProviderSessionManager.ts: scheduleThreadUnload / unloadIdleThread use the idle timeout, with busy-turn, pending-background-work and generation guards. The default is 30 minutes (line 56); production layer = layerWithOptions() (line 2479) is used by runtimeLayer.ts (line 133).
  • Orchestrator.ts: finalizeAppOwnedSubagentTask maps delegatedTaskTerminalStatus, publishes completion/result events, and does not request a provider-thread unload in this completion path.
  • CodexAdapterV2.ts: unloadThread sends thread/unsubscribe; the adapter does not set thread_unload_delay_secs in its start/resume config overrides.

Possible direction for triage: release idle delegated children through the session manager after result delivery, reusing its guards, perhaps with a short grace period. Codex #55270, merged 2026-10-19, honours per-thread unload-delay overrides (0 permits immediate cleanup once unsubscribed and inactive). That could remove the second delay on versions containing the change; it was not tested with the observed 0.163.0 binary.

Impact

Major degradation or frequent failure

Memory scales with recent delegation volume as well as active work. In this setup, roughly 20 short delegated reviews/hour left 26 loaded threads, 104 MCP-related processes and about 3.5 GB working set, mostly for completed tasks. Process counts and memory depend on the configured MCP servers; these are observations from one machine.

Version or commit

T3 Code 0.1.0, Beta Windows x64 installer, server bundle built 2026-10-16. Source path rechecked on main at f740a97947cc701859040e530e7fe07b96d02ae5.

Environment

Windows 11 25H2 (build 26200), Node 24.19.0, codex-cli 0.163.0, one shared Codex app-server, two configured stdio MCP servers. A multi-agent orchestration host running short delegated tasks.

Logs or stack traces

Observed 2026-10-19, UTC, from the provider protocol log:

Delegated task completedthread/unsubscribethread/closed (MCP processes exit)
18:10:4318:40:4319:10:43
18:31:3419:01:3419:31:34
18:33:4319:03:4319:33:43
18:56:1319:26:13Ended manually before close
19:06:1219:36:12Ended manually before close
19:07:4819:37:48Ended manually before close

MCP process starts matched thread/start within 0–4 seconds. In naturally closed cases, the whole tree exited at thread/closed, including grandchildren.

Separate model-free control with a throwaway CODEX_HOME, the stub above and server-wide thread_unload_delay_secs = 20: thread/start at +0.4 s, unsubscribe at +1.4 s, thread/closed and MCP tree gone at about +23.4 s. Hard-killing a separate test app-server also ended its MCP tree. These controls support working teardown on this Windows setup, not a general guarantee for all MCP servers.

Workaround

Set top-level thread_unload_delay_secs = 300 in ~/.codex/config.toml, then restart the app-server for it to take effect. This reduces the Codex-side delay from 30 to 5 minutes; T3's 30-minute window remains, so expected combined retention is about 35 minutes rather than 60.

  1. Note

    Grok responding on behalf of Julius.

    Thanks for the stub and the clear timeline. What you measured is the idle unload working as designed.

    T3 unsubscribes a provider thread after it has been idle for 30 minutes (apps/server/src/orchestration-v2/ProviderSessionManager.ts:56, :1548-1565), and the server uses that default with no setting (ProviderSessionManager.ts:2479). Finishing a delegated task doesn't unsubscribe early, and the Codex adapter doesn't change Codex's own unload delay. Codex then keeps an unsubscribed idle thread for its default 30 minutes before closing it. Together that adds up to the hour you saw. Nothing is orphaned.

    This isn't a duplicate of #21354, which covers threads that are never unsubscribed.

    Releasing delegated children right after their result is delivered would be new behavior. Please open an Idea for it: https://github.com/pingdotgg/t3code/discussions/new?category=ideas

    For now, setting thread_unload_delay_secs in your Codex config shortens the Codex half of that wait. The 30 minutes on the T3 side stays the same.

    Closing this as working as intended.

  2. juliusmarminge added labelsenhancement

  3. juliusmarminge added labelsvia-triage

  4. juliusmarminge closed this

Sign in to join this conversation.