Repository navigation
Description
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
Linux with a systemd user manager, so agent scopes are on. The model turn in step 2 was not run for this report; the same outcome happened on its own (see Actual behavior), and the systemd half is checked without a model below.
- Start the T3 server (0.1.13, or main at
ff26e6a632) with the Codex provider enabled. - In a Codex thread, ask the agent to run a command that detaches a daemon from its process group, for example
setsid -f sleep 3600, orpg_ctl -D <dir> -o "-p 55439" -l <dir>.log -w starton a scratch cluster. Let the turn finish. - Leave every Codex thread idle for more than 2 minutes, so the session manager releases the shared Codex session and the app-server process ends (or end it with
kill <app-server pid>). - Run
systemctl --user list-units 't3code-codex-*'andsystemd-cgls --user-unit <that scope>.
Mechanism check without a model turn, on systemd 259 and kernel 7.0: a scope launched with the options a shared Codex scope gets (--scope --collect --property=OOMPolicy=continue --property=TimeoutStopSec=10s --property=Delegate=yes), whose main shell starts setsid sleep 900 and is then sent SIGTERM, still reads ActiveState=active with the daemon inside it 30 s later. systemctl --user stop --no-block <scope> then removes the unit and the daemon.
Expected behavior
When the app-server exits, its scope is stopped and the daemons it started end with it. That is what Claude, ACP, Pi, Muse and Cursor scopes do, under the rule #21299 set: "Agent-started background work, including intentional daemons and dev servers, ends with its owning agent/session, including ... the 30-minute idle release".
Actual behavior
The old t3code-codex-<id>.scope stays active with only the daemon inside it and no Codex process. The next Codex turn starts a new app-server in a new scope. The old scope is stopped only when the T3 server next starts (stopLeftoverAgents), so on a host whose server runs for days the daemon runs for days.
Seen on a headless Linux host running the server as a systemd user service:
- 2026-11-27 16:44Z: a new Codex app-server initialized in
t3code-codex-fa363ada.scope. - 16:47:30Z: a Codex thread ran
pg_ctl -D <scratch dir> ... -w start; the command completed and Postgres daemonized. - 17:26:31Z: a new app-server initialized, so the old one had ended. The T3 server process ran without a restart from 2026-11-26 23:22 local time through 2026-12-01.
- 2026-12-01: the old scope still held
postgresand its 5 workers and no Codex process, withOOMPolicy=continue,Result=successandmemory.events oom_kill 0, so this was not an out-of-memory kill. It ended only when stopped by hand.
Impact
Major degradation or frequent failure
(Every idle release of the shared Codex session can leave a database or dev server running and holding its port and memory until the T3 server restarts, with nothing in the UI.)
Version or commit
Server 0.1.13 (installed), desktop 0.1.9; same code on main @ ff26e6a632.
Environment
Ubuntu, kernel 7.0, systemd 259, cgroup v2; server run as a systemd user service (boot-service); codex-cli 0.172.0.
Logs or stack traces
$ journalctl --user | grep t3code-codex-fa363ada
2026-12-01T13:58:36-08:00 systemd[2728]: Stopping t3code-codex-fa363ada.scope - [systemd-run] ~/.local/bin/codex app-server -c thread_unload_delay_secs=0...
2026-12-01T13:58:36-08:00 systemd[2728]: Stopped t3code-codex-fa363ada.scope - [systemd-run] ~/.local/bin/codex app-server -c thread_unload_delay_secs=0.
2026-12-01T13:58:36-08:00 systemd[2728]: t3code-codex-fa363ada.scope: Consumed 1h 1min 826ms CPU time over 4d 5h 14min 20.085s wall clock time, 10.9G memory peak, 1.5G memory swap peak.Code on main ff26e6a632:
apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts:1898-1905: the app-server is wrapped withshared: true, and the returnedlaunch.unitis never used. The process is spawned into the session's Scope at:2116, so a release ends the process but not its systemd scope.apps/server/src/process/agentScope.ts:490-509: a shared scope getsOOMPolicy=continue, no owning thread, and--collect.apps/server/src/process/agentScope.ts:397-399:killreturns false for shared scopes.apps/server/src/process/agentScope.ts:371-396:stopexists for this case ("Reaps processes left after the owning agent exits, including setsid descendants",packages/shared/src/AgentScope.ts:20-23). Its callers are Claude (ClaudeAdapterV2.ts:1841), ACP, Pi, Muse and Cursor; Codex is not one.apps/server/src/process/agentScope.ts:141-169:stopLeftoverAgentsstops the owned slice, and it runs only at server start.apps/server/src/orchestration-v2/ProviderSessionManager.ts:94,:1886-1900: a native-resume session is released 2 minutes after its last turn settles, which is the usual way the shared app-server ends.
Workaround
systemctl --user stop <old t3code-codex-*.scope> once no Codex process is in it, or restart the T3 server.
Related
- fix(server): agent-browser and Chrome no longer outlive the agent that started them #21299 (merged) added scope stops for the other providers and left shared Codex and OpenCode servers out ("retain their existing ownership"). A live shared app-server serves several threads, so its scope cannot be stopped while it runs; once it has exited, nothing else uses that scope, since each spawn gets its own.
- [Bug]: OpenCode shell commands survive restart after their server exits #37848 / PR fix(opencode): restart stops shell commands left by an exited OpenCode server #37880 (open): the same gap for OpenCode, fixed there at restart time.
- [Bug]: Idle-reaped provider sessions leave their agent-spawned child processes running forever (no crash, no app quit) #20717 (closed by fix(server): agent-browser and Chrome no longer outlive the agent that started them #21299): the idle-release version of this for Claude.
- fix(server): Codex works again after its app-server is killed #26188 (merged): Codex recovers after its app-server dies; the dead app-server's scope is still left.
Proposed fix
Return launch.unit from makeCodexAppServerSpawnCommand, and in CodexAppServerClientFactory.open register a finalizer on the session scope, after the spawn, that calls agentScope.stop(unit) once the app-server process has exited, both when the scope closes (idle release, Stop, server shutdown) and when the process exits on its own (the awaitTermination path from #26188). This only ever stops a scope whose app-server is gone, so no live thread loses its processes.
One detail: stop skips any scope whose oom_kill counter is above 0, so a shared scope where one tool was OOM-killed earlier would still be left; nothing reads a continuing shared scope's OOM result (agentScope.ts:490-491), so the Codex path can stop it regardless.
Activity