12 Commits

Author SHA1 Message Date
Benjamin Schwing
7938c6f40c fix(mastery): accept retained archive ids in tutoring memory coverage (#2947)
The fold prompt lets memory entries cite previously retained archive IDs,
but covered_archive_ids had to equal the newly supplied set exactly. A
model that also lists retained IDs as covered failed every fold, so the
watermark never moved and the session stayed on degraded raw history.

Accept covered IDs that are the newly supplied ones plus IDs the prior
memory already covered or cited. Still reject omitted, invented or unseen
IDs, and store only the newly folded IDs as covered.

Signed-off-by: Benjamin Schwing <63053132+BenjiAvH@users.noreply.github.com>
2026-11-28 18:24:06 +08:00
wojiecihuo
ce831dd4c3 fix: keep sent runtime snapshots in mastery replay, and keep them small (#2992)
* 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
2026-11-28 12:57:21 +08:00
Bingxi Zhao (Frank)
e0872716f0 fix(runtime): announce input waits and reject oversized history plans
Local dev repairs for #2387, #2433, #2496. Regression checks cover reported symptoms and compatibility boundaries.
2026-11-15 00:44:09 +08:00
Harsh
f76de28db9 fix(mastery): count the whole memory request against the history plan
The fold loop counted only each exchange's archive text and always folded
the oldest exchange, so one exchange over the plan was sent whole, and
prior learner memory could push a fitting exchange over it.

Fold the longest prefix of whole exchanges whose complete request fits:
prior memory, the system instruction and the exchanges as _summarize()
serializes them, plus a reserve for the length line. If even the oldest
exchange doesn't fit, send no memory call; the watermark stays and the
exchange stays in exact recall.
2026-11-11 11:32:20 +05:30
Harsh
4ddaf9c0aa fix(mastery): stop tutoring-memory retries from growing every turn
A failed tutoring-memory call keeps the watermark, so the next turn
retried with the same backlog plus the newest exchange, and the call
grew without limit (#2496). Fold in only the oldest whole exchanges
that fit one history plan, at least one, and leave the rest
unsummarized so the watermark moves only past what was covered.

Related to #2496
2026-11-07 10:40:37 +05:30
x-labb
15c79b4356 fix(mastery): stop retrying a truncated tutoring memory on every turn 2026-11-02 18:44:34 +01:00
AleFlyX
8f9fb42b6b fix(mastery): 阻止历史回忆递归归档膨胀
变更:
- 将归档与历史回放中的历史读取正文替换为可回查引用,保留原始存储记录
- 为精通之路历史归档增加每页 16000 字符的分页读取
- 增加多轮重复读取、旧大记录兼容和分页还原的回归测试

验证:
- 216 项相关 pytest 测试:PASS
- 修改文件的 Ruff lint 与格式检查:PASS
- scripts/check_architecture.py:PASS
- git diff --check:PASS

Fixes #2032
2026-10-23 12:44:33 +08:00
Bingxi Zhao (Frank)
4fe1b5b24a fix(mastery): finish bounded memory and count preparation usage (#1920, #1926) 2026-10-19 03:44:51 +08:00
Bingxi Zhao (Frank)
8b73efbaeb Merge PR #1958: stabilize cached prefixes with bounded sources and complete summary accounting 2026-10-19 00:59:30 +08:00
Bingxi Zhao (Frank)
1497994c9f Merge PR #1938: bound tutoring history and retain exact recall when condensation fails 2026-10-19 00:57:48 +08:00
yepyhun
539bd80f06 fix(mastery): align memory accounting with routed image replay
Forward the optional route into native replay and measure duplicate-image projection in final accounting without rewriting retained history. GREEN: 20 focused tests pass in clean PR1938 worktree; corresponding local suites pass 22 tests.
2026-10-13 09:06:52 +02:00
yepyhun
499e6bc75f feat(mastery): bound tutoring memory with exact branch recall 2026-10-12 11:16:34 +02:00