Skip to content

fix(wrap): isolate proxy stdio from proxy.log on Windows#1191

Open
rodboev wants to merge 1 commit into
chopratejas:mainfrom
rodboev:pr/1184-windows-proxy-log-rollover
Open

fix(wrap): isolate proxy stdio from proxy.log on Windows#1191
rodboev wants to merge 1 commit into
chopratejas:mainfrom
rodboev:pr/1184-windows-proxy-log-rollover

Conversation

@rodboev

@rodboev rodboev commented Jun 20, 2026

Copy link
Copy Markdown

Description

Fix the Windows proxy.log rollover storm by separating wrap-managed subprocess stdio from the proxy's rotating runtime log. headroom/cli/wrap.py currently opens ~/.headroom/logs/proxy.log and hands that file handle to the proxy subprocess, while headroom/proxy/helpers.py also rotates that same path at 10 MB with five backups. On Windows, the inherited stdio handle prevents the rename in RotatingFileHandler.doRollover(), which matches the repeated WinError 32 traceback loop documented in #1184. This change keeps proxy.log as the canonical rotating runtime log and moves wrap-managed stdio into a dedicated sibling file so rollover can succeed without losing startup diagnostics. Closes #1184

The reproduction and split-fix sketch in #1184 materially shaped the chosen scope; this PR follows that root-cause split rather than changing the proxy's rotation policy.

Type of Change

  • 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

  • redirect wrap-managed proxy subprocess stdout and stderr into a dedicated sibling log instead of proxy.log
  • keep proxy.log as the success-path Logs: target and the sole rotating runtime log owned by the proxy
  • read startup-failure tails from the dedicated stdio log so early crashes remain debuggable
  • add focused regression coverage around _start_proxy() and document the behavior change in CHANGELOG.md

Testing

  • Unit tests pass (uv run pytest tests/test_cli_proxy_env.py)
  • Linting passes (uv run ruff check headroom/cli/wrap.py tests/test_cli_proxy_env.py)
  • Formatting checks pass (uv run ruff format headroom/cli/wrap.py tests/test_cli_proxy_env.py --check)
  • Type checking passes (uv run mypy headroom)
  • New tests added for new functionality when applicable
  • Manual testing performed

Test Output

uv sync --extra dev

uv run pytest tests/test_cli_proxy_env.py
# Result: 46 passed in 2.79s

uv run ruff check headroom/cli/wrap.py tests/test_cli_proxy_env.py
# Result: All checks passed!

uv run ruff format headroom/cli/wrap.py tests/test_cli_proxy_env.py --check
# Result: 2 files already formatted

Real Behavior Proof

  • Environment: Windows, Python 3.12.13, local worktree with no live provider dependency.
  • Exact command / steps: uv run pytest tests/test_cli_proxy_env.py -k "start_proxy_redirects_subprocess_stdio_to_standalone_log or start_proxy_tail_reads_standalone_stdio_log_on_process_exit or start_proxy_passes_resolved_copilot_api_url_to_proxy" -q
  • Observed result: 3 passed, 43 deselected in 0.37s; the regression slice proves _start_proxy() now routes subprocess stdout and stderr to proxy-stdio.log, still reports Logs: .../proxy.log to the user, reads startup-failure tails from proxy-stdio.log, and preserves Copilot target URL/token env wiring.
  • Not tested: a live Windows rollover reproduction with a real proxy process writing enough output to rotate proxy.log; uv run mypy headroom; the repo-wide suite beyond the focused regression and lint checks.

Review Readiness

  • I have performed a self-review
  • This PR is ready for human review

Checklist

  • My code follows the project's style guidelines
  • 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
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the CHANGELOG.md if applicable

Screenshots (if applicable)

Not applicable, the proof is command and log behavior rather than a visual change.

Additional Notes

The intended scope stayed narrow: isolate wrap-managed stdio from proxy.log, keep runtime logging semantics unchanged, and avoid widening into proxy-side logging policy changes unless the wrap-only fix proves insufficient during implementation.

@github-actions

github-actions Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

PR governance

This PR follows the template and is marked ready for human review.

@github-actions github-actions Bot added status: needs author action Pull request body or readiness checklist still needs author updates status: ready for review Pull request body is complete and the author marked it ready for human review and removed status: needs author action Pull request body or readiness checklist still needs author updates labels Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: ready for review Pull request body is complete and the author marked it ready for human review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Windows: proxy.log RotatingFileHandler rollover fails (WinError 32) -> per-request traceback spam, log balloons to 100s of MB, CPU storm

1 participant