Skip to content

fix(platform): dedupe video links per chat, keep cues, explain refusals - #3884

Merged
yannickmonney merged 12 commits into
mainfrom
fix/video-link-dedup-captions-remove-feedback
Sep 29, 2026
Merged

yannickmonney merged 12 commits into
mainfrom
fix/video-link-dedup-captions-remove-feedback

Conversation

@yannickmonney

@yannickmonney yannickmonney commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Three defects in the chat's video-link attachments, reproduced locally in #3704, #3705 and #3720, fixed on current main with 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. ingestVideoUrl read 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), so LIMIT 1 picks 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. rollingWindowDedup kept 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 under Method: 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 (no does not begin now 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. cancelJob restored the chip, logged and rethrew into ChatSurface's void, 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's void is correct again). A Remove that meets notFound (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's failureDetail (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's hideJobIds.

Locales, docs, manual. New EN/DE/FR keys chat.videoLink.toast.removeFailedTitle, chat.videoLink.toast.removeFailedDescription, and chat.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.md say 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 suite video-links: VID-F8 (A/B/A in existing chats) and VID-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 the VID-F2/VID-F3 and VID-B1–VID-B3 rows, and the suite count (13 → 15; on top of main'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:

Test Before After
backend/domains/video_links/service.dedup.test.ts — the lookup evaluated predicate by predicate over an in-memory table (an unknown predicate throws) 2 failed: A/B/A answers job-new; an eligible job behind a newer failed one in the same chat is missed 11/11 (incl. failed, removed, sent, another member's, day-old and trashed jobs not reused)
checkVideoLinkComposerChips lane — native Hono routes + real Postgres 16 (ITEST_LANES=checkVideoLinkComposerChips bun run backend:integration) A/B/A: "A again=…eb142c7c (want …e93ebfc3), unsent in A=2, chips in A=2, video.ingest jobs=3" 6/6 lane checks
backend/core/video_links/captions_parser.test.ts 6 failed on main (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) 42/42
backend/core/video_links/ingest_video_link.transcript.test.ts — the real worker, yt-dlp replaced at its module boundary, fixed VTT fixture human track stores only Bob's line both lines, captions_human; auto-track control captions_auto
app/features/chat/hooks/use-chat-video-links.test.tsx — real hook, chip and toaster; fetch answers as the routes do 4 failed + 3 unhandled rejections: chip back, no toast 7/7 (incl. a gone job and the reread)
app/features/chat/components/deferred-send-tray.test.tsx (new case) failed, unhandled rejection 4/4

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 still queued, then a successful Remove — lane; a lost connection then success — hook test); retry feedback (a live retry's 409 notRetryable and 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: insertSyntheticFileMetadata answers null, no file row, job stays skipped). No video is downloaded and no media executable, model or provider runs: the lane holds the video.ingest jobs 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 fetch answers: 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 79166624e was green except Docs container test, which was cancelled at its 15-minute job timeout in the middle of the docs image's vite build (other runs of that job take 3–6 minutes); the platform lint, typecheck, test, test:ui and test:browser tasks all ran (cache miss, executing) and passed, and the new test files appear in their logs. The token cannot re-run jobs, so current main was merged in (4f9b77c15, resolving tests/manual/readme.md against #3859's recount) and CI runs again on that head.

Checks run locally

  • Server (bunx vitest run --project server): backend/core/video_links, backend/domains/video_links, backend/domains/chat/deferred-sends.test.ts, lib/i18n/messages.test.ts and the guards error-message-description, single-failure-toast, chat-turn-error-toast — all green; after the rebase onto dfacbd122, lib/i18n/messages.test.ts, the caption, transcript and video-link domain tests again (8 files, 99 passed).
  • Client (--project client): the hook, tray, chat-surface.test.tsx and composer.test.tsx; app/routes/dashboard/$id/chat.loader.test.ts under 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 with main's versions of the changed files.
  • bunx oxlint --type-aware --type-check on every changed TypeScript file and backend/integration-check.ts before the rebase: clean. After the rebase (a conflict-free replay; the only overlap in integration-check.ts is 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. oxfmt on the changed files.
  • bun run lint:manual: ok. check-guide.ts on video-links.md: OK; on automation.md and pins.md the findings are identical to main's copies (pre-existing false positives).
  • services/docs (bunx vitest --run, serial): 36 files, 200 passed.
  • backend:integration with ITEST_LANES=checkVideoLinkComposerChips on 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's pg_search locally.

Found while testing, not changed here

  • Caption cues in one paragraph are glued without a space. joinSegmentsWithParagraphs (backend/core/file_metadata/paragraphize.ts) joins a paragraph's segments with ''; Whisper segments carry a leading space but parseVtt trims every cue, so consecutive cues read …the itest video.Second cue… and now 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).
  • The video-link routes answer a rate-limited paste (checkOrganizationRateLimit) with a 500: handleError rethrows RateLimitExceededError, where the file routes use rateLimitedResponse.
  • The transcript-donor scan (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.
  • Two pastes of one URL in the same chat at the same instant can still both miss the dedup (the lookup runs before the insert transaction's advisory lock); not what Bug: Pasting the same video in another chat defeats current-chat deduplication #3704 reports.
  • A queued message's own ✕ (cancelDeferredSendRequest) and the send-failure unbind (void chatSend.unbindVideoJobs(…)) still drop a refusal silently; they act on a message, not a video chip.
  • Focus is not moved when a chip leaves optimistically (successful or not); the restored chip's Remove is reachable again by keyboard, and the toast is announced.

Closes #3704
Closes #3705
Closes #3720

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.

@yannickmonney yannickmonney left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@yannickmonney
yannickmonney merged commit b7f8ca0 into main Sep 29, 2026
50 checks passed
@yannickmonney
yannickmonney deleted the fix/video-link-dedup-captions-remove-feedback branch September 29, 2026 14:00
@yannickmonney

Copy link
Copy Markdown
Contributor Author

Independent native follow-up on exact reviewed head 4f9b77c1575793270ff1bd5338701fb5f5aa4b31: 23/23 PostgreSQL checks passed, including all six checkVideoLinkComposerChips cases. The actual Hono routes and PostgreSQL 16.13 now independently confirm same-chat reuse, different-chat separation, A/B/A reuse, membership-refused Remove/Retry, live-job retry refusal, and successful cancellation followed by a late finalizer/redelivery that creates no file row. Boot migration and pg_search/vector health controls passed too.

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: /Users/yannick/.codex/notes/tale-1000-additional/review-3884/native-proof-20260929/. The separate pre-existing caption-spacing defect is now #3928. GitHub records this PR as already merged; this audit performed no merge or deployment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant