Skip to content

fix(platform): bound large contact list search and sorting - #4243

Merged
yannickmonney merged 2 commits into
mainfrom
fix/contacts-server-search
Oct 4, 2026
Merged

yannickmonney merged 2 commits into
mainfrom
fix/contacts-server-search

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

What changed

  • Contacts search uses debounced server pagination. serverSide: true explicitly excludes that controlled search from the client completeness drain, including during debounce. Managed filters, ordinary controlled client searches and client-side sorts retain Bug: List search/filter only scans already-loaded pages (client-side filter + infinite-scroll) — knowledge-entries, websites, conversations #2054's drain semantics.
  • Preserve name/email/external-id search; the server additionally matches phone through its existing predicate.
  • Replace raw-field locale pre-sorting with the complete TanStack column-aware row model. Contacts supplies its actual columns before windowing and uses sorting.manual so DataTable does not re-sort the slice. Accessor/custom/multi-sort behavior is preserved; other hosts keep their existing complete-sort behavior unless they opt into column-aware windowing.
  • Keep the 50-row sorted control visible; initially render only 20 rows from a 5,000-row sorted buffer. The window still expands on scrolling; this is not viewport virtualization.
  • Update the manual not-a-finding/PERF-B2 contracts and the shared table/list-page API guides.

Repair of independent findings

Original review: #4243 (comment)
Repair head: 851c8072e9963465b99d6dc77ce63193e349be2c

  • P1 regression: seven successive CanLoadMore completions cause zero unsolicited loadMore calls for a server search. A loopback HTTP regression counts one initial list request plus one debounced broad-query request, with zero cursor requests; it does not count distinct search strings. Contacts component coverage also uses CanLoadMore rather than masking the behavior with Exhausted.
  • P2 regression: 20 Zebra / 80 Álvaro contacts match the complete TanStack model's first 20 rows in both directions and after window expansion. Additional tests cover custom accessors/comparators, multiple keys, manual window rendering, and 50/5,000-row controls.

Verification

  • Node Vitest, scoped shared UI hook/table/pagination suites: 94 passed (3 files).
  • Node Vitest, scoped Contacts table/config suites: 11 passed (2 files), including jsdom axe coverage. The earlier Zod collection failure does not occur with this Node invocation.
  • Targeted type-aware Oxlint, code Oxfmt check, manual-doc lint, whitespace/conflict and pre-commit SAST gates: passed.
  • Scoped UI TypeScript check: passed.
  • Scoped platform TypeScript check: two unchanged prev parameters at Contacts table lines 63/77 lack inference when the isolated slice omits the full registered router. No whole-workspace typecheck was run; CI must verify the complete registered-router context.

Still unproven / handoff

  • Independent exact-head re-review and required CI remain outstanding. No merge, self-acceptance, task moves, CI rerun/cancel or infrastructure changes.
  • No real browser, real database, stack or performance harness was run. The TALE-361 recheck must verify the 1.5 s sort / 1.0 s search / DOM / long-task / scrolling budgets and 50-contact timing nonregression. Client sorting still drains the complete source; only its initial rendered window is bounded. Accumulated scrolling DOM and keyboard/screen-reader runtime behavior remain for that recheck.

Closes #4211

@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent review — REQUEST CHANGES

Task TALE-568; reviewer agent #9 b7c66e31, run d38e6c47-2f46-4b84-86d8-e99aa59a1d4a, distinct from implementation agent #12/run 207c05df. Reviewed exact head c3e6751f5a8b2e2c267238c2543eeb155f742111, confirmed at start and immediately before posting. Contract: TALE-551, #4211 and #2054.

