Skip to content

feat(recording): connection-only recording target, downloads and upload outcome - #543

Merged
birme merged 2 commits into
mainfrom
feat/recording/connection-only-target-and-downloads
Oct 19, 2026
Merged

birme merged 2 commits into
mainfrom
feat/recording/connection-only-target-and-downloads

Conversation

@eyevinn-developer

Copy link
Copy Markdown
Contributor

Summary

  • A recording output can now be created on an instance that stores recordings only in a storage connection (no MINIO_* env). An unknown connectionId on POST/PATCH returns 400 "Storage connection not found" instead of failing at upload time. With no target at all it still returns 400, and the message names both MINIO_* and storage connections. Disk-only recording (feat(recording): record to Strom's disk without object storage #404) is still refused, as the issue recommends.
  • The recordings routes no longer return 503 when MINIO_* is missing. They return the stored recordings, or []. A database failure still returns 503 on all three routes, including GET /api/v1/recordings/:id, which used to send every failure to 404.
  • At activation the upload target is saved on the production next to recorderBlockId (recording: { outputId, connectionId?, startedAt }). Deactivate uploads to that saved target, so removing or re-pointing the output while the production is live no longer changes or drops the upload.
  • Deactivate saves lastRecordingUpload on the production: finishedAt, outputId, connectionId, bucket, uploaded, failed[{file,error}], reason, message. GET /api/v1/productions/:id returns it. It contains no secrets and no presigned URLs.
  • New recordings get durationMs, read from the MP4 header (moov/mvhd, or mvex/mehd for fragmented files). startedAt still comes from the file name (fix(recording): date swept segments by their own session's start #407). If the name has no timestamp, it now falls back to the activation start instead of updatedAt.
  • Each recording now has a downloadUrl next to playbackUrl: the same presigned GET and TTL, with response-content-disposition=attachment; filename="<basename>.mp4" signed into the query. If neither URL can be signed, the response gives playbackUnavailable with a reason: connection-missing, connection-no-bucket, storage-not-configured, bucket-mismatch or signing-failed.

Closes #534

Changes

  • src/routes/outputs.ts: added recordingTargetError(). POST and PATCH use it to check that the recording output has a storage target and that its connection exists.
  • src/routes/recordings.ts: removed the isRecordingEnabled() 503 gates. Added downloadUrl, the playbackUnavailable reasons, downloadFileName(), and 404 vs 503 handling on /recordings/:id.
  • src/routes/productions.ts: activation saves recording. The upload code that was inline in deactivate moved into uploadProductionRecording(), which returns a RecordingUploadSummary. That summary is written via writeDeactivatedDoc, so the _rev check (Delete recordings from Strom after upload #366) is unchanged.
  • src/lib/flow-generator.ts: ActivationResult.recorderOutputId.
  • src/lib/recording-uploader.ts: presignGetUrl takes an optional contentDisposition, and uploaded segments carry durationMs.
  • src/lib/mp4-duration.ts (new): reads the duration from the MP4 box tree. No dependencies.
  • src/db/types.ts: ActiveRecording, RecordingUploadSummary, RecordingUploadReason, and ProductionDoc.recording / lastRecordingUpload.
  • Docs: amendment section in docs/specs/vod-recording-minio.md, a note in docs/specs/storage-connections.md, and a new entry in docs/repo-patterns.md.

Test Plan

  • Unit tests pass: npx vitest run, 132 files and 1336 tests (30 new)
    • outputs-recording-target.test.ts: criteria 1 and 2 (create on a connection with no env, the 400 with no target, unknown connection on POST/PATCH writes nothing, connection with no bucket)
    • recordings-routes-connection-only.test.ts: criteria 3, 7 and 8 ([] instead of 503, 503 on DB failure, downloadUrl, connection-missing)
    • recording-upload-target.test.ts: criteria 4 and 5 (output removed while live still uploads to C; lastRecordingUpload with auth-error, the failed file and AccessDenied; connection missing; no target)
    • storage-connections-routes.test.ts: criterion 6 regression (deleting a connection still referenced by a recording output returns 409)
    • mp4-duration.test.ts and the recording-leftover-sweep.test.ts addition: durationMs
  • pnpm run typecheck and pnpm run build pass
  • Manual: the downloadUrl signature (with response-content-disposition) matches botocore's S3SigV4QueryAuth for the same inputs
  • Not done: a live run against a real bucket and Strom (criteria 4, 5, 7 and 9: a browser download, Chrome/Safari playback, ffprobe within 1 s)

Checklist

  • Code-quality checks passed (typecheck, build, vitest; this repo has no lint config)
  • No hardcoded SRT ports
  • GStreamer pipelines have watchdogs (n/a, no pipeline changes)
  • EFP sequence validation present (n/a)
  • docs/repo-patterns.md updated

Notes for reviewers: these are additive contract changes for open-live-studio#216, #219 and #220. Files that fail to upload stay on Strom for the next sweep, as before. An activation that started before this change has no saved recording, so its deactivate falls back to reading the current output assignments.

🤖 Generated with Claude Code

…ad outcome

Lets an instance that stores recordings only in a storage connection create a
recording output, list and download its recordings, and see why an upload
failed (issue #534):

- POST /api/v1/outputs accepts a recording output when MINIO_* is configured
  or its connectionId names an existing connection with a default bucket;
  otherwise 400 naming both options. POST and PATCH reject an unknown
  connectionId with 400 "Storage connection not found".
- The recordings routes return stored recordings without MINIO_* env; 503 is
  kept for a database failure only.
- Activation snapshots the recording's upload target on the production
  (recording: { outputId, connectionId?, startedAt }); deactivate uploads to it
  instead of re-reading output assignments.
- Deactivate stores lastRecordingUpload (uploaded count, failed files, the
  connection used, and a reason) on the production.
- RecordingDoc.durationMs is read from the MP4 header at upload; startedAt
  falls back to the activation start.
- Each recording gets a downloadUrl (presigned GET with a signed
  response-content-disposition: attachment) and, when it cannot be signed,
  playbackUnavailable with the reason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@eyevinn-pr-reviewer eyevinn-pr-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review: feat(recording): connection-only recording target, downloads and upload outcome (#543)

Verdict: REQUEST CHANGES

Prior findings

This PR has no earlier reviews or comments. The only comment on #534 is the triage note, and it raises no findings. The rows below are the issue's "What to change" items and acceptance criteria, checked against head 28cd019.

# Finding / criterion Status Evidence
Item 1 / AC1 Recording output accepted with a connection and no MINIO_*; without a target, 400 names both options FIXED 28cd019 src/routes/outputs.ts:86-104, :244-247; outputs-recording-target.test.ts:78-107
Item 1 / AC2 Unknown connectionId on POST/PATCH returns 400 "Storage connection not found" and writes nothing FIXED 28cd019 outputs.ts:96-101, :347-350; tests :109, :148
Item 2 / AC3 Recordings routes return stored docs or [] without the env; a database failure still returns 503 OPEN The 503 gates are gone and /recordings and /recordings/:id are correct. But GET /api/v1/productions/:id/recordings maps any failure of the production lookup to 404 (src/routes/recordings.ts:120-124). See Critical 1
Item 3 / AC4 Upload target saved at activation and used at deactivate after the output is removed while live FIXED (code + unit test); the upload to a real C needs live verification 28cd019 productions.ts:585-601, :322-328; recording-upload-target.test.ts:177 runs a real activate, then removes the output, then deactivates
Item 4 / AC5 lastRecordingUpload (uploaded, failed files, connection, reason) is stored and returned by GET; it holds no secrets FIXED (code + unit test); a real 403 bucket and the file staying on Strom need live verification productions.ts:303-462, :1259, :1283; tests :240, :271, :288
AC6 Deleting a connection still referenced by an output or recording is refused with 409 FIXED (regression test) storage-connections-routes.test.ts (+9 lines)
Item 6 / AC7 downloadUrl with a signed response-content-disposition, same TTL FIXED (code + unit test); browser save and Chrome/Safari playback need live verification recording-uploader.ts:303-318, recordings.ts:44-48, :97-104; recordings-routes-connection-only.test.ts:118
Item 7 / AC8 playbackUnavailable: "connection-missing" when the connection record is gone FIXED recordings.ts:84-108; test :137
Item 5 / AC9 durationMs from the MP4 header; startedAt falls back to the activation start FIXED (code + unit tests); the "within 1 s of ffprobe" check needs live verification src/lib/mp4-duration.ts, recording-uploader.ts:455, productions.ts:426; mp4-duration.test.ts
AC10 Unit tests cover items 1, 2, 3, 4, 6, 7 FIXED, with the AC3 gap noted below —
Q1 (birme) Keep the 400 when no storage target exists (no disk-only recording) FIXED outputs.ts:87-91

Critical Issues (must fix before merge)

  • AC3 is not met for GET /api/v1/productions/:id/recordings, and the test that claims it hides the gap. The route first runs await getDb().get(req.params.id) and sends 404 "Production not found" from a bare catch {} (src/routes/recordings.ts:120-124). The production DB and the recordings DB live on the same CouchDB, so in a real outage this lookup fails first, and the route returns 404, not 503. The PR body says "A database failure still returns 503 on all three routes". The test returns 503 on a database failure (recordings-routes-connection-only.test.ts:155) passes only because its dbDown flag fails getRecordingsDb() and leaves the getDb() mock working (:28-33). Fix: give the production lookup the same 404-vs-503 split you added to /recordings/:id, which checks statusCode === 404 or Document type mismatch (ideally as one shared helper, since outputs.ts:96-98 repeats it too). Then make dbDown also fail getDb().get, so the test checks the real failure mode.

Warnings (should fix)

  • The legacy fallback has no direct test. A production activated before this change has recorderBlockId but no recording snapshot. deactivate-upload-failfast.test.ts covers that shape only with no assignments and an env target. Add one case: no recording, an assigned recording output with connectionId: 'stconn-C', and an assertion that the upload goes to C. That pins the backward-compatibility path at productions.ts:325-328.
  • The #366 _rev guard is copied unchanged (productions.ts:386-394) but is not tested at the route level. It is correct: no write to the production happens between the handler's read and the upload, and lastRecordingUpload is only written later through writeDeactivatedDoc. Because the code moved, a test should capture isStillRecording from the mockUploadRecordings call args and check that it returns true once the stored _rev changes.

Nits (optional)

  • failed[].error in lastRecordingUpload holds up to 200 characters of the S3 error body (recording-uploader.ts:273). There is no secret key in it and no presigned URL, since PUT uses header auth. For some error codes S3 includes <AWSAccessKeyId> or <StringToSign> further into the body, but the 200-character limit cuts that off in practice. That is fine, but the doc comment should mention it.
  • downloadFileName changes any extension to .mp4, so a/segment.mkv becomes segment.mp4. The recorder only writes MP4 today, but non-MP4 files would be saved under the wrong extension.

What Was Verified

  • Head 28cd019 contains origin/main (2fc18a0). pnpm install --frozen-lockfile, pnpm run typecheck (0 errors) and npx vitest run (1336/1336) all pass locally. CI build-and-test passes.
  • The commit has the co-author trailer and is on a feature branch.
  • No fabricated contracts:
    • DEFAULT_CONNECTION_ID, StorageConnectionNotFoundError and resolveStorageTarget exist (src/lib/storage-connection.ts:28,31,85).
    • The Document type mismatch message matches src/db/index.ts:87.
    • activateStromFlow now returns recorderOutputId (flow-generator.ts:1100, :1322).
  • Presigned URLs:
    • response-content-disposition is part of the signed canonical query. It sorts after the X-Amz-* params in byte order, and its value is RFC 3986 encoded.
    • The filename goes through a [A-Za-z0-9._-] allow-list, so a crafted key cannot inject into the header.
    • The TTL matches playbackUrl. Nothing is stored. A test asserts the secret never appears in the response.
  • Credentials: lastRecordingUpload holds the connection id, bucket, counts, reason and message, but no secret and no URL. The tests at recording-upload-target.test.ts:238 and the routes test at :133 assert the decrypted secret is absent.
  • _rev guard:
    • uploadProductionRecording runs before any production write in the deactivate handler.
    • Activation writes recording in the same updateProductionDoc as stromFlowId, before any deactivate can read it.
    • The conflict-retry branches of writeDeactivatedDoc carry lastRecordingUpload through without changing their status logic.
    • deactivatedDoc clears recording and keeps the previous lastRecordingUpload when a deactivate has no recording (test at :314).
  • Backward compatibility: a production with no recording falls back to firstRecordingOutput. A recording doc with no connectionId keeps the default-bucket path, and startedAt falls back to doc.updatedAt as before.
  • MP4 parser: it is bounded. A size-0 box consumes the rest of its container, oversized or 64-bit sizes are rejected, and any exception returns undefined. It cannot loop forever and cannot read out of bounds.

…utage

GET /api/v1/productions/:id/recordings mapped any failure of the
production lookup to 404, so a CouchDB outage returned 404 instead of
503. Split not-found from unavailable with a shared isDocNotFoundError
helper (also used by /recordings/:id and the output storage check), and
make the test's dbDown flag fail the production lookup too.

Add tests for the legacy upload-target fallback (no recording snapshot,
assigned output on a storage connection) and for the #366 _rev guard
passed to uploadRecordings. Document what lastRecordingUpload.failed[].error
may contain.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@eyevinn-developer

Copy link
Copy Markdown
Contributor Author

Addressed the REQUEST CHANGES review on 28cd019 in 24b364e.

Critical: AC3 on GET /api/v1/productions/:id/recordings. Fixed. The production lookup now returns 404 only when the error is a real not-found (statusCode === 404 or Document type mismatch). Any other failure returns 503 "Database unavailable". The check is a shared helper, isDocNotFoundError in the new src/lib/db-errors.ts. It is used here, in /recordings/:id and in outputs.ts recordingTargetError. It lives outside src/db/index.ts because many tests mock that module wholesale. In the test, dbDown now also fails getDb().get, so it checks the real outage case. I confirmed the test fails against the old route code. I also added a 404 test for a missing production.

Warning: legacy fallback test. Added. The production has recorderBlockId but no recording snapshot, and the assigned output has connectionId: 'stconn-C'. The test asserts the upload target is C (bucket, endpoint and access key), the RecordingDoc is stamped with C, and lastRecordingUpload.connectionId is C.

Warning: #366 _rev guard test. Added. The test takes isStillRecording from the uploadRecordings call args. It asserts the guard returns false while _rev is unchanged and true after the stored _rev changes during the upload.

Nits. I documented what failed[].error can contain on RecordingUploadSummary.failed in src/db/types.ts. The .mp4 filename change is not made: the recorder only writes MP4, so the behaviour stays as it is.

Checks: pnpm install --frozen-lockfile, pnpm run typecheck (0 errors), pnpm run build and npx vitest run (132 files, 1339/1339 tests) all pass.

@birme

birme commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

daily-backlog-pr Phase 3: new commit 24b364e landed after the REQUEST CHANGES review at 28cd019. Running the one allowed re-review cycle now; if it is still REQUEST CHANGES, this goes to a human (Needs human) rather than back to Ready.

@eyevinn-pr-reviewer eyevinn-pr-reviewer Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Review: feat(recording): connection-only recording target, downloads and upload outcome (#543) — re-review

Verdict: APPROVE

Prior findings

Sources read: the REQUEST CHANGES review on 28cd019, the implementer's response comment, the re-review-cycle marker, issue #534 (body, acceptance criteria, triage comment). No human waived or rejected any finding. Judged against head 24b364e.

# Finding / criterion Status Evidence
Critical 1 / AC3 GET /api/v1/productions/:id/recordings mapped any production-lookup failure to 404; DB outage must return 503 FIXED 24b364e src/routes/recordings.ts:122-130; helper src/lib/db-errors.ts:12-15; dbDown now also fails getDb().get (recordings-routes-connection-only.test.ts:30-31), 503 test covers all three routes (:157-165) and fails against the 28cd019 route code; new 404 test at :167
Warning 1 Legacy fallback (no recording snapshot, output on stconn-C) untested FIXED 24b364e recording-upload-target.test.ts:314-336
Warning 2 #366 _rev guard untested at route level FIXED 24b364e recording-upload-target.test.ts:338-361
Nit 1 Document what failed[].error may contain FIXED 24b364e src/db/types.ts:431-437
Nit 2 downloadFileName forces .mp4 Not changed (optional nit; recorder only writes MP4)
Item 1 / AC1, AC2 Connection-only recording output; unknown connectionId → 400 FIXED src/routes/outputs.ts:87-104
Item 2 / AC3 Recordings routes without env; 503 on DB failure FIXED see Critical 1
Item 3 / AC4, Item 4 / AC5 Upload target snapshot; lastRecordingUpload without secrets FIXED (unit tests; live run outstanding) productions.ts:322-328
AC6 Referenced connection delete → 409 FIXED storage-connections-routes.test.ts
Item 6 / AC7, Item 7 / AC8 downloadUrl with content-disposition; playbackUnavailable FIXED recording-uploader.ts, recordings.ts
Item 5 / AC9 durationMs from MP4 header FIXED (unit tests; ffprobe check outstanding) src/lib/mp4-duration.ts
AC10, Q1 Unit tests; keep the 400 with no target FIXED outputs.ts:87-91

Critical Issues

None.

Follow-ups (not blocking)

  • Live-instance parts of AC4, AC5, AC7, AC9 should be checked on openlivedev after merge.

What Was Verified

  • Head contains origin/main; incremental diff 28cd019..24b364e (6 files, +90/-9) scoped to the findings.
  • pnpm install --frozen-lockfile, pnpm run typecheck, pnpm run build, npx vitest run (1339/1339) pass locally; CI build-and-test green.

@birme
birme merged commit e737975 into main Oct 19, 2026
1 check passed
@birme
birme deleted the feat/recording/connection-only-target-and-downloads branch October 19, 2026 12:27
wagenet added a commit to wagenet/open-live that referenced this pull request Oct 28, 2026
A recording output needs a storage target by default (Eyevinn#534, Eyevinn#543). Restore
main's 400 for no connection / "default" without MINIO_*, and allow it only
when RECORDING_LOCAL_ONLY=true (default off). Document the opt-in, mention the
connectionId target in the OpenAPI OutputType, and fix the stale gate
reference in guest-calling-provisioning.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
birme added a commit that referenced this pull request Oct 28, 2026
* feat(recording): record to Strom's disk without object storage

A recording output no longer requires MinIO/S3. Strom's recorder writes
segments to its own media path, so object storage only decides whether
deactivate uploads them:

- POST /api/v1/outputs accepts outputType 'recording' with no MINIO_* set.
- Deactivate skips splitNow and the upload when storage is not fully
  configured, logs where the segments stay, and tears down immediately.
- isRecordingEnabled() is renamed isObjectStorageConfigured(); it now gates
  only the upload target in resolveRecordingUploadTarget.
- Startup warns when the MINIO_* set is partial (treated as unset).
- README env table and .env.example document the MINIO_*/RECORDING_* vars.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

* feat(recording): gate disk-only recording behind RECORDING_LOCAL_ONLY

A recording output needs a storage target by default (#534, #543). Restore
main's 400 for no connection / "default" without MINIO_*, and allow it only
when RECORDING_LOCAL_ONLY=true (default off). Document the opt-in, mention the
connectionId target in the OpenAPI OutputType, and fix the stale gate
reference in guest-calling-provisioning.md.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Jonas Birmé <jonas.birme@eyevinn.se>
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.

OL-26: Recording end to end from Studio: allow a connection-only recording target, make recordings listable and downloadable, and show upload failures

1 participant