Skip to content

fix(ui-web): settle the desk's seen record past its cap - #1346

Open
LivXue wants to merge 1 commit into
mainfrom
fix/desk_seen_cap
Open

LivXue wants to merge 1 commit into
mainfrom
fix/desk_seen_cap

Conversation

@LivXue

@LivXue LivXue commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Summary

Clicking the diff tab of the desk palette froze the web UI in a session with a large diff. The cause is a mark that never settled: DeskPalette calls desk.seeTab(state.tab) from an effect with no dependency list, so it runs after every render, and seeTab publishes a store write whenever seen.mark reports news. mark stores at most CAP (300) ids per tab, but unseen and seeTab compared it against the whole tab. Past 300 ids the write dropped ids that were still in the list, so the next call read them as new again: mark returned true forever, set({}) re-rendered the palette inside flushSync, and the effect marked again. A session with 25 delegated tasks and 907 changed-file rows reproduced it as soon as the diff tab was clicked.

The fix gives the count and the mark one bounded source of truth. seen.tracked(ids) is the first CAP ids of a tab's list, the end its newest items sit on; unseen counts only that slice and seeTab marks only that slice, so a badge never reports ids the record cannot retire. mark now keeps the caller's order instead of appending, so marking the slice writes exactly that slice back and a second call of the same list changes nothing. A single item opened from outside the slice is left alone rather than evicting one inside it.

mark also keeps the marked value in memory until the next reload. A storage write refused in private mode, or by quota, previously read back the old record, which made every mark report news again even for a one-item tab; the in-memory copy keeps the answer independent of a successful write. Storage remains the across-reload record.

Type

  • Fix
  • Feature
  • Docs
  • CI / tooling
  • Refactor
  • Other

Verification

  • Relevant tests pass locally

  • Relevant lint / type checks pass locally

  • User-facing docs or screenshots are updated when needed (not needed: the freeze is gone and no other visible behavior is intended)

  • vitest run src/features/desk -> 9 files, 287 passed (+5 in the new seen.test.ts, +2 in store.test.ts)

  • vitest run (full ui-web) at the fix head -> 314 files, 5460 passed

  • vitest run (full ui-web) at origin/main (a6399354) on the same machine -> 313 files, 5453 passed; the delta is exactly the 7 new tests

  • tsc --noEmit -p tsconfig.json -> exit 0; --listFiles names the changed files inside this worktree

  • eslint src/features/desk/seen.ts src/features/desk/store.ts src/features/desk/seen.test.ts src/features/desk/store.test.ts -> exit 0

  • scripts/check_commit_messages.py origin/main..HEAD -> exit 0; the commit message is pure ASCII

  • scripts/check_source_language.py origin/main..HEAD -> exit 0

  • Mutation checks, each reverted separately: the old append rule -> the two cap tests fail; counting and marking the whole tab -> the settle test and the past-slice test fail; the past-slice guard in readItem -> its test fails; the in-memory copy -> the storage-refusal test fails

  • Served page rebuilt from this branch (python ui-web/build.py) and driven in headless Chromium against a session with 907 changed-file rows: after opening the session and the desk, clicking Deliverables then Diff left the diff tab current with 907 rows, a 25 ms main-thread interval kept ticking (27 -> 88 ticks across the sequence), and the console stayed clean

  • Control on the same page and session with the pre-fix build: clicking Diff never returned, and the run ended at the 6 s click timeout -- the freeze the report described

  • One full-suite run on this machine produced collection failures in six unrelated files under load; those files pass serially (244 passed) and the next full run at the same head is green, which matches this box's known ui-web load sensitivity. The origin/main control and the final head run were clean.

Risk

  • Security impact considered: no new input, no credential, and the change only decides which ids count as read.
  • Backward compatibility considered: the stored slot keeps its shape and version, so a record written by the old code reads back unchanged. A tab with more than CAP items now reports at most CAP unseen ids, and ids beyond that slice are not counted; this is the stated limit of the bounded record. An item opened from outside the slice is not recorded as read; it is not counted either, so the badge is unchanged.
  • Rollback path is clear for risky changes: revert the commit on this branch.

Related Issues

None.

The palette marks the tab it is drawing after every render, so `seen.mark`
has to settle. Past the record's 300-id cap it did not: the write kept the
newest 300 while the caller handed over the whole tab, so the ids the write
dropped read back as new on the next call. `set({})` then re-rendered the
palette inside `flushSync`, which marked again, forever -- a session with
about 900 changed files froze the web UI the moment the diff tab was clicked.

Count and mark now share one tracked slice -- `seen.tracked`, the first cap
of the tab's list -- so a badge only reports ids the record can retire.
`mark` keeps the caller's order, so marking that slice writes it back
unchanged and a second call answers false; a single item read from outside
the slice is left alone instead of evicting one inside it. The record also
keeps the marked value in memory until the next reload, so a storage write
refused in private mode cannot make the next read report the same ids again.
@LivXue
LivXue requested review from 0xKT and gloryfromca November 17, 2026 16:21

@gloryfromca gloryfromca left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blockers; suggestions only, and they are marked inline.

The cap fix now settles repeated marks, keeps badge counting bounded to what can be retired, and preserves progress when session storage rejects a write. I found one narrow over-cap follow-up in the deliverables ordering and marked it inline; it does not outweigh the freeze this change removes.

Covered: AGENTS.md/CLAUDE.md and Web UI context rules; the full diff; palette, desk, workspace, deliveries, tasks, persistence, and session callers; relevant history and blame; backward compatibility and storage-failure behavior; test changes for weakening; and the Web UI store/domain architecture.

Verification: npm test passed 168 files / 2,848 tests; the focused desk run passed 87 tests; npm run type-check passed. The full run emitted happy-dom abort/network teardown diagnostics but exited 0 with no failed tests.

Comment thread ui-web/src/features/desk/seen.ts Resolved
@LivXue

LivXue commented Nov 17, 2026

Copy link
Copy Markdown
Member Author

Windows compatibility review — 76c59bfe93

Reviewed at head 76c59bfe93ae494ac3e89374295096011ff26cb5 (base a639935478). Scope: the PR's own diff (ui-web/src/features/desk/seen.ts, ui-web/src/features/desk/store.ts, and their two test files), read against the storage slot (KEPT) and the callers of seen.mark / seen.unseen.

No Windows compatibility issue found.

The change bounds the desk's seen record to the slice it can speak for (tracked()), makes mark order-stable so a caller marking on every render settles, and adds an in-memory marked cache so a refused localStorage write does not make ids look new forever. It is browser-side state over string ids: no filesystem, subprocess, path comparison, encoding or platform branch. The desk ids for the diff tab are paths, but only ever compared as opaque strings with Set/includes, never split, joined or stat'ed — so drive letters, separators and case are the server's business here, not this module's. CAP is now exported and referenced through the module namespace at both call sites, which typechecks.

Verification (native Windows host — the whole gate chain for this PR runs here):

  • node node_modules/vitest/vitest.mjs run src/features/desk/seen.test.ts src/features/desk/store.test.ts --no-file-parallelism → 2 files, 87 tests passed
  • node node_modules/vitest/vitest.mjs run scripts/gates --no-file-parallelism → 73 files, 350 tests passed
  • node node_modules/typescript/lib/tsc.js --noEmit -p tsconfig.json → clean

Coverage gaps: happy-dom only, so a real browser's localStorage quota behaviour (the case the marked cache exists for) is simulated by the tests rather than hit; no live gateway session produced the id lists.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants