Skip to content

feat: Codex /responses support + web search (WebIQ) + tool-call recovery fix - #4

Merged
wangcansunking merged 8 commits into
masterfrom
worktree-web-search-support
Jun 26, 2026
Merged

wangcansunking merged 8 commits into
masterfrom
worktree-web-search-support

Conversation

@wangcansunking

@wangcansunking wangcansunking commented Jun 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

This branch grew well beyond the original WebIQ change. It now covers three threads:

  1. Codex support — implement the OpenAI Responses API so Codex (which dropped wire_api="chat") connects again, with per-model endpoint routing.
  2. Web search for Claude Code & Codex — fulfilled through Microsoft Web IQ by default (a Copilot "borrow" backend exists but is disabled — see below); Codex gets native server-side web_search.
  3. Tool-call recovery fix — a recurrence of the text-emitted-tool-call bug where a namespaced <invoke> split across stream chunks leaked as literal text.

Codex /responses

  • New OpenAI Responses API translators (responses-inbound.ts inbound, responses-upstream.ts outbound): item-centric request ↔ canonical, response object, and a stateful SSE emitter with sequence_number.
  • POST /openai/responses endpoint + Codex config writes wire_api="responses".
  • Per-model endpoint routing: fetchModelEndpoints reads each model's supported_endpoints; the adapter routes responses-only models (gpt-5.5, gpt-5.3-codex, …) to /responses, with a /chat 400 → /responses safety-net.
  • Codex's native web_search hosted tool is passed through to Copilot (new CanonicalRequest.hostedTools) and runs server-side with citations.

