Skip to content

fix: keep the terminal usable after upgrades and startup failures - #507

Open
Yaroslav Slepukhin (yslpn) wants to merge 1 commit into
microsoft:mainfrom
yslpn:fix/seamless-upgrade
Open

Yaroslav Slepukhin (yslpn) wants to merge 1 commit into
microsoft:mainfrom
yslpn:fix/seamless-upgrade

Conversation

@yslpn

Copy link
Copy Markdown
Contributor

Problem

After upgrading the binary (e.g. brew upgrade inshellisense 0.0.4 → 0.1.0), the unpacked resources still carried the old version.txt. is printed inshellisense resources out of date, run "is reinit" and exited with code 1. The shell plugin (is -s zsh ; exit) then exited the parent shell, so new terminal tabs (e.g. Ghostty) closed immediately. The error could not be read and is reinit could not be run from that terminal.

There was a related bug: copyAssets/copyFiles skipped files that already existed. As a result, is init after an upgrade bumped version.txt but kept stale pty.node, spawn-helper and shell integration scripts.

Changes

  • Refresh resources in place on version mismatch (root.ts, node.ts). Shell plugins and resources are regenerated at the current resource location. There is no legacy → XDG migration here; that is still done by is reinit. version.txt is written last so an interrupted refresh is retried.
  • Atomic file writes (utils/file.ts). Each file is written to a temp file and renamed over the target. Files with identical content are skipped, and the replaced file's mode is preserved (spawn-helper stays executable). This avoids races when several tabs start at once after an upgrade, and running sessions keep the native module they already loaded.
  • Fallback to the plain shell if startup or render setup fails. This covers resource refresh errors, invalid config (via exitOverride) and pty spawn errors. The error and a hint are printed, then the user's shell is launched with ISTERM=0. Any non-empty value stops existing plugins from relaunching is, and is inside that shell can still retry. The shell's exit code is propagated. Executable and login-argument logic was moved to getShellExecutable/getShellLoginArgs in shell.ts and is shared with pty.ts, so the fallback path does not load node-pty.
  • Shell plugins only start inshellisense when is is on PATH, so a missing binary does not close the terminal.
  • Development (non-SEA) builds resolve the source resources relative to the entry point instead of the cwd.
  • README: is reinit is no longer required after upgrading.

Testing

  • New unit tests: src/tests/utils/file.test.ts, src/tests/utils/node.test.ts, and getShellLoginArgs cases in shell.test.ts. npm run lint passes.
  • Manual runs of the dev build in a pty with an isolated XDG_DATA_HOME:
    • Simulated upgrade (stale version and files): the session starts, files are restored, and the exit code propagates.
    • Read-only resources and invalid rc.toml: an error message is shown, then the plain zsh opens without relaunching is.
    • 3 concurrent startups after a simulated upgrade: all start and no .tmp files are left.
    • Started from /tmp: works.
    • zsh with the new plugin and no is on PATH: the shell stays open.
    • Generated bash, zsh and fish plugins pass a syntax check.

Not verified:

  • The packaged SEA binary.
  • Windows. A changed pty.node that is locked by a running session would fail to refresh and use the fallback path.
  • pwsh, nu and xonsh plugins.
  • The render-failure path, which was not triggered manually.

Several existing suites (config, ui, pty, runtime, suggestionManager…) fail to run locally with TS2307 module resolution errors. The same happens on main.

After upgrading the binary, `is` exited with "resources out of date" and the
shell plugin's trailing `exit` immediately closed the terminal tab, leaving no
way to read the error or run `is reinit`.

- refresh unpacked resources and shell plugins in place when their version
  doesn't match the binary, using atomic writes so tabs starting concurrently
  don't race and running sessions keep their loaded native module
- actually overwrite stale files when unpacking (previously skipped)
- on any startup or render failure, print the error and fall back to the plain
  shell (ISTERM=0 prevents the plugin from relaunching inshellisense)
- only start inshellisense from the shell plugins when `is` is on PATH
- resolve development resources relative to the entry point, not the cwd
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.

1 participant