Blocking findings

  1. [P1] Server search still eagerly drains all matching pages; the ≤5-list-request budget is not enforced. services/platform/app/features/contacts/components/contact-table.tsx:185 changes to a controlled search, but packages/ui/src/hooks/use-list-page.ts:290 still marks a nonempty controlled search.value as hasActiveClientFilter. The render-body drain at line 498 therefore calls loadMore whenever the source returns CanLoadMore, even with no scroll and no sort. The query adapter does send search, but broad queries still download the complete matching collection; during the debounce, the old unfiltered source can drain as well. Independent jsdom probe supplied successive 20-row completions from 20 through 140 rows, without scrolling, and observed 7 unsolicited loadMore calls. The actual cached pagination hook fetches each next page with initialNumItems (20), not the requested pageSize * 3. This is deterministic control-flow evidence, not a measured HTTP trace. The new Contacts test cannot detect it: its mock is always Exhausted, and it counts distinct search strings rather than list requests. Make server-controlled search explicitly opt out of the client completeness drain without breaking managed client search/filter or genuine client-sort completeness; test paginated CanLoadMore results and request counts, including a broad query and the debounce interval. The new not-a-finding/PERF-B2 statement that server search does not drain is currently false.

  2. [P2] Pre-window sorting and DataTable sorting disagree, so the large-list first window is not the global first page. packages/ui/src/hooks/use-list-page.ts:352 sorts raw fields with localeCompare(..., {numeric:true, sensitivity:'base'}) before slicing, but DataTable still runs TanStack's column sorting on that slice (packages/ui/src/components/data-table/data-table.tsx:487). For the real Name column, TanStack's default comparator differs from locale collation. Independent probe: 100 contacts, 20 Zebra N and 80 Álvaro N, ascending Name. The complete TanStack model starts with IDs 0–19 (Zebra); the new displayed model starts with IDs 20–39 (Álvaro). When later windows expand, rows move ahead of already displayed rows despite backend exhaustion. This changes today's sorting and violates global-order completeness. Use one column-aware ordering model before windowing (or explicit, consistently applied server ordering); do not assume arbitrary TanStack column IDs are raw row keys. Cover accented names and full-model versus window order; preserve accessor/custom/multi-sort behavior for this shared API.

Verified portions

  • Search wiring reaches the existing query key and HTTP search parameter. SQL adds external_id alongside name/email/phone while retaining org scoping, trash exclusion and keyset cursor predicates. No actual Postgres matching test was run.
  • Initially sorted 5,000-row buffer renders 20 rows and retains all 5,000 in processedData; the 50-contact sorted path still returns all 50. These are hook assertions, not browser performance measurements.
  • Knowledge entries, websites and products retain managed searches and no hook-level sorting input; their drain path remains intact by inspection. Conversations uses its separate list. No DataTable implementation file changes in this PR.
  • Both manual-reference entries are updated, but the search budget assertion needs the P1 repair.

Checks and limits

  • packages/ui: bunx vitest run --project unit --maxWorkers 1 src/hooks/use-list-page.test.ts src/components/data-table/data-table.test.tsx src/components/data-table/data-table-pagination.test.tsx — 86 passed (hook suite: 27). Storybook preset warnings did not prevent these tests from running.
  • Independent output-only jsdom acceptance probes — 2 passed / 2 failed, reproducing the two findings above.
  • Platform server: targeted Contacts service.test.ts, service.external-id.test.ts, routes.test.ts — 13 passed across the two service suites; route suite blocked before collection by z.enum undefined. An initial --project unit invocation matched no project; corrected to server.
  • Platform jsdom: Contacts table/config, products and websites — 4 suites blocked before collection by existing Zod resolution (z.number undefined). The requested knowledge-entries-table test path has no matching test file. These are not passing UI/accessibility evidence.
  • Targeted type-aware Oxlint on the six changed TS/TSX files — exit 0. Oxfmt — clean for the six matched code files (Markdown inputs are ignored by this configuration). git diff --check origin/main...HEAD — clean.
  • No standalone typecheck, browser, E2E, container, full suite, timing claim, keyboard/screen-reader runtime proof, or database integration run. The 50-contact timing nonregression and performance harness recheck remain for TALE-361/CI.
  • Passive CI readback: five Candidate-source checks pending. No CI rerun/cancel. Disk was 203 GiB free initially and 197 GiB on recheck, above the 20 GiB floor.

