Skip to content

fix(coding-agent): replace TUI process after update - #1631

Merged
snimu merged 5 commits into
mainfrom
fix/update-relaunch-tui
Sep 1, 2026
Merged

fix(coding-agent): replace TUI process after update#1631
snimu merged 5 commits into
mainfrom
fix/update-relaunch-tui

Conversation

@sethkarten

@sethkarten sethkarten commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Linear: ENG-5434

Summary

  • replace the current TUI process in place after a successful interactive self-update on Node 26.1 and newer
  • preserve the current session, cwd, environment, CLI arguments, terminal, and shell job
  • keep the existing child relaunch on Windows, IBM i, Node 26.0 and older, and runtimes without process.execve
  • cover the full update teardown, daemon coordination, and process replacement order

Design

The existing updater already completes the package update, session teardown, and daemon restart before relaunch. The last step used spawnSync, which kept the old TUI process alive until the new TUI quit.

On POSIX Node 26.1 and newer, the relaunch now uses execve after cleanup. This replaces the old process while keeping its PID and foreground terminal ownership. A detached frontend would break shell job and TTY ownership, so the existing inherited-stdio child relaunch remains the compatibility fallback where process replacement is unavailable or fails.

Validation

  • npm run check
  • ../../node_modules/.bin/vitest run test/interactive-update-relaunch.test.ts (15/15)
  • Node 22.22 focused run (15/15)
  • reproduced aborting execve failures on Node 22.22, 24.13, 25.8, and 26.0; verified thrown ENOENT on Node 26.1 and 26.2
  • git diff --check
  • independent process/lifecycle review: approved
  • independent test/maintainability review: approved after fixing its repo-convention finding

Note

Medium Risk
Changes interactive self-update process replacement and terminal/shell job ownership; mitigated by platform/version gating and spawnSync fallback, with env reduced to string values on the execve path.

Overview
After a successful interactive /update, the relaunch step no longer relies solely on spawnSync, which left the old TUI process running until the child exited.

On POSIX with Node ≥ 26.1 (where failed execve throws instead of aborting), the agent now tries tryExecUpdateRelaunch: chdir to the update cwd, then process.execve with a launch spec from createCliSubprocessLaunchSpec, string-only env, and argv0 preserved. Windows, IBM i, older Node, missing execve, or exec failures still use the child spawnSync relaunch, with a console message on exec failure.

Tests cover execve behavior, platform/version gates, cwd restore on thrown execve, and update teardown ordering ending in execve instead of waiting on a child TUI.

Reviewed by Cursor Bugbot for commit 40bd188. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Replace TUI process in place via execve after /update on Node 26.1+

  • Adds tryExecUpdateRelaunch in interactive-mode.ts to replace the current process via execve on non-win32/non-os400 platforms and Node >= 26.1, preserving argv0 and string-only environment entries.
  • handleUpdateCommand now tries in-place replacement first; on failure or unsupported platforms it logs a message and falls back to the previous spawnSync child-process approach.
  • Risk: tryExecUpdateRelaunch filters environment to string-only values before calling execve; any non-string env entries (e.g. injected by native addons) will be silently dropped during relaunch.

Changes since #1631 opened

  • Clarified platform-specific TUI process replacement behavior in changelog documentation [40bd188]

Macroscope summarized 7fb4798.

Dormancy note: on today's Node 24.x runtimes the execve path is dormant and everyone takes the existing child-relaunch fallback; the in-place replacement activates when the runtime reaches Node >=26.1, the version where a failed process.execve throws instead of aborting (confirmed against the official Node docs).

samsja
samsja previously approved these changes Aug 26, 2026
@sethkarten
sethkarten force-pushed the fix/update-relaunch-tui branch from c8ad10e to b1b1ae4 Compare August 26, 2026 22:28
Comment thread packages/coding-agent/src/modes/interactive/interactive-mode.ts Outdated
Comment thread packages/coding-agent/.changes/update-tui-in-place-relaunch.md Outdated
…s back

The relaunch chdirs before replacing the process; a thrown execve (Node >=26.1)
left the old process on the update cwd while the child fallback ran. The seam
now restores the captured previous cwd on the throw path so a failed attempt
leaves no silent process-state difference.
@snimu
snimu merged commit 083c68d into main Sep 1, 2026
23 checks passed
@snimu
snimu deleted the fix/update-relaunch-tui branch September 1, 2026 13:34
ketema added a commit to ketema/prime-agent that referenced this pull request Sep 1, 2026
- Direct session transport between TUI and worker (ENG-5817, PrimeIntellect-ai#1926)
- Event-driven supervisor agent roster with push subscriptions (PrimeIntellect-ai#1897, PrimeIntellect-ai#1900, PrimeIntellect-ai#1895)
- Hardened daemon startup, recovery ownership, and worker launch diagnostics (PrimeIntellect-ai#1929, PrimeIntellect-ai#1918)
- Python REPL runtime single-dump snapshots and bash preview tool (PrimeIntellect-ai#1945, PrimeIntellect-ai#1911)
- Non-blocking RLM subagent deletion and snapshot update suppression (PrimeIntellect-ai#1954, PrimeIntellect-ai#1944)
- Saved catalog loading on Agents View open (PrimeIntellect-ai#1960)
- Advanced Anthropic prompt caching marker across tool results (PrimeIntellect-ai#1927)
- TUI process replacement on update and empty draft eviction (PrimeIntellect-ai#1631, PrimeIntellect-ai#1946, PrimeIntellect-ai#1920)
paralin pushed a commit to paralin/prime-agent that referenced this pull request Sep 2, 2026
…i#1631)

* fix(coding-agent): replace TUI process after update

* fix(coding-agent): guard unsafe execve failures

* fix(coding-agent): restore the previous cwd when a thrown execve falls back

The relaunch chdirs before replacing the process; a thrown execve (Node >=26.1)
left the old process on the update cwd while the child fallback ran. The seam
now restores the captured previous cwd on the throw path so a failed attempt
leaves no silent process-state difference.

* docs(coding-agent): qualify the update-relaunch changelog with the platform restriction

---------

Co-authored-by: Sebastian <sebastian@primeintellect.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants