Repository navigation
feat(meditations): add a Transcript tab and Lemonfox transcription job - #882
sydevs-bot wants to merge 23 commits into
Conversation
…x job Adds the restricted `meditation-transcripts` collection, one row per meditation, and the `transcribeMeditation` task on a new `transcription` queue. The task sends the recording's public R2 URL to Lemonfox (verbose_json with word timestamps) and stores normalized segments. Without LEMONFOX_API_KEY, any deployment but production stores a labelled sample transcript; production fails with a clear error. The task carries no concurrency key: Payload holds back every job whose key matches one still marked processing, and a run lost to a restart keeps that flag, which would block Try again for good. Refs #881 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The new first sub-tab, before Frames and Add New, reads GET /api/meditations/:id/transcript and requests a transcription through the POST. It polls while a request is queued or processing, and shows failed, stalled, out-of-date and sample states. Clicking a phrase seeks the existing live preview, and the phrase under the playhead is highlighted, through the frame editor's preview bridge. Pauses of 3 s start a paragraph; pauses of 10 s show a silence marker. Both endpoints are manager-only and check meditation read or update at the request locale. They read the meditation's latest draft, whose recording is the one the editor hears. Refs #881 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The int spec drives both endpoints' gates (anonymous, API client, inactive, roleless, wrong-locale editor, read-only translator), the one-job dedupe, the sample transcript, out-of-date audio, a stale run for replaced audio, a stalled request, and production without a key. The unit specs cover the Lemonfox normalizer for both verbose_json word layouts and the tab's grouping, highlight and phase logic. The test env pins LEMONFOX_API_KEY empty, so no test can make a paid call even when a shell exports a real key. The sample transcript now fits a short recording, since the test audio is 42 seconds. Refs #881 Co-Authored-By: Claude Opus 5.5 <[email protected]>
While the preview plays, the Transcript tab now marks the word being spoken inside the highlighted phrase, from the stored word timings. The phrase's written text still renders in full: a word Whisper could not time stays as plain text rather than dropping out. An off-screen playing phrase scrolls into view. A wheel, touch or scroll key pauses following for 5 seconds, so it never fights an editor who is reading elsewhere. Refs #881 Co-Authored-By: Claude Opus 5.5 <[email protected]>
The meditation's locale maps to a Lemonfox language name (en-AU and pt-BR to their base language). A name outside Lemonfox's documented list is now left out, so Lemonfox detects the language rather than refusing the request. Every locale the app has today maps to a listed name, and a unit test holds that. Refs #881 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…layer Tested against a locally run WeMeditateWeb preview, which surfaced three gaps the faked playback had hidden: - After Transcribe, the tab never polled again: caching the POST result without revalidating left SWR's refresh timer unarmed, so it showed "Waiting to start" until a reload. - The preview reports the playhead in whole seconds, so the word highlight jumped once a second. While those reports tick up steadily, the tab now carries the time forward by its own clock, never past the next second. - A clicked phrase seeks to its whole second, which falls just before the phrase's start, so it did not light up. A phrase now counts from the whole second it starts in. Refs #881 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Payload ships no waveform icon, so it is lucide's AudioLines, as the admin icon rule allows when no built-in fits. Refs #881 Co-Authored-By: Claude Opus 5.5 <[email protected]>
`pnpm lint` runs with `--max-warnings 0`, so the missing blank line failed the gate. Refs #881 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012qvtsTmV3bdrMwYmffERQg
…e 202 The race recovery was written for the unique-`meditation` collision that only a create can lose, but it wrapped the update branch too. There `findTranscriptRow` always finds the row, so any update failure answered 202 with the row unchanged and queued no job — Try again became a silent no-op with no error anywhere. Scoping the recovery to the create path also lets the two handlers share one guard: they differed only in the operation required and the wording of the refusal, so the permission shape, the locale scope (#701) and the id validation were each stated twice. The GET's two reads feed nothing into each other, so they now run together on the endpoint the tab polls. Refs #881 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012qvtsTmV3bdrMwYmffERQg
…d one A stalled row accepts a fresh request, so two runs can hold the same recording. If the first completes while the second fails, the second wrote `failed` over a good transcript and the text was gone. The failure path now leaves a `completed` row alone. The job also carried its own copy of the row query. `meditation` is unique, so there is at most one row per meditation and the recording is a field comparison — it reuses `findTranscriptRow` rather than keeping a second set of `depth`/`pagination`/`overrideAccess` choices in step by hand. Refs #881 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012qvtsTmV3bdrMwYmffERQg
`playing` is recomputed only when a new second arrives, and a pause sends none — the preview either stops posting or repeats the second it stopped on. The carry therefore ran to its clamp and held the highlight a second ahead of the audio for as long as the tab stayed open. An overdue report now counts as stopped. The spec asserted the old behaviour at three seconds, which is the bug itself; it now pins the clamp inside the tolerance and the hold beyond it. Refs #881 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012qvtsTmV3bdrMwYmffERQg
SWR lists `refreshInterval` in its polling effect's dependencies, so the inline arrow re-armed the timer on every render. The playhead re-renders this component ten times a second, so the 3 s timer never elapsed: an editor who pressed play while a transcription ran saw the spinner until they left the tab. The callback is now declared once, at module scope. Refs #881 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012qvtsTmV3bdrMwYmffERQg
The transcript endpoint restated a mechanism `runScreeningQueueAfterCommit` already owned, down to the warning sentence: the `NODE_ENV=test` suppression, the never-reject-the-caller rule, and the autoRun safety net behind both. That helper's own docblock claimed to own the contract, which the second copy quietly made false. `runQueueAfterCommit` now holds the generic mechanism, with the wait as a parameter — that is the only real difference between the callers. Screening queues inside its own transaction and keeps its 2 s wrapper, which is where that reason belongs; this endpoint queues outside one and waits not at all. It also settles a cross-owner import that predates this ticket: `ScreenSubmissions` was already reaching into `UserSubmissions/` for the helper, which `src/AGENTS.md` rule 4 prohibits. Refs #881 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012qvtsTmV3bdrMwYmffERQg
…keting Three small things the review pass turned up: - The tab reached into `FrameEditor/hooks` and `/utils` by path. That barrel already re-exports all three symbols as its public API, so a second consumer no longer depends on the owner's internal layout. - `PARAGRAPH_GAP_SECONDS` and `SILENCE_GAP_SECONDS` were exported with no consumer outside their own module, which reads as an external contract. - The top-level word buckets were built on every normalize and discarded whenever the segments carried their own `words`, which is the shape Lemonfox documents. The pass is now skipped when nothing needs it. The per-word scan still restarts at segment 0 on purpose: the top-level list arrives unsorted, so carrying the pointer forward would mis-assign a word that comes back out of order. Refs #881 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012qvtsTmV3bdrMwYmffERQg
The ticket requires the collection be absent from `/api/docs`, and nothing asserted it. Two independent things each hide it — the `ALWAYS_HIDDEN_COLLECTIONS` entry, and belonging to no project, which `filterSpec` already treats as hidden — so the entry is redundant today and the realistic regression is someone putting the slug in a project. The assertion is on the outcome rather than either mechanism, so it goes red only when the collection would genuinely be published. Confirmed by doing it: green with either safeguard alone, red with both removed, naming the project tier that would serve it. Tiers come from `getProjectSlugs()` rather than a list here, so a fourth project cannot publish these paths silently. `pnpm typecheck:tests` caught the first draft inventing a `we-meditate` slug that does not exist. Refs #881 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012qvtsTmV3bdrMwYmffERQg
`src/plugins/access/config/projects.ts`'s own docblock was updated when `meditation-transcripts` was added to `RESTRICTED_COLLECTIONS`, but the rule doc that mirrors it still named four collections and called them all "personal data and credentials". The fifth is neither — it is internal working data, restricted because shared read would hand every API client the transcript of every recording. `tests/COVERAGE.md` asks to be updated whenever an endpoint or a scheduled task is added. This adds a collection, two endpoints and one task. Refs #881 Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_012qvtsTmV3bdrMwYmffERQg
|
🚅 Deployed to the SahajCloud-pr-882 environment in sahajcloud
1 service not affected by this PR
|
|
🤖 no session running recent dispatchesWritten by the sydevs dispatcher. Sessions never edit this comment. |
sydevs-bot
left a comment
There was a problem hiding this comment.
🧐 Adversarial review
The diff tracks #881 line for line, and its size is the ticket's: one collection, two endpoints, one task, one tab. It stays Payload-native, and payload-types.ts only gains lines, so the consumer sync is routine.
One deviation the PR body omits: the task drops the ticket's concurrency key. Documented in the code, and right — a key would block Try again after a stall, for good.
The one unasked-for change: the shared queue helper, which pulls the screening pipeline in. Extracting it was right.
Findings
- consider — the helper's name no longer fits its new caller —
runQueueAfterCommit.ts:20 - consider —
runScreeningQueueAfterCommitis now a defaulting wrapper —screeningQueue.ts:35 - consider —
toMillisreturns seconds —lemonfox.ts:86
What was checked
Read whole: both endpoints, the guard, the task, the Lemonfox client, the tab, its hooks and model, screeningQueue.ts either side. payload-types.ts removes nothing. The overrideAccess: false readback docs/rules/access.md demands is in the int spec.
🤖 Written by the sydevs autonomous loop — see what this is
Generated by Claude Code
`toMillis` claimed a unit conversion it never did: it rounds a seconds value to millisecond precision and returns seconds. Every caller stores the result in a field documented as seconds from the start of the recording, so the old name was the only thing suggesting otherwise. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014nBC19SRP6v4et4WKiEoF5
The transcript endpoint queues outside a transaction and passes `delayMs: 0`, so `runQueueAfterCommit` promised that caller something it neither needs nor gets. Waiting for a commit is the `delayMs` caller's concern, so the commit story moves onto that option's doc line and the function says only what it does: run the queue soon. `runScreeningQueueAfterCommit` keeps its name — it is the one caller that does queue inside its own transaction, and it now reads as the specialization rather than a synonym. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_014nBC19SRP6v4et4WKiEoF5
|
Answered the adversarial review's three findings. Two renames pushed, one left open. Adopted
Rebutted, left open
Neither rename changes behaviour. Lean gate green, plus 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
main (#880) moved `jobs.autoRun` out of `payload.config.ts` into `JOB_AUTO_RUN` in `src/jobs/queues.ts`, while this branch added a `transcription` entry to the inline array. Both sides are kept: the config takes main's `autoRun: JOB_AUTO_RUN` — which `job-schedules.spec.ts` asserts as source text — and the transcription safety net moves into `JOB_AUTO_RUN`. Its cron changes from `*/15` to `3-59/15`. #880 added the rule that two queues ticking on the same minute lose one `lastScheduledRun` to the other's write, and `*/15` collided with `screening`, `invitations` and `nightly`. :03 and every 15th minute after clears all three and `monthly`'s :07, keeping the 15-minute worst-case lateness the entry was written for. `src/payload-types.ts` and `importMap.js` regenerated: both already matched the textual merge. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01K3UtS1SCwASAkNJri3QE7w
|
Merged #880 moved One deliberate change, not a pure resolution. Its cron is now Lean gate green (2,355 unit tests), 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
One conflict, in `tests/unit/openapi-custom-endpoints.spec.ts`: both sides added an import on the same lines. Kept both — `getProjectSlugs` for this branch's `meditation-transcripts` project-tier assertions, and main's `limitParameter`/`pageParameter` for the client-limit bounds spec (#890). Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01L39RLXia3g6pcNupvCQMpz
|
Merged One conflict, in Gate: 🤖 Written by the sydevs autonomous loop — see what this is Generated by Claude Code |
Pull request was closed
Summary
meditation-transcriptsrow, never onto the meditation — so transcribing creates no version and cannot publish an editor's draft.Changes
src/collections/MeditationTranscripts/— the row (one per meditation), plus the shared view builder both endpoints read.src/collections/Meditations/endpoints/—GET/POST /api/meditations/:id/transcript, over one shared manager-only guard.src/jobs/TranscribeMeditation/— the task, the Lemonfox client, and the sample response used where no key is configured.src/components/admin/MeditationTranscript/— the tab, its paragraph/silence grouping, and the two playback hooks.src/lib/jobs/runQueueSoon.ts— the "kick the queue now, autoRun is the safety net" mechanism, now shared with the screening pipeline instead of copied.Preview
/api/docs— confirmmeditation-transcriptsis absent./api/meditation-transcripts— confirm it refuses a non-admin manager and an API key.Migration
src/migrations/20261002_154706_meditation_transcripts.tsmeditation_transcriptsand its two enums, addsmeditation_transcripts_idtopayload_locked_documents_rels, and addstranscribeMeditationto both job task-slug enums. No existing row is read or rewritten.downdrops the table and column and rebuilds both enums without the new value.migration-validator: 4 pass, 0 fail; its two warnings are theDROP TABLE/DROP COLUMNindown, which is what reversing a new table looks like.Test results
pnpm lint,pnpm typecheck,pnpm typecheck:tests,pnpm test:unit(2,327 unit tests) — re-run after the two renames belowmeditation-transcript.int.spec.ts15 passed;screen-submissions.int.spec.ts17 passed (it shares the queue helper this PR extracted)src/plugins/access/config/projects.tsandpayload.config.tsall match this repo's trigger paths. No findings: the shared guard refuses anonymous callers, API clients and inactive managers before parsing the route param, the collection is closed off three independent ways, and the Lemonfox host and protocol come from trusted env rather than any request.Manual verification
⚠ A Railway PR preview carries no content, so there is no meditation to open. Create one with a recording first.
LEMONFOX_API_KEYon the preview you should get the sample transcript behind its "placeholder text" banner, with no reload.verbose_jsonshape survives the normalizer. This is the one claim no test here can make — the key in a developer's.env.localanswered401 invalid API key / no active subscriptionon 2026-10-02, so the live response shape is still unverified and the normalizer is written defensively for it.Notes for reviewer
I picked this up from seven commits already pushed to this branch with no PR open, so the first commit here is a lint fix and the rest are review findings. Four were real defects, each with its own commit:
202unchanged and queued no job — Try again was a silent no-op;The two most recent commits answer the adversarial review's naming findings. Both are renames with no behaviour change:
runQueueAfterCommit→runQueueSoon(the transcript endpoint queues outside a transaction and waits for nothing, so the commit story moved ontodelayMs's own doc line), andtoMillis→roundToMillisecond(it returns seconds rounded to the millisecond, which is what every caller stores).Open question, unchanged from the ticket: who provisions a working
LEMONFOX_API_KEYfor Railway production, and do previews get one? Nothing here depends on the answer — without a key every non-production deployment writes a labelled sample, and production fails the request with a clear error rather than storing sample text.One follow-up I deliberately did not take.
RESTRICTED_COLLECTIONSnow names five collections, and its docblock says the list "fails open the day a sixth is added". This PR is the first time that count has moved, and nothing asserts the set is complete. A unit test requiring every registered collection to be in a project or in that list would turn the documented fail-open into a red test. That is a repo-wide invariant rather than this ticket's, so I left it — say the word and I will file it.Review findings I dismissed, and why
runScreeningQueueAfterCommitinto the generic helper, since it only pins two arguments. Declined: with the generic one renamed torunQueueSoon, the two names no longer say the same thing. The wrapper is the after-commit case, and it owns both the 2s delay and the reason a row queued withreqneeds one. Inlining it would copy the delay to both call sites and leave that reasoning with no home.transcriptPhaseintosrc/lib/meditations/transcript.tsso the server'sisTranscriptionActivecan share it. Declined: that module importszodat module scope for the segment schema, and the tab imports only types from it today, so zod stays out of the admin bundle. A value import would pull it in — the hazardsrc/collections/AGENTS.mddocuments. The two also answer different questions (a boolean server gate vs a six-way display phase) and agree on one branch.assignWordsToSegmentsinstead of restarting at segment 0. Declined, and it would have been a bug: the top-level word list arrives unsorted, so a forward-only pointer would mis-assign any word that comes back out of order. The redundant pass is skipped instead, which was the real waste.TranscriptView.updatedAt— nothing reads it. Kept: the ticket names it in the response shape.TranscriptParagraph.start(derivable fromsegments[segmentIndexes[0]]) and thecurrent &&guard ingroupTranscript(unreachable given theInfinityseed). Both declined as churn: removing the guard would make the function depend on that seed for its safety, and the field has one reader.playingcheck inuseSmoothPlaybackTime's interval, since the pure function re-checks it. Kept: it avoids asetStateten times a second while paused.iso-639-1instead ofIntl.DisplayNamesfor the Lemonfox language name. Declined — not a drop-in:getLocaleLabelyieldsFarsi/PersianandBrazilian Portuguese, which Lemonfox does not list.revalidateIfStale: false, and aselecton the POST's row read. Both declined as marginal — one refetch per tab switch, against the risk of showing a stale transcript.playbackTimeStoreout ofFrameEditor/now that two tabs share it. Declined as out of scope, but the tab now imports the three symbols fromFrameEditor's barrel, which already declares them public, rather than by deep path.Docs synced, and the fixture check
docs/rules/access.mdstill saidRESTRICTED_COLLECTIONS"holdsusers,user-submissions,managersandclients— personal data and credentials", and that "all four" collections in no project were named. The code docblock had been updated to five; this doc had not, and the fifth entry is explicitly not personal data.tests/COVERAGE.mdasks for a row whenever an endpoint or scheduled task is added, and gained three: the collection, the two endpoints, andtranscribeMeditation.Checked and found not stale:
docs/rules/endpoints.md's OpenAPI registration step does not apply — a manager-only endpoint is deliberately absent fromCUSTOM_ENDPOINT_PATHS, exactly asPOST /api/user-submissions/:id/reviewis, which I confirmed by readingcustomEndpoints.tsrather than assuming.collections-smoke.int.spec.tsis hand-written per content-bearing collection, and this one is not content. Neither rename reaches any doc — nothing outsidesrc/named either symbol.Fixture pre-mortem. The int spec's environment assumes
LEMONFOX_API_KEYis pinned empty, so no test can make a paid call even when a developer's shell exports a real key, and that no Railway environment name is set, soisProductionDeployment()is false and the sample provider runs. I verified both against the realvitest.config.mts(sharedTestEnv) rather than trusting the spec's own comment.Closes #881
🤖 Generated with Claude Code
https://claude.ai/code/session_014nBC19SRP6v4et4WKiEoF5