Skip to content

feat(memos): the consent screen, the enrollment settings and the admin switch - #1560

Merged
hrustalq merged 5 commits into
devfrom
feat/1555-voice-consent
Dec 3, 2026
Merged

hrustalq merged 5 commits into
devfrom
feat/1555-voice-consent

Conversation

@hrustalq

@hrustalq hrustalq commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

Closes #1555
Refs #1403
Refs #1400

What this ships

The voice feature's surface: the person's consent card on Settings → Profile, the workspace admin's switch and
enrolled count on Settings → Features, and the small admin API that carries them. No person's route changes, no
schema, no migration, no matching, no memo-page UI.

The admin API — a dedicated, admin-only pair

GET | PUT /v1/workspaces/:id/voice-settings, declared by VoiceSettingsController under
@Controller('v1/workspaces') beside HomeController (the house shape for a second controller on the same base),
both @Access('admin', 'workspace'). The answer is VoiceSettingsResponse: the stored voiceProfiles policy
(null off / 'allow' on), ceilingEnabled (VOICE_PROFILES_ENABLED), enabled (both on) and enrolledCount.

  • The read works with the ceiling off. The person's routes answer a bare 404 there; an admin screen that hid the
    switch could not say why it is unavailable, which the doc's § Fallback asks it to. The write refuses 409
    ceiling-off
    with error.voice.ceilingOff and writes nothing — an admin cannot turn on what the env left off.
  • The count is active consents: prisma.voiceProfile.count({ where: { workspaceId, revokedAt: null } }). A row
    whose embedding failed still counts (it is a consent); a withdrawn row does not. No query selects a user id, a
    vector or a sample key.
  • The write is audited only when it moved: workspace.voice_profiles_updated with params { from, to } and
    target: workspaceId; a no-op write records nothing (the audit spec's "no action that nothing records" gate
    covers the new action).

The person's screen

VoiceProfileSection mounts below the Profile page's two groups, full width — a biometric consent is a third
consequence, not a row in "Profile" or "Signing in". It renders nothing when the GET answers 404 (either gate off
is "not offered", not an error) and a retry line for any other failure. States: not enrolled (consent text, an
unchecked checkbox, controls disabled until checked), enrolled (the date, the sample count, re-enroll, withdraw,
delete), withdrawn (the date, the enroll flow again), busy, and a refused sample rendered inline through the
reason map — never a toast, because the person must read why.

The consent text is the doc's § Consent block verbatim, one version (v1), in en and ru; the POST echoes the
consentVersion the screen showed. Re-enroll is the same flow and requires a fresh checkbox — consent is not
inherited. Withdraw keeps the revoked row and deletes the signature; delete removes both; delete is the destructive
confirm.

The admin screen

VoiceRecognitionPanel follows the purpose/features form, inside the admin branch, and saves on change — it never
rides the page's Save. It shows the stored choice (not the effective one), disables the box with the ceiling off and
names VOICE_PROFILES_ENABLED; the count uses plural copy and is the only per-workspace answer.

Recording and the sample

getUserMedia runs on click only; MediaRecorder uses audio/webm;codecs=opus when supported, else the browser's
default. The timer is wall-clock from the start and ends the take at 60 s; Stop is disabled under 30 s. Every
track is stopped in the release path and on beforeUnmount, and the take becomes a File that one multipart POST
carries and then drops — no object URL, no storage entry, no reference after the answer. Uploads have no client-side
duration bound: the browser cannot read an arbitrary file's duration, so the server's 422 is the refusal, rendered
inline through the same map.

The POST goes through http (axios), not api.post: that route's typed body is the JSON DTO, so the typed client
would serialise a File as JSON. No Content-Type is set by hand — axios writes the boundary — and the existing
cookie/CSRF/locale/trace interceptors apply unchanged.

Divergences, named

  1. A new route, not "the existing settings PATCH". The doc's § Operations / route table says the workspace
    policy "rides the existing settings PATCH, no new route". No such PATCH exists (PATCH /v1/workspaces/:id only
    renames), so the settled decision is the dedicated analytics/settings-shaped pair above. The doc's row is the
    sentence this supersedes; it is not edited here because the task's deliverable list does not carry the doc.
  2. The issue's SettingsPage.vue line is answered "no new page". There is no nav row, router change or
    meta.feature: the person's card lives on the existing Profile page and the admin panel on the existing Features
    page. SettingsPage.vue, the router and nav.ts are untouched.
  3. The issue's apps/web/src/shared/api/ line is answered by the existing client. The calls live in the module's
    model/voice-api.ts on api/http; shared/api/ gains no file. The reads use apiQueryOptions, the app's one
    read path, so voice-api.ts carries the calls that builder cannot express (multipart, the mode-bearing DELETE, the
    PUT).
  4. profileSettings.voice.uploadHint, not upload.hint. The copy list gives upload as a label and
    upload.hint as a hint; one JSON node cannot be both a string and a namespace, so the hint is a flat sibling and
    t('profileSettings.voice.upload') stays a label.
  5. The async one-voice refusal has no reason on the screen. The POST answers before the worker embeds; a
    multiple-voices refusal deletes the row and the next read is not-enrolled. That is the doc's async shape, and the
    screen deliberately has no "failed" state for it.
  6. One extra audit action (workspace.voice_profiles_updated) beyond the three voice.* the doc names, because
    the admin's policy write is a new write; the three person actions stay 2.2a/b's.
  7. The ru plurals carry four forms, not the three the copy list gave. The app's Russian rule
    (russianPluralRule) picks form 0/1/2/3 for 0/1/2–4/5+, so a three-form string puts a count of two on the 5+ copy
    («2 участников зарегистрированы»). features.voice.count and profileSettings.voice.samples therefore carry the
    «2 участника / 5 участников» pair, and a model case pins it. English keeps its two/three forms: its default rule
    maps 0 onto the plural copy, which is correct.

