Skip to content

fix(platform): lists and transfers tell the truth about their bounds - #3166

Merged
larryro merged 7 commits into
mainfrom
fix/pagination-caps
Sep 3, 2026
Merged

larryro merged 7 commits into
mainfrom
fix/pagination-caps

Conversation

@larryro

@larryro larryro commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

The invariant

A bounded list or transfer tells the truth. Either it returns everything (pages to the end), or it says precisely that it was cut and how to continue — and it never trusts an unbounded input into memory. Every finding below is a lane that silently dropped data a user or agent had no way to notice was missing.

Per finding

1. Task comments silently capped at the OLDEST 200 — fix(platform): page task discussions from the newest comment

  • Was: listTaskComments → listThreadMessages with no options → the store's default LIMIT 200 … ORDER BY "order" ASC. The first 200 comments won forever; a 201st comment saved (POST 200) and rendered nowhere — UI feed, REST GET /tasks/{id}/comments, and the task.list_comments native all shared it.
  • Fix: the threads store grows a newest-first keyset read (listThreadMessagesTail, (order, step_order) cursor, limit+1 for hasMore); listTaskComments pages from the tail (limit default 200, max 500, before cursor). App door answers the {page, isDone, continueCursor} envelope the infinite-query lane already walks (newest first; bad cursor → 400); REST answers {comments, isDone, continueCursor} with limit/cursor (the GET also survives into openapi.json now — the POST block used to reassign the path and clobber it); the native returns truncated (declared mock updated). The task panel walks older pages with Show earlier comments (en/de/fr) and shows the task-wide count.
  • Tests: app/lib/backend/tasks.test.ts (cursor walk), task-comments.test.tsx (earlier-pages control at the oldest end, count), natives wiring test; itest checkTaskDiscussionPaging — 522 comments paged 200/200/122 newest-first, REST walk covers every id exactly once, native truncated: true.

2. document.list reported truncated:false over a 200 cap and dead-ended on folderPath/recursive — fix(platform): document.list tells the truth about its folder listing

  • Was: pgDocumentStore.listFolder hardcoded truncated: false, returned null ("the folder does not exist") for every folderPath, ignored recursive.
  • Fix: folderPath resolves through the folders domain's existing findHubFolderByPath; recursive walks subfolders breadth-first (collectWorkflowFolderFiles, names prefixed with their path, MAX_FOLDER_DEPTH-bounded); truncated is real — judged on stored rows before the team filter (listFolderDocumentsBounded), so a hidden row never masks a cut, and conservative when the cap is reached with folders still unread.
  • Folded medium (webdav, low): webdav.list dropped the tree handler's truncated bit — it now rides the WebdavStore.list contract and the native output (declared mock updated).
  • Tests: document-listing.test.ts (8 cases: exact cap, over cap, recursive prefixes, depth bound, root), webdav.test.ts truncated pass-through; itest checkWorkflowDocumentListing — 201 files → 200 + truncated, folderPath resolves, recursive prefixes, missing path → coded refusal.

3. OneDrive/SharePoint pickers and one-time folder imports silently truncated — fix(platform): page OneDrive and SharePoint listings to the end

  • Was: listFiles took Graph's first /children page ($top=100, search 50), listSharePointFiles its first 200; neither followed @odata.nextLink. The import dialog expands selected folders through them, so a 300-file folder imported 100 and toasted success.
  • Fix: a shared Graph collection pager (graph_collection.ts) follows @odata.nextLink to the end, bounded at 10k items (500 for search) with truncated when the bound cut it. Both listers use it; the picker shows a notice under the table when the shown folder holds more; folder expansion refuses a truncated or failed listing instead of importing part of a folder as a success (en/de/fr strings; Documents docs page notes it).
  • Tests: list_files.test.ts (multi-page whole, bound → truncated, overflow page trimmed, error contract, SharePoint folders-first), dialog tests (truncated folder → no import + destructive toast, failed listing → stop, notice shown/absent); itest — a 250-child folder browses whole across three fake Graph pages.

