Files
acebf20b47 fix(openclaw): keep the Python launcher fallback off the working directory (#4843)
## Description

`ProxyManager.buildLaunchSpecs()`
(`plugins/openclaw/src/proxy-manager.ts`) has a Python fallback: it
probes with `python -c "...find_spec('headroom')..."` and starts the
proxy with `python -m headroom.cli proxy ...`. Both put the current
directory first on `sys.path`, and the spawned process inherits
OpenClaw's working directory, so a `headroom/` folder there was found
and run instead of the installed package.

Both the probe and the launch now pass `-P` (Python 3.11+: do not
prepend the cwd to `sys.path`). Interpreters older than 3.11 reject
`-P`, so their probe fails and the launcher moves on; `headroom-ai`
requires 3.11+ so they could not hold a real install. `-P` rather than
`-I` keeps `PYTHONPATH` and user-site installs working.

Companion to the same change in
`plugins/headroom-agent-hooks/bin/headroom-hook.sh` (#4842); kept
separate because this plugin has its own test suite.

## Type of Change

- [x] Bug fix (non-breaking change that fixes an issue)

## Changes Made

- `plugins/openclaw/src/proxy-manager.ts`: `-P` on the configured-python
and fallback-python launch and probe args.
- `plugins/openclaw/test/proxy-manager.test.ts`: updated expected args;
new test that runs each Python spec's probe with a real Python 3.11+
(site-packages disabled) from a directory containing a `headroom/`
package and expects "not found".

## Testing

- [x] Unit tests pass (`vitest`)
- [ ] Linting passes (`ruff check .`) (no Python changed)
- [x] Type checking passes (`npm run typecheck`)
- [x] New tests added for new functionality
- [x] Manual testing performed

### Test Output

```text
# new test on origin/main (fix stashed), python3 = 3.12
$ npx vitest run test/proxy-manager.test.ts -t "working directory"
AssertionError: expected +0 to be 1 // Object.is equality
      Tests  1 failed | 34 skipped (35)

# with the fix
$ npx vitest run test/proxy-manager.test.ts
      Tests  35 passed (35)
$ npx vitest run
      Tests  2 failed | 161 passed (163)
# the 2 failures are test/advancement-key-store.test.ts "...two separate OS processes..."; they fail identically on origin/main (2 failed | 160 passed) and are unrelated.
$ npm run typecheck
(no output, exit 0)
```

## Real Behavior Proof

- Environment: macOS, Node + vitest from the plugin's lockfile, Python
3.12.
- Exact command / steps: in a temp dir containing
`headroom/__init__.py`, run each Python launch spec's probe as `python3
-S <checkArgs>` (`-S` so no installed headroom can be seen).
- Observed result: main exits 0 (the folder in the cwd is accepted as
headroom); this branch exits 1 (not found), so the launcher would move
to the next spec.
- Not tested: Windows `py` launcher (it forwards `-P` to the
interpreter).

## Runtime Rollout Safety

- Rollout-managed feature(s): none
- Minimum rollout channel: n/a
- Stable/default behavior changed: the Python fallback only starts an
installed headroom; a source checkout reachable only through the cwd is
no longer picked up (set `pythonPath`/`PYTHONPATH`, or put `headroom` on
PATH).
- Kill switch / disable path: a `headroom` executable on PATH or an
explicit `proxyUrl` bypasses the fallback.
- Unsafe override required: no
- Qualification impact: none
- Rollback path: revert this PR

## 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`

## Additional Notes

No docs change needed.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- devin-review-badge-begin -->

---

<a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/4843"
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 -->

Reported by @JoaoMarcos44. Thank you for your contribution! 🩵

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: JerrettDavis <mxjerrett@gmail.com>
2026-11-17 19:08:42 +05:30
..