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
* 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>
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>
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>
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.
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>
* 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>
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.
* 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.
Prepare v1.7.3 notes for reading and book editing, expanded provider and
agent connections, learning records, model streams, and desktop upgrades.
Sync README prose and 11 translations, archive older release notes, and
update the package version. Resolve release lint/type blockers with explicit
parser and capability contracts, compatible Book call forwarding, accurate
auth task types, and quoted SQLite schema identifiers. Cover positional Book
calls and quoted legacy columns; align KB seed tests with visible retrieval
failure reporting. Keep HTTP fixtures independent of host proxies and translate
new Portuguese UI copy.
Release notes: assets/releases/ver1-7-3.md
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).
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.
Encode foreign tool IDs injectively with a reserved URL-safe prefix; test distinct calls, paired results, native IDs, and unchanged history (39 passed).
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>
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>
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
_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.
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>
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>
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.