Skip to content

feat(memos): separate tracks, their presigned uploads and named attribution - #1549

Merged
hrustalq merged 2 commits into
devfrom
feat/1415-memo-tracks
Dec 3, 2026
Merged

hrustalq merged 2 commits into
devfrom
feat/1415-memo-tracks

Conversation

@hrustalq

@hrustalq hrustalq commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Closes #1415
Refs #1402
Refs #1400

What

A memo can now arrive as one track per speaker. POST /v1/memos accepts a tracks manifest instead of the single file — never both — and answers with one presigned PUT per track beside the existing upload; 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, no speaker_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. upload stays required (decision 3), still signing the nominal source<ext> key; a tracks caller ignores it. Caps: 1–50 tracks, key ≤ 80, participantExternalId ≤ 200, each a MEMO_FORMATS extension.

Why the client names a key and the server the object

The 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 carries key, participantExternalId, filename and sizeBytes; the service mints the row first and stores the doc's MemoTrack shape { key, participantExternalId, audioKey } with audioKey derived as track-<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

create starts with hasTracks === (input.filename !== undefined) → 400 error.memo.oneSource (the notes.service.ts sources !== 1 precedent). The DTO makes the file trio required only when tracks is 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 against MEMO_FORMATS and refused with the existing error.memo.unsupportedFormat naming the track's filename; duplicate keys are refused with error.memo.tracksInvalid.

Finalize, the sum, and no single stream

finalize parses the stored manifest first: invalid → 400 error.memo.tracksInvalid and the row stays. tracks → HEAD every object, refuse a missing one with error.memo.uploadMissing, sum the lengths and apply maxBytes to the sum (the whole recording), then the same guarded updateMany on pending with sizeBytes: 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: audioAvailable is false, GET /v1/memos/:id/audio answers 410 error.memo.audioGone, and remove purges the nominal key and every track object. MemoRetentionSweeper selects tracks in 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

readTracks runs once at the top of transcribe. invalid fails the memo with error.memo.tracksInvalid on the existing fail(row.id, 'transcribing', …) path and transcribes nothing. tracks → for each track: download to source-<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 get speaker: trackLabel(row.participants, track): the participant whose folded name is the track's participantExternalId (the same foldName 1.2 uses), else the track's key. The parts go through mergeTrackTranscripts: chronological, ties in manifest order, renumbered from 0, emitting exactly { i, start, end, text, speaker }. durationSeconds is the largest segment end, not the sum of the tracks; language is the first non-null part; one memo.update. The bill box 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)

criterion status evidence
A two-track manifest yields two correctly attributed speakers without a voice profile. met apps/api/src/memos/transcript.ts (readTracks, trackLabel, mergeTrackTranscripts); worker branch in memos.processor.ts; specs transcribes each track on its own, labels it and merges…, presigns one URL per track…
A mixed file still produces Speaker 1..N exactly as today. met readTracks returns none for null and the branch keeps speech.speakers and the error.memo.speaker voice callback; spec keeps the single-file path for a mixed memo
A track key outside the memo prefix is refused. met the caller names no audioKey (request shape above); the stored manifest is refused unless every key starts workspaces/{ws}/memos/{id}/ and has no .. — readTracks, spec refuses a manifest with a bad entry, a duplicate key or a foreign object…; finalize answers 400 and the worker fails the memo
Memo specs and make verify pass. met make verify exit 0: API 350 files / 5392 tests; web 105/776; admin 1/2 (api lint, typecheck, depcruise and test all cache miss)

#1402 rows advanced

row status evidence
A two-track manifest yields two named speakers and a participant list; a mixed file yields numbered speakers plus the roster. met the transcript carries the label; the roster is 1.1/1.2's memos.participants, read by GET /v1/memos/:id; spec transcribes each track on its own… (Ada from the roster, bob from the key) and keeps the single-file path…
The upload path accepts tracks: [{ key, participantExternalId, audioKey }] and each audioKey sits under the memo's prefix. met, per decision 2 the request omits audioKey and the server derives it under the prefix; the stored row is the doc's shape and readTracks is the prefix guard (see Divergences)

Verification

  • make db-generate — Memo['tracks'] typechecks.
  • Migration 20270222100000_memo_tracks/migration.sql is one line, produced without a database:
    ALTER TABLE "memos" ADD COLUMN "tracks" JSONB;
  • Proven on a throwaway database (memo_tracks_probe, created and owned for this check, then dropped): prisma migrate deploy applied all migrations, information_schema.columns reported tracks | jsonb | YES, an INSERT naming no tracks read tracks 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; only openapi.json, contract-schemas.json and packages/api-client/src/schema.d.ts changed (the docs reference table does not list request/response bodies).
  • Load-bearing spot checks: removing the readTracks prefix 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

  • The doc's MemoTrack.audioKey is 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 derives audioKey; the stored row is the doc's shape, so a retry resumes from it (decision 2).
  • Files beyond the issue's five. 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.ts and CHANGELOG.md.
  • i18n.generated.ts is hand-updated to the exact bytes the dev generator writes. make api-schema boots the Nest app without init(), so the nestjs-i18n generator (which runs at bootstrap) does not rewrite it; leaving it stale would dirty the tree on the next make 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.

  • Fixed: 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 ever purge those versions. It now purges every version of each track object and of the nominal key, like remove and the sweeper; the spec asserts those keys and that deleteObject is not called.
  • Fixed: a track probed over the minute ceiling was not added to 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 += length now runs before the check, with a case asserting audioSeconds: 90, ok: false.
  • Fixed: the tracks spec harness ignored createdBy in findFirst, 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 hands readTracks frozen copies so an in-place rewrite throws; the missing-track 400 asserts the row, memo.delete and 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, ru over en).
  • Rejected: “the expired retention branch purges a null audioKey, which can throw and stall the batch” — Memo.audioKey is non-nullable (schema.prisma:4857), a tracks create always writes the nominal source<ext> key, and the unguarded call is the branch's pre-existing shape on dev; purgeObjectVersions('') matches no key.
  • Rejected: “participantNames accepts a source-less roster entry, contradicting the read it mirrors” — the read defaults an absent source to manual (memos.service.ts, parseParticipants), which is exactly what the helper does; its JSDoc now says so. The behaviour was correct, the comment was not.
  • Rejected: “the changelog has no entry for feat(memos): call participants 1.3 — separate tracks and named attribution #1415” — a slice artifact: that reviewer's input did not include CHANGELOG.md; the generated-artefacts slice carried it and confirmed the entry.

No finding was deferred.

…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
@hrustalq
hrustalq merged commit ff0149e into dev Dec 3, 2026
2 checks passed
@hrustalq
hrustalq deleted the feat/1415-memo-tracks branch December 3, 2026 12:11
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.

1 participant