Closes#2909.
Omit the fewest eligible historical tool-argument payloads so oversized completed exchanges remain replayable, without touching signed/native provider rounds or durable history.
Long mastery sessions froze the event loop: every existence-only probe
(history_groups, context-builder guards) ran normalize_model_turn, which
deep-copies the whole request record via a JSON round-trip. A 121-message
session re-serialized megabytes per probe, holding the GIL long enough for
health checks to time out and the worker to be declared lost.
Extract the structural acceptance checks into _is_complete_model_turn and
add has_model_turn for existence-only sites. normalize_model_turn delegates
to the same predicate, then cleans and copies as before, so replay keeps its
full isolation. Stored records are normalize's own JSON-safe outputs, so the
predicate accepts exactly what normalize accepts on stored rows; a parity
corpus pins the shared rejections.
Fixes#2788
Co-authored-by: ZQR1101 <278034003+ZQR1101@users.noreply.github.com>
* fix(chat): isolate PDF attachment extraction
Run PDF-bearing chat attachment extraction outside the API process and reuse the single PDF image pass for both page markers and embedded attachments. Addresses the chat attachment reproduction in #2865.
* perf(pdf): skip decoding images after the count cap
Keep lookups for previously accepted image references ahead of the quota check so repeated pictures are still mapped to each page.
* perf(chat): reuse native PDF markdown for text-only parsing
Match the stored attachment bytes and preserve the configured parser path for other engines and incomplete native results.
* fix: keep sent runtime snapshots in mastery replay
Mastery replay dropped every runtime snapshot from history and the loop
re-appended them after it, so each follow-up request diverged from the
previous one at message 1 and only tools + system hit the prompt cache.
- project_mastery_replay(keep_snapshots=True) for the tutor request and
its token accounting; memory material still drops snapshots
- replay_group no longer blanks a tagged mastery_status_snapshot while
removing the legacy fused suffix
- status snapshot anchors are numbered from the start (occurrence), so a
later snapshot never changes how an earlier turn is projected
Refs #2922
* fix: keep runtime snapshots out of the mastery history budget
Replayed snapshots stay in the request so follow-up turns extend the cached prefix, but counting them made a large mastery_status snapshot push the history over its 20k budget after two turns; the next turn then paid a memory rewrite and a full prefix miss. The budget now measures the learning history only, as before. Refs #2922
* fix: bound the runtime snapshots kept in mastery history
Keeping sent snapshots out of the history budget entirely let many short
exchanges accumulate them without limit (80 quiz-style turns: 5.4k counted,
62k sent). Dialogue still keeps to the plan; dialogue plus snapshots keep to
twice the plan, and only as far as the model's window allows. Refs #2922
* fix: keep only this turn's state in the mastery status snapshot
Every mastery turn sends a fresh mastery_status snapshot and, since the
replay change, keeps earlier ones in history, so whatever a snapshot
carries is paid for once per turn and then kept. A full status read
repeats fixed guidance (open question, question group, working brief,
intake, teaching guidance and focus) and every default value of every
knowledge point.
The snapshot now drops empty and default values and the fixed guidance.
That guidance lives in named constants and is stated once in a new
mastery_status_guide system block, which also explains the omitted
defaults. Snapshots start with a one-line header; history sharing reads
both the header and the longer notice older sessions stored. An explicit
mastery_status call still returns the full payload.
Measured over 54 recorded snapshots: working briefs 1,454 -> 645 tokens
(median), full outline snapshots 6,352 -> 2,954. The guide adds 861
tokens (en) to the cached system prompt.
Refs #2922
* fix: size the exact tail the way the plan does, and share full reads with compact snapshots
Two gaps left by keeping snapshots in mastery replay (review on #2992):
- Recent-history selection counted kept snapshots in full while the plan
discounted them, so a session of short exchanges with large snapshots
archived most of them as soon as selection ran. ContextBuilder now sizes
the candidate tail through _recent_history_tokens(), and the mastery
builder answers with the same _plan_tokens() measure.
- Snapshots carry the compact form of map, learner_profile, learning_stages
and visual_requirements, so a later full mastery_status result never matched
them exactly. Sharing now also compares a full field's compact form and
marks such references with "defaults_omitted": true, which the state
reference notice explains.
Also: rename _next to _compact_next_step, and say in the status guide that
the omitted-default rules cover only what the snapshot includes.
Refs #2922
Independent maintainer review approved for 257c5e62. Windows Python 3.12 pre-commit 15/15, targeted Windows and WSL Linux regressions passed; latest HEAD CI has no failures.
Local dev repairs for #2168, #2631.
Real child-process recovery: 16 tests passed, including queued, running, waiting_input, process exit and PID reuse. Existing coordination/application tests: 65 passed, 10 optional Redis skips.
Retain admission error text and localized model-access guidance; allow explicit retry to revalidate access instead of permanently blocking stored messages. No automatic retry on reload. Backend tests and both manual retry paths passed.
All attached units together stay within one unit's cap (60k chars). The unit
that crosses it is cut with a named marker; later units are listed by name.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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>
Chat turns reach attached reading units through the source inventory and
read_source. Deep Solve, Visualize, Math Animator and the other non-chat
capabilities get attachments inlined into the user message instead, but
reading references were left out there, so a turn with reading sections
attached ran without them. They now go in as [Reading Sections], next to
[Attached Documents] and [Book Context].
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Practice notebook entries recorded in one session now share a single
sidebar row, titled by that session with its question count, expandable
to each question's own practice link. Entries without a session (and
sessions that produced one question) keep individual rows, and the
Question Bank, answers and review links are unchanged.
The learning index navigation read gains the existing session id and
title (no new persisted field); grouping happens in the projection.
Sidebar strings added to every locale.
Document selected-text speech, model discovery, NVIDIA NIM embeddings,
mastery reliability, Windows improvements, and complete desktop downloads.
Sync all eleven README translations and archive the v1.7.0 release notes.
Add platform-specific typing annotations for Windows APIs without changing
runtime behavior. See assets/releases/ver1-7-2.md for changes and upgrades.
Validation: pre-commit and Ruff passed; 12,782 Python tests passed
(51 skipped), 1,349 Node 22 tests passed, and the docs build passed.
msvcrt's LK_LOCK gives up with EDEADLK after about ten seconds, and a
one-time upgrade of a large session database can hold the lock longer than
that. Retry on EDEADLK so the other workers wait, as flock does on POSIX;
any other lock error still propagates.
msvcrt's LK_LOCK gives up with EDEADLK after about ten seconds, and a worker
importing a large legacy store holds the lock longer than that. Retry on
EDEADLK so the other workers wait, as flock does on POSIX; any other lock
error still propagates.
LegacyChatSessionMigrator.migrate runs under _migration_lock because
every worker runs it at startup, but the lock used fcntl only and was a
no-op on Windows. Workers there copied, imported and archived the same
v1 sessions file at once: with 4 processes x 5 rounds, 17 of 20 runs
failed (LegacyMigrationError from colliding imports, WinError 32 on the
backup copy).
Take an msvcrt byte-range lock when fcntl is unavailable, in the same
shape as the other cross-process locks.
SQLiteSessionStore runs its WAL switch and schema creation under
_migration_lock, which serializes worker processes with fcntl.flock but
was a no-op on Windows. Processes opening the store together there
raced: on a fresh database 14 of 30 concurrent opens failed with
"database is locked" (PRAGMA journal_mode = WAL) or "trigger
practice_capture_update already exists".
Take an msvcrt byte-range lock when fcntl is unavailable, in the same
shape as the grants, cron and Codex-auth locks.