Skip to content

fix(installer): cleanup orphan testgen+postgres and log-file encoding on Windows#89

Merged
aarthy-dk merged 2 commits into
mainfrom
fix/TG-1084-installer-orphan-cleanup-and-log-encoding
May 15, 2026
Merged

fix(installer): cleanup orphan testgen+postgres and log-file encoding on Windows#89
aarthy-dk merged 2 commits into
mainfrom
fix/TG-1084-installer-orphan-cleanup-and-log-encoding

Conversation

@aarthy-dk
Copy link
Copy Markdown
Contributor

Summary

Two Windows-installer robustness fixes surfaced while testing TG-1083.

  1. Orphan cleanup before install/delete. When a previous standalone session exited dirty (force-killed via Task Manager, browser tab close, etc.), the embedded postgres survives — it was spawned with `CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW`. Next `tg install` then fails at `standalone-setup` because the orphan still owns `~/.testgen/pgdata`; next `tg delete` half-finishes because Windows file-locks the running `testgen.exe` binary, blocking `uv tool uninstall`. New `stop_standalone_orphans()` helper kills the postgres PID read from `postmaster.pid` (precise — other Postgres installs untouched) and force-kills `testgen.exe` by image name (safe — installer is `dk-installer.exe`). Wired into `_delete_pip` and `TestgenStandaloneSetupStep.pre_execute`. The pre-execute hook runs only after `_resolve_install_mode` confirms no install marker, so the existing "you already have an install" guard is preserved.
  2. UTF-8 log file. `logging.FileHandler` was being constructed without an `encoding=` argument, so on Windows it opened the log file with cp1252 (locale default). Lines containing `✓` (used in prereq-status output) hit UnicodeEncodeError on emit, producing alarming `--- Logging error ---` tracebacks on stderr even though the install completed. Adds `"encoding": "utf-8"` to the dictConfig.

Jira

TG-1084

Test plan

  • Full suite still passes locally (182 tests).
  • `ruff check` + `ruff format --check` clean.
  • Helper is a silent no-op on a clean dev machine.
  • Windows: with an orphan `postgres.exe` from a prior dirty exit, `tg install` completes (the failing case from `chip_installer_logs.txt`).
  • Windows: with an orphan `testgen.exe`, `tg delete` completes including binary removal.
  • Windows: install log file `installer_log.txt` contains `✓` characters without the `--- Logging error ---` traceback (the failing case from `chip_install.txt`).

aarthy-dk and others added 2 commits May 15, 2026 17:56
A previous standalone session that exited dirty (force-killed via Task
Manager, browser tab close, etc.) leaves the embedded postgres alive —
it was spawned with CREATE_NEW_PROCESS_GROUP | CREATE_NO_WINDOW, so it
survives its parent. `tg install` then fails at standalone-setup because
the orphan still owns ~/.testgen/pgdata; `tg delete` half-finishes
because Windows file-locks the running testgen.exe binary, blocking
`uv tool uninstall` from removing it.

Add a `stop_standalone_orphans()` helper that:
- reads ~/.testgen/pgdata/postmaster.pid → kills that specific PID
  (so a user's unrelated postgres installs are untouched),
- then force-kills testgen.exe by image name (safe — installer is
  dk-installer.exe; no self-kill risk).

Called from `_delete_pip` before `uv tool uninstall`, and from
`TestgenStandaloneSetupStep.pre_execute` — which only runs after
`_resolve_install_mode` has confirmed no install marker, so the
existing "you already have an install, use upgrade or delete"
invariant is preserved.

Best-effort: silent on a clean machine, never raises (outer try/except
guards against transient filesystem/permission glitches).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
On Windows, `logging.FileHandler` opens the log file with
`locale.getpreferredencoding()` when no encoding is passed — cp1252 on
a US-English install. Lines containing non-ASCII glyphs like ✓ (used in
prereq-status output) hit UnicodeEncodeError on emit; the logging
module catches it and prints `--- Logging error ---` plus a traceback
to stderr. The install still completes, but the noise is alarming.

Add `"encoding": "utf-8"` to the file-handler dictConfig so the file is
opened in UTF-8 regardless of locale.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@aarthy-dk aarthy-dk merged commit 6be5e37 into main May 15, 2026
3 checks passed
@aarthy-dk aarthy-dk deleted the fix/TG-1084-installer-orphan-cleanup-and-log-encoding branch May 15, 2026 22:07
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.

2 participants