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).
The chat loop replays the workspace note as the "workspace" runtime
snapshot, which lives inside the cached prompt prefix. The note embedded
workspace.logical_output_dir — outputs/chat/<session>/<turn>/ — so its
bytes changed on every turn: the snapshot-replace logic cut the old copy
out of the middle of the rebuilt history and appended a fresh one,
invalidating the provider prompt cache on every multi-turn request
(cached-token hit rate <1%; single-turn tool loops were unaffected).
- workspace_system_note(state_turn_path=False) keeps the replayed chat
snapshot byte-identical for the whole session and points at the current
user message for the exact path instead.
- new workspace_turn_note() delivers the per-turn output folder in the
trailing user message — fresh bytes each turn, so cache-safe by
construction.
- phase-built prompts (question/research pipelines) keep embedding the
exact path via the default state_turn_path=True; their behavior is
unchanged.
- model-history reconstruction keeps an exact prefix once snapshots are
stable; new multi-turn replay tests assert byte-level prefix extension
across three consecutive turns, plus the second factor named in the
issue turns out to be a consequence of the turn-scoped snapshot and
needs no separate change.
Verified: tests/agents/chat 273 passed; tests/capabilities 739 passed;
tests/services/workspace+session 709 passed (8 failures pre-exist on the
clean tree and are unrelated); remaining tests/agents failures pre-exist.
Exclusive knowledge capabilities (obsidian, marginnote4, subagent) dropped
the whole chat built-in surface, including web_search (still shown on in
settings) and the always-on web_fetch. Add a coexisting_tools declaration
to KnowledgeCapability (default empty; the product KBs declare the web
pair), honoured in compose_enabled_tools' exclusive branch under each
tool's usual gate (user toggle / always-on / conditional flag) and the
partner builtin_whitelist, mirroring the #650 KB coexistence. The
capability's system prompt now also names what actually mounted via
coexisting_tools_block, so the model no longer disclaims mounted tools.
Fixes#2612
Signed-off-by: evan188199-tech <238371241+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>
Carry the #958 service-layer reasoning_effort override through the whole
turn contract: the core TurnRequest LLMSelection accepts the field
(validated against VALID_REASONING_EFFORTS, old two-ID payloads unchanged),
the generated web contracts are regenerated, and ChatStateAdapter's
asLLMSelection restores a legal override instead of dropping it.
The composer gains a selector beside the model picker, offering only the
levels the selected model supports (live supported_reasoning_efforts or
the provider/model tables) narrowed to the wire vocabulary, hidden when
the model has none. The choice persists on the conversation's
llm_selection, so the next send uses it without a backend restart and
other conversations are unaffected; switching models resets the override.
Precedence stays conversation override -> profile/model default ->
provider default, and the context-budget readout reports the effective
effort beside the model when one was used.
Keep learner-facing explanations visible across finish checks, persistence, and replay. Remove mastery prose heuristics and prioritize learner objections.
Coordinate service shutdown and descendant cleanup, and preserve video lesson identity and playable results across chat completion and reload.
Remove course pages, APIs and the course_study capability. Add anchored note
threads and reviewed learning-block generation, queued and withdrawable chat
messages, quote attachments, side chats, and the calendar/favorites/navigation
updates.
Keep preview's existing backend architecture. Wire the new features through
its Python application and existing chat engine, retain legacy selected-text
requests, persist mid-turn messages in replay, and restore note context when
regenerating. Leave stored user data intact.
Validate frontend contracts, dependency boundaries, types, 1290 node tests,
840 rendered tests, lint, localization and the production build. Exercise
session/notes/API regressions, 53 chat-engine tests and 20 Python/native
integration tests with isolated runtime data.
Add rich text and learning blocks, media uploads, page trees, and revisioned notebook storage. Present AI suggestions at their target blocks with durable accept and dismiss actions.
Unify saved outputs as Favorites with typed expandable blocks, stable source links, atomic batch insertion, nesting, dragging, and undo/redo.
Validation: 99 frontend tests and 99 backend tests pass in an isolated snapshot, along with TypeScript, scoped ESLint, dependency architecture, and locale parity checks.
A checkpoint may now carry an optional `state` next to `summary`. The fold
keeps appending summaries before the boundary as before and places `state`
in one system message after it, so the next fold replaces the state instead
of stacking stale copies. Checkpoints without `state` behave exactly as before.
The guard sized the request from message content alone. It ignored
assistant tool_calls arguments and the tool schemas sent with the call,
so a request over the window could go out untrimmed.
- Count each message with the counter history planning uses, leaving out
the _context_snapshot key that _call_llm strips before sending.
- Pass the call's tool_schemas into the guard. The forced-finish round
sends none, so it passes none.
- Keep a running total while tool results are snipped instead of
re-estimating the whole request after every snip.
- Log a warning when nothing is left to trim and the request still does
not fit, rather than passing it silently.
With the call's tool schemas, the 8k reproduction from #1961 now trims all
three tool results, taking the request from 10435 to 6514 tokens against a
7372-token budget.
Refs #1961
The summary was prepended inside the replayed history, so every
compaction rewrite changed bytes at the head of the request and threw
away the whole cached prefix behind it. Measured on a six-turn session
on a custom OpenAI-compatible route: the turn that rewrote the summary
dropped the shared prefix to one message and ran 21,629 prompt tokens
for 5,888 cached (27.2%).
Deliver it where the runtime-snapshot machinery already puts per-turn
context: as a trailing role=user message tagged _context_snapshot. A
rewrite is then a pure append, and an unchanged revision is a no-op.
replay_history no longer injects the summary, which is what kept it
mid-request whatever position it was given.
Two smaller fixes ride along, both in the same summary path:
* The summariser's scratchpad leaked into compressed_summary when the
route emits reasoning inline. The stored summary was 6,933 characters,
half of them the model's drafting monologue under an unclosed think
tag, and the real summary was truncated by it. clean_thinking_tags
cannot be used here - it deletes through end of text for an unclosed
block - so the tag is honoured only when it is closed, and an unclosed
one is cut at the first heading.
* _model_tokens counts the summary the way the request carries it.
The two regression tests that pinned the summary inside model_history
now assert the new delivery: the history starts at the oldest retained
turn and the summary still reaches the model.
`_append_loop_instruction` appended a recovery directive by rebuilding the
trailing user message as a string. A user message can carry content parts —
chat PDF attachments add image blocks beside the text — and `str()` on that
list folds every `data:...;base64,` URL into prompt text, so the next round
sends image bytes to the provider as language tokens instead of images.
A scanned 7-page PDF (whole-page JPEGs harvested as embedded figures) turned
into a ~5.9 MB prompt string: the image-aware context counter reported
4,014,309 tokens for the round against a 1M window, the provider answered
400 InvalidParameter, and the turn ended on the empty-response fallback.
The directive now extends the message's own text part, or appends a text part
when the message holds only images. Image parts, their order and the durable
model turn are unchanged; only the text grows.
Reached whenever a round ends with nothing to replay: an empty finish, or one
whose stream carried no text, reasoning or tool call.
Bind original visual sources and keys to supported tasks; verify accepted model pixels, preserve cues/assistance and canonical attempts, keep uncertainty ungraded, expose challenge/repair, and separate required visual evidence from generic text mastery.
Adapt the journal foundation from PR #1226 and add a read-only mission, handoff and confirmed-record panel. Share its snapshot with turn injection, preserve corrupt files, and serialize worker writes.
Co-authored-by: ZQR1101 <278034003+ZQR1101@users.noreply.github.com>