Skip to content

fix: export-chat "Deselect all" no-op and dead download-disabled state (#2080) - #2140

Merged
cursor[bot] merged 1 commit into
mainfrom
tale/xs764ehrzrdnft95849dd2x4j1898pm3
Jul 3, 2026
Merged

cursor[bot] merged 1 commit into
mainfrom
tale/xs764ehrzrdnft95849dd2x4j1898pm3

Conversation

@larryro

@larryro larryro commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes #2080.

The export-chat dialog used an empty Set as a sentinel meaning "default = all selected". As a result:

  • Deselect all was a no-op — setSelectedIds(new Set()) instantly re-resolved to allIds on the next render.
  • Deselecting messages one-by-one never reached zero — removing the last id emptied the set, re-triggering the sentinel.
  • noneSelected was therefore always false, making the disabled={noneSelected} guards on both download buttons dead code.

Fix

Replaced the overloaded empty-set sentinel with an explicit discriminated selection model: selection is either the 'all' sentinel (default, selects every message including ones that load later) or an explicit Set<string>. An explicit empty set now genuinely means "nothing selected", so:

  • Deselect all sets selection = new Set() → counter reads 0 of N, toggle flips to Select all, both download buttons disable.
  • Deselecting the final message empties the set instead of re-selecting everything.

Tests

Added two regression tests in export-chat-dialog.test.tsx:

  • Clicking Deselect all → 0 of N, no checkboxes checked, both downloads disabled.
  • Deselecting messages one-by-one reaches zero (final message no longer re-selects all).

All 5 UI tests pass; tsc --noEmit and oxlint --type-aware are clean on the changed files.

@larryro

larryro commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

Desk Review — READY TO MERGE ✅

Reviewed the fix for #2080 on branch tale/xs764ehrzrdnft95849dd2x4j1898pm3 using a two-round, fan-out method (5 dimension reviewers + adversarial confirmation).

CI & tests

  • CI: all checks green (Type check, Lint, Format, Knip, UI, Unit, Storybook, Playwright ×16, builds, scans — every required check passes; only fork-only/optional jobs skipped).
  • Tests run locally: bunx vitest --run --config vitest.ui.config.ts app/features/chat/components/export-chat-dialog.test.tsx → 5 passed (5).
  • Regression genuineness confirmed: ran the two new tests against the pre-fix (origin/main) implementation — both fail ("2 of 2" instead of "0 of 2"), proving they pin the exact bug. They pass on the fix.

Assessment by dimension

  • Correctness: The selection: 'all' | Set<string> discriminated model cleanly separates "default-all (incl. later-loaded messages)" from "explicit empty = nothing". All branches traced — 'all' default, Deselect-all → empty Set, one-by-one to zero, individual toggle from 'all' vs explicit Set, stale-ID pruning, and messages.length === 0. Both reported sub-bugs are resolved: Deselect-all genuinely reaches 0 of N, and disabled={noneSelected} is now live, not dead.
  • Robustness: useMemo/useCallback dependency arrays are tightened correctly ([selection, allIds], [allSelected], [allIds]); functional state updaters avoid stale closures; no leaks introduced. Async message loading is handled — explicit selections persist and stale IDs are filtered.
  • Elegance: Minimal, focused change; old empty-set sentinel fully removed (no dead code); accurate explanatory comment; clear rename selectedIds → selection. oxlint + tsc clean on the changed file.
  • Tests: Two added regression tests cover both bug facets and correctly assert disabled download buttons. Untested branches (PDF download path, select-all-after-deselect, empty dialog) are low-risk nits given symmetric logic and the dual guard (disabled + if (selected.length === 0) return).
  • Boundaries: Export handlers are double-guarded against empty selection; getSelectedMessages filters strictly by effectiveSelected membership, so no stale/unselected message can be exported.

Adversarial pass

A skeptic agent tried 13 interaction sequences (deselect→toggle→select-all→deselect, async load races, stale-id size collisions, disabled-state inversions) and could not produce a wrong selection, counter, button state, or export.

Verdict: READY TO MERGE.

@cursor
cursor Bot force-pushed the tale/xs764ehrzrdnft95849dd2x4j1898pm3 branch from de3396c to 1aa7120 Compare July 3, 2026 20:42
@cursor
cursor Bot merged commit c15cae0 into main Jul 3, 2026
27 of 31 checks passed
@cursor
cursor Bot deleted the tale/xs764ehrzrdnft95849dd2x4j1898pm3 branch July 3, 2026 20:42
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.

Bug: Export-chat dialog "Deselect all" is a no-op (empty-set sentinel re-selects everything); download-disabled state is dead code

1 participant