Skip to content

1.44.1: end terminals one at a time (no remove_pty_baton assertion on quit / Update all) - #62

Merged
writingdeveloper merged 2 commits into
mainfrom
fix/quit-once
Oct 21, 2026
Merged

writingdeveloper merged 2 commits into
mainfrom
fix/quit-once

Conversation

@writingdeveloper

Copy link
Copy Markdown
Owner

Symptom (reported with a screenshot): on Windows, quitting or running Update all with two or more sessions open sometimes shows a Microsoft Visual C++ Runtime Library dialog:

Assertion failed!
Program: …node-pty-prebuilt-multiarch\build\Release\conpty.node
File: …conpty.cc  Line: 106
Expression: remove_pty_baton(baton->id)

Other times DevDeck stays alive after its window is gone, or exits with 0xC0000005.

Cause: in conpty.cc, each terminal's exit thread calls remove_pty_baton(). That function edits the global std::vector ptyHandles without a lock. When two terminals end together, the two threads race on the vector. @homebridge/node-pty-prebuilt-multiarch adds a mutex only in 0.15.0-beta (0.14.1 stable does not have it).

Fix: PtyHost.kill ends terminals one at a time. The next kill starts once the previous exit has reached JS, by which point its thread has finished with the vector, or after 4 s. The default shutdown budget scales with the number of terminals (1.5 s each, at least 5 s).

Evidence:

  • A harness quit trace showed the hang happening after Node's exit 0, during native teardown.
  • qa/claude-update.mjs stops all sessions at once twice, at Update all and at quit:
    • before: 3/20 and 3/32 runs hung or crashed at quit
    • after: 0/50
  • vitest: 1511 passed, including a new test that terminals end one after another and that a missing exit holds the next one up for at most 4 s.

🤖 Generated with Claude Code

https://claude.ai/code/session_016NLGwiBY5uEivJqERQzcoY

writingdeveloper and others added 2 commits October 21, 2026 16:42
…ndows)

Quitting or Update all with two or more sessions intermittently showed "Assertion failed:
remove_pty_baton(baton->id)" from conpty.node, or left DevDeck hanging or crashing
(0xC0000005) on the way out. node-pty's Windows exit threads remove a terminal from one
shared std::vector without a lock (a mutex lands only in 0.15.0-beta); two terminals ending
together corrupted it.

PtyHost.kill now chains: the next terminal is killed once the previous exit has been
reported (by then its thread has finished with the list), or after 4 s. Shutdown's
default budget grows with the number of terminals (1.5 s each, at least 5 s).

qa/claude-update.mjs failed at quit on 3/20 and 3/32 runs before; 0/50 after.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016NLGwiBY5uEivJqERQzcoY
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016NLGwiBY5uEivJqERQzcoY
@writingdeveloper
writingdeveloper merged commit b2ad14c into main Oct 21, 2026
16 checks passed
@writingdeveloper
writingdeveloper deleted the fix/quit-once branch October 21, 2026 23:48
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