277 Commits

Author SHA1 Message Date
Yuchuan He
e70a6be7e3 fix(llm): recover Responses after a stream read disconnect (#3073) 2026-12-01 21:55:56 +08:00
Yuchuan He
38af3bc518 fix(llm): preserve Responses system instructions across summaries (#2711) 2026-12-01 21:36:30 +08:00
Yuchuan He
a35231eb92 fix(llm): retain Azure streamed response replay state (#2712) 2026-12-01 21:36:03 +08:00
Sanae
b14267bacf fix(llm): preserve Responses wire aliases during tool replay (#2734)
Serialize SDK responses using API field aliases and omit unset optional
fields before persisting native replay state. Repair legacy async_ fields
on a copy at replay time without altering stored history or argument JSON.

Cover streaming and non-streaming SDK continuations, alias precedence,
and legacy SQLite replay.

Co-Authored-By: GPT-6.1 Sol High
2026-12-01 21:35:29 +08:00
Shaikh Fardin
8a8cdf785f fix(llm): force temperature 1.0 for gpt-6 and drop reasoning_effort before tools (#2446)
* fix(llm): force temperature 1.0 for gpt-6 and treat reasoning_effort+tools rejection as tool-schema unsupported

* fix(llm): drop reasoning_effort instead of tools when combined request is rejected

---------

Co-authored-by: Shaikh Fardin <152140625+Fardin7798@users.noreply.github.com>
Co-authored-by: OrdoAbChao7 <2369980241@qq.com>
2026-12-01 19:27:05 +08:00
bluefateludi
c20e42fd99 fix(llm): record nested prompt cache write counts (#3108) 2026-12-01 17:26:47 +08:00
iron ox
97e9ef8d44 fix(llm): omit optional replay status for custom Responses gateways (#2487)
Omit optional status on message/reasoning/function_call items when building
Responses requests for the custom binding, so gateways that reject
unknown_parameter inside an HTTP 200 stream no longer fail durable turns.
Keep the bounded HTTP-error retry for other cases.

Co-authored-by: zhouyao01 <zhouyao01@mucang.cn>
2026-12-01 14:55:05 +08:00
Alex Castillo González
12e3a8ae0d fix(llm): accept list-of-blocks content from OpenAI-compatible providers (#2795)
Mistral reasoning models return `content` as a list of typed blocks
(thinking + text). `_parse_chunks` joined those lists directly and raised
TypeError, and `_parse` / the streaming content callback passed the raw
list through. Normalise with the existing `_extract_text_content` helper.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-12-01 14:17:51 +08:00
crimson-gzx
f56225f9b1 fix(llm): send session-scoped prompt_cache_key on Responses API requests (#2827)
Co-authored-by: Josh Guo <crimsongzx@gmail.com>
2026-12-01 14:13:16 +08:00
iQuantum
b5fb281a3e fix: default Anthropic to a Claude model Anthropic still serves (#2888)
AnthropicProvider and the agentic client's Anthropic adapter fell back to claude-sonnet-4-20250514, which Anthropic retired on 2026-06-15, so an Anthropic binding with no model failed with not_found_error. Both now use one DEFAULT_ANTHROPIC_MODEL constant, claude-sonnet-5-5.
2026-12-01 11:20:50 +08:00
Oikantik Basu
9e5a4e64c9 fix: preserve thinking-off settings on research outline retries (#3134) 2026-12-01 09:34:04 +08:00
Alex Castillo González
bc9a289b3f fix(llm): report token usage from the Codex OAuth provider (#2797)
OpenAICodexProvider._request_codex called consume_sse without an
on_provider_event hook and built LLMResponse without usage, so Codex turns
were counted as 0 tokens/cost. Collect the terminal usage event and attach it
to the response, as the openai_compat Responses path already does.

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-12-01 00:26:23 +08:00
wojiecihuo
62c383caf1 Merge pull request #3069 from zszz3/fix/reasoning-empty-tool-round
fix: send an empty reasoning_content on reasoning-less tool rounds
2026-11-30 23:20:56 +08:00
Michael Chen
436ec67e2d fix(llm): resolve Moonshot K3 context windows (#3013) 2026-11-30 15:48:57 +08:00
Benjamin Schwing
48502be836 fix(llm): close pooled providers on the event loop that owns them (#2948)
* fix(llm): close an evicted pooled provider on the loop that owns it

The runtime provider pool is keyed per event loop and shared by the server
loop and synchronous callers that run asyncio.run() in a worker thread, such
as the exam question extractor. Two cross-loop problems followed:

- When a worker loop's lookup evicted a server-loop client, the client's
  aclose() was scheduled on the worker loop. It ran on the wrong thread, or
  never ran when asyncio.run() cancelled it on exit. For Claude Code this
  tears down the server loop's persistent CLI sessions from a foreign thread.
- Every finished worker loop left its entry behind. With a pool of two,
  that stale entry could push the server loop's live client out, discarding
  warm CLI sessions.

Each entry now records its loop. Evictions close on that loop: directly
when it is the running loop, otherwise through run_coroutine_threadsafe.
Entries whose loop is closed are dropped before a new client is added.

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>

* fix(llm): close every retired pooled provider on its own loop

close_runtime_provider_pool() awaited aclose() of every pooled client on
the caller's loop, and reset_runtime_provider_pool() scheduled them on the
caller's loop or ran each on a fresh asyncio.run() loop. A client built on
another loop, such as a long-lived worker loop, was therefore closed on a
loop that does not own its sockets or tasks.

The bulk paths now keep each retired entry's loop. close awaits only the
clients owned by the current loop and hands the rest to their owner loop;
reset routes every client through the same owner-loop close. The final
release of a leased client also uses the entry's recorded loop.

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>

* fix(llm): create a cross-loop close coroutine on the owner loop

run_coroutine_threadsafe() builds the close coroutine on the calling
thread. When the owner loop is stopped but not yet closed and never runs
again, that coroutine is dropped unawaited and Python warns "coroutine was
never awaited". Schedule a callback instead that creates the close task on
the owner loop, so a loop that never runs again leaves nothing behind. A
closed loop rejects the callback, which also replaces the separate
is_closed() check.

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>

---------

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
2026-11-30 14:18:16 +08:00
zszz3
8ca3ebf869 fix: send an empty reasoning_content on reasoning-less tool rounds
A thinking model occasionally streams a tool call with no reasoning. The loop only writes reasoning_content when there is text, so DeepSeek rejected the next request of the turn with "The reasoning_content in the thinking mode must be passed back to the API". Once the request already carries reasoning elsewhere, the reasoning-less tool round now gets an explicit empty field.
2026-11-29 16:06:49 +08:00
wojiecihuo
651a616b02 fix(visualize): raise the budget to 32k, cap it to the model, and retry without thinking (#3019)
* fix(book): retry an interactive page with thinking off when it runs out of room

deepseek-flash thinks by default and can spend the whole 16000-token
visualize budget on reasoning, so a book interactive block came back with
no code. When the page is empty or cut off before </html>, ask once more
with thinking turned off (thinking_off_effort_for) before failing. If that
still runs out of room, the error names the budget sent to the model and
the settings that change it.

The shipped default stays at 16000: the budget is shared by every visualize
caller, and 32768 breaks models with a lower output cap (#3018).

Refs #3011

* fix(llm): raise the visualize budget to 32k and cap each request to the model

A thinking model can spend 16k tokens before it writes any code, so the
visualize default is now 32768. Sent unchanged that would be rejected by
models whose output stops lower (gpt-4o and gpt-4o-mini at 16384) and could
overflow a small local context window, so every request now carries
min(budget, the model's known output limit, half the configured context
window). The cap lives in get_token_limit_kwargs, so it applies to every
caller; BaseAgent and the agentic loop pass the configured window.
2026-11-27 22:26:59 +08:00
Bingxi Zhao (Frank)
3166cda206 fix(llm): bound effective progress and recover known responses
Fixes #2538
2026-11-15 01:42:46 +08:00
Bingxi Zhao (Frank)
ea67eb00cb fix(llm): accept offered Claude SDK tools without the MCP prefix
Local dev repairs for #2539, #2686. Regression checks cover reported symptoms and compatibility boundaries.
2026-11-15 00:44:10 +08:00
Bingxi Zhao (Frank)
6c1e3b6e60 Merge PR #2549: fix(llm): map Anthropic context-window, refusal and stop_sequence stop reasons
Move the context-full finish reason into the shared LLM protocol and add English and Chinese notices; test both localized warnings and provider mappings (186 passed).
2026-11-14 23:09:35 +08:00
Bingxi Zhao (Frank)
0d9b45f37f Merge PR #2562: fix(llm): stop dropping the answer when a reply mentions <think>
Protect fenced and inline Markdown examples while stripping real closed, mixed-spelling, and interrupted reasoning blocks; add regressions for literal tags and code inside reasoning.
2026-11-14 23:08:23 +08:00
Bingxi Zhao (Frank)
d0fc167b9e Merge PR #2606: fix: make foreign tool call ids valid for Anthropic
Encode foreign tool IDs injectively with a reserved URL-safe prefix; test distinct calls, paired results, native IDs, and unchanged history (39 passed).
2026-11-14 23:04:28 +08:00
Bingxi Zhao (Frank)
f8d7ea9012 Merge PR #2491: fix(llm): recognize published GPT-6 context capacities
Add regression coverage for all four GPT-6 model names and explicit catalog-window overrides.
2026-11-14 23:03:51 +08:00
Bingxi Zhao (Frank)
39239ac1a8 Merge PR #2624: fix: sanitize raw agentic chat replay messages 2026-11-14 22:58:48 +08:00
Bingxi Zhao (Frank)
3658dd6854 Merge PR #2633: fix(chat): label reinjected prior-turn images as historical 2026-11-14 22:52:56 +08:00
Bingxi Zhao (Frank)
20019bdcf8 Merge PR #2615: fix(llm): report semantic silence on the Responses stream without touching the deadline
Preserve managed stream cleanup around semantic-silence tracking; 202 combined runtime tests passed.
2026-11-14 22:52:55 +08:00
Bingxi Zhao (Frank)
75becb0ad8 Merge PR #2543: fix(llm): name a reason when a local SDK turn fails with no text 2026-11-14 22:51:17 +08:00
Bingxi Zhao (Frank)
c4c37ee7f7 Merge PR #2567: fix(llm): drop null text parts instead of streaming the word None 2026-11-14 22:51:16 +08:00
Bingxi Zhao (Frank)
00f26d3fb0 Merge PR #2592: fix(llm): preserve encrypted thinking in Anthropic tool continuations 2026-11-14 22:51:16 +08:00
Bingxi Zhao (Frank)
e19631ada3 Merge PR #2645: fix(llm): preserve explicit Anthropic tool suppression 2026-11-14 22:51:16 +08:00
Bingxi Zhao (Frank)
604db7e558 Merge PR #2647: fix(llm): retain usage from consumed local SDK results 2026-11-14 22:51:15 +08:00
Bingxi Zhao (Frank)
58d12688a2 Merge PR #2665: fix(llm): reject Responses streams without a terminal event 2026-11-14 22:51:15 +08:00
Bingxi Zhao (Frank)
374b885b7d Merge PR #2666: fix(llm): close provider SDK streams on every exit 2026-11-14 22:51:15 +08:00
Bingxi Zhao (Frank)
46dca9fd5a Merge PR #2672: fix: accept case-insensitive HTTP URL schemes 2026-11-14 22:49:41 +08:00
Bingxi Zhao (Frank)
dc54a4f649 Merge PR #2503: fix(llm): keep pooled clients alive for active requests 2026-11-14 22:49:39 +08:00
mpichini1
b9a86ec831 fix: accept case-insensitive HTTP URL schemes 2026-11-13 19:05:15 +01:00
stefanielizeth73-art
5efd0c2031 fix: reject Responses streams without a terminal event 2026-11-13 22:54:44 +08:00
stefanielizeth73-art
38bb483ba6 fix: close provider SDK streams on every exit 2026-11-13 22:54:44 +08:00
stefanielizeth73-art
f3ae46f641 fix: keep SDK usage patches composable with error details 2026-11-13 22:45:06 +08:00
stefanielizeth73-art
fe0fb10ccc fix(llm): retain token usage from consumed local SDK results 2026-11-12 23:07:46 +08:00
stefanielizeth73-art
4bf6f46b98 fix(llm): honor explicit Anthropic tool suppression 2026-11-12 23:07:33 +08:00
evan188199-tech
7d2989e250 fix(chat): label reinjected prior-turn images as historical
Images re-injected via chat_prior_image_reinject_max landed in the
current user message with no origin marker, so the model treated them
as fresh uploads of that message even when it was text-only. Mark the
collected prior images historical with their source message id and
insert a brief origin note before such images during multimodal
assembly; current-turn uploads keep their existing behavior.

Fixes #2632

Signed-off-by: evan188199-tech <238371241+evan188199-tech@users.noreply.github.com>
2026-11-12 06:14:40 +08:00
elvisgraho
ab7e94a3c0 fix: make foreign tool call ids valid for Anthropic
History written by the Codex (Responses API) provider stores tool call ids
as "call_id|item_id". Switching a session to Anthropic replays them as-is,
and the API rejects the request:

  messages.1.content.0.tool_use.id: String should match pattern
  '^[a-zA-Z0-9_-]+$'

Map invalid characters to "_" when building tool_use and tool_result blocks.
The mapping is deterministic, so pairs still match; stored history is left
untouched, so the Codex provider can still split its compound ids.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 19:02:28 +01:00
Adithya
9d8742e994 fix: sanitize raw agentic chat replay messages 2026-11-11 14:07:44 +05:30
ZQR1101
5eb1748a93 fix(llm): report semantic silence on the Responses stream
chat_stream bounds every Responses iterator read, so each SDK event restarts
the 90s deadline -- including lifecycle frames like response.in_progress that
carry no answer, reasoning or tool output. Such a stream looks alive while
producing nothing, and nothing in the logs says so.

Derive semantic progress from the callbacks consume_sdk_stream already
dispatches and name a silent stretch once, re-armed by real output. Reporting
only: the read deadline, the stall error path and retries are unchanged.

Refs #2538
2026-11-11 05:36:52 +00:00
AleFlyX
03fd0e500e fix(llm): keep a rejected tool call visible when errors[] carries a stub
_error_detail() compared containment both ways to skip a rejection the CLI
had already reported. The reverse direction is wrong: a short errors[] entry
such as "Error" is a substring of every rejection, so the only mention of
the refused tool was dropped. That is the same silence #2539 is about.

Compare one way instead, after stripping the "Error: " prefix the CLI wraps
around the sentence it also reports. The intended dedupe still holds, and
both directions now have a regression test.
2026-11-11 09:39:30 +08:00
evan188199-tech
c3ece0b899 fix(llm): align Claude Code advertised tools and keep tool-rejection evidence (#2539)
Layer the parts of #2546 that #2543 does not cover on top of #2543:

- Rewrite the system prompt's tool manifest so every advertised name is
  the reachable mcp__deeptutor__<name> form, prune entries for tools the
  call did not mount, and state plainly when no tools are mounted. A
  bare-name call is rejected by the CLI, which is what kills the turn.
- Collect error text from tool_result blocks so a turn that dies right
  after a rejected tool call still names it; the CLI's own errors[] /
  result / subtype priority from #2543 is kept, rejections are appended
  as evidence and never repeated.

Signed-off-by: evan188199-tech <evan188199-tech@users.noreply.github.com>
2026-11-11 08:42:32 +08:00
Alex Castillo
f4566a3769 fix(llm): keep a full input context out of the output-truncation recovery
model_context_window_exceeded mapped to "length", which the agent loop
treats as an output cap and answers with continue_truncated, resending the
same full history. Report it as context_length_exceeded instead, and have
the loop end the round with a notice.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 11:52:13 -04:00
stefanielizeth73-art
1278483a64 fix(llm): preserve redacted thinking during tool continuation 2026-11-10 19:57:16 +08:00
yxh123739
39f42490c3 fix: recognize DeepSeek-V4.1-Flash vision support
DeepSeek-V4.1-Flash is natively multimodal, but every `deepseek-*` id
matched the broad `deepseek` override and resolved to
`supports_vision: False`. Mastery Path then refused to open source pages
with "The active model cannot inspect original pages", and the
multimodal layer stripped images before the request was sent — the model
was never asked.

Add narrow, vision-only overrides for the ids this model ships under,
including the namespaced spellings gateways publish, following the
existing Qwen-VL convention of listing both forms. Other DeepSeek text
models stay fail-closed, and the broader `deepseek` entry keeps
supplying response-format and thinking-tag handling.
2026-11-10 14:47:33 +08:00