Per-criterion table

#1403's acceptance rows this task touches:

#1403 criterion status evidence
A workspace admin can enable/disable the feature but cannot enroll another person or read an embedding met VoiceSettingsController is admin-only; the response is five fields, the count a number; no route here takes a user id. voice-settings.spec.ts pins the ACL metadata and the field set
Settings shows enrolled/not enrolled, re-enroll and delete; deleting purges the row and the vector met (this task's half) VoiceProfileSection states + smoke: enroll → date and count; delete → not enrolled, row and sample object gone; withdraw → withdrawn with its date. The vector purge itself is 2.2b's (voice.service.ts), untouched
A second user cannot enroll for another; an admin sees only enrolled/not enrolled, never the vector met The admin answer has enrolledCount only; the person's routes keep taking the principal (2.2a, untouched). No new surface names a person
With the workspace feature off, enrollment is unavailable and no profile is written met Smoke: ceiling off → section absent, switch disabled with the notice, direct PUT 409 ceiling-off, stored value unchanged
Consent is a versioned screen: what is stored, why, who can use it, how to delete; explicit opt-in met The doc's block verbatim in en/ru, VOICE_CONSENT_VERSION shown and echoed; checkbox starts unchecked; re-enroll re-asks
Specs cover consent version, deletion, cross-workspace isolation and the admin boundary met (this task's rows) voice-settings.spec.ts: count predicate, ceiling refusal, audit-on-move, ACL metadata, DTO; the 2.2a/b specs cover consent version, deletion and cross-workspace isolation
make verify met exit 0 on this head; see Verification

#1406 (phase 5) re-proves the durable browser gate: consent, deletion, guest and cross-workspace flows at three
widths, keyboard and both languages. This task's browser run is the bounded manual smoke below, not a committed spec.

Verification

  • make verify — exit 0: lint 9/9, typecheck 9/9, dependency rules 4/4, tests 4/4; web 787 tests (message-keys,
    catalogue parity, security labels included), API 5528 + 1 skipped, UI 4.
  • pnpm exec vitest run test/voice-settings.spec.ts test/voice.spec.ts — 44 tests, 2 files.
  • make api-client — the diff is the one new path, VoiceSettingsResponse and VoiceProfilesPolicy, the client,
    contract-responses.generated.ts and the docs reference; no other feature's route or type moved.

Manual smoke (throwaway database, API :3110, web :5180)

One run against a fresh knowledge_voice_1555 database, the model dir and VOICE_PROFILES_ENABLED=true:

  1. /settings/features: the switch off → count "No one is enrolled yet."; turned on through the UI → toast
    "Voice recognition updated.", count 0, no error.
  2. /settings/profile: the card appears below the two groups; the consent text renders with the bold lead-in and the
    model name as a code span; the checkbox starts unchecked.
  3. A 40 s sample → "Enrolled since 3 Dec 2026, 23:29", "1 sample"; the row is in PG, one .wav under
    workspaces/<ws>/voice/<user>/<profile>.wav, and voice.consent {consentVersion: 'v1'} in the audit. A 10 s file
    → the inline role=alert "That recording is shorter than 30 seconds." and nothing written.
  4. Delete → "Not enrolled", row and object gone, voice.revoked {mode: 'delete'}, count 0. Re-enrolled (the text
    shown again, fresh checkbox) and withdrawn → "Consent withdrawn on 3 Dec 2026, 23:33", row kept with revokedAt,
    object gone, voice.revoked {mode: 'withdraw'}, count 0.
  5. Restarted the API with VOICE_PROFILES_ENABLED=false: the panel shows the checked-but-disabled switch and
    "Unavailable on this server: VOICE_PROFILES_ENABLED is off…"; the profile page renders no card and no error; a
    direct PUT 'allow' answers 409 ceiling-off and the stored value stays allow.
  6. The recorder with a fake capture device (uncommitted Playwright harness): "1 s of 30–60 s" and "4 s" with Stop
    disabled, "32 s" with Stop enabled; stopping sent the take and the server refused it — sample-clipped
    ("That recording is distorted — the level is too high.") inline. Chrome's fake device emits a full-scale tone, so
    the take cannot pass the level check; the recording path is therefore proven from getUserMedia through the
    multipart POST to the server's 422 and its inline reason, and a successful synthetic enrollment is feat(memos): call participants phase 5 — evaluation, false-identification guardrails and release #1406's.

Every resource was torn down: the database dropped, the three ports free, the object-store bridge and the throwaway
harness removed.

Review

Independent review before opening this PR (spec + work, fresh contexts). The range was sliced by area — API service
and DTO, controller/contracts, the two API spec halves, the web model, the calls/panel/mounts, the card's script and
template, the model spec, and both catalogues — and every fix went through a delta round. An interrupted slice was
re-cut smaller and re-dispatched; none was read as a pass.

  • Fixed: the ru features.voice.count and profileSettings.voice.samples had three forms, so a count of two read
    «2 участников»; both carry the 2–4 form now and a model case pins it — 1bf4e51.
  • Fixed: a duplicate "follows the ceiling" GET assertion sat inside describe('PUT'); the GET suite already
    proves the same fields, so it is dropped — 1bf4e51.
  • Fixed: withdraw, delete and re-enroll were disabled only by busy, so a delete under a take left the recorder
    POSTing an enrollment for a row that no longer existed; all three are disabled while recording — 02d790e.
  • Fixed: the elapsed line mounted its live region with its content and wrapped the Stop button, so the
    announcement carried the control; the seconds own the live region now — 02d790e.
  • Fixed: a getUserMedia promise resolving after unmount could keep a stream running to its 60 s stop; the mount
    stops what arrived and records nothing — 0a2d2fb.
  • Fixed: the model spec only asserted "not the fallback" per reason; it now proves one distinct key per reason and
    that the fallback resolves in en and ru — 02d790e.
  • Fixed: a second click during getUserMedia's permission prompt opened a second stream, overwriting and leaking
    the first recorder and ticker; a starting flag closes that window and every control that depends on the take is
    disabled through it — e379211.
  • Rejected: "en profileSettings.voice.samples lacks a zero form." English has two plural categories, and the
    app's default rule (choice === 1 ? 0 : 1) renders a count of 0 as "0 samples", which is correct; the line is only
    drawn when enrolled anyway, and the agreed copy is two forms.
  • Deferred: none.

…n switch

Settings → Profile gains the person's voice card: the versioned consent text
(en and ru, `VOICE_CONSENT_VERSION = 'v1'`), one 30–60 s recording or upload,
the enrolled date and sample count, withdraw and delete. Re-enrolling shows the
text again and asks for a fresh checkbox; a refused sample renders its reason
inline; recording stops every track in its cleanup path and keeps no copy.

Settings → Features gains the workspace admin's switch and the enrolled count,
saved on change rather than with the page's Save. With the deployment's ceiling
off the box is disabled and the notice names `VOICE_PROFILES_ENABLED`; the
stored value stays visible so the admin's choice survives.

The pair behind them is a dedicated, admin-only
`GET | PUT /v1/workspaces/:id/voice-settings` (the `analytics/settings` house
shape): the read answers with the ceiling off so the screen can say why the
switch is unavailable — the person's routes keep their 404 — and the write
refuses 409 `ceiling-off`, auditing `workspace.voice_profiles_updated` only
when the value moved. The count is this workspace's active consents
(`revokedAt` null), a number and never a person or a vector.

Refs #1555
Refs #1403
Refs #1400
The permission prompt outlives a navigation: getUserMedia can resolve on an unmounted card, and the take would then run to its 60 s stop with nobody watching. Unmounting during the prompt now stops what arrived and records nothing.

Refs #1555
…suite

The russian rule picks form 0/1/2/3 for 0/1/2-4/5+, so the brief's three-form plural put a count of two on the 5+ copy («2 участников»). Both ru plural keys carry the four forms now, pinned by a case. The API spec's duplicate 'follows the ceiling' GET assertion inside describe('PUT') is dropped: the GET suite already proves the same three fields.

Refs #1555
… pinned per reason

Withdrawing or deleting under a recording left the take to POST an enrollment for a row that no longer existed; the three actions are disabled while a take runs. The elapsed seconds get their own live region instead of wrapping the Stop button, so the announcement is the time and not the control. The model spec now proves one distinct key per reason and that the fallback resolves in en and ru.

Refs #1555
Between the click and a running recorder the permission prompt leaves the button live, so a second click started a second getUserMedia; the first stream, recorder and ticker were then overwritten and leaked. A starting flag closes that window and every control that depends on the take (consent box, record, upload, withdraw, delete, re-enroll) is disabled through it.

Refs #1555
@hrustalq
hrustalq merged commit 012b2c7 into dev Dec 3, 2026
2 checks passed
@hrustalq
hrustalq deleted the feat/1555-voice-consent branch December 3, 2026 21:47
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