Web search backends

  • Default = WebIQ. Set the key with /webiq (get one at https://webiq.microsoft.ai/profiles/); /webiq clean clears it. With no key, the tools return a message pointing to /webiq instead of failing silently.
  • Copilot "borrow" backend (disabled by default). A gpt-5-mini-based backend that needs no key exists behind COPILOT_WEB_SEARCH_ENABLED, but is off because gpt-5-mini is currently badly congested on Copilot's /responses (measured 20s–7min stalls / 503s) while WebIQ is sub-second. Re-enabling is a one-flag flip. resolveWebSearchBackend(mode, hasKey) centralises the policy (copilot | webiq | unavailable).
  • borrowSearch runs at reasoning.effort:"low" (~5-6× faster) and has a 30s timeout (the missing timeout was why a stalled search hung a whole turn for minutes).
  • Replaces the earlier /web-search-support command. Status card + HUD show the resolved backend (incl. an unavailable state).

Invariant (unchanged, still enforced)

A gateway tool must never reach the client — Claude Code has no handler for web_search and would stall. Enforced and tested in both stream and non-stream paths, including a mixed gateway+client turn and loop-cap exhaustion.

Tool-call recovery fix

ToolCallExtractor's split-sentinel hold-back listed only the bare <invoke / <function_calls> forms (the two namespaced slots were duplicate bare copies). Copilot streams Claude's antml:-namespaced tool call token-by-token, so an opening <invoke split across chunks leaked as text and the whole call rendered literally. Fixed + split-at-every-offset regression tests.

Verification

  • npm test → 356 passed (55 files); npm run test:e2e → 31 passed; tsc build clean.
  • Live (real Copilot + WebIQ):
    • Claude web_search via WebIQ → stop_reason=end_turn, grounded answer, no tool_use leak.
    • No-key path → returns the /webiq guidance message.
    • Codex gpt-5.5 → completes/streams through /responses; native web_search returns citations.

Test plan

  • Codex: codex exec against a responses-only model (gpt-5.5) runs end-to-end.
  • Claude Code: ask something needing current info with a WebIQ key set → cited fresh answer as plain assistant text.
  • No key set → tools return the "run /webiq" hint (with profile URL), model answers from its own knowledge (no hang).
  • /webiq sets a key; /webiq clean clears it; status card + HUD reflect the backend.

Changeset: minor.

🤖 Generated with Claude Code

wangcansunking and others added 8 commits June 26, 2026 08:05
… Web IQ

A third-party gateway can't fulfil Anthropic's server-side web tools, so
the gateway dropped them and Claude Code lost web access. Now the inbound
translator converts web_search/web_fetch to function tools, and a capped
agentic loop in the Anthropic endpoint runs them internally against
Microsoft Web IQ, feeding results back — the client only ever sees the
final grounded answer (transparent). A new /web-search-support command
stores the WebIQ key (data dir or WEBIQ_API_KEY, read lazily).

Invariant enforced + tested in both stream and non-stream paths: a
gateway tool never reaches the client (it has no handler and would
stall), including on a mixed gateway+client turn and on loop-cap
exhaustion.

Verified live end-to-end (real Copilot + real WebIQ): a web_search
request returns stop_reason=end_turn with a fresh answer and no tool_use
leaked to the client.

Co-Authored-By: Claude <noreply@anthropic.com>
Show a status overview on startup (GitHub login state, web search
readiness, worker, configured clients) and a live web ✓/✗ marker in the
HUD footer, which is now two lines so it doesn't crowd. GitHub shows a
login STATE (connected/expired/signed-out) rather than an expiry — the
device-flow OAuth token has no real expiry, so a countdown would be fake
data. When web search isn't configured the indicator and card both point
to /web-search-support.

Co-Authored-By: Claude <noreply@anthropic.com>
Make /status render the same overview card as startup (GitHub login
state via a live token-exchange check, web search readiness, worker,
configured clients) followed by the worker restart history, instead of a
plain worker-state line. Falls back to the registry's text /status when
the App has no status props wired (keeps tests/headless paths working).

Co-Authored-By: Claude <noreply@anthropic.com>
New Codex removed wire_api="chat" (codex#7782) and requires "responses",
which makes it POST {base_url}/responses — an endpoint we didn't serve,
so Codex failed to start. Add POST /openai/responses with a full
Responses translator (item-centric request → canonical, canonical →
response object, and a stateful SSE emitter carrying sequence_number and
the response.created → output_item.added → content_part.added →
output_text.delta → … → response.completed sequence). Flip the Codex
config to wire_api="responses" (base_url stays …/openai; Codex appends
/responses, no /v1).

Verified live against real Copilot: non-stream returns a completed
response object; stream begins response.created and ends
response.completed.

Co-Authored-By: Claude <noreply@anthropic.com>
…login

Codex was still prompting for OpenAI login because our custom provider
block had no auth field — Codex then defaults to the OpenAI login flow.
Per the Codex config reference a custom provider needs an API key source.
env_key is unreliable here (a standalone Codex CLI won't see our .env),
so inline a static experimental_bearer_token plus requires_openai_auth =
false. The worker ignores the key value; it just satisfies Codex's auth
requirement and pins it to our local proxy.

Co-Authored-By: Claude <noreply@anthropic.com>
config.toml was assembled by appending model/model_provider at the END
of the file — after the user's existing [windows]/[marketplaces] tables.
In TOML a bare key after a [table] header belongs to that table, so
model_provider got silently nested under the last table and Codex never
saw it, falling back to provider "openai" (hence the login prompt).

Rewrite the assembler to split existing content into top-level keys vs.
table blocks and emit ALL top-level keys first, then tables, then our
provider table. Also de-dupe managed keys a previous buggy write left in
the table region. Verified live: Codex now shows provider:
copilot-reverse and connects to the local worker.

Co-Authored-By: Claude <noreply@anthropic.com>
The /setup-codex card showed "wrote …/codex.env" — a legacy .env file
the standalone Codex CLI doesn't read — which looked like the config was
written to the wrong place. Both files are still written, but return the
~/.codex/config.toml result (the native config Codex actually reads) so
the card surfaces the path and keys that matter.

Co-Authored-By: Claude <noreply@anthropic.com>
Reads supported_endpoints from Copilot's /models so the adapter can route
each model to the right upstream — newer gpt-5.x models are /responses-
only and reject /chat/completions. First piece of the adapter
upstream-/responses work (gpt-5.5 via Codex). Returns {} on failure so
callers fall back to chat/completions.

Co-Authored-By: Claude <noreply@anthropic.com>
@wangcansunking wangcansunking changed the title feat(web): web_search/web_fetch through the gateway via Microsoft Web IQ feat: Codex /responses support + web search (WebIQ) + tool-call recovery fix Jun 26, 2026
@wangcansunking
wangcansunking merged commit 6d04024 into master Jun 26, 2026
4 checks passed
wangcansunking added a commit that referenced this pull request Jun 26, 2026
The original changeset was consumed by the partial v0.3.0 release (which
shipped only PR #4's first commit); its changelog text is stale. This fresh
changeset describes the full set of changes landing in this PR.

Co-Authored-By: Claude <noreply@anthropic.com>
wangcansunking added a commit that referenced this pull request Jun 29, 2026
…plate, config, banner (#15)

* feat(tui): scope+model status, chat-setup confirmation, parity, report template, config, banner

- #6 /status + HUD show each client's scope AND pinned model, not a bare check
- #5 chat setup_claude/codex require scope+model (ask first, never assume)
- #7 add recent_errors + metrics chat tools to match slash commands
- #4 /report body follows the #5 template (Summary/Environment/Repro)
- #3 GitHub heartbeat interval/delay now configurable via AppConfig
- #1 versioned "what's new" banner, shown ~3 launches then suppressed
- #2 README reflects guards, runaway reporting, scope+model, config knobs

Co-Authored-By: Claude <noreply@anthropic.com>

* feat(report): add #5-style issue template; banner = major changes only

- .github/ISSUE_TEMPLATE/bug.yml (Summary/Environment/Repro/Diagnostics/fixes) so manual
  issues match the rich #5 shape; /report still auto-fills the same sections.
- what's-new banner trimmed to major changes only (the freeze fix); minor polish dropped.

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant