Skip to content

fix(platform): defer chat upload success toast until indexing completes (#1457) - #2225

Merged
cursor[bot] merged 2 commits into
mainfrom
tale/xs7bf5vdnse67tcewchgn99rnn89eq28
Jul 3, 2026
Merged

cursor[bot] merged 2 commits into
mainfrom
tale/xs7bf5vdnse67tcewchgn99rnn89eq28

Conversation

@larryro

@larryro larryro commented Jun 27, 2026

Copy link
Copy Markdown
Contributor

Problem

When a PDF (or any RAG-indexable file) is attached in Chat, the composer flashed "uploaded successfully" the instant the bytes finished uploading — but indexing runs asynchronously afterwards and can still fail, leaving an "Index failed" badge on the same file. The toast contradicted the actual outcome.

Closes #1457

Fix

  • use-convex-file-upload.ts: for files the backend will RAG-index (mirrors shouldIndex in saveFileMetadata — non-audio, indexing not disabled, isRagIndexableFile), the immediate "uploaded successfully" toast is suppressed. Non-indexed files (images, audio/video, unsupported types, or conversations with indexing disabled) keep the instant toast since they have no further processing gate.
  • use-file-indexing-status.ts: now owns the terminal signal. When a tracked file transitions out of a pending state (queued/running) it fires the deferred success toast on completed, or an "Index failed" error toast on failed. Keying on the transition (not the absolute status) keeps a remount of an already-finished file silent and fires the success toast exactly once per upload.
  • Added i18n key chat.indexingFailedDescription (en/de/fr) for the failure toast body.

Tests

  • New regression suite use-convex-file-upload.indexing-toast.cap.test.ts: an indexable PDF saves metadata but shows no immediate success toast; with disableIndexing the immediate toast still fires.
  • vitest --project client (upload-hook suites) — 4 passed
  • vitest --project server lib/i18n/messages.test.ts (i18n parity/usage enforce) — 23 passed
  • oxlint --type-aware on changed files — 0 warnings / 0 errors
  • tsc --noEmit — clean

@larryro

larryro commented Jun 27, 2026

Copy link
Copy Markdown
Contributor Author

Desk Review — #2225 (fix for #1457)

Verdict: NOT READY — one blocking gap (test coverage of the core new behavior). The fix itself is correct and well-reasoned; CI is fully green; the only thing missing is a test that the deferred toast actually fires.

CI

All required checks pass (Unit, Type check, Lint, Format, Knip, Build platform, all 16 Playwright shards, etc.). No failing or pending required checks.

Tests I ran locally (bun + vitest)

  • vitest --run --project client app/features/chat/hooks/use-convex-file-upload app/features/chat/hooks/use-file-indexing-status → 2 files / 4 tests passed
  • vitest --run --project server lib/i18n/messages.test.ts → 23 passed (i18n parity/usage enforce mode clean; de-CH.json is a partial overlay that correctly falls back to de.json, so the omitted indexingFailedDescription key is not a defect)

What is correct (verified by code walk)

  • The frontend suppression gate willIndex in use-convex-file-upload.ts (!disableIndexing && !isAudioOrVideo(resolvedType) && isRagIndexableFile(...)) exactly mirrors the backend shouldIndex in convex/file_metadata/mutations.ts (!skipRagIndexing && !isAudio && isRagIndexableFile(...)), where backend isAudio is defined to include video/. So no file is ever suppressed-but-not-indexed or indexed-but-not-suppressed. (A double-toast for video was considered and ruled out — both sides treat audio+video identically.)
  • The deferred toast in use-file-indexing-status.ts keys on the transition out of queued/running, with prevStatusRef guarded by before === current, so it fires exactly once and stays silent on remount of an already-finished file. The [metadata, t] effect cannot double-fire because of that guard.
  • Fresh-upload happy path is sound: saveFileMetadata commits ragStatus:'queued' synchronously and is awaited before setAttachments, so the status query reliably observes queued first and the success toast fires on completed.
  • Stuck-in-queue is bounded: checkFileRagStatuses + expireStaleRagQueue (STALE_QUEUE_MS = 90_000) flips an orphaned queue entry to failed, which then fires the deferred "Index failed" toast — so the user is never left permanently without feedback.
  • Images get the deferred toast (they are RAG-indexable); audio/video keep the immediate toast (transcription path, ragStatus stays undefined) — no double toast there.

BLOCKING

  1. No test covers the deferred-toast firing path — the heart of this fix. The new suite use-convex-file-upload.indexing-toast.cap.test.ts only verifies the suppression side (indexable PDF shows no immediate toast; disableIndexing shows it). Nothing tests the new useEffect in app/features/chat/hooks/use-file-indexing-status.ts that actually fires the toast. A regression that breaks firing would revive the original "no/incorrect feedback" bug while every test stays green. Add a use-file-indexing-status test (mock useQuery/toast) asserting:
    • transition queued/running → completed fires the success toast (fileUploaded / uploadedSuccessfully) exactly once;
    • transition queued/running → failed fires the destructive indexingFailed / indexingFailedDescription toast (the error branch, currently fully untested);
    • first observation of an already-completed file (remount) fires no toast.

Non-blocking (no action required, noted for awareness)

  • Extremely narrow race: if RAG completed in the few ms between the mutation commit and the query's first snapshot, the first observed status could be terminal and the toast would be skipped. Not reproducible in practice (real indexing is network-bound) and self-heals on the next upload; not worth code changes.

NOT READY — CHANGES REQUIRED: add the test coverage in (1) above for the deferred success and failure toast transitions in use-file-indexing-status.ts.

@larryro

larryro commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

Desk Review — PR #2225 (fixes #1457)

Verdict: NOT READY — CHANGES REQUIRED (single blocker: CI is red — see below). The code change itself meets the review bar; the gate is the failing CI check, which must go green before merge.

What I verified

  • Local tests (run once on this branch):
    • bunx vitest --run --project client on the three upload/indexing suites → 3 files, 7 tests passed.
    • bunx vitest --run --project server lib/i18n/messages.test.ts (i18n parity/usage) → 23 passed.
  • Correctness — frontend/backend mirror is faithful. willIndex (use-convex-file-upload.ts:364-370) is computed from the exact same fileName + contentType (resolvedType || 'application/octet-stream') + disableIndexing that are sent to saveFileMetadata, and the backend shouldIndex (convex/file_metadata/mutations.ts:96-99) uses the same shared isRagIndexableFile + equivalent audio guard. So the suppress-toast decision can't diverge from the backend's queue decision → no "no toast ever" / "double toast".
  • "Toast lost if you send before indexing finishes" — refuted. Send is blocked while isIndexing is true (chat-input.tsx:466 & :1122, use-assistant-chat.ts:194); isIndexing is true while any file is queued/running. The metadata update that flips a file to a terminal state both fires the deferred toast and unblocks send, so the toast always fires before a send is possible.
  • Non-indexed paths unchanged: images, audio/video, and disableIndexing (external-agent) threads keep the immediate toast (images also filtered out of the status query). Tested.
  • i18n: new chat.indexingFailedDescription present and translated in en/de/fr; indexingFailed title key already existed.
  • Genuinely fixes Bug: PDF upload shows “uploaded successfully” but indexing fails (“Index failed”) #1457: indexable PDFs no longer flash a false "uploaded successfully"; success fires on completed, destructive "Index failed" on failed.

BLOCKING

  1. CI is red. Playwright (platform 2/16) = fail (45 pass / 5 expected fork-PR skips / 0 pending). Root cause from the job log is an infrastructure flake — the Convex local backend failed to boot ("Convex preflight (npx convex dev --once) failed … stale backend is holding port 3210"); the E2E web server never started, so the shard's tests never ran. This is not a defect in this change, but merge is gated on green CI: re-run the failed Playwright (platform 2/16) shard and confirm it passes.

Non-blocking (optional polish — not required for merge)

  • Test coverage could add: the non-indexable-image branch firing the immediate toast (currently only the disableIndexing operand of willIndex is asserted), a mixed multi-file batch, and a completed→queued→completed re-upload re-fire.
  • Pre-existing (not introduced here): the polling effect's .catch(() => {}) (use-file-indexing-status.ts:126,130) is an empty catch, which CLAUDE.md discourages — consider logging.
  • Minor DRY: resolvedType || 'application/octet-stream' now appears 3× in the upload hook; a local const would tidy it.

Once Playwright (platform 2/16) is re-run green, this is ready to merge.

@larryro

larryro commented Jun 28, 2026

Copy link
Copy Markdown
Contributor Author

Desk Review — PR #2225 (fixes #1457)

Verdict: READY TO MERGE.

Reviewed the whole implementation (not just the diff) across correctness, robustness, elegance, tests, and boundaries, in two rounds (breadth fan-out + independent confirmation).

CI & tests

  • CI: green. gh pr checks shows every check pass (Type check, Lint, Unit, Build platform, UI, Browser, Storybook, all 16 Playwright shards, Smoke test, Scan, etc.). The only non-passing entries are conditional fork/container jobs reported skipping and Trivy neutral — none failed, none pending.
  • Tests (run locally on this branch, client project):
    • bunx vitest --run --project client app/features/chat/hooks/use-convex-file-upload.indexing-toast.cap.test.ts app/features/chat/hooks/use-file-indexing-status.toast.test.ts → 5 passed
    • Full chat-hooks suite … --project client app/features/chat/hooks → 327 passed (19 files)
    • i18n parity/usage … --project server lib/i18n/messages.test.ts → 23 passed

What's correct

  • willIndex exactly mirrors backend shouldIndex (use-convex-file-upload.ts:364 vs convex/file_metadata/mutations.ts:96): !disableIndexing/!skipRagIndexing, !isAudioOrVideo/!isAudio, and the same shared isRagIndexableFile(name, contentType). No drift → no file is suppressed-but-never-indexed, nor shown-immediately-but-actually-indexed.
  • Transition state-machine is sound (use-file-indexing-status.ts:71-97): success only on pending→completed, destructive error only on pending→failed, keyed on prevStatusRef so a remount observing an already-terminal file stays silent and each upload toasts exactly once. The before === current guard makes effect re-runs idempotent.
  • Re-upload retry works: saveFileMetadata resets failed→queued (needsRagRetry); failed→queued does not toast (wasPending false), then queued→completed fires success. No stale-terminal suppression.
  • Audio path is unaffected: post-transcription RAG uses the separate transcriptRagStatus field, so audio (which keeps ragStatus undefined and gets the immediate toast) is not double-toasted.
  • Security/boundaries: filename flows through t() into the toast description, rendered as a React text node (no dangerouslySetInnerHTML) — no injection.
  • i18n key chat.indexingFailedDescription added in en/de/fr with genuine (non-placeholder) translations.

Non-blocking observations (do not gate merge)

  1. Deferred toast is tied to the composer lifecycle. If the user sends the message or removes the attachment before indexing reaches a terminal state, no success/failure toast fires. This does not re-introduce Bug: PDF upload shows “uploaded successfully” but indexing fails (“Index failed”) #1457 (no false "uploaded successfully" is shown), and the in-composer indexing badge still reflects status while the attachment is present — acceptable.
  2. Duplicate-toast across the two mount sites (chat-interface.tsx and use-assistant-chat.ts) is not a real risk: each calls useConvexFileUpload independently so they never share a storageId, and TOAST_LIMIT = 1 collapses any concurrent toasts to one.
  3. Test gaps (behavior is correct, just untested): the re-upload failed→queued→completed re-fire and the immediate-toast path for image/audio/video files have no dedicated test. Worth adding later; not blocking.

READY TO MERGE.

@cursor
cursor Bot force-pushed the tale/xs7bf5vdnse67tcewchgn99rnn89eq28 branch from 681d40f to 7645b19 Compare July 3, 2026 21:29
@cursor
cursor Bot merged commit af1a0d7 into main Jul 3, 2026
44 of 47 checks passed
@cursor
cursor Bot deleted the tale/xs7bf5vdnse67tcewchgn99rnn89eq28 branch July 3, 2026 21:46
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: PDF upload shows “uploaded successfully” but indexing fails (“Index failed”)

1 participant