Disposition: return for author repair and renewed exact-head independent review. No merge, push or card move; preserve the existing protected review. Evidence/probes/logs are delivered under /agent/output/79aae226-fb4a-4902-809e-a2d9394c3159/.

@yannickmonney

Copy link
Copy Markdown
Contributor Author

TALE-589 — independent re-review: ACCEPT repaired code scope

PR: #4243

Exact reviewed head: 851c8072e9963465b99d6dc77ce63193e349be2c. Confirmed at start and again immediately before posting. Reviewer: Codex #9, agent b7c66e31-fc10-4e92-ae49-80c467ee7feb, independent of implementation agent Codex #12 (31b27429). This supersedes the two code findings in the round-1 request for changes at c3e6751f5. This is an independent review record, not a native task decision or permission to merge.

Verdict: ACCEPT the P1/P2 repairs; no remaining code finding in the requested re-review scope. This does not certify #4211's performance budget or whole-task completion. TALE-361 owns the production-browser performance recheck, and required CI is still outstanding.

Evidence

  • P1 resolved — actual request counts, not distinct query strings. The explicit controlled search.serverSide flag excludes server search from the completeness drain, including the pre-debounce interval. An independent jsdom probe composed the real Contacts query hook, cached pagination hook, adapter registry, HTTP client, useDebounce(250) and useListPage against a synthetic loopback HTTP cursor server. Broad query Zebra returned 20 rows and a remaining cursor. Observed: 1 initial list request + 1 debounced search request; 0 requests during debounce; 0 unsolicited cursor requests after the query settled and another 600 ms elapsed. Input events were separated by 100 ms, with a further 150 ms check after the last event. An explicit load-more then caused exactly 1 cursor request, and no follow-on drain. URLs retained orgId, search, limit and both cursor fields. This is real HTTP transport over synthetic responses, not a real backend/database or browser performance measurement. The candidate's separate regression also passes through seven successive CanLoadMore buffers without unsolicited loads.
  • P2 resolved — column-aware global order before windowing. The hook now uses TanStack's full sorted row model and actual columns rather than raw-key locale collation; Contacts sets sorting.manual so DataTable preserves that ordered window. The independent Zebra/Álvaro probe passes ascending → descending → ascending toggles and window expansions against the full TanStack model. In ascending order, the first 20 are the Zebra rows, not Álvaro. Candidate Contacts component coverage verifies the real Name header/column path. Custom accessor/comparator and multi-column tests pass; hosts not supplying sortingColumns keep their full-model path.
  • Small-list control and Bug: List search/filter only scans already-loaded pages (client-side filter + infinite-scroll) — knowledge-entries, websites, conversations #2054 preserved. Passing tests retain all 50 sorted rows, while a 5,000-row sorted buffer initially displays 20 and retains all 5,000 in processedData. Ordinary controlled client search and genuine client sorting still drain. An independent managed-filter probe combined a server search with a client-only category filter, observed the drain despite an initially empty result, and found row 99 after the later page arrived. Products and websites component suites also pass. The opt-out is not applied to their managed searches.
  • Interdiff is focused. The single repair commit touches 11 files: the two shared API options and ordering/drain logic, Contacts opt-ins, regression tests, and corrected manual/component/list-page documentation. No extra backend, infrastructure, secrets, locale or unrelated feature changes were added since c3e6751f5. The original SQL external-id addition retains org scoping, trash exclusion and cursor predicates by inspection; real Postgres matching remains unrun.
  • Documentation no longer overclaims global bounded DOM. It distinguishes Contacts' bounded initial sorted window from other hosts and explicitly says scrolling expands the window. Genuine client sorts still drain; sorting while searching can therefore still load the matching collection. The no-drain finding concerns server-search-only behavior, not active client-sort completeness.

Checks run at the exact head

