Repository navigation
Description
Problem
Closing a tab takes the reader's place in the document with it. closeDocuments drops the positions entries of every tab it closes (ui-packages/web/src/features/workspace/workspace-store.ts:89-101), and storage holds the same rule at both ends: a position is restored and persisted only while its id sits in tabs (ui-packages/web/src/features/workspace/workspace-storage.ts:18-25,47,55-61 — "A position is kept only while its document is open, so closed and removed files age out"). When the document is opened again, defaultPosition comes from that map (ui-packages/web/src/features/reader/document-tabs.tsx:300); with the entry gone, a PDF opens at page 1 (ui-packages/web/src/features/reader/pdf-reader.tsx:22), text at its top, a workbook at its first sheet (ui-packages/web/src/features/reader/xlsx-reader/index.tsx:44).
So every way a tab closes — the X on the tab (ui-packages/web/src/features/reader/document-tab-bar/index.tsx:116-123), or the context menu's Close, Close others, Close to the right, Close all (…/document-tab-bar/index.tsx:135-160) — silently discards where the reader stopped. A reader who clears the bar at the end of an evening comes back tomorrow to a 200-page paper at page 1. #40 promised "reopen documents at their page or scroll position"; as delivered, the promise lasts exactly as long as the tab does, and closing tabs is a normal act of tidying the app itself invites.
Proposal
- Keep a position when its tab closes:
closeDocumentsstops filteringpositions(it still drops source drafts, which belong to the open editor). - Drop a position only when its file leaves the library — removal already routes through
closeDocuments(ui-packages/web/src/shell/workbench.tsx:200wiresonRemovedto it), so the "removed files age out" half of the rule survives; positions whose file is gone can be pruned when the library loads. - Stop filtering positions to open tabs in
workspace-storage.ts, and bound what is kept with a recency cap, so a long-lived browser does not accumulate places for documents it no longer opens.
Goal
After this, closing a tab — or all of them — costs the reader nothing they will notice: reopening the document later from Files or Recent lands on the page, block or sheet they left, and a place is retired only when its file leaves the library or ages past the cap.
Verification
grep -n "position" ui-packages/web/src/features/workspace/workspace-store.test.ts
pnpm --filter @gamma-reader/web test src/features/workspace
pnpm checkRefs
- ui-packages/web/src/features/workspace/workspace-store.ts:89-101 — closeDocuments drops positions with the tab
- ui-packages/web/src/features/workspace/workspace-storage.ts:18-25,55-61 — positions kept only while their tab is open, on read and write
- ui-packages/web/src/features/reader/document-tabs.tsx:300 — defaultPosition reads the positions map
- ui-packages/web/src/features/reader/pdf-reader.tsx:22, ui-packages/web/src/features/reader/xlsx-reader/index.tsx:44 — no position means page 1 / first sheet
- ui-packages/web/src/features/reader/document-tab-bar/index.tsx:116-123,135-160 — every close path, from the X to Close all
- Remember where the reader stopped — reopen documents at their page or scroll position #40 — the promise this carries past the tab's life; as implemented it covers tabs that stay open, across restarts
- Cap what open tabs hold in memory — every visited tab stays mounted today, and each open PDF keeps its loaded document until the tab closes #175 — the memory-bounds family; the recency cap keeps remembered places bounded
Activity
bencode commentedon Oct 26, 2026
Independent review — posted by the scheduled issue-reviewer loop, independent of the authoring session, against
main@e8c930f.Evidence audit: every citation confirmed on main.
workspace-store.ts:89-101—closeDocumentsfilterspositions(alongsidesourceDrafts, as the issue notes); ✅workspace-storage.ts:18-25,47,55-60—openPositionsfilters to open tabs at both read and write, rule comment verbatim; ✅document-tabs.tsx:300—defaultPositionfrom the positions map; ✅pdf-reader.tsx:22(? defaultPosition.page : 1) andxlsx-reader/index.tsx:44(? defaultPosition.sheet : 0); ✅ tab-bar X:116-123and Close/others/all:135-160; ✅workbench.tsx:200—onRemoved={workspace.closeDocuments}.Duplicate check: none — #40 (completed) is the reopen-at-position promise this carries past the tab's life, not an overlap; #192/#212 are different surfaces.
Refs: accurate — #40 COMPLETED, #175 OPEN and honestly cited for the recency cap.
Sensor + Verification block repaired (logged per policy): lint ✓, but the original block was suite-only and
verifypassed vacuously on main while the feature is demonstrably absent (positions filtered atworkspace-store.ts:91-93and in storage at both ends). First repair attempt used negated greps (! grep -q …), which the verify harness ignores — errexit exempts!-prefixed commands — so it stayed vacuous; replaced with a positive gate,grep -n "position" ui-packages/web/src/features/workspace/workspace-store.test.ts, red today (that test file has zero position coverage) and green exactly when the survival rule lands with its test. Re-linted ✓; verify now ✗ on main as it should.Verdict: valid, keep open. Two sharpenings:
onRemovedroutes throughcloseDocuments(workbench.tsx:200). OncecloseDocumentsstops filtering, removal loses its cleanup — the proposed prune-on-library-load must land in the same change, or removed files leak positions forever. Pin it with a test (remove file → position gone; close tab → position kept).:47) filters as well as the write (:60); removing only the write leaves a mid-session reload silently dropping closed-tab positions.bencode commentedon Nov 1, 2026
Re-audit — posted by the scheduled issue-reviewer loop, independent of the authoring session. Against
main@d05b6b6(15 commits since the last review ate8c930f; three touch the cited files:de9243bplugin wiring shiftedworkbench.tsx+3,4f2d801/7f7ac7alanded in the xlsx reader).Evidence audit: premises hold almost to the line.
workspace-store.ts:89-101→:89-102—closeDocumentsstill dropspositionswith the tab (filter now:98-100).workspace-storage.ts:18-25(openPositions), read filter:47, write filter:60with the rule comment at:55— both ends still filter to open tabs, verbatim.document-tabs.tsx:300,pdf-reader.tsx:22(? defaultPosition.page : 1),xlsx-reader/index.tsx:44(? defaultPosition.sheet : 0) — all exact; the xlsx anchor survived the chart-sheet and scroll-ref work untouched.:116-123exact; Close others / Close to the right / Close all at:145/:152/:159, inside the cited band.workbench.tsx:200→:203—onRemoved={workspace.closeDocuments}still the removal hand-off.Duplicate check: clean (open + closed); #40 remains the completed reopen-at-position promise this carries past the tab's life, not an overlap.
Sensor: lint ✓; verify ✗ as it should (
grep position workspace-store.test.tsred — the survival rule has no test coverage yet).Verdict: valid, keep open. Both prior sharpenings stand unchanged: the prune-on-removal must land in the same change that stops the filtering (once
closeDocumentsstops dropping positions, removal loses its only cleanup), and both storage filters (read:47, write:60) must go together or a mid-session reload silently drops closed-tab places. One reinforcing observation, not new code: the xlsx reader already keeps its sheet scroll in a ref "across a hidden tab" (xlsx-reader/index.tsx:46-47, fromc4f831c— the #40 delivery) — the app already fights to preserve the reader's place through every hiding mechanism except close; that in-reader precedent is worth naming when this is implemented.bencode commentedon Nov 9, 2026
Re-audit (third pass) — posted by the scheduled issue-reviewer loop, independent of the authoring session. At
main@d05b6b6— HEAD unchanged since the 2026-11-01 re-audit (no commits since 2026-10-28); this pass re-opened the anchors with fresh eyes, refreshed the duplicate check against everything filed since, and re-ran the sensor.Evidence audit: every anchor re-confirmed.
workspace-store.ts:89-102—closeDocumentsstill dropspositionswith the tab (filter at:98-100).workspace-storage.ts:18-25—openPositionsstill applied at both ends: read:47, write:60, rule comment verbatim at:55.document-tabs.tsx:300,pdf-reader.tsx:22(? defaultPosition.page : 1),xlsx-reader/index.tsx:44(? defaultPosition.sheet : 0), tab-bar X:116-123, Close/others/right/all inside:135-160— all exact.workbench.tsx:200→ still:203(onRemoved={workspace.closeDocuments}) — the drift already logged on 11-01; narrative anchor only, unedited per policy.Duplicate check (refreshed): nothing filed since 11-01 overlaps — #294 (single-file project export), #295 (preset-key model list), #292 (cross-tab keys) are different families; #40 (completed) remains the reopen-at-position promise this carries past the tab's life, not an overlap.
Sensor: lint ✓; verify ✗ on unfixed main as it should —
grep -n "position" workspace-store.test.tsis red (zero position coverage), so the gate still discriminates.Verdict: valid, stays open. Both standing sharpenings remain the ones to hold an implementation to: removal's only position cleanup today is the
closeDocumentsfilter itself (workbench.tsx:203), so the prune-on-library-load must land in the same change that stops the filtering, and the two storage filters (read:47, write:60) must move together or a mid-session reload silently drops closed-tab places.