Repository navigation
fix(platform): dedupe video links per chat, keep cues, explain refusals - #3884
Conversation
The in-thread dedup of a pasted video URL read the organization's newest job for the URL hash and only then checked its chat, uploader, bind state, status and age. Pasting the URL in chat A, then in chat B, then in A again found B's newer job, rejected it, and started a second job and a second extraction in A, spending one of the organization's three in-flight slots (#3704). Every eligibility rule is now part of the lookup, so LIMIT 1 picks the newest job this member may reuse in this chat. A job the chip list hides (trashed) is not reused either. service.dedup.test.ts evaluates the lookup's predicates over an in-memory table and fails on the old query (A/B/A, and an eligible job behind a newer failed one in the same chat); the real-Postgres arc through the Hono routes is the checkVideoLinkComposerChips lane.
rollingWindowDedup kept only the longest cue of every run of cues sharing a start time, whatever they said. A human caption track that times two speakers talking at once to the same start (Alice 1.0-4.0 "The shipment is ready.", Bob 1.0-9.0 "Hold the shipment until Monday.") lost Alice's line from the stored transcript and blob, which still completed under a captions_human header (#3705). A cue now collapses into an earlier cue of its window only when it is that line growing: the same speaker, and one text's words begin the other's, compared blind to case and punctuation and on whole words. The longer text is kept, as before, so auto-caption prefixes ("We", "We will", "We will ship Monday.") still collapse to one line; every other cue that shares the start stays, in order. The comparison looks back at most eight kept lines, which keeps a hostile track of 50,000 same-start cues linear; a line it misses is kept twice, never lost. captions_parser.test.ts and ingest_video_link.transcript.test.ts (the worker with yt-dlp replaced at its module boundary and a fixed VTT fixture) fail on the old dedup.
A refused Remove hid the chip, brought it back and said nothing: the hook restored it, logged and rethrew, and ChatSurface fired it with `void`, so the rejection went unhandled while the job stayed queued (#3720). The queued-send tray's Try again on a failed video dropped its refusal the same way, while the composer's Try again toasted. Remove now reports its own failure as the composer's retry always did: a destructive "Couldn't remove this video" toast, the chip back where it was, and a promise that never rejects. Both retries share one reporting helper (retryVideoLinkJob), so a refusal reads the same in the composer and in the tray. Every video-link toast reads the failure one way: the chip's own sentence for a video-link code, else the platform's failureDetail (the refusal's words, a lost connection, an ended session), else the caller's line, which for Remove says the video is still attached. There is no second state store: the optimistic hide stays the hook's hideJobIds. New EN/DE/FR keys chat.videoLink.toast.removeFailedTitle and removeFailedDescription, plus errors.threadNotFound, the one video-link refusal code that had no sentence. use-chat-video-links.test.tsx renders the real hook, chip and toaster over a fetch stub answering as the routes do, and deferred-send-tray.test.tsx covers the tray; both fail on the old hook, the first with unhandled rejections.
checkVideoLinkComposerChips runs the chip journeys of #3704 and #3720 through the native /api/app/video-links routes on real Postgres, in an organization of its own. A second paste in the same chat reuses its job and takes the new token; the URL in another chat starts that chat's own job; back in the first chat the paste answers the first job, with one unsent job and one chip there and two video.ingest jobs in all. With the membership disabled, cancel and retry answer 403 ORG_FORBIDDEN with a message and the job stays queued; a retry of a live job answers 409 notRetryable; once the membership is back the cancel of a job a worker was storing succeeds, and the finalizer that worker still held, plus a redelivered ingest job, write nothing. No job runs: a trigger that exists only for the lane holds every video.ingest it enqueues a day out, so nothing resolves, downloads or spawns. Before the dedup fix the A/B/A check fails with two unsent jobs and two chips in the first chat and three video.ingest jobs.
The chat attachments page, in EN, DE and FR, now says that pasting the same link again in a chat keeps its one attachment there even after it was pasted in another chat, that captions showing two people speaking at once keep both lines, and that a link Tale cannot remove comes back with a message saying why and stays attached. The troubleshooting table gains the row for a removed video link that comes back.
VID-F8 pastes a URL in chat A, in chat B and in A again and judges one chip in A; VID-B5 blocks the cancel (then the retry) request and judges the toast, the chip that comes back and a later removal that succeeds. Their pins name the mechanism and the tests, the automation register records what the new specs own (and corrects the VID-F2/VID-F3 row's files, which named Convex-era tests that no longer exist), and the suite total moves from 13 to 15 boxes.
Review of the caption dedup found two gaps in its growth check. A line in Japanese, Chinese or Thai grows by characters with no space between words (今日は, 今日はいい, 今日は、いい天気ですね。), so the whole-word prefix never matched and every step of the line stayed in the transcript, where the old longest-wins rule kept one. When the shorter line is in such a script the check now compares characters, spaces aside, so punctuation that appears as the line grows does not break it; two speakers of such a script who start together still both stay, and a symbol-only cue is not swallowed. The kept cue was also picked by raw text length, so "we -- will" beat "we will go" (both ten characters) and "go" was lost. The line with more compared characters now wins, the raw text only breaks a tie. The hostile window test allows five seconds: quadratic would take minutes.
Review of the Remove feedback found a dead end. A chip whose job is gone (the unbound-job sweep deletes old unsent jobs) answered every Remove with 404 notFound: the chip came back from the cached read, the toast said the link was not found, and a settled chip no longer polls, so it could never be removed. A Remove that meets notFound now counts as done: the chip stays hidden and the next read drops it. After any Remove or Try again, refused or not, the chips read again, so a refusal that met a job which moved on (a retry refused because the job is already processing again) shows its current state; before, only a success asked. The retry helper resolves nothing and never rejects.
Review of the Postgres lane found that its BEFORE INSERT trigger held every video.ingest job a day out, not only its own, and that its setup ran before the try whose finally cleans up. A killed run would have left the trigger holding the ingests of the next run's checkVideoLinks on a reused database, and a failed setup insert would have leaked the organization. The trigger now holds only jobs of this lane's organizations, and the setup runs inside the try. A rerun on real Postgres passes all six checks and leaves no trigger, function, row or pg-boss job behind. service.dedup.test.ts also pins the lookup's lifecycle rule: a trashed job is not reused, a job whose lifecycle was never stamped still is.
Review of the attachments page found two overclaims. A re-pasted link reuses the chat's attachment only in an existing chat, before sending, while it has not failed or been removed and was added less than a day earlier; the page said the chat always keeps its one attachment. And unlabeled caption lines that begin with one another still collapse, so the transcript keeps the words of both speakers rather than both lines. EN, DE and FR say so now, and the French wording reads more naturally (and uses the UI's "Reconnecte-toi" sense for signing in again).
Review of the new boxes: pastes on the new-chat page are never deduplicated, so VID-F8 runs in existing chats; a request blocked in DevTools reads as an unreachable backend, so VID-B5 names the Can't reach Tale notice that may cover the page, and says how to put a failed chip in a queued message's row. The VID-B1 to VID-B3 row names the ytdlp test where it lives. The readme keeps only this suite's delta (13 to 15, total 945 to 947); several other suites' counts have drifted on main.
…captions-remove-feedback
yannickmonney
left a comment
There was a problem hiding this comment.
Scoped independent review at 4f9b77c1575793270ff1bd5338701fb5f5aa4b31: no actionable new defect established in the changed paths.
66 focused existing tests passed: 55 parser, worker and eligibility tests, plus 11 hook/tray tests. Three additional controls passed in both jsdom and real Chromium with the same mounted hook across A-to-B navigation: late successful cancellation, late refused cancellation, and late successful retry. B retained its own chip/state; the returning A read settled correctly; refusal produced one truthful toast. I independently replayed all three Chromium controls.
The reviewed SQL applies thread/uploader/status/lifecycle eligibility before ordering and limiting. Caption controls preserve unrelated same-start speaker lines and collapse progressive caption prefixes. Native PostgreSQL/queue/storage integration was read but not executed, so real-storage late-finalization acceptance remains unverified. The browser transport and worker extraction boundaries were synthetic; no production or provider operations occurred.
The author's disclosed adjacent existing caveats are not newly counted. This is a scoped review comment, not merge approval. Please return exact-head native integration evidence before final acceptance.
|
Independent native follow-up on exact reviewed head This used two newly created isolated databases and isolated config roots. Existing databases/state were not reset; new databases and evidence are retained. The ingest jobs were held by the lane's fixture so no video download, media process or provider ran. This is one filtered lane out of 193, not the full integration suite. S3 was omitted: attempted cleanup of the synthetic blob reference logged ObjectStoreUnconfiguredError, so this run does not verify real blob deletion. It does verify the database finalization fence. Together with the previously reported 66 focused unit/component tests and three independent late-settlement controls in jsdom and Chromium, the scoped review found no actionable new defect in this PR. Logs and resource receipt: |
Three defects in the chat's video-link attachments, reproduced locally in #3704, #3705 and #3720, fixed on current
mainwith tests that fail on the old code. One cohesive PR in atomic commits: one per defect, the real-Postgres lane, docs, manual boxes, then the fixes from an adversarial review of the first six (kept as separate commits so the review trail stays readable; the PR squash-merges).What changed
#3704 — a chat keeps its own video job when another chat pastes the URL.
ingestVideoUrlread the organization's newest job for the URL hash (LIMIT 1) and only then checked its chat, uploader, bind state, status and age. Pasting a URL in chat A, then in chat B, then in A again found B's newer job, rejected it, and started a second job and a second extraction in A, spending one of the organization's three in-flight slots. Every eligibility rule is now part of the lookup (backend/domains/video_links/service.ts), soLIMIT 1picks the newest job this member may reuse in this chat. A job the chip list hides (lifecycle_status = 'trashed') is not reused either; an unstamped lifecycle still is.#3705 — both speakers survive when caption cues share a start.
rollingWindowDedupkept only the longest cue of every run of cues with the same start, whatever they said, and the worker runs it on human tracks too: Alice 1.0–4.0 "The shipment is ready." and Bob 1.0–9.0 "Hold the shipment until Monday." completed as Bob's line alone underMethod: captions_human. A cue now collapses into an earlier cue of its window only when it is that line growing: the same speaker, and one text's words begin the other's — case and punctuation blind, whole words (nodoes not beginnow we), and by character when the shorter line is in a script written without spaces (Japanese, Chinese, Thai…;今日は→今日は、いい天気ですね。). The line with more compared characters is kept, the raw text only breaking a tie, so auto-caption prefixes still collapse to one line; every other same-start cue stays, in order. The comparison looks back at most eight kept lines, which keeps a hostile track of 50,000 same-start cues linear; a line it misses is kept twice, never lost.#3720 — a refused Remove says why and the chip comes back.
cancelJobrestored the chip, logged and rethrew into ChatSurface'svoid, so the rejection went unhandled and nothing was shown while the job stayed queued. Remove now reports its own failure the way the composer's Try again always did: a destructive toast Couldn't remove this video with the reason, the chip back in place, and a promise that never rejects (ChatSurface'svoidis correct again). A Remove that meetsnotFound(the job is already gone, e.g. swept) counts as done instead of leaving an unremovable chip, and after any Remove or Try again the chips read again. Sweeping the concept found the same silent refusal on the queued-send tray's Try again; both retries now go through one reporting helper (retryVideoLinkJob). Every video-link toast reads a failure one way: the chip's own sentence for a video-link code (videoLink.errors.*), else the platform'sfailureDetail(the refusal's words, a lost connection, an ended session), else the caller's line — for Remove, that the video is still attached. No second state store: the optimistic hide stays the hook'shideJobIds.Locales, docs, manual. New EN/DE/FR keys
chat.videoLink.toast.removeFailedTitle,chat.videoLink.toast.removeFailedDescription, andchat.videoLink.errors.threadNotFound(the one video-link refusal code without a sentence, which the shared reading would otherwise show in English).docs/{en,de,fr}/platform/chat/attachments.mdsay when a re-pasted link is reused (existing chat, before sending, not failed/removed, under a day old), that captions of two people speaking at once keep both people's words, and what a refused removal looks like (plus a troubleshooting row). Manual suitevideo-links:VID-F8(A/B/A in existing chats) andVID-B5(refused Remove and Try again, including the connection notice a blocked request raises), their pins, the automation register rows, corrected stale test paths in theVID-F2/VID-F3andVID-B1–VID-B3rows, and the suite count (13 → 15; on top ofmain's recount in #3859 the total reads 983, and every suite's row matches its boxes).Tests that fail before the fix
Each was run against the unfixed code (the fix stashed) and then with it:
backend/domains/video_links/service.dedup.test.ts— the lookup evaluated predicate by predicate over an in-memory table (an unknown predicate throws)job-new; an eligible job behind a newer failed one in the same chat is missedcheckVideoLinkComposerChipslane — native Hono routes + real Postgres 16 (ITEST_LANES=checkVideoLinkComposerChips bun run backend:integration)backend/core/video_links/captions_parser.test.tsmain(two speakers, distinct unlabeled lines, cross-speaker, whole words, interleaved growth, hostile window); after review, 2 more that failed on the first fix (unspaced scripts, word weight)backend/core/video_links/ingest_video_link.transcript.test.ts— the real worker, yt-dlp replaced at its module boundary, fixed VTT fixturecaptions_human; auto-track controlcaptions_autoapp/features/chat/hooks/use-chat-video-links.test.tsx— real hook, chip and toaster;fetchanswers as the routes doapp/features/chat/components/deferred-send-tray.test.tsx(new case)What the brief asked to cover: same-chat and different-chat controls (lane + unit); overlapping cues (parser + worker); transient cancellation refusal (member disabled → 403
ORG_FORBIDDEN, job stillqueued, then a successful Remove — lane; a lost connection then success — hook test); retry feedback (a live retry's 409notRetryableand a disabled member's 403 over Hono; cooldown and membership toasts in the composer and the tray); successful cancellation (200 →skipped, chip gone, no toast); and a late worker result (a job a worker was storing is cancelled, then the finalizer it held and a redelivered ingest job land nothing:insertSyntheticFileMetadataanswersnull, no file row, job staysskipped). No video is downloaded and no media executable, model or provider runs: the lane holds thevideo.ingestjobs of its own organizations a day out with a trigger that exists only while it runs, and leaves no trigger, function, row or pg-boss job behind.Real browser
A throwaway browser-mode render (real Chromium 1208, not committed) of the real hook, chip and toaster over the same
fetchanswers: after a refused Remove the chip is back and the toast reads Couldn't remove this video / Video konnte nicht entfernt werden / Impossible de retirer cette vidéo with the refusal's words; a second Remove clears the chip with no toast. Screenshots are attached to the task (TALE-86).CI
The first run on
79166624ewas green except Docs container test, which was cancelled at its 15-minute job timeout in the middle of the docs image'svite build(other runs of that job take 3–6 minutes); the platformlint,typecheck,test,test:uiandtest:browsertasks all ran (cache miss, executing) and passed, and the new test files appear in their logs. The token cannot re-run jobs, so currentmainwas merged in (4f9b77c15, resolvingtests/manual/readme.mdagainst #3859's recount) and CI runs again on that head.Checks run locally
bunx vitest run --project server):backend/core/video_links,backend/domains/video_links,backend/domains/chat/deferred-sends.test.ts,lib/i18n/messages.test.tsand the guardserror-message-description,single-failure-toast,chat-turn-error-toast— all green; after the rebase ontodfacbd122,lib/i18n/messages.test.ts, the caption, transcript and video-link domain tests again (8 files, 99 passed).--project client): the hook, tray,chat-surface.test.tsxandcomposer.test.tsx;app/routes/dashboard/$id/chat.loader.test.tsunder the UI config. The host was shared and heavily loaded (load average above 100): some axe audits (waitFor, 1 s) and the loader test (5 s) timed out once and passed on rerun;chat-surface's axe audits also pass withmain's versions of the changed files.bunx oxlint --type-aware --type-checkon every changed TypeScript file andbackend/integration-check.tsbefore the rebase: clean. After the rebase (a conflict-free replay; the only overlap inintegration-check.tsis this lane's import and registration) the rerun was starved by the host load and did not finish; CI's lint and typecheck jobs cover it.oxfmton the changed files.bun run lint:manual: ok.check-guide.tsonvideo-links.md: OK; onautomation.mdandpins.mdthe findings are identical tomain's copies (pre-existing false positives).services/docs(bunx vitest --run, serial): 36 files, 200 passed.backend:integrationwithITEST_LANES=checkVideoLinkComposerChipson a local PG16 with pgvector: 22/23 before and after the review fixes; the one failure is the boot check "knowledge BM25 indexes verified", expected without ParadeDB'spg_searchlocally.Found while testing, not changed here
joinSegmentsWithParagraphs(backend/core/file_metadata/paragraphize.ts) joins a paragraph's segments with''; Whisper segments carry a leading space butparseVtttrims every cue, so consecutive cues read…the itest video.Second cue…andnow we willsee how it works. Pre-existing, outside these three issues, and no issue exists for it yet; it needs its own fix (the join is shared with Whisper, whose CJK output has no spaces to add).checkOrganizationRateLimit) with a 500:handleErrorrethrowsRateLimitExceededError, where the file routes userateLimitedResponse.findReusableTranscriptDonor) has the same newest-then-filter shape, bounded to 20 rows by design; a missed donor only costs a fresh extraction instead of a clone. Transcripts stored before this change keep a lost speaker line and can be cloned for 30 days.cancelDeferredSendRequest) and the send-failure unbind (void chatSend.unbindVideoJobs(…)) still drop a refusal silently; they act on a message, not a video chip.Closes #3704
Closes #3705
Closes #3720