Make your computer a home for your AI partner. Avibe is the local-first Agent OS: Vibey, its built-in AI partner, works out of the box, and Claude Code, Codex & OpenCode run unchanged beside it — reach them from your browser, phone, or any chat app.
Python agentagent-osaiai-agentsai-partnerchatopsclaudeclaude-codecodexdevtoolsdiscord-botlark-botllmlocal-firstlong-term-memoryopencodeslack-botvibe-codingvibeywechat
fix(model-hub): stop adding the hosted image tool to Codex CLI requests (#2631)
Call White9eb326ee4ffc
diff --git a/docs/plans/backend-model-catalogs.md b/docs/plans/backend-model-catalogs.mdindex aa88f7a68..49d9c5797 100644--- a/docs/plans/backend-model-catalogs.md+++ b/docs/plans/backend-model-catalogs.md@@ -562,8 +562,7 @@ display names, no protocol chatter.are rewritten by the engine (S3): the implementation verifies each real `openai_responses`Source still serves such requests and files the engine follow-up. Tools are the exception:with `disable-image-generation: passthrough` the engine forwards exactly the declared tools,- and only Codex CLI requests get the hosted image tool, from the gateway- (`vibey-hosted-tools.md` §7.1). A Hub-held Claude+ and nothing adds the hosted image tool (`vibey-hosted-tools.md` §7.1). A Hub-held Claudesubscription (OAuth credential) keeps the engine's cloaking: the vendor accepts those tokensonly from the Claude Code identity the cloak reproduces, so rows served by a subscriptionget the reasoning-preserving path of S4, not the body-identical guarantee. The engine has onediff --git a/docs/plans/model-hub-contracts/opencode-overlay.md b/docs/plans/model-hub-contracts/opencode-overlay.mdindex af0deced3..835940f03 100644--- a/docs/plans/model-hub-contracts/opencode-overlay.md+++ b/docs/plans/model-hub-contracts/opencode-overlay.md@@ -88,8 +88,7 @@ contract (one OpenAI-compatible provider, `vendor/model` ids); nothing of that sdropped; `parallel_tool_calls: true`, `instructions: ""`) — a known engine limitation the implementation verifies against each real`openai_responses` Source before enabling the route, and tracks as an engine follow-up.The engine no longer adds its hosted `image_generation` tool: it runs with- `disable-image-generation: passthrough`, and the gateway adds that tool back for Codex CLI- requests only (`vibey-hosted-tools.md` §7.1).+ `disable-image-generation: passthrough`, and nothing adds it back (`vibey-hosted-tools.md` §7.1).When the hop's protocol differs, the engine's automatic translation applies; S4 records whatsurvives: Responses-frontend effort reaches an `anthropic` upstream intact, anAnthropic-frontend `output_config.effort` is dropped on the way to an `openai_chat` upstreamdiff --git a/docs/plans/vibey-hosted-tools.md b/docs/plans/vibey-hosted-tools.mdindex 940bf8bd9..0e4cbd821 100644--- a/docs/plans/vibey-hosted-tools.md+++ b/docs/plans/vibey-hosted-tools.md@@ -557,48 +557,39 @@ Each has a **Re-verify** action with its cost. Unknown shows nothing.## 7. Image generation (Phase 1)-### 7.1 The injected tool moves from the engine to the gateway, per caller--- **Today.** The engine injects `{"type": "image_generation", "output_format": "png"}` into every Codex-executor- request: CPA `ensureImageGenerationTool`, with `disable-image-generation` unset in- `vibe/model_hub_runtime/config.py`. That covers OpenAI API keys, the ChatGPT subscription and xAI keys, for any- caller, Claude Code and OpenCode included. GPT calls it from a Vibey request when asked for a picture; the image is- billed and then dropped.-- **How Codex consumes it today.**- - Codex maps a hosted `image_generation_call` item to a `TurnItem::ImageGeneration` (`codex-rs/core/src/event_mapping.rs`)- and emits app-server `imageGeneration` thread items.- - Avibe's Codex backend persists those items as files: `modules/agents/codex/event_handler.py`- `_persist_generated_image`, covered by `tests/test_codex_event_handler.py`.- - Codex's own `image_gen` extension tool is gated to OpenAI-auth providers (`codex-rs/core/src/tools/spec_plan.rs`- `image_generation_available`). So through Model Hub, the injected hosted tool is Codex's only image path, and it- must be preserved exactly.-- **Decision (orchestrator, 2026-10-13):**+### 7.1 No caller gets an image tool it did not declare++- **Before.** The engine injected `{"type": "image_generation", "output_format": "png"}` into every Codex-executor+ request (CPA `ensureImageGenerationTool`): OpenAI API keys, the ChatGPT subscription and xAI keys, for any caller,+ Claude Code and OpenCode included. GPT could call it when asked for a picture, and the image was billed and then+ dropped.+- **Codex no longer reports hosted image calls.** From Codex CLI 0.144.0 (2026-07-09, openai/codex#31596, "Use the+ image generation extension by default"), Codex produces images only through its own `image_gen` extension tool,+ which `codex-rs/core/src/tools/spec_plan.rs` (`image_generation_available`) gates to OpenAI-auth providers. A hosted+ `image_generation_call` in a response stream is no longer mapped to a turn item: `stream_events_utils.rs` maps only+ messages, reasoning and web search calls. So Codex emits no `imageGeneration` item, and Avibe's Codex backend+ (`event_handler.py` `_persist_generated_image`) has nothing to persist.+ - Observed in the 3.2.1rc4 release E2E with Codex CLI 0.162.1: the gateway and engine delivered the image intact,+ and Codex reported only the user and agent messages.+ - Avibe does not pin Codex: it installs `npm install -g @openai/codex`, the latest release. Every Codex it has+ installed since July 2026 is at least 0.144.0.+- **Decision (orchestrator, 2026-10-13, revised 2026-10-14):**1. The engine runs with `disable-image-generation: passthrough`, a fixed key in `config.py`. CPA then forwardsrequests with exactly the tools the client declared, never injecting and never stripping.- 2. The gateway reproduces CPA's injection **only for Codex CLI requests** (`backend == "codex"`), byte for byte,- under CPA's own conditions:- - the hop's Source is served by CPA's Codex executor (an `openai_responses` API key or the ChatGPT subscription);- - the model id does not end in `spark`;- - the credential is not a ChatGPT free plan, read from the same plan attribute CPA reads;- - the body's `client_metadata.ws_request_header_x_openai_internal_codex_responses_lite` is not true. The header- form is not forwarded by the gateway today, so it is not consulted.-- It then appends the same tool to `tools`, or sets `tools` to it when absent. It leaves the body unchanged when- an `image_generation` tool, or the `image_gen` function or namespace, is already present.- 3. Vibey declares `image_generation` itself, only when the user's toggle is on.-- **Effect on other backends.** Claude Code and OpenCode requests routed to a Codex-executor Source stop receiving- the hidden image tool. They could not show the result, so this removes billed images that nobody saw.-- **Rule boundary.** "The gateway never rewrites hosted content" (§3.5) is about Vibey's requests. This injection is- a compatibility step for one native caller and adds the tool CPA added.+ 2. Nothing adds the tool back, for Codex CLI either. An injected tool only billed images that Codex then+ dropped.+ 3. Vibey declares `image_generation` itself, only when the user's toggle is on (§7.2).+- **Effect.** No caller routed to a Codex-executor Source receives a hidden image tool. A user still on a Codex CLI+ older than 0.144.0 loses images through Model Hub that it used to show. Codex's own `image_gen` remains available+ wherever Codex enables it.- **Regression tests.**- - **Gateway, table-driven from CPA's injection cases:** for a Codex request, the fake engine receives exactly the- bytes CPA would have produced. One row per condition: no tools, other tools, an existing image tool, the- `image_gen` function and namespace, `spark`, free plan, and lite metadata.- - **Other backends:** Claude, OpenCode and Vibey requests reach the engine with no image tool unless they declared- one.- - The existing Codex image persistence tests stay unchanged.- - **E2E once per release:** the real engine in passthrough, a stub upstream, a Codex request. The upstream sees- exactly one image tool and the Codex backend persists the image.+ - **Gateway:** every caller (Codex CLI with an API key and with a subscription, Claude, OpenCode and Vibey)+ reaches the engine with exactly its declared tools, declared image tool or not (MH-HOSTED-GATEWAY-001).+ - The existing Codex image persistence tests stay unchanged; they cover Codex's own `image_gen` output.+ - **E2E once per release** (`tests/e2e/test_model_hub_codex_image.py`): the real engine in passthrough, a stub+ upstream and the real Codex CLI. A Codex turn through the Hub reaches the upstream with no image tool, and a Vibey+ request to the same Source with none either. Persistence is not asserted, because current Codex never reports+ a hosted image.### 7.2 Native and proxy@@ -706,8 +697,8 @@ Each has a **Re-verify** action with its cost. Unknown shows nothing.- `HopResolution.hosted_tools`, request pinning and `pin_unavailable`, and the V2 `hosted_tools` config;- the C-1 blocks and adapter parsing;- replay and conversion, `pause_turn` continuation, the tool card, and the IM line;- - image generation (§7): engine passthrough, the gateway's per-caller injection for Codex, files instead of- base64, partial images, and the SSE caps.+ - image generation (§7): engine passthrough with no injected tool for any caller, files instead of base64,+ partial images, and the SSE caps.## 10. Acceptance properties@@ -728,8 +719,7 @@ Each has a **Re-verify** action with its cost. Unknown shows nothing.`interrupted` error that keeps the partial.7. A generated image never enters model context or history as bytes. The model gets the text path record, and theuser sees the image.-8. A Codex CLI request reaches the upstream with exactly the image tool CPA would have injected. No other caller- gets one unless it declared it.+8. No caller, Codex CLI included, reaches the upstream with an image tool it did not declare (§7.1).9. No probe and no proxy call runs without a user action or a model tool call in a turn the user started. Everyprobe shows its cost first.10. A real error creates evidence only through a narrow rule for the named (Source, model, feature).@@ -750,7 +740,7 @@ shapes. No live upstream and no real credentials.| Proxy executor | gateway endpoint, stub provider | executor choice; no effort sent; the record with excerpts; metering on the executor Source; error when no executor is verified; refusal of a Claude subscription || Record rendering and citations | the record-to-text function; `core/citations.py` builder | completed, failed, incomplete and pending records; every action's synthetic rule; summary cited sources listed once; provider annotations through to the Web sidecar and the IM Markdown link (end to end) || Config | `ModelHubConfig` loader | a released config without `hosted_tools` loads with all tools off; an unknown tool key degrades with a warning |-| Image injection | gateway + loopback fake engine | the §7.1 table (CPA's conditions, byte for byte); Claude, OpenCode and Vibey requests get no image tool unless declared; the existing Codex image persistence tests unchanged |+| Declared tools only | gateway + loopback fake engine | Codex (API key and subscription), Claude, OpenCode and Vibey requests reach the engine with exactly their declared tools; the existing Codex image persistence tests unchanged || Images | Responses adapter against stub SSE | partials then a final image twice: one file written, no base64 in history, the duplicate in `response.completed` not decoded, a 9 MiB image line accepted under the image cap, the text path record as model context || Probes | gateway, stub provider | verified / unsupported / dropped / transient outcomes; a replay probe whose answer lacks the first search's URL is `unsupported`; probes only from the API action || UI | Models Tools tab, Source chips, tool card | toggle off by default; Verify shows the cost; chips per evidence state; card modes; IM line |@@ -808,8 +798,8 @@ encoded either as a schema clause or as a producer test. The PR names which for11. Native replay requires all three: same Source, same origin, and current `replay` evidence. `image_generation`blocks are never replayed verbatim, and their synthetic call carries `size` when the action has it.12. A probe with no tool item is inconclusive and writes no evidence.-13. The engine config renders `disable-image-generation: passthrough`. The gateway's Codex image injection is a- single function covered by the §7.1 table.+13. The engine config renders `disable-image-generation: passthrough`, and no caller, Codex CLI included, reaches the+ engine with an image tool it did not declare (§7.1).**Added after review of the final design head (implementation-level, binding on the Phase 1 PR):**diff --git a/tests/e2e/test_model_hub_codex_image.py b/tests/e2e/test_model_hub_codex_image.pynew file mode 100644index 000000000..06b578a75--- /dev/null+++ b/tests/e2e/test_model_hub_codex_image.py@@ -0,0 +1,179 @@+"""MH-HOSTED-GATEWAY-001, once per release (``vibey-hosted-tools.md`` §7.1): no image tool for Codex through the Hub.++The real Codex CLI sends a turn through the production gateway and the pinned+engine, which runs with ``disable-image-generation: passthrough``, to a+loopback upstream. The upstream must see no image tool: the engine no longer+adds one, and neither does the gateway. A Vibey request to the same Source must+see none either.++What Codex does with an image is not asserted. From Codex CLI 0.144.0+(openai/codex#31596) a hosted ``image_generation_call`` in a response stream is+not reported as an ``imageGeneration`` item, so Avibe's Codex backend never+receives one to persist; that is why nothing adds the tool for Codex.++Run it with ``-m e2e_model_hub``, ``VIBE_MODEL_HUB_ENGINE_MANIFEST_PATH`` set to+an offline manifest of the engine under test, and ``codex`` on ``PATH``.+"""++from __future__ import annotations++import asyncio+import json+from contextlib import AsyncExitStack, asynccontextmanager+from pathlib import Path++import aiohttp+import pytest+from aiohttp import web++from config.v2_config import ModelHubBackendModelConfig, model_hub_fixed_menu_ids+from core.handlers.model_hub.turn_gateway import ModelHubTurnGateway+from modules.agents.codex.transport import CodexTransport+from modules.agents.model_hub import ModelHubRuntimeRouter, build_codex_hub_launch+from tests.e2e.test_model_hub_catalog_consumer import (+ codex_catalog_runtime, # noqa: F401 -- fixture dependency+ rejected_external_proxy, # noqa: F401 -- fixture dependency+)+from tests.e2e.test_model_hub_runtime import _isolated_engine_adapter+from tests.scenario_harness.model_hub import MemoryModelHubStore, service_for+from tests.test_model_hub_google import _server+from tests.test_model_hub_l3 import _source+from tests.test_model_hub_vibey_consumer import _vibey_service+from vibe.backend_model_catalog import _codex_hub_catalog_bytes+++pytestmark = pytest.mark.e2e_model_hub++MODEL = "fixture-image-model"+++def _event(payload: dict) -> bytes:+ return f"event: {payload['type']}\ndata: {json.dumps(payload)}\n\n".encode()+++def _answer() -> list[bytes]:+ message = {"id": "msg_fixture", "type": "message", "role": "assistant", "status": "completed",+ "content": [{"type": "output_text", "text": "I can't draw here.", "annotations": []}]}+ events = [+ {"type": "response.created", "response": {+ "id": "resp_fixture", "object": "response", "status": "in_progress", "model": MODEL, "output": []}},+ {"type": "response.output_item.added", "output_index": 0,+ "item": {**message, "status": "in_progress", "content": []}},+ {"type": "response.output_text.delta", "output_index": 0, "item_id": "msg_fixture", "content_index": 0,+ "delta": "I can't draw here."},+ {"type": "response.output_item.done", "output_index": 0, "item": message},+ {"type": "response.completed", "response": {+ "id": "resp_fixture", "object": "response", "status": "completed", "model": MODEL, "output": [message],+ "usage": {"input_tokens": 12, "output_tokens": 6, "total_tokens": 18}}},+ ]+ return [_event({**event, "sequence_number": index}) for index, event in enumerate(events)]+++def _image_tools(body: dict) -> list:+ tools = body.get("tools") if isinstance(body, dict) else None+ return [tool for tool in tools or () if isinstance(tool, dict) and tool.get("type") == "image_generation"]+++@asynccontextmanager+async def _through_engine(tmp_path, monkeypatch):+ """The production gateway and the pinned engine in front of a recording upstream."""++ requests: list[dict] = []++ async def respond(request):+ requests.append({"path": request.path, "body": await request.json()})+ response = web.StreamResponse(headers={"Content-Type": "text/event-stream"})+ await response.prepare(request)+ for frame in _answer():+ await response.write(frame)+ await response.write_eof()+ return response++ with _isolated_engine_adapter(tmp_path / "engine", monkeypatch) as adapter:+ async with AsyncExitStack() as stack:+ root = await stack.enter_async_context(_server(respond))+ # An OpenAI-protocol API key: the engine serves it through its Codex executor,+ # where it used to add its image tool.+ source = _source("src_codeximage1", "Image fixture", vendor="custom", protocol="openai_responses",+ model_id=MODEL)+ source.base_url = root + "/v1"+ source.credential_ref = adapter.state_store.store_api_key(+ "sk-synthetic-codex-image", vendor="custom", protocol="openai_responses", base_url=source.base_url,+ )+ (tmp_path / "service").mkdir()+ config = _vibey_service(tmp_path / "service", [source]).store.config+ service = service_for(tmp_path / "service", MemoryModelHubStore(config), adapter)+ await service.runtime_start()+ gateway = ModelHubTurnGateway(service)+ try:+ yield ModelHubRuntimeRouter(service=service, turn_gateway=gateway), requests+ finally:+ await gateway.close()+++async def _codex_turn(codex_runtime, launch) -> None:+ """One real Codex CLI turn asking for a picture, through the launch Avibe issued."""++ binary, runtime, raw_catalog = codex_runtime+ Path(runtime.env["CODEX_HOME"], "config.toml").write_text('cli_auth_credentials_store = "file"\n')+ catalog_path = runtime.home / "image-models.json"+ catalog_path.write_bytes(_codex_hub_catalog_bytes(+ raw_catalog, [ModelHubBackendModelConfig(id=launch.runtime_model, context_window=128_000).to_payload()],+ ))+ args, env = build_codex_hub_launch([], runtime.env, launch, model_catalog_path=catalog_path)+ transport = CodexTransport(binary=binary, cwd=str(runtime.home), runtime_args=args, runtime_env=env)+ completed: asyncio.Queue = asyncio.Queue()++ async def notify(method, params):+ if method == "turn/completed":+ await completed.put(params)++ transport.on_notification(notify)+ await transport.start()+ try:+ thread = await transport.send_request(+ "thread/start", {"model": launch.runtime_model, "cwd": str(runtime.home), "approvalPolicy": "never"},+ )+ await transport.send_request("turn/start", {+ "threadId": thread["thread"]["id"],+ "input": [{"type": "text", "text": "Draw a small red square."}],+ # As Avibe's Codex backend sends it: the route and turn this request belongs to.+ "responsesapiClientMetadata": dict(launch.gateway_request_metadata),+ })+ finished = await asyncio.wait_for(completed.get(), timeout=60)+ assert finished["turn"]["status"] == "completed", finished+ finally:+ await transport.stop()+++async def test_codex_through_the_hub_gets_no_image_tool_from_a_passthrough_engine(+ tmp_path, monkeypatch, codex_catalog_runtime,+):+ """MH-HOSTED-GATEWAY-001: a Codex turn and a Vibey request reach the upstream with no image tool they did not declare."""++ async with _through_engine(tmp_path, monkeypatch) as (router, requests):+ _binary, runtime, _catalog = codex_catalog_runtime+ launch = await router.resolve(+ "codex", model_hub_fixed_menu_ids("codex")[0], process_scope=str(runtime.home), turn_id="turn-codex-image",+ )+ await _codex_turn(codex_catalog_runtime, launch)+ codex_requests = list(requests)++ hop = await router.resolve_hop("menu-alias", process_scope="vibey:image", turn_id="turn-vibey-image")+ async with aiohttp.ClientSession() as client:+ async with client.post(+ f'{hop["base_url"]}/responses',+ headers={"Authorization": f'Bearer {hop["token"]}', **hop["request_headers"]},+ json={"model": hop["runtime_model"], "stream": True, "input": "Say hello."},+ ) as response:+ assert response.status == 200, await response.text()+ await response.read()+ vibey_requests = requests[len(codex_requests):]++ # Codex declares its own tools, none of them a hosted image tool, and nothing adds one on the way.+ assert codex_requests+ assert all(_image_tools(request["body"]) == [] for request in codex_requests), [+ request["body"].get("tools") for request in codex_requests+ ]+ assert len(vibey_requests) == 1 and _image_tools(vibey_requests[0]["body"]) == []diff --git a/tests/scenarios/INDEX.yaml b/tests/scenarios/INDEX.yamlindex 43104cebf..7d621d277 100644--- a/tests/scenarios/INDEX.yaml+++ b/tests/scenarios/INDEX.yaml@@ -45,6 +45,7 @@ capabilities:- tests/e2e/test_model_hub_sources.py- tests/e2e/test_model_hub_usage_events.py- tests/e2e/test_model_hub_service_acceptance.py+ - tests/e2e/test_model_hub_codex_image.pyharness:- tests/scenario_harness/model_hub.pyunit_or_contract_tests:@@ -98,7 +99,7 @@ capabilities:- tests/test_opencode_model_hub_retry.py- ui/src/lib/modelHubRecovery.test.ts- tests/test_model_hub_request_body_budget.py- - tests/test_model_hub_codex_image_tool.py+ - tests/test_model_hub_declared_tools.py- tests/test_model_hub_l3.py- tests/test_model_hub_hosted_executor.py- tests/test_model_hub_usage.pydiff --git a/tests/scenarios/model_hub/catalog.yaml b/tests/scenarios/model_hub/catalog.yamlindex 5f4877e9a..65c52f1f3 100644--- a/tests/scenarios/model_hub/catalog.yaml+++ b/tests/scenarios/model_hub/catalog.yaml@@ -43,7 +43,7 @@ capability:- tests/test_opencode_model_hub_retry.py- ui/src/lib/modelHubRecovery.test.ts- tests/test_model_hub_request_body_budget.py- - tests/test_model_hub_codex_image_tool.py+ - tests/test_model_hub_declared_tools.py- tests/test_model_hub_l3.py- tests/test_model_hub_hosted_executor.py- tests/test_model_hub_usage.py@@ -103,6 +103,7 @@ capability:- tests/e2e/test_model_hub_sources.py- tests/e2e/test_model_hub_usage_events.py- tests/e2e/test_model_hub_service_acceptance.py+ - tests/e2e/test_model_hub_codex_image.pystatus_legend:covered:description: closed-loop coverage exists at the declared layer@@ -976,13 +977,13 @@ scenarios:layer: unittest: tests/test_model_hub_request_body_budget.py::test_bad_auth_does_not_parse_or_admit- id: MH-HOSTED-GATEWAY-001- name: The engine forwards declared tools unchanged; only Codex CLI gets the engine's hosted image tool, byte for byte under its skip conditions+ name: The engine forwards declared tools unchanged, and no caller, Codex CLI included, gets a hosted image tool it did not declarestatus: coveredkind: contractlayer: contract- test: tests/test_model_hub_codex_image_tool.py::test_codex_requests_reach_the_engine_with_the_engines_own_image_tool+ test: tests/test_model_hub_declared_tools.py::test_every_caller_reaches_the_engine_with_exactly_its_declared_toolsrelated_tests:- - tests/test_model_hub_codex_image_tool.py::test_other_callers_reach_the_engine_with_exactly_their_declared_tools+ - tests/e2e/test_model_hub_codex_image.py::test_codex_through_the_hub_gets_no_image_tool_from_a_passthrough_engine- tests/test_model_hub_runtime.py::test_mixed_anthropic_credentials_disable_cloak_only_for_api_key_entry- id: MH-PROTOCOL-001name: Source protocol is response-observed before persistence with no transient residuediff --git a/tests/scenarios/model_hub/observations.yaml b/tests/scenarios/model_hub/observations.yamlindex 6d11ec702..1da6562a5 100644--- a/tests/scenarios/model_hub/observations.yaml+++ b/tests/scenarios/model_hub/observations.yaml@@ -1,6 +1,11 @@version: 2capability: model_hubobservations:+ - id: MH-OBS-015+ source: codex-0.162.1-release-e2e-hosted-image-call-2026-10-14+ summary: In the 3.2.1rc4 release E2E (shipped engine v8.0.23-3 in passthrough, a stub upstream, Codex CLI 0.162.1), the gateway added the engine's hosted image tool to the Codex turn and delivered the upstream's image_generation_call intact, but Codex reported only the user and agent messages, so Avibe's Codex backend had no imageGeneration item to persist. From Codex 0.144.0 (openai/codex#31596) a hosted image call in a response stream is no longer mapped to a turn item, and Codex makes images only through its own image_gen extension, gated to OpenAI-auth providers. The added tool only let the model trigger billed images nobody saw, so nothing adds it for any caller now. Avibe installs the latest Codex unpinned, so every Codex it installed since July 2026 is at least 0.144.0.+ affects:+ - MH-HOSTED-GATEWAY-001- id: MH-OBS-014source: engine-v8.0.23-3-stream-cadence-and-idle-bound-2026-10-13summary: The engine sets no post-connect timeout (CPA #6534 declined), so a relay that stays alive while its upstream is stuck kept a stream silent until the caller's bound. Through the local engine, untranslated Anthropic streams carried a ping every 10 s and OpenAI Responses streams never paused more than 36 s, while xAI sent a 15K-token tool call after 188 s of silence and translated streams dropped the upstream heartbeat for up to 142 s. The gateway now bounds engine silence at 120 s for the measured Anthropic and OpenAI Sources only; on the shipped engine the upstream saw the cancellation within 0.02 s.diff --git a/tests/test_model_hub_codex_image_tool.py b/tests/test_model_hub_declared_tools.pysimilarity index 57%rename from tests/test_model_hub_codex_image_tool.pyrename to tests/test_model_hub_declared_tools.pyindex ce971e369..98a4b66b8 100644--- a/tests/test_model_hub_codex_image_tool.py+++ b/tests/test_model_hub_declared_tools.py@@ -1,17 +1,17 @@-"""MH-HOSTED-GATEWAY-001: with the engine in passthrough, only Codex CLI gets the hosted image tool.+"""MH-HOSTED-GATEWAY-001: the engine forwards declared tools unchanged, for every caller.The engine used to add ``{"type": "image_generation", "output_format": "png"}``-to every request its Codex executor served, for any caller. It now forwards-declared tools unchanged, and the gateway adds the tool back for Codex CLI-alone, under the engine's own skip conditions. Each case drives the real-gateway and engine adapter against a loopback engine and compares the exact-body bytes it receives with what the engine itself would have produced-(CLIProxyAPI ``ensureImageGenerationTool`` at d318bcc3).+to every request its Codex executor served, for any caller (CLIProxyAPI+``ensureImageGenerationTool`` at d318bcc3). It runs with+``disable-image-generation: passthrough``, and nothing adds the tool back:+Codex CLI from 0.144.0 drops a hosted ``image_generation_call`` instead of+reporting it, so an added tool only billed images nobody saw. Each case+drives the real gateway and engine adapter against a loopback engine and+checks the tools it receives."""from __future__ import annotations-import base64import jsonfrom contextlib import asynccontextmanagerfrom dataclasses import replace@@ -31,11 +31,9 @@ from vibe.model_hub_runtime.adapter import CLIProxyEngineAdapterfrom vibe.model_hub_runtime.client import EngineClient, EngineConnectionfrom vibe.model_hub_runtime.state import EngineStateStore-IMAGE_TOOL = {"type": "image_generation", "output_format": "png"}SHELL = {"type": "function", "name": "shell", "parameters": {"type": "object", "properties": {}}}DECLARED_IMAGE = {"type": "image_generation", "quality": "high"}INPUT = [{"role": "user", "content": [{"type": "input_text", "text": "画一只猫 café"}]}]-LITE = "ws_request_header_x_openai_internal_codex_responses_lite"COMPLETED = {"/v1/responses": (b'event: response.output_text.delta\ndata: {"type":"response.output_text.delta","delta":"ok"}\n\n'@@ -54,13 +52,6 @@ COMPLETED = {}-def _id_token(claims: dict) -> str:- def part(value: dict) -> str:- return base64.urlsafe_b64encode(json.dumps(value).encode()).decode().rstrip("=")-- return f"{part({'alg': 'none'})}.{part(claims)}.signature"--@asynccontextmanagerasync def _engine(received: list[bytes]):async def respond(request: web.Request) -> web.Response:@@ -117,96 +108,23 @@ def _subscription(source):return replace(source, kind="subscription", billing="monthly")-# (case, request fields after model/stream/input, hop model, ChatGPT grant or None for an API key,-# the tools the engine must receive; ABSENT when the request has no tools key and gets none)-ABSENT = object()-CODEX_CASES = [- ("no_tools", {}, "gpt-fixture", None, [IMAGE_TOOL]),- ("tools_null", {"tools": None}, "gpt-fixture", None, [IMAGE_TOOL]),- ("tools_object", {"tools": {"type": "function"}}, "gpt-fixture", None, [IMAGE_TOOL]),- ("other_tools", {"tools": [SHELL]}, "gpt-fixture", None, [SHELL, IMAGE_TOOL]),- ("image_tool_present", {"tools": [DECLARED_IMAGE, SHELL]}, "gpt-fixture", None, [DECLARED_IMAGE, SHELL]),- (- "image_gen_function",- {"tools": [SHELL, {"type": "function", "name": "image_gen.imagegen"}]},- "gpt-fixture", None,- [SHELL, {"type": "function", "name": "image_gen.imagegen"}],- ),- (- "image_gen_namespace",- {"tools": [{"type": "namespace", "name": "image_gen", "tools": [{"type": "function", "name": "imagegen"}]}]},- "gpt-fixture", None,- [{"type": "namespace", "name": "image_gen", "tools": [{"type": "function", "name": "imagegen"}]}],- ),- (- "namespace_without_imagegen",- {"tools": [{"type": "namespace", "name": "image_gen", "tools": [{"type": "function", "name": "edit"}]}]},- "gpt-fixture", None,- [{"type": "namespace", "name": "image_gen", "tools": [{"type": "function", "name": "edit"}]}, IMAGE_TOOL],- ),- ("spark", {"tools": [SHELL]}, "gpt-fixture-codex-spark", None, [SHELL]),- ("spark_with_thinking_suffix", {}, "gpt-fixture-spark(high)", None, ABSENT),- ("plan_free", {}, "gpt-fixture", {"plan_type": " Free "}, ABSENT),- ("plan_plus", {}, "gpt-fixture", {"plan_type": "plus"}, [IMAGE_TOOL]),- ("token_plan_free", {}, "gpt-fixture", {"id_token": _id_token({"https://api.openai.com/auth": {}})}, ABSENT),- (- "token_plan_pro",- {}, "gpt-fixture",- {"id_token": _id_token({"https://api.openai.com/auth": {"chatgpt_plan_type": "pro"}})},- [IMAGE_TOOL],- ),- ("token_unreadable", {}, "gpt-fixture", {"id_token": "not-a-jwt"}, ABSENT),- ("grant_without_plan", {}, "gpt-fixture", {}, [IMAGE_TOOL]),- ("lite_true", {"client_metadata": {LITE: True}}, "gpt-fixture", None, ABSENT),- ("lite_string", {"client_metadata": {LITE: " TRUE "}}, "gpt-fixture", None, ABSENT),- ("lite_false", {"client_metadata": {LITE: "false"}}, "gpt-fixture", None, [IMAGE_TOOL]),-]--[email protected](("fields", "model", "grant", "tools"), [case[1:] for case in CODEX_CASES],- ids=[case[0] for case in CODEX_CASES])-async def test_codex_requests_reach_the_engine_with_the_engines_own_image_tool(- tmp_path, fields, model, grant, tools,-):- """MH-HOSTED-GATEWAY-001: one row per CPA condition; the engine receives exactly CPA's bytes."""- configured = _source("src_codex001", "Codex", model_id=model)- if grant is not None:- configured = _subscription(configured)- service = _service(tmp_path, sources=[configured])- models = _canonicalize_fixed_test_routes(service)- received: list[bytes] = []- async with _engine(received) as root:- state = _wire(service, tmp_path, root, {configured.id: grant} if grant is not None else {})- gateway = ModelHubTurnGateway(service)- try:- base_url, token = await gateway.endpoint(- "codex", process_scope="/repo", turn_id="turn_image_tool",- requested_model_id=models["codex"], resolved_model_id=model, source_id=configured.id,- )- await _post(f"{base_url}/v1/responses", token, {"model": model, "stream": True, "input": INPUT, **fields})- finally:- await gateway.close()- routed = f"{state.get_source(configured.id).prefix}/{model}"- expected = {"model": routed, "stream": True, "input": INPUT, **fields}- if tools is not ABSENT:- expected["tools"] = tools- # The engine appends a missing key at the end of the object and replaces an existing one in place.- assert received == [json.dumps(expected).encode()]--@pytest.mark.asyncio@pytest.mark.parametrize("declared", [False, True], ids=["undeclared", "declared"])[email protected](("backend", "path"), [- ("claude", "messages"), ("opencode", "responses"), ("vibey", "responses"),-])-async def test_other_callers_reach_the_engine_with_exactly_their_declared_tools(tmp_path, backend, path, declared):- """MH-HOSTED-GATEWAY-001: Claude, OpenCode and Vibey get no image tool they did not declare.[email protected](("backend", "path", "subscription"), [+ ("codex", "responses", False), ("codex", "responses", True), ("claude", "messages", False),+ ("opencode", "responses", False), ("vibey", "responses", False),+], ids=["codex_api_key", "codex_subscription", "claude", "opencode", "vibey"])+async def test_every_caller_reaches_the_engine_with_exactly_its_declared_tools(+ tmp_path, backend, path, subscription, declared,+):+ """MH-HOSTED-GATEWAY-001: no caller, Codex CLI included, gets an image tool it did not declare.A Vibey request that declares it is a native declaration, so it is pinned toa hop verified for the tool (MH-HOSTED-GATEWAY-002)."""configured = _source("src_shared001", "Responses key", model_id="gpt-6-astra" if backend == "vibey" else "shared-model")+ if subscription:+ configured = _subscription(configured)tools = [SHELL, DECLARED_IMAGE] if declared else [SHELL]if backend == "claude":tools = [{"name": "shell", "input_schema": {"type": "object"}}, *([DECLARED_IMAGE] if declared else [])]@@ -218,7 +136,8 @@ async def test_other_callers_reach_the_engine_with_exactly_their_declared_tools(service = _service(tmp_path, sources=[configured])_canonicalize_fixed_test_routes(service)service.store.requested_models["opencode"] = "shared-model"- _wire(service, tmp_path, root, {})+ # A ChatGPT subscription's grant on a paid plan: where the engine's skip conditions never applied.+ _wire(service, tmp_path, root, {configured.id: {"plan_type": "plus"}} if subscription else {})pin = {}if backend == "vibey" and declared:source = service.store.config.sources[0]diff --git a/tests/test_model_hub_runtime.py b/tests/test_model_hub_runtime.pyindex 6c5da6e14..f90d7d155 100644--- a/tests/test_model_hub_runtime.py+++ b/tests/test_model_hub_runtime.py@@ -1932,7 +1932,7 @@ def test_mixed_anthropic_credentials_disable_cloak_only_for_api_key_entry(payload = yaml.safe_load(config_path.read_text(encoding="utf-8"))assert payload["disable-claude-cloak-mode"] is True- # The engine forwards declared image tools unchanged; Codex CLI gets its own from the gateway.+ # The engine forwards declared image tools unchanged and never adds one.assert payload["disable-image-generation"] == "passthrough"assert payload["claude-api-key"] == [{@@ -7513,9 +7513,6 @@ def test_slow_source_prelude_is_bounded_without_blocking_other_routes(def get_source(self, source_id: str) -> SourceRecord | None:return self.sources.get(source_id)- def codex_plan_type(self, *_args, **_kwargs) -> str | None:- return None # API keys carry no plan-class Supervisor:def __init__(self, client: EngineClient) -> None:self._client = clientdiff --git a/vibe/model_hub_runtime/adapter.py b/vibe/model_hub_runtime/adapter.pyindex 3b57270a4..f3a59c951 100644--- a/vibe/model_hub_runtime/adapter.py+++ b/vibe/model_hub_runtime/adapter.py@@ -59,7 +59,6 @@ from vibe.model_hub_runtime.client import (upstream_api_url,)from vibe.model_hub_runtime.api_key_vendors import pinned_api_key_protocol, validate_api_key_auth_scheme-from vibe.model_hub_runtime.codex_image_tool import with_codex_image_toolfrom vibe.model_hub_runtime.installer import (INSTALL_ALREADY_RUNNING_REASON,INSTALL_PLATFORM_UNSUPPORTED_REASON,@@ -2822,17 +2821,6 @@ class CLIProxyEngineAdapter:raise EngineStateError("source is not registered")if source.allowed_origins and origin not in source.allowed_origins:raise OriginNotAllowedError(f"origin {origin!r} is not allowed to use source {source_id!r}")- # The engine serves every Responses Source through its Codex executor- # (an API key or the ChatGPT grant), where it used to add its image tool.- codex_image_tool = origin == "codex" and source.protocol == "openai_responses"- plan_type = (- await asyncio.to_thread(- self.state_store.codex_plan_type,- source.credential_ref, source_id=source.source_id, vendor=source.vendor,- )- if codex_image_tool- else None- )try:client = await asyncio.to_thread(self.supervisor.client)except EngineUnavailableError as exc:@@ -2862,8 +2850,6 @@ class CLIProxyEngineAdapter:"claude": "anthropic","codex": "openai_responses",}.get(origin, getattr(request, "protocol", None) or source.protocol)- if codex_image_tool:- request = with_codex_image_tool(request, model_id=model_id, plan_type=plan_type)return await client.invoke(source,model_id,diff --git a/vibe/model_hub_runtime/codex_image_tool.py b/vibe/model_hub_runtime/codex_image_tool.pydeleted file mode 100644index 8c8bcae9a..000000000--- a/vibe/model_hub_runtime/codex_image_tool.py+++ /dev/null@@ -1,86 +0,0 @@-"""The hosted image tool for Codex CLI requests, added by Avibe instead of the engine.--The engine runs with ``disable-image-generation: passthrough`` (``config.py``), so-it forwards exactly the tools a client declares and adds none. Through Model Hub,-the hosted tool the engine used to inject is Codex's only image path-(``docs/plans/vibey-hosted-tools.md`` §7.1), so the gateway adds it back for Codex-CLI requests alone, with the engine's own tool and skip conditions. Every other-caller reaches the upstream with exactly the tools it declared.--Ported from CLIProxyAPI (MIT), ``internal/runtime/executor/codex_executor_request.go``-(``ensureImageGenerationTool``, ``isImageGenerationFunctionTool``,-``isCodexFreePlanAuth``), ``internal/util/codex.go`` (``IsCodexResponsesLiteRequest``)-and ``internal/thinking/suffix.go`` (``ParseSuffix``), at d318bcc3 (v8.0.23).-"""--from __future__ import annotations--import copy-from typing import Any, Final, Mapping--IMAGE_GENERATION_TOOL: Final = {"type": "image_generation", "output_format": "png"}-_RESPONSES_LITE_METADATA: Final = "ws_request_header_x_openai_internal_codex_responses_lite"---def with_codex_image_tool(- request: Mapping[str, Any], *, model_id: str, plan_type: str | None-) -> Mapping[str, Any]:- """Return a Codex Responses request with the engine's image tool, as the engine added it.-- Call it only for a Codex CLI request to a Source the engine serves through its- Codex executor. ``model_id`` is the hop's model and ``plan_type`` the plan the- engine derives for the credential (None for an API key). The request is- returned unchanged when the engine would have skipped it: Responses-Lite- metadata, a ``spark`` model, a free plan, or an image tool already present.- Otherwise the tool is appended to ``tools``, or ``tools`` becomes that one- tool when it is absent or not a list.- """-- if _responses_lite(request) or _base_model(model_id).endswith("spark"):- return request- if plan_type is not None and plan_type.strip().casefold() == "free":- return request- tools = request.get("tools")- if isinstance(tools, list):- if any(_declares_image_tool(tool) for tool in tools):- return request- injected_tools = [*tools, dict(IMAGE_GENERATION_TOOL)]- else:- injected_tools = [dict(IMAGE_GENERATION_TOOL)]- # A shallow copy keeps the request's metadata (protocol, caller headers).- injected = copy.copy(request)- injected["tools"] = injected_tools- return injected---def _responses_lite(request: Mapping[str, Any]) -> bool:- # The header form is not forwarded by the gateway, so only the body mirror counts.- metadata = request.get("client_metadata")- value = metadata.get(_RESPONSES_LITE_METADATA) if isinstance(metadata, Mapping) else None- return value is True or (isinstance(value, str) and value.strip().casefold() == "true")---def _base_model(model_id: str) -> str:- """The model without a ``(value)`` thinking suffix, as the engine compares it."""-- opening = model_id.rfind("(")- if opening == -1 or not model_id.endswith(")"):- return model_id- return model_id[:opening]---def _declares_image_tool(tool: Any) -> bool:- if not isinstance(tool, Mapping):- return False- kind = tool.get("type")- if kind == "image_generation":- return True- if kind == "function":- return tool.get("name") == "image_gen.imagegen"- if kind == "namespace" and tool.get("name") == "image_gen":- nested = tool.get("tools")- return isinstance(nested, list) and any(- isinstance(item, Mapping) and item.get("type") == "function" and item.get("name") == "imagegen"- for item in nested- )- return Falsediff --git a/vibe/model_hub_runtime/config.py b/vibe/model_hub_runtime/config.pyindex a5a13a51b..482afd3d3 100644--- a/vibe/model_hub_runtime/config.py+++ b/vibe/model_hub_runtime/config.py@@ -97,8 +97,8 @@ def render_engine_config("disable-cooling": True,"disable-claude-cloak-mode": True,# Forward exactly the tools a client declares: never add the hosted image- # tool, never strip one. Codex CLI requests get it from the gateway instead- # (codex_image_tool.py), and Vibey declares it only when the user enabled it.+ # tool, never strip one. Vibey declares it only when the user enabled it;+ # Codex CLI drops a hosted image call it did not ask for (vibey-hosted-tools.md §7.1)."disable-image-generation": "passthrough","save-cooldown-status": False,"transient-error-cooldown-seconds": -1,diff --git a/vibe/model_hub_runtime/state.py b/vibe/model_hub_runtime/state.pyindex 536a94843..b22908ac5 100644--- a/vibe/model_hub_runtime/state.py+++ b/vibe/model_hub_runtime/state.py@@ -1,6 +1,5 @@from __future__ import annotations-import base64import hashlibimport hmacimport json@@ -1064,31 +1063,6 @@ class EngineStateStore:)return _oauth_account_label(payload) if payload is not None else None- def codex_plan_type(self, credential_ref: str, *, source_id: str, vendor: str) -> str | None:- """The plan the engine derives for a bound Codex grant; None for any other credential.-- It is the engine's own reading of the auth file it watches (CLIProxyAPI,- MIT, ``internal/watcher/synthesizer/file.go`` at d318bcc3): the file's- ``plan_type``, which the engine rewrites on every refresh, else the- ``id_token`` claim ``chatgpt_plan_type``, defaulting to ``free`` when- the token carries none or does not parse.- """-- payload = self._bound_oauth_payload(- credential_ref, source_id=source_id, vendor=vendor, auth_provider="codex",- )- if payload is None:- return None- plan = payload.get("plan_type")- if isinstance(plan, str) and plan.strip():- return plan.strip()- id_token = payload.get("id_token")- if not isinstance(id_token, str) or not id_token.strip():- return None- auth = _jwt_claims(id_token).get("https://api.openai.com/auth")- plan = auth.get("chatgpt_plan_type") if isinstance(auth, dict) else None- return plan.strip() if isinstance(plan, str) and plan.strip() else "free"-def _bound_oauth_payload(self, credential_ref: str, *, source_id: str, vendor: str, auth_provider: str,) -> dict[str, Any] | None:@@ -1509,18 +1483,6 @@ class EngineStateStore:raise EngineStateError(message)-def _jwt_claims(token: str) -> dict[str, Any]:- """A token's claims as local grant metadata, never a signature verdict; {} when unreadable."""- parts = token.split(".")- if len(parts) != 3:- return {}- try:- claims = json.loads(base64.urlsafe_b64decode(parts[1] + "=" * (-len(parts[1]) % 4)))- except (ValueError, UnicodeError):- return {}- return claims if isinstance(claims, dict) else {}--def _oauth_account_label(payload: dict[str, Any]) -> str | None:"""Only provider-declared public identity fields can become UI metadata."""secrets = {