Repository navigation
feat(memos): separate tracks, their presigned uploads and named attribution - #1549
Merged
Merged
Conversation
…bution A recording can arrive as one track per speaker: `POST /v1/memos` takes the manifest (up to 50 tracks) instead of the single file, never both, and answers with one presigned PUT per track beside the existing `upload`. The server derives every object key under the memo's own prefix — `track-<i><ext>` — because the memo id does not exist when the request is made, and stores the manifest in `memos.tracks` so a retry resumes. The worker transcribes each track on its own (`speakers: false`: one track is one voice by construction) and merges the parts into one chronological transcript whose segments carry the participant's name, or the track's key when nobody matches. The byte ceiling applies to the sum at finalize, delete and retention purge every track object, and a tracks memo offers no single stream: `audioAvailable` is false and the audio route answers 410. Refs #1415
…s gaps Review findings on the tracks work: - `finalize`'s over-ceiling cleanup used `deleteObject`, which on a versioned bucket only writes a delete marker. The row was about to go, so nothing would have purged those versions later; it now purges every version of each track object and of the nominal key, like `remove` and the sweeper. - A track probed over the minute ceiling was not added to `seconds`, so its usage row under-billed it. The single-file branch has always billed probed audio even when the ceiling rejects it (#793); a track now does the same. - The tracks spec's fakes now apply the predicates the production lines send (`require`'s `createdBy`, the worker's claim status), the sum fixture sits below the byte ceiling so it cannot be read as a clamped value, the merge fixture's largest end is not its last segment and a second non-null language proves the first wins, and the missing-track 400 asserts nothing was destroyed. Refs #1415
This was referenced Dec 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1415
Refs #1402
Refs #1400
What
A memo can now arrive as one track per speaker.
POST /v1/memosaccepts atracksmanifest instead of the single file — never both — and answers with one presigned PUT per track beside the existingupload; the worker transcribes each track on its own and writes one transcript whose segments carry the speaker's name. No voice model, no diarization inside a track, nospeaker_matches, no UI.Request (a tracks create sends no
filename/contentType/sizeBytes):{ "workspaceId": "…", "projectId": "…", "tracks": [ { "key": "ada", "participantExternalId": "ada@example.com", "filename": "Ada.m4a", "sizeBytes": 400 }, { "key": "bob", "participantExternalId": "Bob", "filename": "bob.wav", "sizeBytes": 600 } ] }Response:
{ memo, upload, tracks: [{ key, url, method: 'PUT', headers, expiresAt }] }— in manifest order.uploadstays required (decision 3), still signing the nominalsource<ext>key; a tracks caller ignores it. Caps: 1–50 tracks,key≤ 80,participantExternalId≤ 200, each aMEMO_FORMATSextension.Why the client names a
keyand the server the objectThe memo id does not exist when the request is made, so no client can name an object under
workspaces/{ws}/memos/{id}/— and a caller-chosen key would need an ownership check this path cannot do before the row exists. The request therefore carrieskey,participantExternalId,filenameandsizeBytes; the service mints the row first and stores the doc'sMemoTrackshape{ key, participantExternalId, audioKey }withaudioKeyderived astrack-<i><ext>under the memo's own prefix (memos.service.ts,create).track-<i>is unique by construction, so the manifest cannot collide.The one-source rule and the derived row
createstarts withhasTracks === (input.filename !== undefined)→ 400error.memo.oneSource(thenotes.service.tssources !== 1precedent). The DTO makes the file trio required only whentracksis absent (@ValidateIf), so an existing uploader is unchanged and a tracks body sends none of them.For tracks the row describes the manifest:
filename= first track's name,contentType= that format's stored type,sizeBytes= the declared sum, title from the first track's name as before. Each track's extension is validated againstMEMO_FORMATSand refused with the existingerror.memo.unsupportedFormatnaming the track's filename; duplicatekeys are refused witherror.memo.tracksInvalid.Finalize, the sum, and no single stream
finalizeparses the stored manifest first:invalid→ 400error.memo.tracksInvalidand the row stays.tracks→ HEAD every object, refuse a missing one witherror.memo.uploadMissing, sum the lengths and applymaxBytesto the sum (the whole recording), then the same guardedupdateManyonpendingwithsizeBytes: total. Over the ceiling: 413, every track object and the nominal key are deleted and the row goes, as the single-file branch does.A tracks memo has no single stream:
audioAvailableis false,GET /v1/memos/:id/audioanswers 410error.memo.audioGone, andremovepurges the nominal key and every track object.MemoRetentionSweeperselectstracksin both purge branches (expired and abandoned) and purges each track object before the key, through the same prefix guard — a tampered manifest can never make it purge a foreign key.The worker: one track, one voice
readTracksruns once at the top oftranscribe.invalidfails the memo witherror.memo.tracksInvalidon the existingfail(row.id, 'transcribing', …)path and transcribes nothing.tracks→ for each track: download tosource-<i>, probe its own length (the minute ceiling is per track, because every track is the whole call),speech.transcribe({ speakers: false })— no diarization inside one voice — then the segments getspeaker: trackLabel(row.participants, track): the participant whose folded name is the track'sparticipantExternalId(the samefoldName1.2 uses), else the track'skey. The parts go throughmergeTrackTranscripts: chronological, ties in manifest order, renumbered from 0, emitting exactly{ i, start, end, text, speaker }.durationSecondsis the largest segment end, not the sum of the tracks;languageis the first non-null part; onememo.update. Thebillbox is shared across the loop and the usage row sums the probed seconds, so a failure on track 3 still records 1–2 (#793). A mixed file (tracks: null) takes today's path untouched, Plaud included.Per-criterion (#1415)
apps/api/src/memos/transcript.ts(readTracks,trackLabel,mergeTrackTranscripts); worker branch inmemos.processor.ts; specstranscribes each track on its own, labels it and merges…,presigns one URL per track…Speaker 1..Nexactly as today.readTracksreturnsnonefor null and the branch keepsspeech.speakersand theerror.memo.speakervoice callback; speckeeps the single-file path for a mixed memoaudioKey(request shape above); the stored manifest is refused unless every key startsworkspaces/{ws}/memos/{id}/and has no..—readTracks, specrefuses a manifest with a bad entry, a duplicate key or a foreign object…;finalizeanswers 400 and the worker fails the memomake verifypass.make verifyexit 0: API 350 files / 5392 tests; web 105/776; admin 1/2 (api lint, typecheck, depcruise and test allcache miss)#1402 rows advanced
memos.participants, read byGET /v1/memos/:id; spectranscribes each track on its own…(Ada from the roster,bobfrom the key) andkeeps the single-file path…tracks: [{ key, participantExternalId, audioKey }]and eachaudioKeysits under the memo's prefix.audioKeyand the server derives it under the prefix; the stored row is the doc's shape andreadTracksis the prefix guard (see Divergences)Verification
make db-generate—Memo['tracks']typechecks.20270222100000_memo_tracks/migration.sqlis one line, produced without a database:ALTER TABLE "memos" ADD COLUMN "tracks" JSONB;memo_tracks_probe, created and owned for this check, then dropped):prisma migrate deployapplied all migrations,information_schema.columnsreportedtracks | jsonb | YES, an INSERT naming no tracks readtracks IS NULL = t, and the rollback (ALTER TABLE "memos" DROP COLUMN "tracks") left no column. Additive and reversible: no backfill, no**Operations:**line.make verify— exit 0 (totals above).make api-client— regenerated; onlyopenapi.json,contract-schemas.jsonandpackages/api-client/src/schema.d.tschanged (the docs reference table does not list request/response bodies).readTracksprefix guard, collapsing finalize's sum to the last track, labeling every segment by the key, and deleting the one-source rule each turned the new cases red; restored, suite green.Divergences
MemoTrack.audioKeyis the server's, not the caller's. § Separate tracks draws the manifest as the request body ({ key, participantExternalId, audioKey }), but the memo id does not exist when the request is made, so a client cannot name an object under the memo's prefix and an ownership check would have nothing to check. The request carries{ key, participantExternalId, filename, sizeBytes }; the server derivesaudioKey; the stored row is the doc's shape, so a retry resumes from it (decision 2).packages/contracts(MemoTrack,MemoTrackUpload,CreateMemoResponse.tracks), the schema and its hand-written migration (the doc's § Operations column), the DTO, the retention sweeper (or every track memo would leak its audio past the window), two i18n keys in both languages, the generated client,apps/api/src/i18n/i18n.generated.tsandCHANGELOG.md.i18n.generated.tsis hand-updated to the exact bytes the dev generator writes.make api-schemaboots the Nest app withoutinit(), so the nestjs-i18n generator (which runs at bootstrap) does not rewrite it; leaving it stale would dirty the tree on the nextmake dev. The two added lines are the new keys in the same order the loader would emit.Review
Independent review before opening this PR: spec and work read by fresh contexts, sliced by area. The first wave of ten was cut off at the provider's ~90 s wall, which is a fail-closed block, not a pass; the same slices were re-sent in waves of four and returned. Fixes are in
e4525ab2; the delta was re-reviewed in three slices, all pass.finalize's over-ceiling cleanup useddeleteObject, which on a versioned bucket only writes a delete marker — the row was about to go, so nothing would ever purge those versions. It now purges every version of each track object and of the nominal key, likeremoveand the sweeper; the spec asserts those keys and thatdeleteObjectis not called.seconds, under-billing it where the single-file branch has always billed probed audio (fix(ai): usage costs can be wrong for transcription, cached tokens and GenAPI #793).seconds += lengthnow runs before the check, with a case assertingaudioSeconds: 90, ok: false.createdByinfindFirst, so a dropped predicate would pass — it now applies both predicates and a case proves a non-uploader gets the bare 404 while an admin proceeds. The sum fixture moved below the byte ceiling (400 + 500) so it cannot be read as a clamped value; the valid-manifest expectation now handsreadTracksfrozen copies so an in-place rewrite throws; the missing-track 400 asserts the row,memo.deleteand the purge were untouched; the worker's claim status is both applied by the fake and asserted on the call; the merge fixture's largest end is no longer its last segment and its language is no longer the only non-null one (14 vs 12,ruoveren).audioKey, which can throw and stall the batch” —Memo.audioKeyis non-nullable (schema.prisma:4857), a tracks create always writes the nominalsource<ext>key, and the unguarded call is the branch's pre-existing shape ondev;purgeObjectVersions('')matches no key.participantNamesaccepts a source-less roster entry, contradicting the read it mirrors” — the read defaults an absentsourcetomanual(memos.service.ts,parseParticipants), which is exactly what the helper does; its JSDoc now says so. The behaviour was correct, the comment was not.CHANGELOG.md; the generated-artefacts slice carried it and confirmed the entry.No finding was deferred.