codex icon indicating copy to clipboard operation
codex copied to clipboard

Windows: Artifact Session host leaves uncancelled shutdown timers, delaying Codex exit ~5s

Open buta-6809 opened this issue 1 month ago • 3 comments

Summary

On Windows, Codex exit is delayed by approximately five seconds. An independently launched, empty Artifact Session host reproduces the delay: its close() completes in under 0.4 ms, but the Node.js process stays alive for ~5 seconds. Inspection of the installed @oai/artifact-tool package identifies uncancelled setTimeout promises used in Promise.race during shutdown.

Environment

  • Windows, Codex desktop application (Store installation)
  • Codex runtime: 26.1017.11052, installed 2026-10-18 19:25 JST
  • @oai/artifact-tool: 2.8.99
  • File: dist/artifact-session/host-daemon.mjs
  • Installed file SHA-256: f0c829aa03f2a500a2ece1582c583e9777fdc6cd1549331b0ee62fbac7b27a9a

Evidence in the installed implementation

The default shutdown grace is shutdownGraceMs:5e3 (5,000 ms), passed into shutdown as:

await this.#W(e.graceMs??this.#i.shutdownGraceMs)

Shutdown uses:

await Promise.race([Promise.allSettled([...this.#c]),aCt(e)]);
await Promise.race([r,aCt(Math.min(e,1e3))]);
await Promise.race([r,aCt(1e3)]);

where:

function aCt(t){return new Promise(e=>setTimeout(e,t))}

When the other promise wins, Promise.race does not cancel the timeout. No clearTimeout or unref is used for these timers. Pending timers keep the Node.js event loop alive after close() returns.

Isolated reproduction

Started the bundled startArtifactSessionHostDaemon in an independent process with an empty temporary store and a dedicated random local pipe. No Codex instance was connected; no external services, model requests, or user/work data were involved. The installed package was not modified. Both processes exited naturally (code 0, no stderr).

Shutdown grace close() duration Time from close() completion to natural process exit
Default (5,000 ms) 0.3823 ms 5,009.8145 ms
Explicit 100 ms (test instance only) 0.3625 ms 1,002.2727 ms

The 100-ms test suggests a separate 1-second timer also remains pending; reducing the grace setting alone does not fully resolve the issue.

Actual Codex exit observation (2026-10-19 JST)

  • Codex PID 30700 began exit around 14:17:28.260.
  • Most MCP/other children had exited by 14:17:28.31.
  • Last Node.js child PID 41556 exited at 14:17:33.230538, exit code 0.
  • Codex PID 30700 exited at 14:17:33.311695, exit code 0.
  • The Node binary was the bundled runtime dependencies/node/bin/node.exe.
  • In a subsequent running Codex instance (PID 19676), its sole child using that same Node binary (PID 39060) was running @oai/artifact-tool/dist/artifact-session/host-daemon.mjs.

Attribution caveat: The command line and stack of the former PID 41556 were not captured. Its identification as the Artifact Session host relies on comparison with the corresponding child of the later instance. The isolated host reproducer independently demonstrates the timer leak.

Potential regression and user impact

A Windows Store update completed around 2026-10-18 19:25 JST; runtime 26.1017.11052 was installed shortly thereafter. An older runtime 26.1013.11914 was previously available. The older artifact-tool implementation was not retained for comparison, so this is not yet confirmed as a regression introduced by that update.

The delayed exit may also widen a race in which a new launch request is delivered to an instance that is shutting down, opening the old window and losing the request. This launch-routing behavior needs separate investigation; the timer leak is the independently reproduced defect.

Suggested fix

Cancel timeout handles when the competing shutdown operation completes (including failure paths), rather than leaving losing Promise.race timers alive. unref() could prevent them from blocking process exit, but cancelling them is preferable.

All evidence above was gathered read-only from the installed implementation or from an isolated empty host. No installed libraries, configuration, or environment variables were modified.

buta-6809 avatar Oct 19 '26 05:10 buta-6809

Confirmed on macOS as well, with a newer artifact-tool version.

Environment

  • macOS 27.2.1 (26B131), Apple Silicon
  • Codex desktop 26.1106.51428 (26605)
  • Runtime bundle 26.1111.10934
  • @oai/artifact-tool 2.8.148
  • Affected file: dist/artifact-session/host-daemon.mjs

I reproduced the delay by launching the bundled host with an empty temporary store, waiting for readiness, sending SIGTERM, and measuring time to process exit. The shutdown grace was 5,000 ms and the process-exit fallback was 8,000 ms.

Isolated host Original Locally patched
No connected clients 5.068 s 0.009 s
One idle Unix-socket client 5.042 s 1.049 s

All four runs exited with code 0. These are individual measurements, not statistical averages.

The local patch replaced the three shutdown Promise.race timeout waits with a helper that clears the timeout in finally:

async function waitWithTimeout(pendingWork, timeoutMs) {
  let timer;
  try {
    await Promise.race([
      pendingWork,
      new Promise(resolve => {
        timer = setTimeout(resolve, timeoutMs);
      }),
    ]);
  } finally {
    clearTimeout(timer);
  }
}

The original cleanup promises and timeout durations were retained. Checks also verified that unresolved work still waits for the timeout, actual cleanup is awaited, and rejection is propagated.

After applying this local workaround to the runtime and restarting, an actual desktop capture showed approximately 5.02 seconds → 0.53 seconds from app-server cleanup starting to the main process being observed gone. Process polling was approximately 150 ms, so these app timings are approximate.

This supports the same uncanceled-timer diagnosis on macOS. It does not establish a fix for the separate launch delay. No raw logs, account details, or personal paths are attached.

patrick6284 avatar Nov 12 '26 03:11 patrick6284

Thanks for confirming this on macOS, and for the careful measurements.

Your results line up closely with what I see on Windows: the same affected file (dist/artifact-session/host-daemon.mjs) and the same ~5 second delay caused by the shutdown timers not being cleared. The isolated-host reproduction with SIGTERM is also a much cleaner test than app-level timing.

The patch shape (clearing the timeout in finally) matches what I expected the fix to look like. Interesting that an idle connected client still leaves ~1 second even after the patch.

Hopefully having independent reports on both platforms, with measurements and a minimal patch, helps the team adopt this upstream — local patches to the bundled runtime get overwritten on every update.

buta-6809 avatar Nov 12 '26 03:11 buta-6809

Additional Windows observation on 13 November 2026, using ChatGPT desktop MSIX package OpenAI.Codex_26.1106.6628.0_x64__2p2nqsd0c76g0: the main app process remained alive for approximately five seconds after its visible window disappeared in two manual close/reopen tests.

Test Window no longer reported (UTC) Main-process exit observed (UTC) Approximate interval Exit code
Delayed reopen 10:41:52.661 10:41:57.679 5.02 s 0
Immediate reopen 10:42:49.341 10:42:54.365 5.02 s 0

The immediate-reopen test also reproduced the user-facing impact discussed in #55739: clicking the taskbar icon while the old process was shutting down briefly brought back a window owned by that old main process, which then exited. An additional short-lived ChatGPT process exited with code 0 during this interval. Waiting ten seconds before launching again worked normally. The delayed-reopen control also succeeded.

The detailed process timeline and reproduction are posted here: https://github.com/openai/codex/issues/55739#issuecomment-6850671657

Scope of this evidence: this confirms the approximately five-second desktop shutdown delay and the associated rapid-reopen symptom on this package version. I did not independently isolate the Artifact Session host, inspect its shutdown timers, or test a timer patch, so this is not an independent confirmation that the timer defect identified here causes this installation's delay. The timestamps are observations from approximately 200-ms process/window polling with retained process handles for exit codes, rather than exact kernel event times. Window ownership was read through Get-Process.MainWindowHandle.

No installed files or app configuration were modified, and no raw logs, personal paths, account information or chat content are included.

DanDG923 avatar Nov 13 '26 10:11 DanDG923