mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 15:10:00 +08:00
feat/https-compose-caddy
25
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
05431b264f |
fix(install): make install status agree with doctor when the proxy is reachable (#3072) (#3141)
## Description `headroom install status` could report `Status: stopped` next to `Healthy: yes`, while `headroom doctor` reported the same proxy as running (#3072, bug 2). The commands used independent process views: `install status` trusted PID/container bookkeeping for `Status`, while both commands used the live HTTP health endpoints to establish health. This change treats a successful `/readyz` probe as authoritative evidence that the deployment is running. If the proxy is not ready, `runtime_status` still distinguishes a running-but-unhealthy process from a stopped process. The PR also adds a focused macOS pytest lane for CLI and install code, closing the Darwin test-coverage gap described in #3065 without duplicating the full four-shard Linux suite. Bug 1 from #3072 (`HEADROOM_PORT` being ignored by `install apply` and `deploy`) was already fixed on `main` by #3085 and is not reimplemented here. Closes #3072 Closes #3065 ## 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 - Updated `headroom/cli/install.py` so `install_status` performs one readiness probe and reports `Status: running` whenever `/readyz` is healthy. - Kept `runtime_status` as the fallback when the proxy is not ready, preserving the distinction between running-but-unhealthy and stopped. - Added regression coverage for the formerly contradictory `Status: stopped` plus `Healthy: yes` output. - Added regression coverage for the not-ready case where process status must still come from `runtime_status`. - Added a `test-macos` CI job that runs the CLI/install pytest subset on `macos-latest`. ## Testing - [x] Unit tests pass (`pytest`) - [x] Linting passes (`ruff check .`) - [x] Type checking passes (`mypy headroom`) - [x] New tests added for new functionality - [ ] Manual testing performed ### Test Output ```text $ uv run --frozen --extra dev pytest tests/test_cli/test_install_cli.py -q ============================= test session starts ============================== platform darwin -- Python 3.11.15, pytest-9.0.3, pluggy-1.6.0 collected 42 items tests/test_cli/test_install_cli.py ..................................... [ 88%] ..... [100%] ============================== 42 passed in 1.79s ============================== $ uv run --frozen ruff check headroom/cli/install.py tests/test_cli/test_install_cli.py All checks passed! $ uv run --frozen ruff format --check headroom/cli/install.py tests/test_cli/test_install_cli.py 2 files already formatted $ uv run --frozen mypy headroom/cli/install.py --ignore-missing-imports Success: no issues found in 1 source file ``` ## Real Behavior Proof - Environment: macOS (Apple Silicon), CPython 3.11.15 via `uv`, pytest 9.0.3. - Exact command / steps: ran `uv run --frozen --extra dev pytest tests/test_cli/test_install_cli.py -q`. The new regression test invokes `headroom install status` through Click's `CliRunner` with `/readyz` returning healthy while PID/runtime bookkeeping returns `stopped`. - Observed result: the command exits successfully and prints `Status: running` with `Healthy: yes`; `Status: stopped` is absent. A second test verifies that when readiness is false, a live runtime still prints `Status: running` with `Healthy: no`. - Not tested: an end-to-end persistent-service installation with a real OS supervisor or Docker daemon. The new macOS CI job itself will be exercised by GitHub Actions rather than locally. ## Runtime Rollout Safety - Rollout-managed feature(s): none; this changes diagnostic display logic and CI coverage only. - Minimum rollout channel: stable/default patch release. - Stable/default behavior changed: yes; `install status` now reports a ready deployment as running even if PID/container bookkeeping says stopped. Unready deployments retain the existing runtime-status behavior. - Kill switch / disable path: no runtime flag; revert this PR if the readiness precedence causes an unforeseen regression. - Unsafe override required: none. - Qualification impact: `tests/test_cli/test_install_cli.py` and the new `test-macos` CI job must remain green. - Rollback path: revert commit `f3ae269b`; no persisted state, schema, manifest, or configuration migration is involved. ## 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 - [x] 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) Not applicable; this is terminal status output and CI configuration. ## Additional Notes - Documentation was not changed because no command, option, configuration contract, or documented workflow changed; this corrects contradictory diagnostic output. - #2787 was also reviewed as an urgent author-reported issue, but it already has active implementation PR #2992. This PR deliberately avoids duplicating or conflicting with that work. <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/3141" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a> <!-- devin-review-badge-end --> ### Maintainer current-main requalification Exact head `f550bf1d05873b20b773d935aa7cb93025b63262`, upstream main `2d3ee51846435ef5b320eea4806af14e602b0d8c`. Re-reviewed latest integration head |
||
|
|
feea130f81 |
fix(wrap): carry the shared proxy's extensions over to a dedicated Copilot proxy (#4154)
## Description A wrap that cannot reuse the proxy on its port starts a dedicated proxy from the shell environment alone. That happens for every Copilot subscription seed (`headroom wrap vscode`, `wrap copilot --subscription`) and for a persistent deployment with other routing: `_ensure_proxy_unlocked` prints "starting a dedicated local proxy instance" and `_start_proxy` spawns `python -m headroom.cli proxy --port N` with `os.environ.copy()` only. An enterprise install enables its savings sinks on the shared proxy as `--proxy-extension control_plane,observability,...` (`headroom start --daemon`, `headroom-start.sh`). Nothing forwarded that flag, so the dedicated proxy came up with no extensions: the local dashboard filled while the team's dashboard stayed empty, with no error anywhere. This is the shape a customer on VS Code Copilot Enterprise reported this week, and one of the explanations for #3716. ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature - [ ] Breaking change - [ ] Documentation update ## Changes Made - `headroom/proxy/server.py`: the loopback `/health` config block now lists `proxy_extensions` (the enabled names only, sorted; no plugin state). - `headroom/cli/wrap.py`: - `_dedicated_proxy_extensions(port, manifest)` reads the extension set of the proxy that owns the requested port: the running proxy's `/health` first, else the `HEADROOM_PROXY_EXTENSIONS` recorded in the persistent manifest's `base_env` (`_manifest_proxy_extensions`; the installer has no extension flag, so that is the only form a manifest records). A running proxy that predates the field falls through to the manifest, and a manifest without the entry is unknown rather than empty (the deployment's runtime env layers on the launch environment). Returns `[]` only for a non-Headroom port holder, a live `/health` reporting an empty list, or an explicitly empty manifest value; `None` otherwise, which triggers the warning. - At the dedicated start, whenever this start leaves a running proxy on the port in place (one `replaces_running_proxy` flag: Copilot seed isolation, persistent routing mismatch, the attached non-persistent routing mismatch, and the unknown-config branch) and `HEADROOM_PROXY_EXTENSIONS` is absent from the environment (an empty value counts as set: it is the way to start a bare dedicated proxy, and click lets the flag outrank the envvar, so wrap must not pass the flag then), the carried set is passed to `_start_proxy(proxy_extensions=...)`, which adds `--proxy-extension <csv>`. The banner prints `Extensions carried over from the proxy on port N: ...`, or one `Warning:` line with the remedy (`HEADROOM_PROXY_EXTENSIONS=<names>`) when the set could not be read. - An explicit `HEADROOM_PROXY_EXTENSIONS` in the environment is inherited by the subprocess and wins; nothing changes when no proxy owns the port. - Tests: `tests/test_cli/test_wrap_persistent.py` (carry-over from `/health`, env wins for both a value and an empty string, warning when unreadable, no warning for a foreign port holder, manifest fallback, older proxy falling through to the manifest, older proxy with a silent manifest warning, explicitly empty manifest value trusted, the attached routing-mismatch branch, plain start unchanged; the two existing isolated-seed tests now stub `_query_proxy_health` so they stay hermetic), `tests/test_cli/test_wrap_helpers.py` (`_start_proxy` emits the flag), `tests/test_proxy_healthchecks.py` (`/health` reports the names). ## Testing - [x] Unit tests pass (`pytest`) - [x] Linting passes (`ruff check .`) - [x] Type checking passes (`mypy headroom`) - [x] New tests added for the fix - [x] Manual testing performed (live run below) ### Test Output ```text $ pytest -q tests/test_cli/test_wrap_persistent.py tests/test_cli/test_wrap_helpers.py \ tests/test_proxy_healthchecks.py tests/test_cli/test_wrap_vscode.py \ tests/test_cli/test_wrap_copilot.py tests/test_proxy_extensions.py 4 failed, 193 passed in 7.25s # The 4 failures are on clean main too (same files, patch reverted): # tests/test_cli/test_wrap_persistent.py::test_{ensure_proxy_recovers_matching_persistent_deployment, # ensure_proxy_recovers_persistent_deployment_when_socket_is_bound, # recover_persistent_proxy_reuses_healthy_deployment,recover_persistent_proxy_warns_for_task_deployment} # AttributeError: '_Manifest' object has no attribute 'runtime_kind' (install/runtime.py:241, since #4123) $ uvx ruff@0.16.8 check <touched files> && uvx ruff@0.16.8 format --check <touched files> All checks passed! / 5 files already formatted $ mypy headroom/cli/wrap.py headroom/proxy/server.py --ignore-missing-imports Success: no issues found in 2 source files ``` ## Real Behavior Proof - Environment: macOS, Python 3.12, repo venv with the branch on `PYTHONPATH`, native core present, `HEADROOM_WORKSPACE_DIR` pointed at a scratch directory so the developer's `settings.json` (which already enables `teams`) and client markers stay out of the run. No credentials involved; nothing redacted. - Exact command / steps: ```text # 1. shared proxy with two extensions (the shape `headroom start --daemon` / headroom-start.sh produce) $ python -m headroom.cli proxy --port 18903 --proxy-extension skill_search,lossless_guard --workers 1 Extensions: ENABLED lossless_guard,skill_search (available: foresight,kiro,lossless_guard,output_pro,routemegood,skill_search,teams,tool_search) $ curl -s 127.0.0.1:18903/health # config excerpt { "backend": "anthropic", "openai_api_url": null, "proxy_extensions": ["lossless_guard", "skill_search"], "pid": 81870 } # 2. another wrap client attached to it (marker under <workspace>/clients/18903/<pid>.json) $ python -c "import time; from headroom.cli.wrap import _register_proxy_client; _register_proxy_client(18903); time.sleep(400)" & # 3. a wrap that requests a different backend -> attached routing mismatch -> dedicated proxy $ HEADROOM_BACKEND=openai python -m headroom.cli wrap cursor --port 18903 Proxy on port 18903 has incompatible routing config (backend), but live session(s) are attached. Starting a dedicated proxy on a different port instead of reusing or disrupting it. Port 18903 is in use, using port 18904 instead. Extensions carried over from the proxy on port 18903: lossless_guard,skill_search Starting Headroom proxy on port 18904... Proxy ready — dashboard: http://127.0.0.1:18904/dashboard $ curl -s 127.0.0.1:18904/health # config excerpt { "backend": "openai", "openai_api_url": null, "proxy_extensions": ["lossless_guard", "skill_search"], "pid": 82266 } ``` - Observed result: the dedicated proxy on the next port runs the same two extensions as the shared proxy it was started beside, and the wrap banner says so. The shared proxy was neither restarted nor killed. - Control run worth knowing about: the same flow with the developer's real `settings.json` (which stores `proxy_extensions: "teams"`) showed no "carried over" line and the dedicated proxy ran `teams`: `settings.json` is applied to the environment before the guard, so a persisted `HEADROOM_PROXY_EXTENSIONS` takes the env-wins path by design. - Unit coverage adds the Copilot-seed, persistent-manifest, older-proxy and env-wins cases that the live run did not exercise. - Live Copilot run (2026-10-13, Copilot Business seat, branch merged with #4155 on current `main`): a shared proxy on 8898 with `--proxy-extension e2e_probe` (a probe extension recording which proxy loaded it and every request it saw, standing in for `control_plane`), then `headroom wrap vscode -p 8898`. Banner: `Extensions carried over from the proxy on port 8898: e2e_probe`; dedicated proxy args `--port 8899 --openai-api-url https://api.business.githubcopilot.com --proxy-extension e2e_probe`. The probe saw every request on the dedicated proxy: a 36-request model sweep plus real VS Code chat, Claude, and Agent-mode turns, all 200. Same scenario with `main`'s `wrap.py`: dedicated proxy args have no `--proxy-extension`, `/health` `proxy_extensions: []`. Also checked live: `HEADROOM_PROXY_EXTENSIONS=` → bare proxy; `HEADROOM_PROXY_EXTENSIONS=control_plane` → env wins; shared proxy with no extensions → none, no warning; no shared proxy → wrap owns the port, nothing carried. - Not tested: the portal heartbeat leg (`headroom login` + `control_plane` reporting to the dashboard). The 4 pre-existing `_Manifest` test failures named under Testing are unrelated. ## Runtime Rollout Safety - Rollout-managed feature(s): none. - Minimum rollout channel: stable. - Stable/default behavior changed: a dedicated proxy started beside a shared one now starts with that proxy's extensions instead of none. A user who wanted a bare dedicated proxy sets `HEADROOM_PROXY_EXTENSIONS=` explicitly. - Kill switch / disable path: `HEADROOM_PROXY_EXTENSIONS=` (empty) starts a bare dedicated proxy; revert the commit. - Unsafe override required: no. - Qualification impact: wrap proxy-lifecycle and health suites. - Rollback path: revert. ## 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 added tests that prove my fix is effective - [x] New and existing unit tests pass locally with my changes (except the 4 pre-existing failures named above) - [x] I did **not** edit `CHANGELOG.md` Refs #3716 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com> Co-authored-by: JerrettDavis <mxjerrett@gmail.com> |
||
|
|
976aa714ef |
fix(cli): name the broken Codex config, write init configs atomically, keep the identity check (#4129)
## Description
This PR fixes four small CLI problems.
1. **`wrap codex` with a broken `~/.codex/config.toml`.** The warning
looked like this:
```
Warning: could not update Codex config: Invalid value (at line 6, column
10)
```
The line number pointed into Headroom's own merged text, not the user's
file, and the file was never named. The warning now names the file,
gives the parse error in the user's own lines, and says what to do. The
generic Codex and Grok config warnings now also name the file.
2. **`headroom init` truncated config files while rewriting them.** It
rewrote `~/.claude/settings.json`, Codex `hooks.json` and
`~/.codex/config.toml` with `Path.write_text`. That truncates the file
before writing, so a crash or ENOSPC mid-write left a half-written file.
`init` now uses `fsutil.write_text`, the atomic writer `wrap` already
uses for these same files.
3. **The runtime identity check could be silently skipped.** `init` and
`wrap` each had a `_wait_for_runtime_ready` wrapper. It caught
`TypeError` "for test doubles" and then retried `wait_ready` without
`require_identity=True`. So any real `TypeError` inside `wait_ready`
dropped the runtime identity check. Both wrappers are removed, and
callers now pass `require_identity=True` directly.
4. **A failed hook recovery left no trace.** `_ensure_profile_running`
(the init hook's recovery path) ended in `except Exception: return`. It
now catches only what the start paths raise (`click.ClickException`,
`RuntimeError`, `OSError`, `subprocess.SubprocessError`) and logs one
WARNING after the suppressed-output block: `headroom: could not start
persistent proxy '<profile>': <error>. Check it with `headroom install
status --profile <profile>`.` A start that succeeds but never becomes
ready within 45s logs the same line with `it did not become ready within
45s` as the reason. It goes to stderr; stdout stays clean for the hook.
Any other exception is a bug and now surfaces.
Refs #4136
## 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/cli/wrap.py` `_inject_codex_provider_config`: it now parses
the user's own content, with Headroom blocks stripped, before building
the candidate.
- If that content does not parse, it warns `could not update Codex
config <path>: it is not valid TOML (<user's own parse error>); Codex
WebSocket traffic will bypass Headroom. Fix or remove the file, then
re-run.`
- If the content parses only once the Headroom block is removed, the old
repair path runs instead.
- The snapshot still happens first, so `unwrap codex` restores the file
exactly as before.
- `headroom/cli/wrap.py`: the generic Codex and Grok config warnings now
include the file path (`grok_config_paths()`).
- `headroom/cli/init.py`: `_write_json`, `_ensure_codex_provider` and
the Codex feature-block writer now call `fsutil.write_text`.
- `headroom/cli/init.py` and `headroom/cli/wrap.py`: removed
`_wait_for_runtime_ready`; callers call `wait_ready(...,
require_identity=True)` directly.
- `headroom/cli/init.py` `_ensure_profile_running`: narrowed `except
Exception: return` to the start-path exceptions and log the failure
once, as above.
- Tests:
- New `test_invalid_user_config_is_named_and_left_untouched` in
`test_wrap_codex.py`.
- New `test_write_json_keeps_the_existing_file_when_the_write_fails` in
`test_init_cli.py`. It simulates ENOSPC at fsync and checks that the
original file survives and no temp file is left.
- New
`test_ensure_profile_running_never_retries_wait_ready_without_identity`:
its `wait_ready` double raises `TypeError` whenever `require_identity`
is passed. It asserts the error propagates and `wait_ready` was called
once, with `require_identity=True`. It fails if the fallback comes back.
- New `test_ensure_profile_running_logs_a_failed_recovery`: no log on a
clean start; exactly the one WARNING above when `start_supervisor`
raises.
- New
`test_ensure_profile_running_logs_a_recovery_that_never_becomes_ready`:
the start succeeds, the 45s `wait_ready` returns False, and the WARNING
names that reason.
- The `wait_ready` doubles in `test_init_cli.py` and
`test_wrap_persistent.py` now accept, or assert, `require_identity`;
`test_recover_persistent_proxy_routes_docker_task_to_docker_supervisor`
asserts `require_identity=True`.
- All four new tests fail on origin/main and pass here.
## 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
$ pytest -q -p no:cacheprovider tests/test_cli/test_init_cli.py tests/test_cli/test_wrap_persistent.py tests/test_cli/test_wrap_codex.py tests/test_cli/test_wrap_grok.py tests/test_cli/test_init_enable_tool_search.py tests/test_cli/test_install_cli.py tests/test_install/test_providers.py tests/test_install/test_runtime.py tests/test_plugin_manifests.py tests/test_cli/test_wrap_helpers.py tests/test_cli/test_port_alignment.py
4 failed, 595 passed in 29.13s
# The 4 failures are in tests/test_cli/test_wrap_persistent.py ("'_Manifest' object has no attribute 'runtime_kind'"). They are pre-existing: clean origin/main gives "4 failed, 59 passed" for that file.
# The new tests against origin/main code:
test_invalid_user_config_is_named_and_left_untouched: 1 failed (old message names no file)
test_write_json_keeps_the_existing_file_when_the_write_fails: 1 failed (DID NOT RAISE: the old write_text never fsyncs and overwrote the file)
test_ensure_profile_running_never_retries_wait_ready_without_identity: 1 failed (DID NOT RAISE: the fallback retried without require_identity)
test_ensure_profile_running_logs_a_failed_recovery: 1 failed (no log record)
$ uvx ruff@0.16.8 check headroom/cli/init.py headroom/cli/wrap.py tests/test_cli/test_init_cli.py tests/test_cli/test_wrap_persistent.py tests/test_cli/test_wrap_codex.py
All checks passed!
$ mypy headroom/cli/init.py headroom/cli/wrap.py --ignore-missing-imports
Success: no issues found in 2 source files
```
## Real Behavior Proof
- Environment: macOS 25.6, Python 3.12, repo `.venv`.
- Exact command / steps:
1. Ran `python -m headroom.cli wrap codex --prepare-only` with a scratch
`HOME` whose `.codex/config.toml` is `model = [unterminated`. This is
the audit's reproduction, and the new test covers it.
2. Called `_recover_persistent_proxy` and `_restart_persistent_proxy`
directly, with the supervisor and `wait_ready` stubbed, and recorded the
arguments `wait_ready` received.
- Observed result:
1. Before: `Warning: could not update Codex config: Invalid value (at
line 6, column 10)`. After: the warning names
`<HOME>/.codex/config.toml`, reports the error at line 1 (the user's
line), and tells the user to fix or remove the file.
2. Both calls passed `{'timeout_seconds': 45, 'require_identity':
True}`.
- Smoke harness (real proxy started from this checkout against a local
fake upstream; temp HOME and workspace, offline):
```text
branch: cleanup/cli-integrations-config-errors-atomic-init @
|
||
|
|
44db755ee6 |
fix(install): replace the launchd wrapper with the proxy listener (#3224)
## Description The persistent service path can leave a wrapper, listener, native supervisor, or Docker container with conflicting ownership. Rebuild runtime ownership so launchd directly owns Python, Docker owns Docker across service/task presets, status and stop require deployment identity, readiness cannot be health-only, and failed cleanup preserves rollback state. Closes #3208 ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (feature that would cause existing behavior to change) - [ ] Documentation update - [ ] Performance improvement - [ ] Code refactoring (no functional changes) ## Changes Made - Make the launchd-owned Python service exec the listener in place. - Classify Docker ownership from both runtime and preset, with no competing native supervisor. - Route Docker service/task start, restart, recovery, and teardown through the Docker owner. - Verify exact process command, port, deployment profile, and runtime before status or stop. - Add POSIX, macOS, and Windows process identity fallbacks without requiring psutil. - Require identity on readiness and fail closed when cleanup cannot prove the new owner stopped. - Persist an inactive previous-deployment snapshot, keep active state durable before owner start, and make environment/provider mutation activation transactional. - Surface cleanup, persistence, supervisor, Docker, and recovery-snapshot deletion failures with actionable recovery guidance. ## Testing - [x] Unit tests pass (`uv run --locked pytest tests/test_provider_package_init.py::test_install_registry_apply_provider_scope_mutations_skips_missing_and_none tests/test_install/test_providers.py tests/test_cli/test_install_cli.py tests/test_install/test_runtime.py tests/test_install/test_supervisors.py tests/test_install/test_paths.py tests/test_install/test_state.py -q`) - [x] Linting passes (`uv run --locked ruff check` on changed install, provider, supervisor, and focused test files) - [x] Type checking passes (`uv run --locked mypy headroom --ignore-missing-imports`) - [x] New tests added for the regression - [ ] Manual testing performed through live process/supervisor environments ### Test Output ```text uv run --locked pytest tests/test_provider_package_init.py::test_install_registry_apply_provider_scope_mutations_skips_missing_and_none tests/test_install/test_providers.py tests/test_cli/test_install_cli.py tests/test_install/test_runtime.py tests/test_install/test_supervisors.py tests/test_install/test_paths.py tests/test_install/test_state.py -q ============================= 197 passed in 1.07s ============================= uv run --locked ruff check . All checks passed! uv run --locked ruff format --check . 1534 files already formatted uv run --locked mypy headroom --ignore-missing-imports Success: no issues found in 527 source files git diff --check passed; the only worktree change is the pre-existing unstaged uv.lock line-ending change ``` ## Real Behavior Proof - Environment: Windows focused process and supervisor tests, with platform-specific launchd and Docker owner paths represented by fakes. - Exact command / steps: run the focused lifecycle and state suite listed above, targeted Ruff and format checks, and the full-head mypy check. - Observed result: each persistent mode has one owner; mismatched, malformed, or unavailable identity cannot authorize cleanup; active state is durable before owner start; failed cleanup retains recovery state; mutation rollback preserves unreverted records. - Not tested: owner-level POSIX exec, a live macOS launchd job, and a Docker daemon ## Runtime Rollout Safety - Rollout-managed feature(s): None. This changes the default persistent install and recovery ownership paths. - Minimum rollout channel: Stable, after platform-specific CI and maintainer review. - Stable/default behavior changed: Yes. Persistent Python service ownership and Docker supervisor routing change. - Kill switch / disable path: `headroom uninstall` removes the managed deployment; users can reinstall with another supported preset or runtime. - Unsafe override required: No. - Qualification impact: launchd, Docker, and Windows identity paths require their platform-owned environments; local proof uses focused tests and process/supervisor fakes. - Rollback path: Revert the rollback-ordering commits in this PR, then reinstall the prior deployment if needed. Uncertain cleanup retains the active new manifest and inactive previous snapshot until the new owner is removed and recovery is completed. ## 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 - [x] I have commented my code, particularly in hard-to-understand areas - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective - [x] New and existing unit tests pass locally with my changes - [x] I have updated the CHANGELOG.md if applicable ## Additional Notes The changelog is generated by the release pipeline. Live launchd and Docker-owner behavior remains platform-owned proof; local tests do not claim those owner environments. Final implementation head: `4004e4a5`. <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/3224" target="_blank"><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.devin.ai/assets/gh-devin-review-dark.svg?v=4"><img src="https://static.devin.ai/assets/gh-devin-review-light.svg?v=4" alt="Devin Review"></picture></a> <!-- devin-review-badge-end --> --------- Co-authored-by: JD Davis <mxjerrett@gmail.com> |
||
|
|
bd0296b5e7 |
fix(wrap): strip -dev from running proxy version in restart check (#3200)
## Description
`headroom wrap` is supposed to restart an already-running proxy whose
Headroom version differs from the CLI's. The check,
`_proxy_needs_version_restart`, strips the `-dev` suffix only from the
CLI's own version. A source-built proxy reporting e.g. `0.34.0-dev`
fails the `^v?\d+\.\d+\.\d+$` release regex, normalizes to `None`, and
the check silently never fires — so any stale dev-built proxy is reused
forever. The docstring already claims the opposite behavior ("a dev CLI
still restarts a stale proxy on a real version difference"); this PR
makes the code match it.
Observed in production on a maintainer machine: a 21-day-old
`0.34.0-dev` proxy (zero attached clients) was silently reused by a
`0.37.0-dev` wrap, which then also inherited its incompatible routing
config (see linked companion PR for the routing half).
Closes #3197
## Type of Change
- [x] Bug fix (non-breaking change that fixes an issue)
## Changes Made
- `headroom/cli/wrap.py`: `_proxy_needs_version_restart` now strips
`-dev` from the *running* proxy version before normalization (mirroring
the CLI side), with a comment pinning the version scheme (`<base>-dev`
from `get_version`) so future suffix styles get stripped too.
- `tests/test_cli/test_wrap_persistent.py`: regression tests — dev proxy
vs dev CLI with different base releases restarts; same base does not;
release proxy vs dev CLI restarts; unparseable/missing versions still
never restart.
## 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 pytest tests/test_cli/test_wrap_persistent.py -q
32 passed in 0.63s
$ uv run pytest tests/test_cli/test_wrap_persistent.py tests/test_cli/test_wrap_helpers.py -q
90 passed in 0.57s
$ uv run ruff format headroom/cli/wrap.py tests/test_cli/test_wrap_persistent.py
2 files left unchanged
$ uv run ruff check headroom/cli/wrap.py tests/test_cli/test_wrap_persistent.py
All checks passed!
$ uv run mypy headroom/cli/wrap.py
Success: no issues found in 1 source file
```
## Real Behavior Proof
- Environment: macOS 26.5 arm64, Python 3.13, local source build
0.37.0-dev (integration overlay), live stale proxy: `headroom proxy
--port 8789` running 0.34.0-dev for 21 days with zero attached wrap
clients.
- Exact command / steps: `GET http://127.0.0.1:8789/health` before and
after; then from the fixed build, `python -c "from headroom.cli import
wrap as w; w._ensure_proxy(8789, False, agent_type='codex')"`.
- Observed result: before fix the same call printed "Proxy already
running" (reused). After fix: `/health` before = `version 0.34.0-dev,
pid 63454, augment_api_url set`; the call killed PID 63454 and started a
fresh proxy; `/health` after = `version 0.37.0-dev, pid 48365,
augment_api_url None`. Against a second stale proxy (port 8788) with one
live wrapper attached, the check correctly deferred ("Leaving it running
because 1 attached wrapper(s)") instead of killing a live session's
proxy.
- Not tested: the persistent-deployment variant of the version-restart
path (unit-tested only); Windows (code path is platform-independent
string handling).
## Runtime Rollout Safety
- Rollout-managed feature(s): none
- Minimum rollout channel: N/A
- Stable/default behavior changed: yes — wraps now actually restart
stale dev-built proxies instead of reusing them. Release-built proxies
(no `-dev` suffix) are byte-identical in behavior.
- Kill switch / disable path: none needed; stopping the old proxy
manually restores prior behavior.
- Unsafe override required: no
- Qualification impact: none
- Rollback path: revert the commit; reuse of stale dev proxies resumes.
## 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
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] 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)
## Additional Notes
Adversarially reviewed by a second model (glm-5.2, high reasoning)
before submission; verdict ready, one nit (version-scheme comment)
accepted and applied. Companion PRs (same incident): routing-config
reuse check, orphan-proxy watchdog.
Co-authored-by: JD Davis <mxjerrett@gmail.com>
|
||
|
|
3ffa57ec25 |
fix(wrap): never reuse a non-Headroom listener on the proxy port (#3799)
## Description
`headroom wrap` decided a proxy was running with `_check_proxy`, which
is a bare TCP connect. Any service listening on the wrap port passed
that check. When something other than Headroom held the port (seen in
practice: a caveman gateway on 8787), wrap would:
- reuse it and route the tool at it
- wait on it as a persistent deployment
- treat it as a live session in the dead-marker self-heal
A listener now counts as Headroom only if its `/health` payload carries
Headroom identity: `service: "headroom-proxy"` (reported by both the
Python and Rust proxies) or a `config` block. Generic JSON such as
`{"status": "ok"}` is foreign. Otherwise wrap uses the existing port
search.
Split out of #3366. These fixes apply to every harness and don't depend
on the wrap-target registry.
Closes #
## Type of Change
- [x] Bug fix (non-breaking change that fixes an issue)
## Changes Made
- `headroom/cli/wrap.py`:
- `_is_headroom_health(payload)`: the identity rule above.
- `_foreign_listener(port)`: TCP accepts, but `/health` does not
identify Headroom.
- `_ensure_proxy_unlocked`: a foreign listener is never reused. The port
search takes over, and a persistent manifest on a foreign-held port
falls through to a fresh proxy instead of raising "not healthy".
- `_check_and_clear_dead_wrap_marker`: a foreign listener on a dead
wrapper's port no longer counts as a live session (the marker is kept
while the writer PID is alive).
- `_launch_tool`: on port fallback the launch banner is rewritten too,
so it shows the URL the child actually got (the env already was).
- `wrap claude`: the marker/owner claim records `actual_port` instead of
the requested port.
- `_ensure_claude_wrap_selfheal_hook`: a marker-bearing hook whose
command drifted (hand edit, moved binary) is rewritten in place instead
of skipped.
- `tests/test_cli/test_wrap_claude_vertex_proxy_env.py`: runs in an
isolated cwd so it can't write a selfheal hook into the repo's
`.claude/settings.local.json`. Also gitignored
`.claude/.headroom_wrap_*.json`.
## 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
$ pytest tests/test_cli/
792 passed, 1 skipped
$ ruff check headroom/cli/wrap.py tests/test_cli/ && ruff format --check headroom/cli/wrap.py tests/test_cli/
All checks passed!
$ mypy headroom/cli/wrap.py
Success: no issues found in 1 source file
```
New: `tests/test_cli/test_wrap_foreign_listener.py` (12 tests, including
a generic-JSON `/health` server and the Rust-proxy `/health` shape),
`test_wrap_selfheal_hook_repairs_stale_command`. Updated:
`test_wrap_kimi.py::test_non_kimi_fallback_display_follows_actual_port`
(asserted the old stale banner), plus two `test_wrap_persistent.py`
tests that now identify the listener as Headroom via `/health`.
## Real Behavior Proof
- Environment: macOS (darwin 25.6.0), Python 3.13, this branch vs `main`
at
|
||
|
|
f69e2463a0 |
fix(wrap): never reuse a proxy with incompatible routing config (#3201)
## Description When `headroom wrap <tool> --port P` finds a proxy already listening, `_ensure_proxy_unlocked` decides reuse-vs-restart by comparing feature flags (`memory`, `learn`, `code_graph`, savings profile) and, only when the caller explicitly requests them, `openai_api_url`/`vertex_api_url`. Two gaps make this silently dangerous: 1. **The backend is never compared** in the shared path (`wrap copilot` has its own guard; every other tool does not). 2. **URL checks are asymmetric**: a proxy started with a non-default upstream (e.g. a Copilot tenant URL, or an augment/factory upstream from a feature-branch build) is "compatible" with every plain wrap that requests nothing, so unrelated sessions silently inherit captive routing. Observed in production: `headroom wrap codex --port 8788` reused a 21-day-old augment-routed proxy (`backend=anthropic`, `augment_api_url` set, zero clients) because nothing in the reuse check objected; the session ended up outside Headroom while the wrap reported "Proxy already running". This PR adds `_proxy_routing_mismatches` (symmetric comparison of effective backend, including `HEADROOM_BACKEND`, plus all upstream-URL keys, where "running has it set, caller did not request it" is a mismatch) and, on mismatch: - **zero live clients**: kill the proxy via the `pid` exposed in `/health` config and restart with the requested config (existing missing-flags mechanics); - **live clients attached**: never reuse and never disrupt — start a dedicated proxy on the next free port (the `wrap auggie` "different session" precedent); - **persistent deployment with routing mismatch**: leave the deployment alone (its routing comes from the manifest; killing its proxy from the ephemeral path orphans the manifest) and start a dedicated proxy on a free port; - **proxy exposes no config block at all**: never reused (it cannot be compatibility-checked and reports no PID to restart with) — dedicated port instead. Closes #3198 ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) ## Changes Made - `headroom/cli/wrap.py`: new `_PROXY_ROUTING_URL_KEYS` + `_proxy_routing_mismatches` helper (module-level so tests and future callers share it; URL keys absent from a running proxy's config compare equal to unrequested/`None`, so they are inert, never wrong, against builds that do not expose them). Wired into the persistent-deployment reuse gate (mismatch now diverts to a dedicated port instead of falling through to the ephemeral kill path) and into the ephemeral/shared branch (mismatch restarts when idle, port-bumps when clients are attached; configless proxies are no longer reused). - `tests/test_cli/test_wrap_persistent.py`: helper unit tests (backend via arg and `HEADROOM_BACKEND`, symmetric URL mismatch both directions, normalization tolerance, missing-key tolerance), restart-on-routing-mismatch, port-bump-with-clients, configless-no-reuse, persistent-divert, happy-path reuse. The pre-existing `..._restarts_persistent_deployment_for_feature_mismatch` test asserted the old kill-and-hijack behavior for a routing mismatch; updated to the divert semantic with an explanatory comment. - `tests/test_cli/test_wrap_helpers.py`: the dashboard-URL regression test now mocks a config-bearing proxy (configless is covered by the new dedicated-port test). ## 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 pytest tests/test_cli/test_wrap_persistent.py -q 38 passed in 0.45s $ uv run pytest tests/test_cli/test_wrap_helpers.py tests/test_cli/test_wrap_persistent.py -q 96 passed in 0.56s $ uv run pytest tests/test_cli -q -k 'wrap or unwrap or proxy' 525 passed, 1 skipped, 182 deselected in 12.27s $ uv run ruff format headroom/cli/wrap.py tests/test_cli/test_wrap_persistent.py tests/test_cli/test_wrap_helpers.py 3 files left unchanged $ uv run ruff check headroom/cli/wrap.py tests/test_cli/test_wrap_persistent.py tests/test_cli/test_wrap_helpers.py All checks passed! $ uv run mypy headroom/cli/wrap.py Success: no issues found in 1 source file ``` ## Real Behavior Proof - Environment: macOS 26.5 arm64, Python 3.13, local source build 0.37.0-dev (integration overlay with this PR applied), live ports: 8789 (plain 0.37.0-dev proxy), 8791 free. - Exact command / steps: with the plain proxy healthy on 8789, `python -c "from headroom.cli import wrap as w; w._ensure_proxy(8789, False, agent_type='auggie', augment_api_url='https://xlb.api.augmentcode.com')"`, then `GET /health` on the resulting port. - Observed result: `Proxy on port 8789 has incompatible routing config (augment_api_url); restarting with the requested config...` — the plain proxy was killed and an augment-routed proxy came up (on 8791: the just-freed 8789 lost the bind race and 8790 was held by another stale listener; the fallback messaging named the port change). `/health` on 8791: `version 0.37.0-dev, augment_api_url https://xlb.api.augmentcode.com`. Before this PR the identical call printed "Proxy already running on port 8789" and reused the plain proxy. - Not tested: the attached-clients port-bump path against real live traffic (unit-tested with mocked markers); the persistent-deployment divert against a real `install agent` deployment (unit-tested); Windows. ## Runtime Rollout Safety - Rollout-managed feature(s): none - Minimum rollout channel: N/A - Stable/default behavior changed: yes — wraps no longer silently reuse proxies whose backend/upstream routing differs, and no longer reuse configless proxies. Previously-correct reuse (identical config) is unchanged and still prints the dashboard URL. - Kill switch / disable path: `headroom wrap <tool> --no-proxy` bypasses the check entirely (pre-existing). - Unsafe override required: no - Qualification impact: none - Rollback path: revert the commit; the previous reuse heuristic returns. ## 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 - [x] I have commented my code, particularly in hard-to-understand areas - [x] 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) ## Additional Notes Adversarially reviewed by a second model (glm-5.2, high reasoning); initial verdict needs-work, all accepted findings applied (configless no-reuse, persistent-divert, honest docstring about which URL keys this build's own `/health` exposes) and re-tested green. Companion PRs (same incident): `-dev` version-restart fix, orphan-proxy watchdog. Follow-up for the auggie/droid feature branches: expose `augment_api_url`/`factory_api_url` in their `/health` config payloads so same-build detection works there too (this PR already catches older/foreign builds that expose them). |
||
|
|
9089e7f7d3 |
feat(opencode): support Copilot subscription backend for headroom models (#2441) (#2445)
## Description `headroom wrap opencode` currently routes `headroom/*` models only to ordinary Anthropic or OpenAI backends. A user with a GitHub Copilot subscription cannot point those `headroom/*` requests at the Copilot seat while keeping Headroom compression and stats, even though Headroom already has the validated subscription resolver, the proxy seed path, and the OpenCode provider route needed to do it. This PR adds `--copilot-subscription` to the OpenCode wrap command. It reuses the existing Copilot subscription token resolver, passes the validated endpoint and token seed into the existing proxy startup path, rejects unsupported runtime modes, and treats any non-empty Copilot API token as a private session seed so token-only sessions do not reuse a shared proxy. The generated OpenCode provider still targets the local proxy, and subscription secrets stay out of OpenCode config, environment, and terminal output. Closes #2441 ## Type of Change - [ ] Bug fix (non-breaking change that fixes an issue) - [x] 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 - Add `headroom wrap opencode --copilot-subscription` in `headroom/cli/wrap.py`. - Reuse the existing validated Copilot subscription resolver through one small required-resolution helper shared with the dedicated Copilot wrapper. - Pass the resolved endpoint and token seed into `_ensure_proxy()` as `openai_api_url`, `copilot_api_token`, `copilot_refresh_oauth_token`, and `copilot_api_token_expires_at`. - Reject `--copilot-subscription` with `--no-proxy`, `--prepare-only`, and translated backends before proxy or OpenCode launch. - Validate subscription mode before snapshotting OpenCode config, so rejected invocations don't create stale backups. - Scrub inherited Copilot proxy seed variables from the OpenCode child environment. - Treat any non-empty Copilot API token as a private session seed so token-only sessions do not reuse shared or persistent proxies. - Add focused OpenCode and persistent-proxy coverage for seed handoff, guard failures, direct-token isolation, secret non-disclosure, and unchanged non-subscription behavior. - Leave `CHANGELOG.md` untouched because Headroom generates changelog entries from conventional commits. ## Testing - [x] Unit tests pass (`uv run pytest tests/test_cli/test_wrap_opencode.py tests/test_cli/test_wrap_persistent.py tests/test_cli/test_wrap_copilot.py -q`, `106 passed in 136.65s`) - [x] Linting passes (`uv run ruff check headroom/cli/wrap.py tests/test_cli/test_wrap_opencode.py tests/test_cli/test_wrap_persistent.py`) - [ ] Type checking passes (`uv run mypy headroom`) - [x] New tests added for new functionality when applicable - [ ] Manual testing performed ### Test Output ```text Targeted subscription tests pass: OpenCode `7 passed, 37 deselected in 0.36s`, persistent proxy `2 passed, 29 deselected in 0.34s`, and dedicated Copilot `11 passed, 20 deselected in 0.39s`. Coverage includes inherited resolver-input env scrubbing, HEADROOM_BACKEND rejection, no-backup-on-rejection, OpenCode-only scrub scoping, and private-proxy teardown on config-injection failure. The full focused command `uv run pytest tests/test_cli/test_wrap_opencode.py tests/test_cli/test_wrap_persistent.py tests/test_cli/test_wrap_copilot.py -q` passed with `106 passed in 136.65s`. Ruff check and format check pass. ``` ## Real Behavior Proof - Environment: Windows, `uv` development environment, local CLI tests, no live Copilot seat on this host - Exact command / steps: run the focused OpenCode and persistent-proxy tests with a mocked `CopilotSubscriptionTokenResolution`, then capture the proof rows for seed handoff, direct-token isolation, guards, and secret non-disclosure - Observed result: Targeted subscription and proxy-seed tests pass, including OpenCode-only resolver-input env scrubbing and private-proxy teardown on config-injection failure; the full focused command passed with `106 passed in 136.65s`; Ruff check and format check pass. - Not tested: live Copilot subscription seat run on this host ## 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 feature works - [x] New and existing unit tests pass locally with my changes - [ ] I have updated the CHANGELOG.md if applicable ## Additional Notes - Feature approval comes from the open `enhancement` label on https://github.com/headroomlabs-ai/headroom/issues/2441. - Keep the final live-backend claim behind manual owner proof. Local CLI tests can prove config, guard, secret, and proxy-seed behavior, but they cannot prove a real Copilot seat on this host. - `CHANGELOG.md` remains untouched because Headroom's release pipeline generates changelog entries from conventional commits. |
||
|
|
5d17e9addc |
fix: check feature configuration before reusing persistent deployments (#1330)
## Description
A persistent proxy started for one use case (e.g. `--backend anthropic`)
would be silently reused for another (e.g. `--subscription
--provider-type openai`) causing 401 auth failures because
`_ensure_proxy()` only checked health + version, skipping the feature
configuration check (memory, openai_api_url, learn, code_graph).
Closes #N/A
## 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
- Added feature configuration check in the persistent deployment path of
`_ensure_proxy()` in `headroom/cli/wrap.py:1726-1752`. When features
mismatch, the code now falls through to the non-persistent path which
handles proxy restart with upgraded config.
- Added three new tests in `tests/test_cli/test_wrap_persistent.py`:
-
`test_ensure_proxy_restarts_persistent_deployment_for_feature_mismatch`
— verifies proxy restart when openai_api_url differs
- `test_ensure_proxy_restarts_persistent_deployment_for_memory_mismatch`
— verifies proxy restart when memory is requested but not enabled
- `test_ensure_proxy_reuses_persistent_deployment_when_features_match` —
verifies proxy reuse when all features match
- Updated `CHANGELOG.md` with fix description
## 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
$ ruff check headroom/cli/wrap.py tests/test_cli/test_wrap_persistent.py
All checks passed!
$ ruff format --check headroom/cli/wrap.py tests/test_cli/test_wrap_persistent.py
2 files already formatted
$ python -c "
from tests.test_cli.test_wrap_persistent import *
import pytest
test_ensure_proxy_restarts_persistent_deployment_for_feature_mismatch(pytest.MonkeyPatch())
print('Test 1 passed: feature mismatch restarts proxy')
test_ensure_proxy_restarts_persistent_deployment_for_memory_mismatch(pytest.MonkeyPatch())
print('Test 2 passed: memory mismatch restarts proxy')
test_ensure_proxy_reuses_persistent_deployment_when_features_match(pytest.MonkeyPatch())
print('Test 3 passed: matching features reuse proxy')
print('All tests passed!')
"
Test 1 passed: feature mismatch restarts proxy
Test 2 passed: memory mismatch restarts proxy
Test 3 passed: matching features reuse proxy
All tests passed!
$ .venv/bin/mypy headroom
headroom/proxy/server.py:1230: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked]
headroom/proxy/server.py:1301: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked]
headroom/proxy/server.py:1305: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs [annotation-unchecked]
Success: no issues found in 397 source files
```
## Real Behavior Proof
- Environment: Linux (WSL2) Ubuntu 24.04, Python 3.12, persistent
deployment via `headroom install agent run --profile default` with
`--backend anthropic`
- Exact command / steps:
1. Started persistent deployment: `headroom install agent run --profile
default`
2. Ran copilot wrapper: `headroom wrap copilot --subscription
--provider-type openai --wire-api responses --memory -- --model
gpt-5.4-mini`
- Observed result:
- Before fix: Proxy forwarded to `api.openai.com` instead of
`api.githubcopilot.com`, causing 401 auth errors
- After fix: Proxy correctly forwards to `api.githubcopilot.com` and
copilot works as expected
- Not tested: macOS, Windows, enterprise/data-residency accounts, other
wrapped tools (claude, codex, aider)
## 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
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] 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 have updated the CHANGELOG.md if applicable
## Screenshots (if applicable)
N/A
## Additional Notes
The fix is minimal and targeted. It only adds a feature configuration
check in the persistent deployment path without changing any other
behavior. The non-persistent proxy path already had this check; this PR
brings the same logic to persistent deployments.
Co-authored-by: carlosduplar <[email protected]>
|
||
|
|
4364eb8dc4 |
fix(copilot): refresh wrapped subscription tokens (#2156) (#2182)
## Description `headroom wrap copilot --subscription` currently validates a Copilot subscription credential once at launch, exchanges it once, and then pins that short-lived API token into the proxy as an explicit override. When the token expires, long-lived wrapped sessions start returning `transient_auth_error` and then a final HTTP 401 until the entire wrapped session is restarted. This PR keeps the validated launch token for first-request determinism, carries reusable OAuth refresh material into the proxy, and refreshes inside `CopilotTokenProvider` when the seeded token is expired. The explicit `GITHUB_COPILOT_API_TOKEN` override path stays unchanged when no reusable OAuth token exists. The configured `GITHUB_COPILOT_API_URL` also stays pinned across refresh, matching the current wrap contract. Closes #2156. ## 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 - Extended the Copilot subscription token resolution path to carry reusable OAuth refresh material and expiry metadata instead of discarding it after the wrap-time exchange. - Reworked `CopilotTokenProvider.get_api_token()` so it seeds the wrapper-validated launch token once for the first request, then refreshes through the existing exchange path when that token is expired and reusable OAuth material exists. - Rejected non-finite seeded expiry values such as `inf`, so malformed `GITHUB_COPILOT_API_TOKEN_EXPIRES_AT` inputs cannot pin a stale launch token forever. - Preserved the explicit `GITHUB_COPILOT_API_TOKEN` override path when no reusable OAuth token exists, so non-refreshable overrides keep today's fixed behavior. - Kept explicitly configured `GITHUB_COPILOT_API_URL` values pinned across refresh rather than adopting a refreshed payload's host. - Replaced wrapper-managed seeded `tid_` bearer passthrough with the refresh-aware provider path, so the wrapped CLI no longer bypasses expiry refresh just because it keeps sending the launch token back to the proxy. - Started a dedicated local proxy instance whenever a subscription-seeded session targets a shared or persistent proxy port, so per-session refresh material is not silently dropped on healthy-proxy reuse or cross-wired between concurrent sessions. - Scrubbed inherited Copilot refresh-seed environment variables from both the Copilot child env and the proxy subprocess env before re-injecting the explicit launch-time values. - Added focused auth, wrap, proxy-env, and proxy-reuse regression coverage for expiry refresh, non-finite expiry rejection, session-local proxy isolation, explicit-override preservation, exchange-flag independence, configured API URL pinning, and secret handling. ## Testing - [x] Unit tests pass (`uv run pytest tests/test_copilot_auth.py tests/test_cli/test_wrap_copilot.py tests/test_cli_proxy_env.py tests/test_cli/test_wrap_persistent.py -q`) - [x] Linting passes (`uv run ruff check headroom/copilot_auth.py headroom/cli/wrap.py tests/test_copilot_auth.py tests/test_cli/test_wrap_copilot.py tests/test_cli_proxy_env.py tests/test_cli/test_wrap_persistent.py`) - [x] Formatting passes (`uv run ruff format --check headroom/copilot_auth.py headroom/cli/wrap.py tests/test_copilot_auth.py tests/test_cli/test_wrap_copilot.py tests/test_cli_proxy_env.py tests/test_cli/test_wrap_persistent.py`) - [x] Type checking passes (`uv run mypy headroom/copilot_auth.py`) - [x] New tests added for new functionality when applicable - [ ] Manual testing performed ### Test Output ```text 195 passed, 1 skipped in 3.14s ``` ```text All checks passed! ``` ```text 6 files already formatted ``` ```text Success: no issues found in 1 source file ``` ## Real Behavior Proof - Environment: Python 3.12.13, `uv`, no live Copilot credentials. - Exact command / steps: run the focused auth, wrap, proxy-env, and proxy-reuse regression suite after seeding an expired launch token plus reusable OAuth refresh material, then rerun lint and format checks on the touched files. - Observed result: base reproduces the bug because the explicit-token branch never refreshes, accepts non-finite expiry inputs, and shared-proxy reuse can keep the wrong per-session refresh seed alive; head refreshes through the reusable OAuth token, rejects non-finite seeded expiry, replaces the wrapper-managed seeded bearer instead of blindly passing it through, preserves the valid-seed fast path and the fixed override path when no refresh material exists, keeps the configured API URL pinned across refresh, starts a dedicated local proxy when the requested port already belongs to a shared or persistent proxy, and keeps the reusable OAuth token confined to explicit proxy launch env only. The focused suite passed with `195 passed, 1 skipped in 3.14s`. - Not tested: live business-subscription session past the provider's real token-expiry window. ## 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 - [x] I have commented my code, particularly in hard-to-understand areas - [x] 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 have updated the CHANGELOG.md if applicable ## Additional Notes - Scope stays provider-local. The fix remains inside `headroom/copilot_auth.py` and the Copilot wrap handoff in `headroom/cli/wrap.py`; it does not add generic 401 retry logic to provider-neutral proxy layers. - The line that disables token exchange for the Copilot CLI child env is unchanged because it never reached the proxy env and was not the root cause. - Subscription-seeded sessions now get a dedicated local proxy whenever the requested port already belongs to a shared or persistent proxy; existing shared proxies are left alone to avoid disrupting attached wrappers. - Live provider confirmation still needs maintainer or reporter validation because that truth is owned by GitHub's real subscription APIs, not by local stubs. - Headroom's release pipeline generates changelog entries from conventional commits, so `CHANGELOG.md` is intentionally untouched. |
||
|
|
1cc99792ac |
fix(version): mark source-checkout builds as -dev (#2072)
## Description
`headroom --version` and the dashboard show `0.32.0` from a source
checkout, but the latest published release is `0.31.0`. That `0.32.0` is
not a real release: on a git checkout `get_version()` predicts the
*next* release from conventional commits since the last tag (`v0.31.0` +
`feat:` commits → `0.32.0`) and renders it identically to a shipped
version — so a dev build looks published.
This appends `-dev` on the source-checkout path so a dev build is never
mistaken for the published release.
Closes #
## Type of Change
- [x] Bug fix (non-breaking change that fixes an issue)
## Changes Made
- `headroom/_version.py`: the source-checkout branch of `get_version()`
now returns `f"{source_version}-dev"`.
- `tests/test_package_init_lazy.py`: updated the source-tree version
test to assert the `-dev` suffix.
Released installs are unaffected: pip wheels and Docker images with a
baked `BUILD_VERSION` never take the source-checkout path, so they still
report clean release versions (`0.31.0` / `v0.31.0`). The suffix makes
`is_release_version()` return `False` and `normalize_release_version()`
return `None`, which every comparison site already handles — e.g.
`wrap.py`'s `_proxy_needs_version_restart` requires both sides to
normalize, so a dev build short-circuits to "no restart" (no behavior
change).
## Testing
- [x] Unit tests pass (`pytest`)
- [x] Linting passes (`ruff check .`)
- [x] Type checking passes (`mypy headroom`)
- [x] New tests added for new functionality (updated the existing
source-tree test)
- [x] Manual testing performed
### Test Output
```text
$ python -m pytest tests/test_package_init_lazy.py tests/test_cli_doctor.py -q
============================== 12 passed in 1.79s ==============================
============================== 51 passed in 0.56s ==============================
$ ruff check headroom/_version.py tests/test_package_init_lazy.py
All checks passed!
$ mypy headroom/_version.py
Success: no issues found in 1 source file
```
## Real Behavior Proof
- Environment: local source checkout (macOS), `.venv`, latest release
tag `v0.31.0`
- Exact command / steps: `headroom --version`
- Observed result:
- Before: `headroom, version 0.32.0` — indistinguishable from a release
- After: `headroom, version 0.32.0-dev`
- Not tested: behavior inside a built Docker image / installed pip wheel
— unchanged by design, since those paths never compute a source-tree
version.
## 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
- [x] 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
- [ ] I have updated the CHANGELOG.md if applicable
## Additional Notes
Scope kept to a bare `-dev` marker, which answers "is this a release?".
Appending the short git SHA (`-dev+g<sha>`) to distinguish individual
dev builds in bug reports is an easy follow-up if wanted. Docs/CHANGELOG
unchecked as N/A for a dev-only version-string fix.
---------
Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
|
||
|
|
38074888ac |
fix(docker): report source build version (#1862)
## Description Closes #1858 Docker/Compose source builds could report stale or misleading version information: the dashboard initially rendered a hardcoded `v0.3.0`, then `/health` replaced it with installed package metadata, which can be stale when building locally from `main` without release metadata in the image. This change makes source Docker Compose builds report an explicit source-build identity, removes the stale dashboard fallback, and keeps CLI/doctor version checks from treating source-build labels as release-version drift. ## 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 - Add `HEADROOM_VERSION` / `HEADROOM_BUILD_VERSION` runtime version overrides and optional packaged `_build_info.py` metadata. - Teach Docker Compose source builds to pass a `source-build` sentinel that the Dockerfile expands to `source-build+g<sha>` when git metadata is available, or `source-build+sha256.<digest>` otherwise. - Keep release/published image builds on normal package metadata when `HEADROOM_BUILD_VERSION` is unset. - Include only minimal `.git` metadata in the Docker build context so the source-build label can identify the checkout without copying git objects. - Treat source-build labels and raw hashes as non-release labels in `wrap` and `doctor`, avoiding false stale-proxy restarts and drift warnings. - Replace the dashboard hardcoded `0.3.0` fallback with `loading` / `unknown` and format non-release build labels without a `v` prefix. - Include the runtime version in proxy startup logs, `/health`, `/livez`, and OTEL service version reporting. ## Testing - [x] Unit tests pass (`pytest` in GitHub CI) - [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 GitHub CI: all checks passing - CI: build, build-wheel, lint, test shards, test-extras, test-agno, test-dashboard-ui - Docker: docker-native-e2e, docker-wrap-e2e, docker-init-e2e - Native wrappers: macOS, Windows, Ubuntu - Security: CodeQL, gitleaks, pip-audit - Governance: template, label, merge-conflicts, commitlint $ HEADROOM_REQUIRE_RUST_CORE=false PYTHONPATH=/Users/vinaygupta/Desktop/git/headroom-fix-1858-version-mismatch pytest tests/test_package_init_lazy.py::test_version_prefers_explicit_build_env tests/test_package_init_lazy.py::test_version_label_helpers_only_prefix_release_versions tests/test_package_init_lazy.py::test_version_uses_packaged_build_metadata tests/test_package_init_lazy.py::test_observability_version_uses_runtime_version tests/test_docker_compose_persistence.py tests/test_cli_doctor.py::TestProxyLiveness::test_up_leaves_source_label_unprefixed tests/test_cli_doctor.py::TestVersionDrift::test_non_release_version_labels_skip_drift_comparison tests/test_cli/test_wrap_persistent.py::test_proxy_version_restart_ignores_non_release_source_labels tests/test_proxy_dashboard_stats_cache.py::test_dashboard_uses_cached_stats_and_lazy_history_feed_polling -q 13 passed, 1 warning $ uvx ruff==0.15.17 check . All checks passed! $ uvx ruff==0.15.17 format --check . 1058 files already formatted $ uvx mypy==1.20.2 headroom --ignore-missing-imports Success: no issues found in 407 source files $ git diff --check # no output $ docker compose config # resolved headroom-proxy build args include HEADROOM_BUILD_VERSION: source-build $ HEADROOM_BUILD_VERSION=6266a1d docker compose config # explicit override is preserved as HEADROOM_BUILD_VERSION: 6266a1d $ docker build --check --build-arg HEADROOM_BUILD_VERSION=source-build . Check complete, no warnings found. ``` ## Real Behavior Proof - Environment: macOS local checkout, Python 3.13.5, Docker Desktop builder `desktop-linux`, plus GitHub Actions CI. - Exact command / steps: `docker compose config`, `HEADROOM_BUILD_VERSION=6266a1d docker compose config`, and `docker build --check --build-arg HEADROOM_BUILD_VERSION=source-build .`. - Observed result: Compose defaults the top-level `headroom-proxy` build arg to the `source-build` sentinel, preserves explicit overrides, and Dockerfile syntax/check validation passes for the source-build path. - Not tested: Full end-to-end release publishing flow; this PR only changes local/source-build reporting. - CI proof: GitHub Actions completed successfully across Docker E2E, CI test shards, lint/type checks, native wrapper checks, security checks, and PR governance. ## 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 - [x] 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/CI with my changes - [ ] I have updated the CHANGELOG.md if applicable ## Screenshots (if applicable) N/A ## Additional Notes Docs and changelog are N/A for this runtime-reporting bug fix. The PR is open and ready for review with all GitHub checks passing. |
||
|
|
b4205c68e6 |
fix(wrap): replace stale-proxy detection with Vite-style port fallback (#1406)
## Description Replace the 180-line process-killing approach with a 15-line Vite-style socket.bind probe: if port is busy (EADDRINUSE or EACCES), try the next available port. Pure stdlib -- no /proc, no lsof, no subprocess -- works identically on Linux/macOS/Windows. ## Problem When `headroom wrap <agent>` is killed without proper cleanup (window close, SSH timeout, crash), the background proxy becomes orphaned and holds the port. The next `headroom wrap` on the same port would wait 30-45 seconds then fail with a confusing error. This PR takes a simpler, safer approach: find the next available port. No process detection, no killing. ### Related issues - **#589** (Port 8787 reserved by Windows) -- partially addressed: EACCES is now skipped together with EADDRINUSE - **#804** (Shared proxy killed by exiting session) -- already fixed upstream via `_live_proxy_clients` marker files; this PR doesn't touch that code ## Type of Change - [x] New feature (non-breaking change that adds functionality) - [x] Code refactoring (no functional changes) ## Changes Made - `headroom/cli/wrap.py`: Add `_find_available_port()` -- socket.bind loop that skips EADDRINUSE (busy) and EACCES (reserved/privileged) ports, returns first available port in range. Replace `_ensure_proxy` port-bind check with auto-fallback call to `_find_available_port`. Remove `_ensure_port_free()` call from `_start_proxy()`. Remove 8 dead functions: `_find_process_on_port`, `_linux_find_process_on_port`, `_resolve_inode_to_pid`, `_is_headroom_proxy`, `_read_process_cmdline`, `_kill_process`, `_ensure_port_free`, `_format_unbindable_port_error`. - `tests/test_cli/test_wrap_helpers.py`: Remove 14 old `TestEnsurePortFree` tests (mocked /proc parsing, process killing). Add 6 new `TestFindAvailablePort` tests covering: port free, first port busy, multiple busy, EACCES skipped, unexpected error propagated, range exhausted. - `tests/test_cli/test_wrap_persistent.py`: Adapt persistence tests for `_find_available_port` mock. Rewrite unbindable-port test to use new error path. Zero new dependencies. Zero changes to core proxy server, MCP, compression, or providers. ## Testing - [x] Unit tests pass (`python -m pytest tests/test_cli/ -v`) - [x] New tests added for new functionality ### Test Output ``` > python -m pytest tests/test_cli/test_wrap_helpers.py::TestFindAvailablePort -v --no-header ============================= 6 passed ============================== test_port_free_returns_same PASSED test_port_busy_finds_next PASSED test_multiple_busy_ports PASSED test_propagates_unexpected_error PASSED test_propagates_eaddrinuse_with_eacces PASSED test_exhausts_range PASSED > python -m pytest tests/test_cli/ -q ============================= 445 passed in 8.40s ============================== ``` ## Real Behavior Proof - Environment: Ubuntu 24.04 x86_64, Python 3.12.3 - Exact command / steps: Ran `python -m pytest tests/test_cli/test_wrap_helpers.py::TestFindAvailablePort -v` -- 6/6 pass for port fallback. Ran full test suite `python -m pytest tests/test_cli/ -q` -- 445/445 pass. - Observed result: `_find_available_port(8787)` returns 8787 when free, 8788 when 8787 is busy. EACCES skipped same as EADDRINUSE. Non-retryable errors (EADDRNOTAVAIL) propagate immediately. - Not tested: Windows EACCES fallback (no Windows CI runner). macOS port fallback (no macOS runner). Code path is identical across platforms (stdlib socket only). ## 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 - [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 |
||
|
|
16c638bc21 |
fix: recover persistent proxy feature checks and reject non-Copilot exchange URL (#1465)
## Description This PR fixes two related reliability issues in Copilot wrap/subscription flows: 1. Recovered persistent proxy instances could be reused too early, before validating requested feature-sensitive config (especially `openai_api_url`), which could lead to wrong upstream routing. 2. Subscription token-exchange payloads could provide a non-Copilot API URL; this is now rejected and we safely fall back to user-info/default Copilot endpoint resolution. Related: #488 ## 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 - Updated persistent proxy recover path to: - continue into feature checks when feature-sensitive options are requested - restart persistent deployment when config is missing/mismatched after recovery - keep historical fast return for plain recover-only calls - Hardened subscription exchange URL resolution: - accept exchange `api_url` only when it is a Copilot host - log warning and fall back when non-Copilot host is provided - Added regression tests for: - recovered persistent proxy feature mismatch and config-unavailable restart behavior - non-Copilot exchange host rejection with/without user-info fallback ## Testing - [x] Unit tests pass (`pytest`) - [x] Linting passes (`ruff check .`) - [ ] Type checking passes (`mypy headroom`) - [x] New tests added for new functionality - [x] Manual testing performed ### Test Output ```text $ python -m pytest -q tests/test_copilot_auth.py tests/test_cli/test_wrap_persistent.py ============================= test session starts ============================= platform win32 -- Python 3.12.8, pytest-9.1.1, pluggy-1.6.0 rootdir: C:\Users\ralf.escher\Documents\headroom collected 82 items tests\test_copilot_auth.py ............................................. [ 54%] ........... [ 68%] tests\test_cli\test_wrap_persistent.py .......................... [100%] ============================= 82 passed in 1.60s ============================== ``` ## Real Behavior Proof - Environment: - Windows - Python 3.12.8 - Local Headroom branch with this patch - Copilot subscription route through local proxy - Exact command / steps: 1. Start local proxy and run Copilot wrap in subscription mode. 2. Execute chat-completions requests through proxy. 3. Inspect runtime proxy logs for outbound target and inbound status. 4. Run focused regression tests: - `python -m pytest -q tests/test_copilot_auth.py tests/test_cli/test_wrap_persistent.py` - Observed result: - Outbound requests routed to Copilot business host: - `path=https://api.business.githubcopilot.com/chat/completions` - Successful proxy responses observed: - `path=/v1/chat/completions status=200` - Model activity logged during successful requests: - `PERF model=gpt-4.1 ...` - Regression tests pass (`82 passed`), covering both fixes. - Not tested: - Full repository test suite - Full lint/typecheck across entire project - Non-Windows runtime verification in this run ## 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 - [x] 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 - [ ] I have updated the CHANGELOG.md if applicable ## Additional Notes - This PR intentionally excludes incidental local edits to `.github/copilot-instructions.md`. - Scope is limited to this bug fix and regression coverage; linked as related work to #488. |
||
|
|
b829ceba84 |
fix(wrap): keep agent savings opt-in (#1294)
## Description Fixes a regression from #830 where `headroom wrap codex` / `claude` / `cursor` treated `agent-90` as required even when the user started a normal proxy without `HEADROOM_SAVINGS_PROFILE`. A plain `headroom proxy` on port 8787 followed by `headroom wrap codex` currently reports `Proxy on port 8787 is missing: --savings-profile` and tries to restart the already-running proxy. The `agent-90` profile was documented as opt-in, so wrap should only require or inject it when `HEADROOM_SAVINGS_PROFILE` is explicitly set. Closes #1293 ## 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 - Stop defaulting agent wrappers to `agent-90` when `HEADROOM_SAVINGS_PROFILE` is unset. - Stop reporting agent-savings config mismatches unless an agent savings profile was explicitly requested. - Add regression tests for default wrap startup, explicit profile forwarding, and reuse/restart behavior around existing proxies. - Fix repo-wide pre-commit issues found during amend: Windows-safe `fcntl` typing, an optional env typing issue, OpenCode JSON parser return typing, and ruff import/format drift. ## 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 > maturin develop -m crates/headroom-py/Cargo.toml Finished `dev` profile [unoptimized + debuginfo] target(s) in 27.41s Built wheel for abi3 Python >= 3.10 Installed headroom-ai-0.27.0 > C:\git\headroom\.venv\Scripts\python.exe -c "from headroom._core import hello; print(hello())" headroom-core > ruff check . All checks passed! > ruff format --check . 913 files already formatted > C:\git\headroom\.venv\Scripts\python.exe -m mypy headroom Success: no issues found in 388 source files > C:\git\headroom\.venv\Scripts\python.exe -m pytest tests/test_agent_savings.py tests/test_cli/test_wrap_persistent.py tests/test_proxy_healthchecks.py tests/test_transforms/test_content_router.py -q collected 112 items 112 passed, 1 warning in 16.04s > git diff --check # no output > git commit --amend --no-edit Sync plugin versions.....................................................Passed ruff.....................................................................Passed ruff-format..............................................................Passed mypy.....................................................................Passed ``` ## Real Behavior Proof - Environment: Windows dev checkout, Python 3.13.3 via `C:\git\headroom\.venv\Scripts\python.exe`, Rust extension built with `maturin develop -m crates/headroom-py/Cargo.toml`. - Exact command / steps: reproduced the code path from #830 by exercising `_ensure_proxy(8787, False, agent_type="codex")` with a running proxy health payload that has no `savings_profile`, and by exercising `_start_proxy(8787, agent_type="codex")` with `HEADROOM_SAVINGS_PROFILE` unset and set. - Observed result: without `HEADROOM_SAVINGS_PROFILE`, wrap reuses the running proxy and `_start_proxy` does not inject `HEADROOM_SAVINGS_PROFILE` or `HEADROOM_TARGET_RATIO`; with `HEADROOM_SAVINGS_PROFILE=agent-90`, wrap still requires/forwards the profile and restarts an incompatible proxy. - Not tested: full end-to-end CLI launch against a live Codex binary. The focused proxy/wrap tests cover the failing restart/config decision directly. ## 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 - [x] 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 - [ ] I have updated the CHANGELOG.md if applicable ## Screenshots (if applicable) N/A ## Additional Notes The pytest run emits an existing Windows `cp1252` background-thread warning while reading subprocess output; the tests still pass. No documentation or changelog update is included because this restores the already-documented opt-in behavior for `agent-90`. |
||
|
|
b4571cc346 |
feat: headroom wrap opencode / unwrap opencode CLI (#1105)
## Summary This PR implements transparent `headroom wrap opencode` support without asking users to edit OpenCode provider URLs, choose an extra CLI flag, or maintain a static provider list. The wrapper now lives at the runtime transport boundary: OpenCode keeps its user/provider config, while Headroom intercepts outbound provider traffic in-process and routes it through the local Headroom proxy. ## What changed ### Transparent OpenCode wrapping - `headroom wrap opencode` injects the `headroom-opencode` plugin through `OPENCODE_CONFIG_CONTENT`. - Existing OpenCode provider URLs are preserved. We do not rewrite user config URLs to point at Headroom. - Existing `OPENAI_BASE_URL` and `ANTHROPIC_BASE_URL` env vars are preserved. - Local OpenCode traffic, localhost traffic, and Headroom proxy traffic bypass the shim to avoid loops. ### Runtime transport interception - Added an OpenCode plugin transport shim that wraps: - `globalThis.fetch` - `http.request` / `http.get` - `https.request` / `https.get` - External provider calls are routed to the local Headroom proxy. - The original upstream origin is passed through `x-headroom-base-url`, so the proxy can forward to the real provider without changing OpenCode config. - External `http2.connect` is blocked loudly instead of allowing direct provider traffic to leak outside Headroom. ### Live provider additions Provider coverage is no longer based on a static config scan. Because routing happens at outbound request time, providers added mid-session are routed through Headroom automatically as long as they use the covered Node transport paths. ### Subagent and child-process coverage - The parent OpenCode plugin sets a packaged Node preload shim through `NODE_OPTIONS=--import=.../hook-shim/handler.js`. - The transport shim patches `child_process.spawn`, `exec`, `execFile`, and `fork` so child Node processes receive the Headroom preload even when OpenCode passes a custom `env`. - The child-process shim fails closed if it loads without `HEADROOM_OPENCODE_TRANSPORT_PROXY_URL`. - This closes the subagent leak path where a child Node process could otherwise start without Headroom transport interception. ## Why this goes beyond PR #1089 PR #1089 improves OpenCode provider registration, but it still focuses on provider config shape. This PR moves the enforcement boundary to runtime transport interception. This PR goes further because: - No provider URL rewriting is required. - New providers added mid-session are covered automatically. - Subagents and child Node processes inherit the Headroom transport shim. - Direct external HTTP/2 paths fail loudly instead of leaking. - The wrap remains transparent to the user's OpenCode provider config. - The wrapper is fail-closed for unsupported child-process preload state. ## Additional robustness fixes While validating the change in Docker, the full Python suite exposed unrelated Linux/container robustness issues. These are fixed in this PR so the suite is green: - Binary cache handling now treats cache paths under a non-writable existing parent as unavailable, including when tests run as root in Docker. - `release_version.py` honors `MANUAL_VER` before git calls so direct script execution works outside a `.git` checkout. - Test logger isolation now resets relevant Headroom child loggers so proxy logging setup cannot poison later `caplog` tests. - The scanner missing-path test now uses a guaranteed missing `tmp_path` child instead of relying on `/nonexistent/path`. ## Validation All implementation validation was run inside Docker. - Full Python suite from a fresh Docker copy: `6605 passed, 523 skipped`. - Ruff on changed Python/OpenCode paths: passed. - OpenCode plugin typecheck: passed. - OpenCode plugin tests: `9 passed`. - OpenCode plugin build: passed. - Hook shim preload smoke test: passed. ## Notes This PR intentionally does not add a CLI option. `headroom wrap opencode` means full wrap. Either Headroom wraps OpenCode transparently, or the path fails loudly instead of silently leaking provider traffic. --------- Co-authored-by: Rudimar Ronsoni <6081613+rudironsoni@users.noreply.github.com> |
||
|
|
05bd56bcb6 |
fix(wrap): track shared proxy clients with markers (#877)
## Description Replace argv-based proxy client detection with per-port wrap client markers so cleanup and ephemeral restarts do not tear down a shared proxy while another wrapped session is still attached. Also prune stale markers, guard against PID reuse when process identity is available, and add coverage for the marker-based lifecycle behavior. Fixes #804 ## 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) ## Testing Describe the tests you ran to verify your changes: - [x] Unit tests pass (`pytest`) - [x] Linting passes (`ruff check .`) - [x] Type checking passes (`mypy headroom`) - [x] New tests added for new functionality --------- Co-authored-by: JerrettDavis <mxjerrett@gmail.com> |
||
|
|
d2cdab268d |
feat(proxy): add agent-90 savings profile (#830)
## Summary - add an `agent-90` savings profile with cross-agent proxy env exports - wire the profile into proxy/router runtime kwargs, including force-Kompress routing and a smaller read-protection window - expose effective savings-profile config in `/stats` and add focused regression coverage ## Type of change - [x] feat (non-breaking change which adds functionality) - [ ] fix (non-breaking change which fixes an issue) - [ ] docs - [ ] test/CI-only - [ ] refactor-only ## Testing - [x] `python3 -m py_compile headroom/agent_savings.py headroom/cli/agent_savings.py headroom/cli/main.py headroom/cli/proxy.py headroom/proxy/models.py headroom/proxy/server.py headroom/transforms/content_router.py tests/test_agent_savings.py tests/test_proxy_healthchecks.py tests/test_cli/test_wrap_persistent.py tests/test_transforms/test_content_router.py` - [x] `git diff --check` - [x] manual smoke: `agent-savings --profile agent-90 --format json` returns `HEADROOM_TARGET_RATIO=0.10` - [x] manual smoke: `proxy_pipeline_kwargs(ProxyConfig(savings_profile="agent-90"))` enables `force_kompress`, system/user compression, and `read_protection_window=2` - [x] manual smoke: Anthropic-style `tool_result` routes through Kompress with `target_ratio=0.10` - [ ] `pytest` suite not run: pytest is not installed in the available local Python environments ## Notes This keeps agent-90 as an opt-in profile. Existing defaults remain unchanged unless `HEADROOM_SAVINGS_PROFILE=agent-90` or `ProxyConfig(savings_profile="agent-90")` is set. |
||
|
|
6dfcaa839f | fix(wrap): report unbindable proxy ports (#602) | ||
|
|
ff4a0c6bc6 |
fix(copilot): support subscription auth through Headroom
Route GitHub Copilot CLI subscription traffic through the Headroom OpenAI-compatible proxy path and resolve the account-specific Copilot API endpoint before launch. Add source-aware Copilot token discovery for explicit Copilot env vars, macOS Keychain, Windows Credential Manager, Linux Secret Service, credential files, and generic GitHub fallbacks. Validate subscription candidates against GitHub Copilot user metadata so generic GH_TOKEN/GITHUB_TOKEN values do not shadow Copilot CLI auth. Document the subscription command and platform status in README: macOS Keychain auth reuse has been smoke-tested, while Windows, Linux, Docker, and CI auth-discovery paths still need real OS validation. Tests: .venv/bin/python -m pytest tests/test_copilot_auth.py tests/test_copilot_macos_keychain.py tests/test_copilot_linux_secret.py tests/test_cli/test_wrap_copilot.py tests/test_cli/test_wrap_persistent.py tests/test_proxy_copilot_auth_hooks.py |
||
|
|
ea1f608e79 |
fix: make proxy upgrades version-aware
Derive source-tree versions from release history so headroom --version no longer reports stale project metadata. Restart stale idle proxies after an upgrade, but leave active sessions running to avoid interrupting ongoing conversations. Remove _version.py from version-sync ownership and make version verification catch package/plugin manifest drift. |
||
|
|
3045b36b52 | fix: stabilize cli test isolation | ||
|
|
bd242fc62d |
test: expand persistent install coverage
Add focused regression coverage for install, runtime, provider, state, health, supervisor, and persistent wrap flows so the new persistent deployment surfaces are exercised more thoroughly in CI. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> |
||
|
|
865bef2216 |
fix: harden persistent install wrappers and review gaps
Align Docker-native wrapper help and runtime behavior with the Python install contract, including persistent deployment metadata, baked install-image defaults, and explicit unsupported wrap targets. Harden the Python persistent-install path with profile validation, safer provider-scope handling, Windows environment restoration, runtime parity improvements, and rollback-safe apply/update behavior. Update README, Docker install docs, CI, and focused regressions to cover the Windows BOM failure, wrapper parity, compose coverage, and Docker-native wrap behavior. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> |
||
|
|
21896a095c |
feat: add persistent install lifecycle management
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> |