## Description
`headroom_compress` hangs (60s `-32001` MCP timeout) in stdio MCP
servers. Root cause: the compression pipeline init → OpenTelemetry
tracer → `get_version()` → `_source_tree_version()` →
`list_release_tags()` runs `git tag -l v*` via `subprocess.run` with no
timeout and inherited stdin. In a stdio MCP server, `git` inherits the
stdio pipe and hangs, so `await run_in_executor(...)` blocks until the
client's 60s timeout.
Fix: pass `stdin=DEVNULL` (stop inheriting the stdio pipe) +
`timeout=10` (fail gracefully through the existing `try/except` and
continue through the packaged, distribution-metadata, or `"unknown"`
fallback chain) on the three version-detection git calls.
## Type of Change
- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Performance improvement
- [ ] Code refactoring (no functional changes)
## Changes Made
- `headroom/release_version.py`: add `stdin=subprocess.DEVNULL` +
`timeout=10` to `list_release_tags`, `list_release_commits`, and
`commit_height_since` git subprocess calls.
- `tests/test_release_version.py`: add
`test_version_detection_git_calls_are_hang_safe` asserting the three git
calls are bounded and do not inherit the caller's stdin.
## Testing
- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`)
- [x] Type checking passes (`mypy headroom`)
- [x] New tests added for new functionality
- [x] Manual testing performed
### Test Output
```text
$ uv run --no-sync python -m pytest tests/test_release_version.py tests/test_observability_metrics.py -q
collected 29 items
tests\test_release_version.py ................ [ 55%]
tests\test_observability_metrics.py ............. [100%]
============================= 29 passed in 6.34s ==============================
$ uv run --no-sync ruff check .
All checks passed!
$ uv run --no-sync ruff format . --check
1415 files already formatted
$ uv run --no-sync mypy headroom/release_version.py --ignore-missing-imports
Success: no issues found in 1 source file
```
## Real Behavior Proof
- Environment: Windows 10, Python 3.13.13, headroom `0.36.0-dev`
(editable install), `headroom mcp serve` (stdio transport), no proxy.
- Exact command / steps: spawned `headroom mcp serve` and sent a raw MCP
`tools/call` for `headroom_compress` with
`{"content":"{"name":"test","items":[1,2,3,4,5]}"}`. Also verified
through the dsh web UI at http://127.0.0.1:3080 (same tool, routed
through a running proxy).
- Observed result: before the fix, `tools/call` hung 70s and returned
`Error: MCP error -32001: Request timed out`. After the fix,
`tools/call` returned in 2.38s:
```json
{"hash":"a76e1fa6b2611dc18b031c6d","original_tokens":24,"compressed_tokens":24,"tokens_saved":0,"transforms":["router:noop"]}
```
The dsh web UI returned the same hash `a76e1fa6b2611dc18b031c6d`.
- Not tested: `headroom_retrieve` / `headroom_stats` against a live
proxy; Linux/macOS stdio MCP clients; the git-hang path with a *running*
proxy (the proxy is not in the tool-call path — the hang reproduces with
no proxy).
## Runtime Rollout Safety
- Rollout-managed feature(s): none.
- Minimum rollout channel: n/a.
- Stable/default behavior changed: version detection now fails
gracefully through the packaged, distribution-metadata, or `"unknown"`
fallback chain instead of hanging when a git subprocess exceeds 10s.
Compression behavior is unchanged.
- Kill switch / disable path: none — the timeout is a bounded safety
net; version detection is already best-effort behind `try/except`.
- Unsafe override required: no.
- Qualification impact: none (version detection is best-effort; failure
already continues through that fallback chain).
- Rollback path: revert this commit.
## Review Readiness
- [x] I have performed a self-review
- [x] This PR is ready for human review
## Checklist
- [x] My code follows the project's style guidelines
- [x] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [x] My changes generate no new warnings
- [x] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [x] I did **not** edit `CHANGELOG.md` — it is generated by
release-please from my Conventional Commit PR title (a CI guard enforces
this)
## Screenshots (if applicable)
N/A
## Additional Notes
-
`tests/test_release_workflows.py::test_no_native_tls_in_wheel_build_tree`
fails locally with `FileNotFoundError` (missing Windows build tool) —
pre-existing and unrelated to this change.
- The commented-code and documentation checklist items are left
unchecked: the change is a small, self-documenting bug fix
(`stdin=DEVNULL` + `timeout=10` are self-explanatory), the rationale is
captured in the commit message and test docstring, and no API/behavior
surface changed to document.
- Not dsh-specific: this affects `headroom mcp serve` for any stdio
client (claude/codex/etc.).
Co-authored-by: Zenjibad <316719033+Zenjibad@users.noreply.github.com>
Co-authored-by: Jerrett Davis <mxjerrett@gmail.com>
Fixes#1310.
## Description
On Windows, `headroom` startup crashes a subprocess reader thread:
```
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8d in position 7894: character maps to <undefined>
... subprocess.py _readerthread -> buffer.append(fh.read())
... encodings/cp1252.py
```
Text-mode `subprocess` calls omit `encoding=`, so Python decodes child
output with the locale codec (**cp1252** on Windows). Children that emit
UTF-8 ??? `cbm index_repository` (indexing sources with chars like
`???`/`???`), `claude mcp get/add`, the memory-sync process ??? produce
bytes invalid in cp1252 and kill the reader thread. Linux/macOS default
to UTF-8, so it's invisible there.
## Type of Change
- [x] Bug fix (non-breaking change that fixes an issue)
## Changes Made
- Add `encoding="utf-8", errors="replace"` to every text-mode
(`text=True` / `universal_newlines=True`) subprocess call in the
`headroom/` package (~50 call sites; several already had it).
- `errors="replace"` (not `ignore`) so corrupt bytes surface as `???`
rather than vanishing from parsed output.
- Add `tests/test_cli/test_subprocess_utf8_encoding.py`: an AST guard
asserting every text-mode subprocess call pins `encoding=`. The runtime
crash can't reproduce on UTF-8 CI, so the invariant is enforced at the
source level instead.
## Testing
- [x] Unit tests pass (`pytest`)
- New guard test passes (validates 51 call sites).
- `tests/test_install`, `tests/test_cli/test_mcp.py`,
`tests/test_mcp_registry` pass.
(`test_runtime_start_lock_blocks_another_process` fails on this Windows
box, but it fails identically on unmodified `main` ??? a pre-existing
`msvcrt` lock flake, unrelated.)
### Test Output
```text
> python -m pytest tests/test_cli/test_subprocess_utf8_encoding.py -q
1 passed in 0.12s
> python -m pytest tests/test_install/ tests/test_cli/test_mcp.py tests/test_mcp_registry/ -q
133 passed, 2 skipped in 15.34s
```
## Real Behavior Proof
- Environment: Windows 11, Python 3.13.13.
- Exact command / steps: Started `headroom` without `PYTHONUTF8=1` on a
repo with UTF-8 chars in indexable files. Observed the
`UnicodeDecodeError` crash. Applied the fix (pinning `encoding="utf-8"`
on all text-mode subprocess calls). Re-ran. No crash. The AST guard
enforces the invariant on CI (which runs UTF-8 locales and cannot
reproduce the cp1252 crash natively).
- Observed result: Subprocess reader threads no longer crash on UTF-8
output under cp1252 locale.
- Not tested: All third-party tools that `headroom` shells out to; each
was given `errors="replace"` as a safety net.
## Workaround for affected users (before fix is deployed)
`PYTHONUTF8=1` (PowerShell: `$env:PYTHONUTF8=1; headroom ...`).
## Review Readiness
- [x] I have performed a self-review
- [x] This PR is ready for human review
---------
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
`.gitattributes` declares `*.py text eol=lf` and `*.sh text eol=lf`, but
74 files (73 .py, 1 .sh) are stored in the index with CRLF line endings,
violating that contract. Every macOS/Linux clone reports these files as
"modified" on fresh checkout because git's diff engine sees the stored
bytes don't match the attribute contract, even though the working tree
and index match byte-for-byte.
Running `git add --renormalize .` rewrites each affected blob so the
stored form matches the attribute declaration. No semantic changes —
every affected file's diff is "N insertions, N deletions" with inserts
and deletes being the same lines modulo line endings.
Follow-up commit adds `.git-blame-ignore-revs` so `git blame` / GitHub
blame skip this mechanical commit.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Do not strip the raw git-log record before splitting on the field
separator, because commits with empty bodies lose their delimiter and get
dropped entirely. Add a deterministic unit test for empty-body parsing.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Determine the release bump from all unreleased commits since the previous
release tag and apply the highest required semantic version increment.
This keeps feat commits at a minor bump unless a breaking change requires
major, even when later patch-level commits are present.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the inline release version math with a tested helper that normalizes legacy four-part tags and computes a single semantic version for packages and GitHub releases.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>