4. Sync/import downloads buffered the whole vendor file before the size cap — fix(platform): refuse oversized downloads and uploads before buffering

  • Was: fetchVendorContentToStorage did await download.arrayBuffer() with no Content-Length check and no timeout; putOrgBlobBytes enforced 512 MB only after the bytes were in the heap.
  • Fix: readBodyBounded (files domain) refuses the declared Content-Length before reading a byte (413 FILE_SIZE_INVALID) and aborts a chunked body at the first chunk past the cap; the vendor fetch carries a 15-minute AbortSignal.timeout. Folded medium: POST /api/app/files/upload buffered the request body the same way — same guard.
  • Tests: bounded-body.test.ts (declared-length refusal reads 0 chunks, over-cap stream aborts at chunk 3 of 10, exact cap accepted); itest — an import of a file declaring 600 MB fails its own row with the limit message and the fake body sees 0 pulls.

Already fixed / refuted in the base

  • REST cursor paging on contacts/products (rest-v1 work) — already in the base; not touched.

Verification (observed)

  • Platform tsc --noEmit: clean. Platform oxlint --type-aware (whole workspace): clean.
  • Server vitest: branch 401 files / 5289 tests pass vs base 398 / 5264; the same 3 app/routes/** files fail on both (Vite "Denied ID" for @fontsource through the worktree's symlinked node_modules — environmental).
  • UI vitest: task-comments.test.tsx 12/12, onedrive-import-dialog.test.tsx 6/6. i18n parity: 48/48. Docs workspace tests 30 files / 194 pass; @tale/ui tests 123/124 files with the same single environmental @fontsource "Denied ID" failure on base and branch. Red-on-base for the colocated tests (run against the untouched base copy): list_files.test.ts fails at file level, the adapter cursor test fails, 10 of the two UI files' tests fail.
  • Integration check (throwaway tale-db + MinIO, Node runtime): base 344/344; branch 347/347 (exit 0; fresh tale-db + MinIO per run). Red-on-base (base code + this branch's integration-check.ts): 343/347 — exactly the four new checks fail on base (old {messages} envelope and cursor-less window with badCursor=200; document.list answers truncated=false over 201 files and throws on folderPath; OneDrive browses 100 of 250 children; the 600 MB download is read whole — 65 chunks — and imported as a success), every pre-existing check passes.

Cross-class discoveries

  • scripts/generate-openapi.ts reassigned paths['/api/v1/tasks/{id}/comments'] for the POST and dropped the GET from the published spec (fixed here since the GET's shape changed).
  • The workflow "system" auth (userId: 'system', no team memberships) hides team-scoped hub documents/folders from document.list — pre-existing scoping, unchanged; truncated is judged before that filter so it stays honest.
  • WebDAV handlers keep a private exact-name findFolderByPath next to folders/paths.ts's validating one — left alone (semantics differ for legacy names).

The discussion read was a fixed oldest-200 window on the message store, so
a busy task's 201st comment saved (POST 200) and rendered nowhere — the UI
feed, REST GET /tasks/{id}/comments, and the task.list_comments native all
shared it. The feed now reads from the thread's tail: a newest-first keyset
page in the threads store (`listThreadMessagesTail`), `numItems`/`cursor`
on the app door with the `{page, isDone, continueCursor}` envelope the
infinite-query lane walks, `limit`/`cursor` + `isDone`/`continueCursor` on
REST (the GET now also survives into the published spec), `truncated` on
the native and its declared mock, and a "show earlier comments" walk in the
task panel. Integration check: 522 comments paged 200/200/122 on every door.
pgDocumentStore.listFolder answered `truncated: false` unconditionally over
a 200-row cap, "the folder does not exist" for every folderPath, and ignored
recursive — an automation iterating a 201-file folder skipped one while
being told the listing was whole. The store now resolves folderPath through
the folders domain's hub path walk, walks subfolders breadth-first when
asked (names prefixed with their path, depth-bounded), and reports the real
truncation bit, judged on the stored rows before the access filter so a
hidden row never masks a cut. Same mechanism on the WebDAV connector
native: `webdav.list` now carries the tree handler's `truncated` bit
through instead of dropping it. Integration check: 201 files → 200 +
truncated, folderPath resolves, recursive prefixes names, missing → error.
The sync/import download lane did `await download.arrayBuffer()` with no
Content-Length check and no timeout, and the direct upload POST buffered
its whole body the same way; the 512 MB ceiling in `putOrgBlobBytes` only
fired AFTER the bytes were in the heap, so one multi-GB vendor file could
OOM the shared worker and a stalled Graph download parked a sync forever.
Both lanes now read through `readBodyBounded`: the declared length is
refused before a byte is read (413 FILE_SIZE_INVALID), the received bytes
abort at the first chunk past the cap, and the vendor fetch carries a
15-minute AbortSignal timeout. The import pipeline's stale "streaming
Convex action" comment now describes the pg lane.
`listFiles` took Graph's first `/children` page (`$top=100`, search 50) and
`listSharePointFiles` its first 200, neither following `@odata.nextLink` —
a 300-file folder showed 100 in the picker, and because the import dialog
expands selected folders through these listers, a one-time folder import
quietly imported 100 and reported success (SharePoint never syncs, so
nothing healed it later). Both listers now walk every page through a
shared Graph collection pager up to a 10k-item bound (500 for search) and
answer `truncated` when the bound cut the walk. The picker says so under
the table, and folder expansion refuses a truncated or failed listing
instead of importing part of a folder as a success. Integration check:
a 250-child folder browses whole across three fake Graph pages, and the
oversized-download refusal lands unread on the same fake drive.
…actly

The connector door throws its coded refusals; the new listing check now records a thrown refusal (or an off-shape answer) as its own failure instead of aborting the probe, and asserts the INPUT_INVALID for a path that names no folder. The oversized-download fake streams with highWaterMark 0, so its pull count means "someone read the body" rather than the stream's construction-time pre-fill.
The Microsoft 365 import now refuses a folder it cannot list whole instead of importing part of it; the Documents page says so in every locale.
@larryro
larryro marked this pull request as ready for review September 3, 2026 07:46
# Conflicts:
#	services/platform/backend/integration-check.ts
#	services/platform/public/openapi.json
#	services/platform/scripts/generate-openapi.ts
@larryro
larryro merged commit d5024e6 into main Sep 3, 2026
48 checks passed
@larryro
larryro deleted the fix/pagination-caps branch September 3, 2026 08:08
larryro added a commit that referenced this pull request Sep 6, 2026
The Google Drive browse/search lister followed `nextPageToken` with no
bound — pageSize 100, `includeItemsFromAllDrives`, and for a search
`name contains '<q>'` across the tenant — so a short search term over a
large Workspace tenant with shared drives ran hundreds of sequential Drive
calls and grew an unbounded array inside one HTTP request after a single
rate-limit charge. The OneDrive twin got its bound and `truncated` flag in
#3166; the Drive twin was missed, and its picker consumed no such flag.

`listFiles` now stops at 10,000 items for a folder browse and 500 for a
search (plus a page-walk fail-safe) and reports `truncated`; the contract,
the hook and the Google Drive picker carry it: the picker names the cut
under the table (the shared copy the OneDrive picker uses, like the
table's own empty state), and a folder import refuses a folder it cannot
list whole instead of importing the rest and calling that a success — a
sub-listing failure now fails the import the way the OneDrive picker does,
rather than toasting and importing around the hole. Docs name the refusal
for Google Drive as they already did for Microsoft 365.

Finding: cloud-drives-5.
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.

1 participant