Skip to content

Keep recently left documents as they were; quiet data tables and scanned PDFs - #796

Merged
yaacovcorcos merged 9 commits into
mainfrom
scient/document-cache-20261108
Nov 10, 2026
Merged

yaacovcorcos merged 9 commits into
mainfrom
scient/document-cache-20261108

Conversation

@yaacovcorcos

@yaacovcorcos yaacovcorcos commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

What Changed

Documents you leave and come back to stay as you left them, and two reading annoyances are gone.

  • Kept documents (scient/documentCache): the opened document of the last two PDF, Word or PowerPoint files you left (pdf.js document; prepared Office file with its engine session) is kept, within 64 MB per GB of the computer's memory (128–512 MB). Coming back no longer downloads, parses or lays out the file again. A changed file opens afresh.
  • Kept views (scient/documentShelf): in the file panel the last left views also stay mounted but hidden, so coming back shows the same view at the same scroll with nothing drawn again. Hidden views and kept documents share one count and one budget, which counts a hidden view's canvases. A hidden PDF pauses pdf.js's rendering queue and drops pages out of view, and a hidden Office view draws only the pages in view. A PDF left while still opening is not kept. Past the limits, documents kept without a view go before hidden views, so a PDF reader reopening its document when its URL is renewed no longer pushes out a hidden view.
  • Data tables read their rows again only when the file's revision changed, instead of blanking after every agent command.
  • Scanned PDFs no longer show a standing warning bar over the page. Pressing Enter on a search that finds nothing shows a small card under the field saying the pages are images.
  • A reload counts only for the file shown when it was asked, so it does not remount another file's hidden view.

Why

The owner found that switching to another file and back reloaded PDFs and Office documents, a data table blanked after each agent command, and a scanned PDF carried a permanent banner while being read.

Measured in the dev app on macOS (Apple silicon):

