* fix(mastery): grade within the objective's covered and own scope
- Reuse the preserved objective-scoped packet for an objective request
after a focus preparation replaced the live slot, and do not rebuild
an incomplete objective packet whose fingerprints are unchanged (#2363).
- mastery_assess grades a concept/design explanation against the covered
facets of an incomplete objective packet, records that scope, and
returns a structured coverage_gap result instead of a bare refusal.
- Tell the learner when an answer was not recorded or was graded only
against the covered part.
- Give the judge sibling objectives as out of scope and return the
single missing element with a next_step to ask for exactly it (#2364).
* test(mastery): cover the focus-only assessment deadlock from #2905
A complete focus-scoped packet with no assessment slot gets a structured
coverage_gap on every repeated mastery_assess, with no judge call and no
recorded evidence. One objective preparation then grades the retained
explanation together with the next reply.
Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
* fix(mastery): make the missing-element step the assess instruction
Since dev added a generic instruction to every final mastery_assess
payload, a non-passing verdict carried two competing moves: next_step
asked for exactly the named missing element (#2364) and instruction
asked the learner to explain the objective again. While the gate is not
cleared, the targeted step is now also the instruction, and it says to
record the reply with mastery_assess.
Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
* fix(mastery): say when an unclear explanation is kept for grading
A non-final verdict in a session keeps the explanation and grades it
together with the follow-up, so the generic "not recorded, progress
unchanged" notice misled the learner into repeating the whole answer.
Add an assessment_needs_clarification notice (en/zh) for that case; an
explanation outside a session keeps the not_recorded notice.
Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
* fix(mastery): preserve the missing assessment element on replay
---------
Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
Co-authored-by: Qiuner <wdst3635@163.com>
TeachingUpdate.model_json_schema() gave knowledge_point_id, strategy and outcome no description, so models filling a preference also set strategy and the call is rejected by check_semantics. Add per-field descriptions (flat schema kept) and a test.
* fix(mastery): ignore knowledge-base sources that no longer resolve
Refs #2748
* fix(mastery): filter the caller's mounted knowledge bases too
A study session left open across a deletion keeps sending the base it was
mounted with, and that list is merged verbatim with the topic's sources.
Run both through knowledge_base_ref_available so a stale name cannot reach
the tool bundles and raise AccessError.
* fix(mastery): keep language-course content in its target language
The reply-language directive is the last thing in every system prompt and
tells the model to write quiz stems and options in the reply language and
never switch. For a course whose subject is itself a language, the model
obeyed literally: an "Antonyms" objective in an English course, studied with
Chinese as the reply language, was drafted as 反义词 and taught in a later
session as Chinese antonyms.
- language_directive now says the reply language governs the explanation,
not the subject: a studied language keeps its own words, sentences and
exercise items.
- Route generation and the tutor's outline drafting name the target
language in every module and knowledge point ("English antonyms").
- The tutor playbook keeps an existing language course on its target
language even when an objective name does not repeat it.
Closes#2933
Co-Authored-By: Claude <noreply@anthropic.com>
* test(mastery): check the composed prompts keep a language course's target language
The strict reply-language directive is appended last, after the route and
tutor instructions. Assert the carve-out survives in the prompts the model
actually receives: zh route generation, and the zh tutor playbook rendered
with a fixed reply language.
Related to #2933
Co-Authored-By: Claude <noreply@anthropic.com>
---------
Co-authored-by: Claude <noreply@anthropic.com>
Mastery Path preparation looked up a knowledge base's index by the global embedding signature. PageIndex, GraphRAG and LightRAG versions carry a provider signature instead, and a LlamaIndex knowledge base can be bound to another embedding, so a ready index was rejected with 'no compatible completed index'. Preparation now resolves the index the way the provider reads it: the KB's bound embedding for LlamaIndex, the newest provider-ready version otherwise. Fixes#2895.
* fix(mastery): name the recovery step when assessment evidence is mis-scoped
The focused-teaching refusal that blocks mastery_assess said only to prepare
assessment-bound evidence, so a session that had only ever prepared focused
packets retried the same call and the learner stayed stuck. Point the refusal
at the preparation that actually clears the gate.
* fix(mastery): avoid misleading recovery for incomplete evidence
Split focus-scoped and incomplete objective-scoped assessment refusals so
only focused packets are told to prepare without a focus. Surface missing
coverage for incomplete objective packets and pin the diagnostic with a
regression test.
---------
Co-authored-by: ZQR1101 <278034003+ZQR1101@users.noreply.github.com>
* 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
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
Update the status contract for session_id and prove concurrent retries in a fresh session create only one card while retaining the archived question (139 passed).
A pending quiz card stores the source snapshot it was verified against,
including a fingerprint of the whole published KB index. Adding any
document to that KB changed the fingerprint, so every grade failed with
"Prepare the lesson again" - which refreshes only the lesson packet,
never the card - and the learner's answer could not be recorded.
An issued question is now bound to the pages it cites: when the index
changed but each cited page (KB, document, page, source digest) is still
published unchanged, the question validates and is graded. If a cited
page did change, the error says so and names the recovery tools.
Lesson packets and question issuance keep the strict whole-index check;
objective, answer-key and scope gates are unchanged.
The reserved-name filter closed the injection path, but the revision branch
still fell back to the public `answer` parameter when `_learner_message`
was absent. `answer` is model-authored, so a tool call without the trusted
key could replace a committed learner reply and credit mastery for text
the learner never typed.
Reproduced on the previous head: commit a help request, grade it
(`is_correct: null`, `final: false`), then call with only
`answer="photosynthesis"` — `is_correct: true`, mastery 0.5, and
`user_answer` rewritten.
Revision now requires `_learner_message`. Without it the stored answer
stands and the call re-grades as ungraded, which costs no credit and
rewrites nothing. This guard existed earlier on this branch and was lost
when the schema layer was removed; the regression test is restored with
it.
Note this is the same defect the reviewer reported on the first commit,
which means removing the schema work also removed the protection that had
been added to answer it. Worth remembering when cutting scope: verify what
each removed commit was actually guarding.
The source selector may ask for an adjacent page ("neighbor": -1 or 1) as
figure/table context. When that page does not exist, for example past the
last page of a PDF, located_sources raised "The requested neighboring page is
unavailable" and the whole preparation was discarded, including the pages
that were actually chosen. On a real course this failed preparation for 4 of
19 concept/design objectives; with the fix, 3 of them prepared complete
lessons and the fourth reached an unrelated coverage gap.
Skip the unavailable context page and keep the chosen pages.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Source selection asks for at most 1800 output tokens and grading for 2200.
Reasoning models count hidden reasoning against max_tokens. On a real course
page set, nvidia/nemotron-3.5-super-vl (OpenRouter) stopped with
finish_reason=length in 5 of 5 runs after spending all 1800 tokens on
reasoning, so the reply had no JSON and preparation failed with "invalid
source-selection response". The #2367 retry lowers reasoning_effort to "low",
which this model does not honour: on a small probe it reasoned more, not less,
and in the app the retry failed the same way.
Raise both caps to 8192. Replaying the same request with an 8000-token cap
finished in 3 of 3 runs (2.4k-4.1k reasoning tokens), and full preparation
then completed for 4 of 4 objectives. max_tokens is a ceiling, so models that
answer briefly are unaffected.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
prepare_lesson tells the model to pick at most MAX_LESSON_PAGES pages, but
models regularly return more (a free reasoning model did so in most runs on a
real course). The whole preparation then failed with "Invalid source selection
count: too many distinct physical pages", and the tutor retried it in a loop.
Keep the model's ranked picks within the cap and drop context-only neighbour
pages first. The lesson stays bounded; every kept page is still inspected.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On a free-text mastery question, a learner's "I don't get it, explain"
was judged ungraded and stored as the interaction's user_answer. Every
later mastery_grade call then preferred that stored reply over the
learner's actual answer — the judge rejected the same help request again
as ungraded, and the question could never be cleared. The gate sat at
mastery 0.0 until the tutor called mastery_skip_question itself.
The committed user_answer is authoritative on purpose: the pause/resume
boundary stores the learner's exact words, and a later model round must
not paraphrase them. It stops being authoritative once the learner has
said something else *and* the stored reply was never ruled on. Revise
through the existing record_question_answer path, which rewrites
user_answer and keeps the superseded attempt in the event log as
assessment.revised.
A repeated, empty, or whitespace-identical reply is not a revision, and
a group interaction is excluded: its child questions keep their own
per-leaf revisable logic.
This is the free-text half of #1004, which only covered choice cards.
Closes#2595.
A visual whose source resolved but whose pixels were never in the model
input was still registered. Grade and correct then failed closed, and only
void could clear the card. Refuse that visual before registration, and tell
a correction of an already stored card to void it.
Fixes#2494
Co-authored-by: markxu <markjoin123@users.noreply.github.com>
Prepare Lesson parsed the model reply with json.loads after stripping
only a leading code fence. Reasoning models add <think> blocks or a
prose preface, and at high effort can spend the 1800-token budget on
hidden reasoning, so every attempt failed as an invalid source-selection
response. Assessment requests share the same parser.
Strip closed <think>/<thinking> blocks, treat a reply that still opens
with reasoning as unanswered, and scan for the first JSON object with
JSONDecoder.raw_decode. Truncated JSON still fails instead of being
repaired into a partial object. When the reply is unusable, retry once
at RETRY_REASONING_EFFORT, the project rule in structured_retry, for
both lesson preparation and semantic assessment.
Fixes#2367
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
resolve_module returned the first substring match in iteration order, so
"Limits and Continuity chapter" resolved to a shorter "Limits" module
that is a substring of it, sending the hand-off card to the wrong lesson.
Pick the match whose name length is closest to the phrase instead.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Builds on the clarification handling from #2261. After a final partial
grade the learner usually sends only the missing part, which was then
graded alone and found partial again, so answers split over several
messages could alternate between partial grades without ever passing.
Keep the graded explanation pending after a final partial, with the same
session/objective scope and TTL as a clarification request, so the next
explanation is graded together with it. Pending explanations are now
dropped when the path moves on after them (a final assessment of any
objective, a deferral, a question on another objective, a reset or
revision); ordering uses event ids instead of timestamps so the partial
that records the request does not cancel it. A pass or an incorrect
grade still ends it, and a retried turn replays its saved verdict.
Refs #2249
mastery_assess returned mastered and next but no instruction, unlike
mastery_grade. After a passing explanation the tutor tended to end the
turn on an announcement of the next topic, leaving the learner nothing
to answer.
Add an instruction to the final mastery_assess payload: when mastered,
confirm briefly and continue with next in the same reply (or say the
path is complete); when not mastered, explain the gap and ask again.
The clarification (non-final) result is unchanged. One matching sentence
in the en/zh mastery loop prompt.
Fixes#2323
When mastery_assess asks for clarification, keep the explanation for that
objective in the session. The next assessment grades the earlier explanation
plus the clarification instead of the short reply alone.
Fixes#2249
Combine same-module imports in the restatement test and collapse the
dict comprehension so CI ruff check/format pass.
Co-authored-by: Nandana Dileep <nandanadileep@users.noreply.github.com>