Chat attachments base64-inline every harvested image into one provider
request, and the byte budgets did not bound what a *page-sized* raster costs
there: a scanned A4 page arrives at ~2900x4032 (~600 KB), so a seven-page scan
rode along as ~4.2 MB of body / ~5.6 MB encoded even though the model is served
a raster scaled toward ~1.5k on the long edge anyway.
Fit a candidate to MAX_INLINE_IMAGE_EDGE (1600) before the byte budgets weigh
it, so the budgets measure what will actually ship. An image already within the
bound keeps its bytes and its format; re-encoding is reserved for rasters past
it, at the same jpg_quality (82) the reading viewport's whole-page render
already uses. Every failure path returns the original bytes, and a pixel count
past MAX_INLINE_FIT_PIXELS is refused before Pillow allocates for it.
The reading-area ingest keeps source resolution (max_inline_edge=0) because
those images are written to disk for the reader pane. The PPTX and DOCX
ingests were still on the chat-attachment budget by default, so they now pass
the reading budget like the PDF ingest already did.
decode_escaped_unicode_for_display repairs double-encoded \uXXXX runs
(#973) with the unicode_escape codec, which turns a surrogate-pair escape
for an emoji into two lone surrogates instead of one emoji. The
result cannot be encoded as UTF-8, so an ask_user card or mastery question
whose escaped text contains an emoji fails when the event is persisted to
SQLite or sent over the WebSocket.
Decode each run as a JSON string instead, matching the web decoder's
JSON.parse, and leave runs with an unpaired surrogate escaped.
_scan_entry treated every double quote as the start of a quoted value,
even inside a braced one. An accent such as {\"u} in
author = {M{\"u}ller, Hans} therefore opened a "quoted" run that swallowed
the entry's closing brace, and the whole entry was silently dropped from
the converted bibliography. Only treat a double quote as a delimiter at
the entry's top level, as BibTeX does.
The reading chain only pulled embedded images out of Office files; the PDF
branch produced text alone, so a slide deck uploaded as PDF reported
media_count 0 and no [图片 N] markers at all. The chat-attachment path already
had the missing half (extract_pdf_images + per-page markers), so the reader
now reuses it: each page's figures are pinned to that page's locator and the
marker lines are appended at the END of the page text, leaving every existing
character offset — and therefore every saved annotation anchor — untouched.
Budgets differ by path. Chat attachments inflate images into one request, so
they keep the 12-image/12MB document cap; the reader stores bytes on disk and
only ever sends the open page, so reading_image_budget() allows 120 images /
60MB per document while capping each page at 4 — the same ceiling the viewport
injection applies per turn, which keeps one dense figure page from eating the
document budget. extract_pdf_images/extract_docx_rich/extract_pptx_rich now
accept an explicit ImageBudget, defaulting to the previous behaviour.
Measured on the physics decks: day03_GaussLaw.pdf goes from 0 to 63 media rows
across 23 of its 42 pages (66 candidates, 3 dropped by the per-page cap).
Finder's "Compress" does two things to an EPUB: it nests the whole book
under one folder, and it writes a parallel `__MACOSX/` tree of AppleDouble
resource forks that carry the content files' names and extensions.
The package lookup only ever looked for `META-INF/container.xml` at the
archive root, so a wrapped book found no container, no OPF and no spine,
and fell back to matching file extensions over the whole archive. That
fallback then read `__MACOSX/OEBPS/._index_split_000.xhtml` — 60 bytes of
binary resource fork — as a chapter. Hence the phantom `._…` sections in
the sidebar and "Could not load this section" on opening them (#1447).
Both halves of the same rule, in one place. Packaging residue (`__MACOSX`,
dotfiles) is not book content and never reaches either reader; the other
archive readers in this codebase already drop it. And a single wrapper
directory is resolved from wherever the container actually sits, so spine
order survives it.
The container/OPF chain was written out twice — once for the spine, once
for the navigation — so a wrapped book silently lost its whole outline
too, by a `return []` in the half nobody was looking at. One resolver now
answers "where is this book's package document" for both.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Back-merge PR #1041 (Anthropic SDK 1.x temperature via extra_body) and
PR #741 (owner-only permissions for auth secret/token files), which were
merged directly into main and never flowed back to dev. Required so the
release cut can fast-forward main from dev.
Models sometimes emit literal \\uXXXX runs in ask_user and mastery_quiz tool args. Decode dense non-ASCII runs when building learner-facing payloads so cards do not leak escapes (#973).
The raw_decode scan added for trailing brace-prose returned the first
decodable value in the response. DeepSeek-style reasoning preludes often
embed a small schema example (e.g. {"chapters": []}) before the real
payload, so the example shadowed the actual object and BookEngine's
SpineAgent fell back to a single Overview chapter. Scan every top-level
candidate and keep the longest decode instead.
Reasoning models (Qwen, DeepSeek, etc.) emit chain-of-thought inside
<think>...</think> blocks before the JSON payload. parse_json_response()
did not account for this: a brace inside the reasoning was picked up by
the raw_decode scan and returned instead of the real object, silently
yielding wrong or empty data (e.g. empty BookEngine proposal fields).
Strip <think> blocks only on the direct-parse failure path, so a valid
JSON payload whose string values legitimately contain the substring
'<think>' is preserved exactly. Also drop an unclosed leading <think>
prelude up to the first JSON opener, and return the fallback when the
response is reasoning-only with no payload.
Fixes#673
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
json-repair wrapped a valid object plus trailing brace-prose into an array,
corrupting book/question callers that expect a single object. Prefer
raw_decode of the first JSON value before repair.
Security: lock down the TutorBot tool sandbox (shell exec is opt-in, all
filesystem/shell access confined to the bot workspace) and isolate per-user
resources, closing #518, #517, #516, #515, #514 and #506 (first hardened in
#507).
Bug fixes: chat input disabled after the first turn (#520), KB embedding
failure on long documents (#521 / #509), profile creation under Docker
(#512 / #513), Qwen reasoning models failing native tool calling (#527 / #528),
the GPT-5 init-wizard token parameter (#508), and oversized session-event
truncation (#524).
Features: HTTP/SSE API for multi-turn chat with a specific TutorBot (#511),
multimodal image fallback for vision-capable providers without a capability
entry, safe ZIP knowledge upload, and a /settings/network page with model
fetching (community PRs #522 and #523 reimplemented locally).
Also bumps __version__ to 1.4.1, adds the v1.4.1 release notes, updates the
README Releases section, and ships the Astro + Starlight docs site under site/.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>