Before After
Return to a 4.9 MB slide PDF ~1.8 s reload same view, first frame (~0.2 s, the app's normal switch time in a dev build)
Return to a Word report ~0.9 s same view, first frame
Hidden view's canvases — PDF 9→4 MB, Word 9→3 MB
Renderer memory, cycling 9 files twice — levels off at ~1.7–2.0 GB

Chat typing with hidden PDFs, measured with the #801 typing harness (production build, headless Chromium, 4× CPU throttle, 149 keys, synthetic 320-page PDFs):

Key-to-paint p50 / p90, keys over 100 ms No hidden view Two hidden PDFs
Composer, PDF shown 16 / 24 ms, 0 16 / 16 ms, 0
Composer, PDF scrolling 16 / 16 ms, 0 16 / 16 ms, 0
Ask in chat, PDF shown 16 / 16 ms, 0 16 / 16 ms, 0
Composer, Python file shown 16 / 16 ms, 0 16 / 16 ms, 0

Codex reviewed the design (3 findings) and the code (1 finding); all fixed, each with a test or a live check.

Documentation Impact

Documentation impact: Updated — docs/user/file-previews.md, UPSTREAM.md (Kept documents).

Platforms

Tested on macOS only. Windows and Linux are not run. Nothing here is platform specific: one budget follows navigator.deviceMemory.

Checklist

  • I explained what changed and why
  • Live-tested in the dev app (same DOM node and scroll on return; file replaced while hidden shows its new version; third left file evicts the first; scanned-PDF search card)

🤖 Generated with Claude Code

yaacovcorcos and others added 6 commits November 8, 2026 13:08
…stant

Switching to another file in the panel and back reopened a document
from scratch: a PDF was downloaded, parsed and painted again, and a
Word or PowerPoint file fetched, prepared, opened in a new engine and
laid out again. A 69-page PDF took about 1.8 s to show again, a Word
report about 0.9 s.

A small cache (scient/documentCache) now keeps the opened document of
the last two files a reader left: the pdf.js document, or the prepared
Office file with its engine session. The drawn pages are not kept. A
document has one reader at a time, a second reader opens its own copy,
and a file whose revision changed opens afresh; edited PDF copies and
files of unknown revision are never kept. Kept documents stay within
64 MB per GB of the computer's memory (128 to 512 MB), each kind
estimating what it holds from measurements in the desktop app: a Word
engine about 120 MB and 1.5 MB per laid-out page, PowerPoint 100 MB
and 32 times the file, a PDF 40 MB and 12 times the file.

Measured in the dev app (macOS, Apple silicon): switching back to the
PDF 1.8 s -> 0.4 s, to the Word report 0.9 s -> 0.4 s; memory stays
level while cycling through twelve files. A kept PDF shows at once
where it was left, its pages painting in place, rather than waiting for
every visible page as a first open does.

Word and PowerPoint open their engine in a session (T3's effect bodies,
moved), which the viewer subscribes to. The revision boundary now opens
the preview once the file's revision is known, and names it for the
cache.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The table read its rows again after every command, edit, tool call or
subagent anywhere in the thread: its revision was the workspace
mutation id, so the cells blanked and refilled while an agent worked.
It now checks the file's revision on each possible change and reads
the rows again only for a new one, or when the reader asks to reload.
An environment that reports no revision reads them on every change, as
before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The pages take their size from a width a resize observer reports after layout. On a loaded
CI runner the jump ran while every page was still zero high, so it stayed at the top.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…shows them as left

Switching to another file and back reopened a PDF or Office file's view: the document was kept,
but its pages were laid out and drawn again. The file panel's body is now ScientDocumentShelf,
which keeps the last left PDF, Word and PowerPoint views mounted but hidden while their reader
keeps them. Coming back shows the same view at the same place, nothing drawn again.

- documentCache: a reader hidden but kept parks its lease. Kept views and kept documents share
  the count (2) and the memory budget, which counts a hidden view's canvases; past them the
  view left longest ago is asked to go.
- A hidden PDF pauses pdf.js's rendering queue and drops pages out of view; a hidden Office view
  draws only the pages in view.
- A reload counts for the file shown when it was asked, so it does not remount another file's
  hidden view.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A PDF whose opening pages had no text showed a standing warning bar over the page, read or not.
The bar is gone; when Enter in the search field finds nothing in such a PDF, a small card under
the field says its pages are images, until the query changes or focus leaves.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:XXL labels Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ The exact PR base did not have a successful artifact. Baseline uses the latest successful main measurement shown below.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire 5.5 KiB 5.5 KiB 0 B (0.0%) 6.8 KiB ✅
Codex Thread snapshot wire 4.2 KiB 4.2 KiB 0 B (0.0%) 4.9 KiB ✅
Codex Live turn WebSocket wire 1.3 KiB 1.3 KiB 0 B (0.0%) 2.0 KiB ✅
Codex Live turn WebSocket decoded 22.3 KiB 22.3 KiB 0 B (0.0%) 24.4 KiB ✅
Codex Live turn messages 1 1 0 (0.0%) 8 ✅
Claude Total thread wire 5.5 KiB 5.5 KiB 0 B (0.0%) 6.8 KiB ✅
Claude Thread snapshot wire 4.2 KiB 4.2 KiB 0 B (0.0%) 4.9 KiB ✅
Claude Live turn WebSocket wire 1.3 KiB 1.3 KiB 0 B (0.0%) 2.0 KiB ✅
Claude Live turn WebSocket decoded 22.7 KiB 22.7 KiB 0 B (0.0%) 24.4 KiB ✅
Claude Live turn messages 1 1 0 (0.0%) 8 ✅

Baseline: 7d52c78 · PR result: a429053 · Source CI: success

Scenario and decoded snapshot size

10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Bounded compact HTTP snapshot with live cursor.

  • Codex decoded thread snapshot: 88.2 KiB
  • Claude decoded thread snapshot: 88.4 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

yaacovcorcos and others added 3 commits November 10, 2026 01:39
A PDF reader reopens its document once its signed URL is renewed, right
after first opening it. For that moment the document counted as left,
one more than the limit, so the hidden view left longest ago was dropped:
with three PDFs visited, only one stayed hidden instead of two.

A hidden view holds its document too, so past the limits documents kept
without a reader now go first, then the hidden view left longest ago.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@yaacovcorcos
yaacovcorcos added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit 8006e7b Nov 10, 2026
56 checks passed
@yaacovcorcos
yaacovcorcos deleted the scient/document-cache-20261108 branch November 10, 2026 01:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant