mirror of
https://github.com/headroomlabs-ai/headroom.git
synced 2026-11-22 18:41:07 +08:00
fix/plugin-launcher-isolated-python
2
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
fda75de505 |
fix(memory): run only the memory tools the proxy injected on the request (#4870)
## Description
With memory enabled (`--memory`, `--learn`, `wrap/init --memory`), the
proxy ran any upstream tool call named
`memory_list`/`memory_save`/`memory_search`/`memory_update`/`memory_delete`,
and hid it from the client. That held even when the proxy had not
offered those tools on the request (`--no-memory-tools`), or when the
client had declared a tool with that name itself.
The proxy now runs only the memory tools it injected on the current
request. Every other call reaches the client unchanged. The proxy does
not run it, does not withhold it, and sends no continuation upstream.
Anthropic streaming already followed this rule
(`_server_memory_tool_names`). That helper is now shared, and every
executor uses it.
**Behaviour change**
- With `--no-memory-tools`, memory tool calls from the model now reach
the client instead of running on the proxy.
- A memory-named tool that the client declares is now the client's. The
proxy no longer runs it on any path, including the streaming path that
used to run it as a side effect.
- Injected memory tools behave as before: they run on the proxy, are
hidden from the client, and the turn continues upstream.
## 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/proxy/memory_handler.py`: `server_memory_tool_names(tools,
client_tools)` moved here from `AnthropicHandlerMixin`. It now reads
Anthropic, Chat and Responses tool shapes through `extract_tool_name`.
`handle_memory_tool_calls` takes a required `tool_names` and skips every
other call.
- `handlers/openai.py`, Chat Completions (non-streaming): records the
injected names and passes them to the executor.
- `handlers/openai.py`, Responses (HTTP): runs a `function_call` only if
its name was injected. Before, any name in `MEMORY_TOOL_NAMES` ran.
- `handlers/openai.py`, Responses over WebSocket: the injected names are
kept per `response.create`, like the user id. The relay holds back and
runs only those calls.
- `handlers/anthropic.py`, non-streaming: passes the injected names it
already computed for streaming.
- `handlers/streaming.py`: removes the branch that ran memory calls
after the stream had already reached the client. It ran only for tools
the proxy had not injected. Memory handling in the stream (SSE
buffering, the Claude Code credential warning) now turns on only when
the proxy injected memory tools.
- Tests: new `tests/test_memory_tools_only_when_injected.py`. Existing
fixtures that relied on the old behaviour now inject the tool they call:
`test_codex_project_context.py`, `test_memory_handler_native_ops.py`,
`test_memory_handler_project_isolation.py`,
`test_memory_tool_stream.py`.
## 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
The new tests use `create_app` with a fake memory backend and a
`MockTransport` upstream. The WebSocket test uses a scripted upstream
socket. For each path (chat, Responses, Responses over WebSocket,
Anthropic, Anthropic streaming) they check two cases. First, injection
is off and the model calls `memory_delete`. Second, injection is on and
the client declares its own `memory_delete`. Each case expects zero
backend calls, exactly one upstream request, and the call in the
client's response. The control cases inject `memory_list` and expect it
to run as before.
On `origin/main` (
|
||
|
|
0396ea2fc2 |
fix(codex): resolve per-turn project context (#2636)
## Description Codex Desktop can send turns from multiple projects through one HTTP or WebSocket route, so a static `/p/<project>` route cannot reliably identify each turn. This PR resolves project context per turn from explicit overrides or Codex thread/turn metadata. Unsafe or inconsistent resolution skips project memory and learning while the model request continues. Related to #2355 and overlaps #2379. ## 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 - Resolve `thread_id` and `turn_id` to the matching rollout cwd. - Use the resolver for HTTP and per-frame WebSocket traffic. - Pin each WebSocket to its first resolved project and fail closed on mismatch. - Strip Codex-only metadata before forwarding upstream. ## 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 121 passed, 1 pre-existing deprecation warning All checks passed! Success: no issues found in 510 source files ``` ## Real Behavior Proof - Environment: macOS; isolated Codex state and project fixtures plus the combined local deployment. - Exact command / steps: Exercised two same-basename projects over HTTP and concurrent WebSockets, including resume/fork, missing, stale, locked, malformed, and mismatched contexts. - Observed result: Each turn resolved to the correct project; unsafe cases skipped project memory and learning without blocking the model request. The integrated patch also ran in the local deployment for more than 39 hours. - Not tested: Linux, Windows, VMs, or GitHub CI. ## Runtime Rollout Safety - Rollout-managed feature(s): None. - Minimum rollout channel: N/A; this change uses stable/default behavior. - Stable/default behavior changed: Codex HTTP and WebSocket turns resolve project context per turn; unsafe resolution skips project memory and learning. - Kill switch / disable path: Run without `--memory`; use `--no-learn` to disable traffic learning. - Unsafe override required: No. - Qualification impact: Codex project-context isolation for HTTP and WebSocket traffic. - Rollback path: Revert this PR. No schema, data, or configuration migration is required. ## 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] Documentation changes are not required for this internal routing fix - [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. ## Additional Notes Waiting follow-up: [project-scoped TrafficLearner](https://github.com/krzkraw/headroom/tree/krz/project-scoped-traffic-learner). It depends on the per-turn project API introduced here. No database or configuration migration is required. <!-- devin-review-badge-begin --> --- <a href="https://app.devin.ai/review/headroomlabs-ai/headroom/pull/2636" 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> |