fix(windows/conpty): pass HPCON value, not &hPC (v0.7.8) #18

Merged
Muyue merged 1 commits from release/v0.7.8 into develop 2026-04-27 13:49:15 +00:00
Owner

Régression v0.7.6 : terminaux en fenêtre externe

Symptôme : depuis v0.7.6, cliquer PowerShell / cmd / WSL dans le tab Terminal ouvre une fenêtre console externe au lieu de s'afficher dans xterm.js. v0.7.5 marchait.

Cause

Le binding ConPTY de v0.7.6 passait &hPC (pointeur vers variable Go locale) à UpdateProcThreadAttribute(PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, ...). C'est un quirk Win32 : pour cet attribut spécifique, lpValue doit être la valeur du handle (cast en PVOID), pas un pointeur vers une variable. Avec &hPC le kernel lit des octets aléatoires, l'attribut est silencieusement ignoré, et CreateProcessW crée une console fraîche pour l'enfant — d'où la fenêtre externe.

Fix

1 ligne :

// Avant
unsafe.Pointer(&hPC)

// Après
unsafe.Pointer(uintptr(hPC))  // HPCON value as PVOID

Conforme à :

  • Microsoft EchoCon sample (référence officielle ConPTY)
  • github.com/UserExistsError/conpty
  • github.com/aymanbagabas/go-pty

Versioning

  • v0.7.7 → v0.7.8
  • CHANGELOG.md : entrée v0.7.8 avec le diagnostic complet (utile pour quelqu'un qui retombe sur le même piège)

Test plan

  • go vet ./...
  • manuel Windows : tab Terminal → "PowerShell" → s'affiche dans xterm.js avec prompt PS, ANSI couleurs OK
  • manuel Windows : tab Terminal → "WSL: Debian" → bash s'affiche dans le tab, vim fonctionne
  • régression macOS/Linux : terminaux locaux + SSH continuent comme avant
## Régression v0.7.6 : terminaux en fenêtre externe Symptôme : depuis v0.7.6, cliquer PowerShell / cmd / WSL dans le tab Terminal ouvre une **fenêtre console externe** au lieu de s'afficher dans xterm.js. v0.7.5 marchait. ## Cause Le binding ConPTY de v0.7.6 passait `&hPC` (pointeur vers variable Go locale) à `UpdateProcThreadAttribute(PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE, ...)`. C'est un **quirk Win32** : pour cet attribut spécifique, `lpValue` doit être la **valeur du handle** (cast en PVOID), pas un pointeur vers une variable. Avec `&hPC` le kernel lit des octets aléatoires, l'attribut est silencieusement ignoré, et `CreateProcessW` crée une console fraîche pour l'enfant — d'où la fenêtre externe. ## Fix 1 ligne : ```go // Avant unsafe.Pointer(&hPC) // Après unsafe.Pointer(uintptr(hPC)) // HPCON value as PVOID ``` Conforme à : - Microsoft EchoCon sample (référence officielle ConPTY) - `github.com/UserExistsError/conpty` - `github.com/aymanbagabas/go-pty` ## Versioning - v0.7.7 → v0.7.8 - CHANGELOG.md : entrée v0.7.8 avec le diagnostic complet (utile pour quelqu'un qui retombe sur le même piège) ## Test plan - [ ] go vet ./... - [ ] manuel Windows : tab Terminal → "PowerShell" → s'affiche dans xterm.js avec prompt PS, ANSI couleurs OK - [ ] manuel Windows : tab Terminal → "WSL: Debian" → bash s'affiche dans le tab, vim fonctionne - [ ] régression macOS/Linux : terminaux locaux + SSH continuent comme avant
Muyue added 1 commit 2026-04-27 12:40:02 +00:00
fix(windows/conpty): pass HPCON value, not &hPC (v0.7.8)
All checks were successful
PR Check / check (pull_request) Successful in 1m3s
a3487392c0
User reported regression introduced in v0.7.6: PowerShell / cmd open
in a separate external console window instead of attaching to the
xterm.js tab (v0.7.5 worked).

Root cause: the ConPTY wiring used
  attrList.Update(PROC_THREAD_ATTRIBUTE_PSEUDOCONSOLE,
                  unsafe.Pointer(&hPC),    // ← wrong
                  unsafe.Sizeof(hPC))

The PSEUDOCONSOLE attribute is a Win32 API quirk: lpValue must be
the HPCON *value* (cast to PVOID), not a pointer to the local
variable holding the handle. With &hPC the kernel reads garbage,
silently drops the attribute, and CreateProcessW spawns the child
with a fresh console — hence the external window.

Fix is one line:
  unsafe.Pointer(uintptr(hPC))

Confirmed against Microsoft's EchoCon sample and Go libraries that
work in production (UserExistsError/conpty, aymanbagabas/go-pty).

- internal/version/version.go: 0.7.7 → 0.7.8
- CHANGELOG.md: v0.7.8 entry with the diagnostic write-up
Muyue merged commit 5fd8cceabd into develop 2026-04-27 13:49:15 +00:00
Muyue deleted branch release/v0.7.8 2026-04-27 13:49:19 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Muyue/MuyueWorkspace#18