Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/added-inbox-recording-delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Inbox: hive recordings get a 🗑 Delete action. It removes the audio stored on the hive, the Inbox item and the recording's Knowledge fact with its transcript, after an in-page confirm that says shared copies (RFCs, issues, DIBS ideas, spek seeds) stay. Owners can delete any recording, read-write members only their own, read members none; each delete is audited as `inbox_recording_delete` (`DELETE /api/inbox/hive-recording/{id}`).
91 changes: 91 additions & 0 deletions dashboard/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -41363,6 +41363,97 @@
}
}
},
"/api/inbox/hive-recording/{id}": {
"delete": {
"tags": [
"Knowledge"
],
"summary": "Delete a hive recording",
"description": "An owner, or the read-write member who recorded it. Deletes a finished recording for good: its stored audio and chunks, the Inbox item and its state, and its Knowledge fact with the machine transcript. What was already shared from it (RFC, issues, DIBS ideas, spek seeds) is not touched. Audited as `inbox_recording_delete`.",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string"
},
"description": "Recording id (the Inbox item id)"
}
],
"responses": {
"200": {
"description": "Deleted",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"deleted": {
"type": "boolean"
},
"fact_removed": {
"type": "boolean"
},
"shares_kept": {
"type": "integer"
}
}
}
}
}
},
"403": {
"description": "Read role, or a read-write member deleting someone else's recording",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
}
}
}
}
},
"404": {
"description": "Unknown recording",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
}
}
}
}
},
"409": {
"description": "Still in progress, or being transcribed",
"content": {
"application/json": {
"schema": {
"type": "object",
"properties": {
"error": {
"type": "string"
}
}
}
}
}
}
}
}
},
"/api/inbox/recordings/{id}": {
"delete": {
"tags": [
Expand Down
2 changes: 1 addition & 1 deletion dashboard/test/inbox-item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function makeContext(role) {
Array,
};
vm.createContext(ctx);
for (const fn of ['inboxSharePillText', 'inboxShareTargetHref', 'inboxSharePillHtml', 'inboxSharePillsHtml', 'inboxCanShare', 'inboxIntentLabel', 'inboxIntentThen', 'inboxSourceIcon', 'inboxItemHasAudio', 'inboxItemKey', 'inboxViewerCanPlay', 'inboxApiPath', 'inboxFmtDuration', 'inboxStatePill', 'inboxSummaryHtml', 'inboxTranscriptHtml', 'inboxTxUnavailableText', 'inboxTxEtaText', 'inboxTxElapsedText', 'inboxTxProgressHtml', 'inboxTranscriptionHtml', 'inboxItemHtml']) {
for (const fn of ['inboxSharePillText', 'inboxShareTargetHref', 'inboxSharePillHtml', 'inboxSharePillsHtml', 'inboxCanShare', 'inboxIntentLabel', 'inboxIntentThen', 'inboxSourceIcon', 'inboxItemHasAudio', 'inboxItemKey', 'inboxViewerCanPlay', 'inboxApiPath', 'inboxFmtDuration', 'inboxStatePill', 'inboxSummaryHtml', 'inboxTranscriptHtml', 'inboxTxUnavailableText', 'inboxTxEtaText', 'inboxTxElapsedText', 'inboxTxProgressHtml', 'inboxTranscriptionHtml', 'inboxCanDeleteRecording', 'inboxItemHtml']) {
vm.runInContext(extractFunction(fn), ctx);
}
return ctx;
Expand Down
1 change: 1 addition & 0 deletions src/docs/api-reference/knowledge.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Part of the [Dashboard REST API reference](../api-reference.md); see that page f
| `POST` | `/api/inbox/recordings/{id}/finalize` | The recorder | End a recording: `{duration_ms?}` (the recorder's count, pauses excluded). The chunks are concatenated in order into `audio.webm` or `audio.mp4`, a pending Knowledge fact (personal layer) is written and the item appears in the Inbox. 200 `{id, state, title, duration_ms, bytes, chunks, transcribes}`; audited as `inbox_recording_finalize` (400 no chunk received, 403, 404, 409 already ended) | `pkg/dashboard/api_inbox_recordings.go:22` |
| `DELETE` | `/api/inbox/recordings/{id}` | The recorder, or an owner | Abort an in-progress recording and delete its chunks; audited as `inbox_recording_abort` (403, 404, 409 already ended) | `pkg/dashboard/api_inbox_recordings.go:23` |
| `GET` | `/api/inbox/recordings/{id}/audio` | Owner or read-write | Play a finished recording from this hive's disk on the dashboard origin: `http.ServeContent` (Range, 206), `Content-Type` audio/webm or audio/mp4, `Cache-Control: no-store`, `Cross-Origin-Resource-Policy: same-origin`. Opening a playback is audited as `inbox_recording_audio` (seeks are not). `GET /api/inbox/hive-recording/{id}/audio/stream` serves the same file (404 unknown or not finished, 410 audio expired after `inbox.recording.retention_days`) | `pkg/dashboard/api_inbox_recordings.go:24` |
| `DELETE` | `/api/inbox/hive-recording/{id}` | An owner, or the read-write member who recorded it | Delete a finished recording for good: its stored audio and chunks, the Inbox item and its state, and its Knowledge fact with the machine transcript. What was already shared from it (RFC, issues, DIBS ideas, spek seeds) is not touched. 200 `{id, deleted, fact_removed, shares_kept}`; audited as `inbox_recording_delete` (403 read role or someone else's recording, 404 unknown, 409 still in progress or being transcribed) | `pkg/dashboard/api_inbox_recordings.go:25` |
| `GET` | `/api/meetings/settings` | Owner only | Meetings settings: `enabled`, `enabled_env_override`, `running`, `vexa_url`, `vexa_key_set`, `discord_token_set`, `transcribe_token_set`, `tts_token_set` (secrets are never returned) and `effective` values of the other `meetings.*` keys ([env vars](../env-vars.md#meetings-quorum)) | `pkg/dashboard/api_meetings.go:123` |
| `POST` | `/api/meetings/settings` | Owner only | Update `meetings.enabled` and `meetings.vexa.url`, and write the Vexa tenant key, Discord bot token, transcription service token and TTS service token to keystore-sealed secret files (`""` clears one): `{enabled?, vexa_url?, vexa_api_key?, discord_token?, transcribe_token?, tts_token?}`. Returns the settings with `restart_required`; 400 on an invalid value. Audited as `meetings_settings` | `pkg/dashboard/api_meetings.go:124` |
| `POST` | `/api/meetings` | Owner only | Send hive to a meeting: `{url}` for Google Meet, Teams or Zoom, or `{platform: "discord", guild_id, channel_id}`, plus `title?` and `voice?`. Returns the meeting record; 400 invalid request, 502 Quorum refused, 503 meetings off. Audited as `meeting_join` | `pkg/dashboard/api_meetings.go:125` |
Expand Down
12 changes: 12 additions & 0 deletions src/docs/inbox-recording.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ HTTP. The transcript is written into the recording's Knowledge fact.
- Transcription limits (`max_bytes`, `max_duration_minutes`, daily and
monthly budgets) apply as for every other source.

## Deleting a recording

**🗑 Delete** on a recording's Inbox item deletes it for good: the audio
stored on this hive (and any chunk left over), the Inbox item and the
recording's Knowledge fact with its transcript. Owners can delete any
recording; read-write members only the ones they recorded; read members
cannot. The dashboard asks first, in the page; when the item was shared, the
question says that what was already shared (RFCs, issues, DIBS ideas, spek
seeds) stays where it is, because delete never touches those copies. A
recording that is being transcribed can be deleted once the transcription
finishes. Every delete is audited as `inbox_recording_delete`.

## Retention

| What | Kept |
Expand Down
32 changes: 31 additions & 1 deletion src/pkg/dashboard/api_inbox_recordings.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (s *Server) registerInboxRecordingRoutes() {
s.mux.HandleFunc("POST /api/inbox/recordings/{id}/finalize", s.handleInboxRecordingFinalize)
s.mux.HandleFunc("DELETE /api/inbox/recordings/{id}", s.handleInboxRecordingAbort)
s.mux.HandleFunc("GET /api/inbox/recordings/{id}/audio", s.handleInboxRecordingAudio)
s.mux.HandleFunc("DELETE /api/inbox/hive-recording/{id}", s.handleInboxRecordingDelete)
}

// inboxRecordingStartRequest is POST /api/inbox/recordings.
Expand Down Expand Up @@ -100,7 +101,8 @@ func writeInboxRecordingError(w http.ResponseWriter, err error) {
code = http.StatusNotFound
case errors.Is(err, inbox.ErrRecordingNotYours):
code = http.StatusForbidden
case errors.Is(err, inbox.ErrRecordingClosed), errors.Is(err, inbox.ErrRecordingMismatch):
case errors.Is(err, inbox.ErrRecordingClosed), errors.Is(err, inbox.ErrRecordingMismatch),
errors.Is(err, inbox.ErrRecordingNotFinished), errors.Is(err, inbox.ErrRecordingTranscribing):
code = http.StatusConflict
case errors.Is(err, inbox.ErrRecordingConsent), errors.Is(err, inbox.ErrRecordingBadRequest), errors.Is(err, inbox.ErrRecordingEmpty):
code = http.StatusBadRequest
Expand Down Expand Up @@ -244,6 +246,34 @@ func (s *Server) handleInboxRecordingAbort(w http.ResponseWriter, r *http.Reques
jsonResponse(w, map[string]any{"id": m.ID, "aborted": true})
}

// handleInboxRecordingDelete deletes a finished hive recording: the stored
// audio and chunks, the Inbox item and its Knowledge fact (the machine
// transcript). Owners may delete any recording, read-write members only
// their own, read members none (403). What was already shared from it is
// not touched. 409 while it is in progress or being transcribed.
func (s *Server) handleInboxRecordingDelete(w http.ResponseWriter, r *http.Request) {
if !requireInboxPlaybackRole(w, r) {
return
}
svc, ok := s.inboxService(w)
if !ok {
return
}
asOwner := isOwnerRole(r.Header.Get("X-Hive-Role"))
res, err := svc.DeleteRecording(strings.TrimSpace(r.PathValue("id")), requestUser(r), asOwner, s.inboxRecordingOptions(r))
if err != nil && res.ID == "" {
writeInboxRecordingError(w, err)
return
}
if err != nil {
// The audio and metadata are gone; a leftover (fact, transcript
// record or item state) is logged, not reported as a failure.
s.logger.Warn("inbox: recording delete left something behind", "recording", res.ID, "error", err)
}
w.Header().Set("Cache-Control", "no-store")
jsonResponse(w, map[string]any{"id": res.ID, "deleted": true, "fact_removed": res.FactRemoved, "shares_kept": res.SharesKept})
}

// handleInboxRecordingAudio (owner or read-write) serves a finished
// recording from this hive's disk, on the dashboard origin, with Range
// support (http.ServeContent) and no-store. After retention the audio is
Expand Down
182 changes: 182 additions & 0 deletions src/pkg/dashboard/api_inbox_recordings_delete_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
package dashboard

import (
"bytes"
"context"
"encoding/json"
"net/http"
"net/http/httptest"
"os"
"path/filepath"
"strings"
"testing"
"time"

"github.com/hivecommons/hive/pkg/config"
"github.com/hivecommons/hive/pkg/inbox"
"github.com/hivecommons/hive/pkg/knowledge/connector"
)

// recordingDeleteOtherUser is a second read-write member: not the recorder.
const recordingDeleteOtherUser = "someone-else@example.com"

// doRecordingAs sends one request as role with an explicit user.
func doRecordingAs(s *Server, method, path, role, user string) *httptest.ResponseRecorder {
req := httptest.NewRequest(method, path, bytes.NewReader(nil))
if role != "" {
req.Header.Set("X-Hive-Role", role)
req.Header.Set("X-Hive-User", user)
if role == config.RoleOwner {
req.Header.Set(ownerRoleVerifiedHeader, "true")
}
}
rec := httptest.NewRecorder()
s.mux.ServeHTTP(rec, req)
return rec
}

// finishTestRecording records one chunk as role and finalizes it.
func finishTestRecording(t *testing.T, s *Server, role string) string {
t.Helper()
id := startTestRecording(t, s, role)
if rec := doRecording(s, http.MethodPost, chunkPath(id, 0), role, recordingWebM, nil); rec.Code != http.StatusOK {
t.Fatalf("chunk = %d %s", rec.Code, rec.Body)
}
if rec := doRecording(s, http.MethodPost, "/api/inbox/recordings/"+id+"/finalize", role, []byte(`{"duration_ms":4000}`), nil); rec.Code != http.StatusOK {
t.Fatalf("finalize = %d %s", rec.Code, rec.Body)
}
return id
}

func recordingDeletePath(id string) string { return "/api/inbox/" + inbox.RecordingType + "/" + id }

func recordingFactPath(src *inbox.RecordingSource, id string) string {
return filepath.Join(src.FactDir, connector.Slug(inbox.RecordingType, inbox.RecordingConnector, id)+".md")
}

func exists(path string) bool {
_, err := os.Stat(path)
return err == nil
}

func TestInboxRecordingDeleteRoleMatrix(t *testing.T) {
s, svc, src := newRecordingTestServer(t, config.InboxRecording{})
id := finishTestRecording(t, s, config.RoleReadWrite)
creator := config.RoleReadWrite + "@example.com"
dir := filepath.Join(src.Store.Dir, id)
if !exists(dir) || !exists(recordingFactPath(src, id)) {
t.Fatal("finalized recording has no audio dir or fact")
}
for _, tc := range []struct{ name, role, user string }{
{"anonymous", "", ""},
{"read", config.RoleRead, config.RoleRead + "@example.com"},
{"read as the recorder", config.RoleRead, creator},
{"read-write non-creator", config.RoleReadWrite, recordingDeleteOtherUser},
} {
if rec := doRecordingAs(s, http.MethodDelete, recordingDeletePath(id), tc.role, tc.user); rec.Code != http.StatusForbidden {
t.Fatalf("%s delete = %d %s, want 403", tc.name, rec.Code, rec.Body)
}
}
if !exists(dir) || !exists(recordingFactPath(src, id)) {
t.Fatal("a refused delete removed something")
}
rec := doRecordingAs(s, http.MethodDelete, recordingDeletePath(id), config.RoleReadWrite, creator)
if rec.Code != http.StatusOK || !strings.Contains(rec.Body.String(), `"deleted":true`) {
t.Fatalf("creator delete = %d %s", rec.Code, rec.Body)
}
if rec := doRecordingAs(s, http.MethodDelete, recordingDeletePath(id), config.RoleReadWrite, creator); rec.Code != http.StatusNotFound {
t.Fatalf("second delete = %d, want 404", rec.Code)
}

// An owner deletes a read-write member's recording.
id2 := finishTestRecording(t, s, config.RoleReadWrite)
if rec := doRecordingAs(s, http.MethodDelete, recordingDeletePath(id2), config.RoleOwner, config.RoleOwner+"@example.com"); rec.Code != http.StatusOK {
t.Fatalf("owner delete = %d %s", rec.Code, rec.Body)
}
if e := s.audit.Recent(1); len(e) != 1 || e[0].Action != "inbox_recording_delete" || !strings.Contains(e[0].Detail, "recording="+id2) || !strings.Contains(e[0].Detail, "recorded_by="+creator) {
t.Fatalf("delete not audited: %+v", e)
}
items, err := svc.Items(context.Background())
if err != nil {
t.Fatal(err)
}
for _, it := range items {
if it.Source == inbox.RecordingType {
t.Fatalf("deleted recording still listed: %+v", it)
}
}
}

// Delete removes the stored audio, the Knowledge fact with its machine
// transcript, and the transcript record; the share history count is
// reported and what was shared is not touched.
func TestInboxRecordingDeleteRemovesAudioAndFact(t *testing.T) {
s, svc, src := newRecordingTestServer(t, config.InboxRecording{})
store := inbox.NewTranscriptStore(filepath.Join(t.TempDir(), "transcripts"))
svc.EnableTranscription(store)
id := finishTestRecording(t, s, config.RoleReadWrite)
audio := filepath.Join(src.Store.Dir, id)
fact := recordingFactPath(src, id)
if err := store.Put(inbox.TranscriptRecord{Source: inbox.RecordingType, ID: id, Status: inbox.TranscriptionDone, Provider: "whisper", Model: "base.en", Text: "ship it", UpdatedAt: time.Now()}); err != nil {
t.Fatal(err)
}
if _, err := svc.Store.AppendShare(inbox.Key(inbox.RecordingType, id), inbox.ShareRecord{Destination: inbox.DestDibs, Actor: "owner@example.com", StartedAt: time.Now(), Status: inbox.StatusFiled, Ref: &inbox.ShareRef{URL: "https://dibs.example/1"}}); err != nil {
t.Fatal(err)
}

// Refused while its transcription runs: nothing is removed.
if err := store.Put(inbox.TranscriptRecord{Source: inbox.RecordingType, ID: id, Status: inbox.TranscriptionRunning, UpdatedAt: time.Now()}); err != nil {
t.Fatal(err)
}
if rec := doRecording(s, http.MethodDelete, recordingDeletePath(id), config.RoleReadWrite, nil, nil); rec.Code != http.StatusConflict {
t.Fatalf("delete while transcribing = %d %s, want 409", rec.Code, rec.Body)
}
if !exists(audio) || !exists(fact) {
t.Fatal("a refused delete removed the audio or the fact")
}
if err := store.Put(inbox.TranscriptRecord{Source: inbox.RecordingType, ID: id, Status: inbox.TranscriptionDone, Text: "ship it", UpdatedAt: time.Now()}); err != nil {
t.Fatal(err)
}

rec := doRecording(s, http.MethodDelete, recordingDeletePath(id), config.RoleReadWrite, nil, nil)
if rec.Code != http.StatusOK {
t.Fatalf("delete = %d %s", rec.Code, rec.Body)
}
var body struct {
Deleted bool `json:"deleted"`
FactRemoved bool `json:"fact_removed"`
SharesKept int `json:"shares_kept"`
}
if err := json.Unmarshal(rec.Body.Bytes(), &body); err != nil {
t.Fatal(err)
}
if !body.Deleted || !body.FactRemoved || body.SharesKept != 1 {
t.Fatalf("delete response = %+v", body)
}
if exists(audio) {
t.Fatal("audio directory survived the delete")
}
if exists(fact) {
t.Fatal("knowledge fact survived the delete")
}
if _, ok := store.Get(inbox.RecordingType, id); ok {
t.Fatal("transcript record survived the delete")
}
if h := svc.Store.History(inbox.Key(inbox.RecordingType, id)); len(h) != 0 {
t.Fatalf("item state survived: %+v", h)
}
if rec := doRecording(s, http.MethodGet, "/api/inbox/recordings/"+id+"/audio", config.RoleReadWrite, nil, nil); rec.Code != http.StatusNotFound {
t.Fatalf("audio after delete = %d, want 404", rec.Code)
}
}

func TestInboxRecordingDeleteInProgressAndUnknown(t *testing.T) {
s, _, _ := newRecordingTestServer(t, config.InboxRecording{})
if rec := doRecording(s, http.MethodDelete, recordingDeletePath("nope"), config.RoleOwner, nil, nil); rec.Code != http.StatusNotFound {
t.Fatalf("unknown = %d, want 404", rec.Code)
}
id := startTestRecording(t, s, config.RoleReadWrite)
if rec := doRecording(s, http.MethodDelete, recordingDeletePath(id), config.RoleReadWrite, nil, nil); rec.Code != http.StatusConflict {
t.Fatalf("in-progress delete = %d %s, want 409", rec.Code, rec.Body)
}
}
Loading
Loading