All test invocations used Node via /opt/node/bin and one worker; no whole-platform suite was run.

  • Shared UI: node ../../node_modules/vitest/vitest.mjs run --project unit --maxWorkers 1 src/hooks/use-list-page.test.ts src/components/data-table/data-table.test.tsx src/components/data-table/data-table-pagination.test.tsx from packages/ui — 94 passed, 3 suites.
  • Platform UI: node ../../node_modules/vitest/vitest.mjs run --config vitest.ui.config.ts --maxWorkers 1 app/features/contacts/components/contact-table.test.tsx app/features/contacts/hooks/use-contacts-table-config.test.tsx app/features/products/components/products-table.test.tsx app/features/websites/components/websites-table.test.tsx — 23 passed, 4 suites, including jsdom accessibility assertions.
  • Platform server/adapter: node ../../node_modules/vitest/vitest.mjs run --project server --maxWorkers 1 backend/domains/contacts/service.test.ts backend/domains/contacts/service.external-id.test.ts backend/domains/contacts/routes.test.ts app/lib/backend/engagement.test.ts — 43 passed, 4 suites. The earlier Bun/Zod collection blockers did not recur under this Node invocation.
  • Independent output-only probes with vitest.review.config.ts — 3 passed, 1 suite. Total: 163 passed across 12 suites; repeated probe runs are not double-counted.
  • Targeted type-aware Oxlint on the 9 changed code/test files — exit 0. Oxfmt on those 9 files — clean. Scoped UI TSC including modified shared source/tests and their imports — exit 0 (the delivery-box config's initial missing type-root setup was corrected; no repository repair was needed).
  • Manual shape lint for services/platform — exit 0; targeted check-guide.ts on performance.md — exit 0. git diff --check origin/main...HEAD — clean. Working tree remains clean.

Unrun / remaining ownership

No browser run, visual-regression gate, production build, E2E, live backend/Postgres integration, keyboard/screen-reader runtime proof, standalone platform TSC, full suite or whole-workspace typecheck was run. jsdom and row-count tests do not establish timings, real DOM/heap behavior or accessibility in a browser. TALE-361 must recheck n≥5 timing, long-task, DOM, scrolling and 50-contact timing budgets under recorded contention; none is claimed here.

Passive CI readback at 07:49Z showed five queued Candidate-source checks. No CI rerun, cancellation or waiting. Required CI remains the merge owner's gate. Disk: 179 GiB free at start, 169 GiB on recheck, above the 20 GiB floor. No push, commit, merge, card move or reviewer/ownership change.

Evidence and runnable output-only probes: /agent/output/22f3c62e-cbb3-4a75-a4d0-11e56dc156e7/, including http-request-evidence.json, test logs, scoped configuration, repair interdiff and exact-head/passive-CI records. Next owners: TALE-359/manager for CI disposition and handoff; TALE-361 for performance acceptance.

@yannickmonney
yannickmonney merged commit beb772a into main Oct 4, 2026
@yannickmonney
yannickmonney deleted the fix/contacts-server-search branch October 4, 2026 14:13
yannickmonney added a commit that referenced this pull request Oct 4, 2026
…errors

Resolve contact-table.tsx and its test with #4243 (beb772a). The
failed-read region, its CatalogLoadError notice, retryRead and
onErrorFocusLost now wrap #4243's server-side search and manual
sorting. The paginated-hook mock filters by search as on main and
answers the recovery fields (error null, retry, isRetrying, unavailable,
errorCount). A search now reads a first page of its own from the
server, so the region comment no longer lists it among the reads that
leave rows on screen.
@yannickmonney

Copy link
Copy Markdown
Contributor Author

TALE-361 performance recheck of this merged PR against #4211's original workload (ABBA with base 1bfa28d5b, 50 and 5,000 synthetic contacts, local production builds): #4211 (comment)

  • Met: search at 5,000 (833 ms, 3 requests, against 12.8 s and 248), the first sorted page (208 ms), peak DOM ≤ 3,000 (2,258), and no regression for cold load or the 50-contact sort.
  • Missed:
    • the longest task during the sort's background drain (351–539 ms, budget ≤ 200 ms);
    • the scroll append at about 600 rows (1.36 s, unchanged);
    • the 50-contact search, which regressed from 92 ms to 527 ms because of the debounced server request.

Routing goes to the manager.

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: sorting a 5,000-contact list freezes the tab for minutes, and a search downloads every contact first

1 participant