Repository navigation
feat(memos): the enrollment surface, its gates and the consent record - #1558
Merged
Merged
Conversation
`GET | POST | DELETE /v1/me/voice-profile` is the person's own surface in one workspace: three gates read on execution (the env ceiling, the workspace's `voice_profiles` column, the person's echoed consent version), two quality checks over the upload, the `voice_profiles` row as the consent record, the sample object and the queue job as one act, and a delete that purges the vector and every version of the sample before the row. The embedding, the `VoiceProfile` write and the sample purge stay with #1557; `VOICE_PROFILES_ENABLED` keeps the whole feature dark until then. Refs #1554
…e targets Independent review of the spec found six places where a case only proved the class of a refusal or the fact of a call: the bare 404 body is now asserted on all three routes (and that no row, vector, sample version, job or audit row was touched behind the gate), a missing consent version answers the same 409 `consent-version` body as a wrong one, the successful enrollment pins exactly one upsert, one object, one job and one audit row, the bare delete names the vector and the purge target, and the key builders are interpolated on two profiles. Also corrects the clipped-peak JSDoc: the rule is `max > -0.1`, so exactly -0.1 dB passes and "at or above" was a sentence the code contradicted. Refs #1554
…sals The second review round found the band read from the constants under test — so a changed bound would carry its cases with it — and the cleanup asserted on the accepted path only. The bounds are now literal and the constants pinned to them, and both refusal exits (the duration short-circuit and a silent sample) prove the temp copy is gone. Refs #1554
The delta review of the previous fix found the one assertion the other refusals already carried: a stale or missing consent version writes no audit row either. Refs #1554
This was referenced Dec 3, 2026
Closed
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 #1554
Refs #1403
Refs #1400
The API half of 2.2: the person's enrollment surface, the three gates, two quality refusals, the consent row and the sample hand-off. Nothing here computes an embedding and nothing here mounts a UI — the ONNX graph, the vector write,
voice.enrolledand the sample purge after embedding are #1557.The row is the consent record, and the API writes it
voice_profiles(#1553) already holds one row per(workspace, user)with the pinnedmodel/dimensionpair, the consent version andrevoked_at. This PR fills it:POST /v1/me/voice-profileupserts on that pair —modelanddimensionfrom the constants,sample_count: 1,consented_at: now,revoked_at: null— so a re-enroll updates the one row and clears a withdrawal instead of colliding with its own key. The doc's GET has two states, enrolled and not, so the row is written at enrollment time and the vector lands asynchronously;enrolledtherefore means "a consent record exists and has not been withdrawn", which is what the contract's JSDoc says. A failed embedding leaves a row that cannot match, and re-enrolling fixes it — the doc's "no sweeper" already accepts that shape.The row, the object and the job are one act from the reader's side: if
putObjectBytesor the enqueue throws, the row is removed again and the error rethrown, so nothing reads as enrolled that will never be embedded.The workspace rides the query
All three routes declare
@Access('viewer', 'query')and@SessionOnly(). A multipart body is parsed by an interceptor that runs after the guards, so'body'cannot resolve the workspace on the POST — the same reasonmemory-upload.guard.tsexists.@SessionOnly()keeps akn_API key out of a biometric write: enrollment is an authenticated session act (doc 89 § Open questions), and a key outlives the browser it was minted in. A guest failsviewer. The person's id comes only from the principal: there is no id in the path and none accepted from the request, which is the admin boundary in its strongest form — there is nothing to point at somebody else.Three gates, read on execution
VOICE_PROFILES_ENABLED(the platform ceiling, default false).workspace_settings.voice_profiles—'allow'is the only value that opens it;nulland anything else close it.consentVersionmust equalVOICE_CONSENT_VERSION, else 409consent-version.Either of the first two answers a bare 404 on all three routes, the notes routes' rule and doc 89 § Fallback's "no enrollment route" — a workspace with recognition off must not confirm that the feature exists. Nothing is read or written behind the refusal.
Two quality checks, the third deferred
voice-quality.tsholds the duration band (30–60 s inclusive), the signal level (mean below −45 dB is silence, peak above −0.1 dB is clipped) and the unreadable case, as pure parsers plus one injectable seam, so the unit suite never needs ffmpeg — thespeech/audio.tsparsePausesprecedent. Each refusal is a stable kebab reason (sample-too-short,sample-too-long,sample-silent,sample-clipped,sample-unreadable, plus the service'ssample-missingandconsent-version) witherror.voice.*copy in en and ru, because 2.3 branches on the reason and renders the message. The upload is written to a throwaway copy for ffprobe/ffmpeg and the directory is removed on every path, refusals included.The one-voice check is #1557's: it compares two halves of the embedding and needs the model this task does not load.
Real files, one manual pass through the built gate (ffmpeg 8.0.1, 16 kHz mono):
The sample key and the version purge
storage.voiceSampleKey(ws, userId, profileId, ext)→workspaces/{ws}/voice/{userId}/{profileId}.{ext}, the extension lower-cased from the client's filename (binwhen absent, and anything that is not a short alphanumeric run is replaced — an extension is a path segment). One object per profile, under the workspace prefix, so a teardown purges it and a re-enroll overwrites it.A delete cannot rebuild the exact key: the extension is not stored on the row (the table has no filename column, and this PR adds none). So the purge is
purgePrefixover the profile's own…/{profileId}.— a UUID, so it can only match that profile's one object — and it removes every version of it, never a delete marker. That is decision 11's substance: a versioned bucket keeps every byte of an overwritten object.Both delete shapes remove the vector first (
GraphService.deleteVoiceProfile,DELETE FROM VoiceProfile WHERE profileId = … AND workspaceId = …— both predicates;DELETE VERTEXdoes not parse on the pinned ArcadeDB), then the sample, then the row (?mode=withdrawsetsrevokedAtinstead). Nothing writes a vertex until #1557, so the vector delete is a no-op today and is called anyway: the row and the vector die together.Two audit actions
AUDIT_ACTIONSgainsvoice.consentandvoice.revoked, and notvoice.enrolled— #1557 writes that one when the embedding lands, and the audit spec fails on a value nosrcfile writes.voice.consentcarries the workspace, the person, the consent version andok;voice.revokedcarries the mode (withdrawordelete). Neither carries the embedding, the vector, the sample, the file name or the consent text. Both fall underauditCategoryOf's default'data', so no prefix map changed.The queue without a consumer
VOICE_QUEUE('voice'),VoiceQueueModuleandVoiceProducerin thememos-queue.module.tsshape:enqueue(profileId)adds{ profileId }withjobId: profileId, so one profile has one pending job and a finished one can be added again.MONITORED_QUEUESnames it, because a queue with no consumer must be visible rather than hidden. The processor is #1557, andVOICE_PROFILES_ENABLEDdefaults false, so no deployment can queue one.Leaving a workspace
WorkspacesService.removeMemberremoves that workspace's profile (vector, sample versions, row) throughVoiceProfileService.removeForMember— one owner for the delete order. Only this workspace's row is in scope; the same person's profile elsewhere is untouched, proved by a fake that applies the(workspaceId, userId)predicate.It runs after the guarded membership removal, not before:
removeMemberGuardedrefuses a last admin, and a profile deleted ahead of a refused removal would be a worse loss than the window the doc already accepts ("matching skips a profile whose owner is no longer a member even before that delete runs").The migration
One additive, nullable column, generated with
prisma migrate diff --from-schema-datamodelagainstdev's schema and replayed by hand (the app role does not own_prisma_migrations):scratch_1554was created for it and dropped afterwards. No default, no backfill, no index; a rollback drops the column and leaves every row as it was.Per-criterion table — #1403's acceptance rows this task touches
writes one row, one object and one job,re-enrolls in place…,withdraws: the vector and every version of the sample go…;deleteVoiceProfilecarries both predicates and is a no-op until a vertex existsnever answers another workspace's or another person's row…); the state is exactly five fields (carries no embedding…)answer a bare 404 on all three routes when …, three gate cases, nothing writtenrefuses a consent version…,deletes: the same order…,removeForMember…leaves the same person's profile elsewhere,never answers another workspace's…make verifyDivergences and deferrals
workspace_settings.voice_profileslands here, though doc 89 § Operations tags it 2.3. The gate that reads it is this task's, and the column is what feat(memos): call participants 2.1 — voice_profiles, the VoiceProfile vertex and the deletion inventory #1553's decision 2 recorded. No writer ships: 2.3 adds the admin PATCH.voice.enrolled/the writer named). A phase label the next worker would trust.voice.enrolledis feat(memos): call participants 2.2 — the ONNX voice embedding, the profile vector and the sample purge #1557's; one-voice is feat(memos): call participants 2.2 — the ONNX voice embedding, the profile vector and the sample purge #1557's. Only the two actions this code writes joinedAUDIT_ACTIONS.removeMemberdeletes the profile after the guarded membership removal, not before — the doc explicitly tolerates the window, and the reverse order can destroy a profile for a member whose removal was refused.EnrollVoiceDto, not asmultipart/form-data. Amultipart/form-datacontent key in this schema makes the generated client'suseMutation(apiMutationOptions(…))infer its variables asundefined: measured,KnowledgeHealthPage.vuefails typecheck with the key present and passes without it, and a$refbody under that key fails the same way. Teaching the shared client a non-JSON body is its own change; the handler and its JSDoc are the truth about the encoding until then.apps/web/src/shared/i18n/messages/{en,ru}.jsongain the two audit labels, which the issue's file list omits:security-labels.spec.tsfails everyAUDIT_ACTIONSvalue without a label in both languages.i18n.generated.tsregen carries only this group — the run also surfaced threenote.quota*keys a merged task never regenerated; they are reverted so the file's diff is this feature's.RoleSyncService(IdP group sync, SCIM) does not purge the profile. This task was givenremoveMember; a non-member's profile is never matched because PG is the truth on read, and the purge belongs with the read side (feat(memos): call participants 2.2 — the ONNX voice embedding, the profile vector and the sample purge #1557) or a follow-up.Review
Independent review before opening this PR: spec + work, fresh context, the committed range sliced by area (service, controller, quality gate, four spec slices, module wiring,
removeMember, graph/storage primitives, contracts/migration, i18n, changelog/doc, the documented contract — the last three re-run after their first child timed out).make verifyexited 0 on every head that was reviewed, and each fix round was re-reviewed as a delta.Fixed
voice-quality.ts— the clipped-peak JSDoc promised "at or above" while the rule ismax > -0.1. Corrected the sentence (exactly −0.1 dB passes) rather than the rule the brief fixes, and named it here because the code would otherwise contradict its own comment. →73db2fba{ message: 'Not Found', statusCode: 404 }on all three routes, and that no row, vector, sample version, job or audit row is touched behind the gate. →73db2fbaupsertbut not thatupdate,delete,deleteVoiceProfileor the sample purge stayed quiet. →73db2fbaconsent-versionbody as a stale one (73db2fba) and audits nothing (f8c51b36).73db2fba73db2fba73db2fba2d5bff552d5bff55Rejected
test/voice-quality.spec.ts) and was reviewed by its own child, which then found the two real gaps above.Deferred — the items under Divergences and deferrals: the vector write,
voice.enrolled, the one-voice check and the post-embedding sample purge (#1557); the profile purge on an IdP/SCIM removal; teaching the shared client a non-JSON body before 2.3 calls this POST.net:eight files underapps/api/src/voiceplus their two specs, no new dependency, no processor, no UI, no new env var; the delete order exists once and both callers share it.