Skip to content

Add mux migrate for moving video libraries into Mux - #79

Draft
davekiss wants to merge 19 commits into
mainfrom
feat/migrate-command
Draft

davekiss wants to merge 19 commits into
mainfrom
feat/migrate-command

Conversation

@davekiss

@davekiss davekiss commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Adds mux migrate, which moves a video library from another platform into Mux with one resumable command that is safe for a coding agent to run unattended. The design is in MIGRATE_SPEC.md.

Commands

init, plan, run, status, verify, export, and retry. plan is free and creates nothing; run requires --yes. Every command supports --json and --agent, and every error carries a stable code, a hint, and a next_command.

Exit codes: 0 complete, 1 failed or only errored items remain, 2 usage or configuration, 3 confirmation required, 4 work remains. Re-running next_command on 4 always makes progress and cannot loop on errors.

Sources

Vimeo, Cloudflare Stream, Bunny Stream, Wistia, S3-compatible buckets (with a dependency-free SigV4 client verified against the AWS signature examples), and CSV or JSON manifests for any other platform. All provider HTTP goes through one client that honors Retry-After, retries 429, 5xx, and network failures with backoff, and maps failures to provider error codes. Credentials come from environment variables, overridable with --credential NAME=value, and are never written to state or output.

Safety

  • No duplicate assets. Each asset carries meta.external_id ({provider}:{source_id}, hashed when longer than 128 characters). Asset creation is never retried on timeouts or 5xx responses, and the SDK's default retries are disabled for it. An interrupted create is adopted from its video.asset.created event or from a scan of recent assets on the next run. A second asset is reported as DUPLICATE_ASSET, never deleted.
  • Resumable. State is in SQLite (bun:sqlite), written before each network call. Crash-and-resume tests snapshot the database at each transition.
  • No polling. Progress comes from the webhook event stream (the same connection mux webhooks listen uses), with reconciliation after reconnects.

Captions

Captions passed by URL go straight to Mux. Caption text (Wistia, Cloudflare Stream) is uploaded to captions.host_bucket and removed after ingest, or saved locally with the mux assets tracks create command that attaches it.

Robots enrichment: on hold

Directive attachment is held until the Robots Directives API settles. A recipe that lists directives is rejected with a message explaining why, and the planned design is kept in the spec under Robots enrichment as a fast follow.

Testing

1,722 tests pass (2 skipped). Providers are tested against recorded responses shaped after each platform's API docs; no test calls a real API. An end-to-end test runs a Wistia migration through the real engine, state, caption store, status, and export. A separate review pass found 13 issues; each fix has a regression test. State reads stay linear in the library size (a 10,000-item run reads 20,000 rows), and the run engine is split into focused modules under src/lib/migrate/run/.

Not yet run against live provider accounts or a live run --yes. Before merging, run a pilot with mux migrate run --yes --limit 2 --test against a manifest, then each provider. API details the docs did not settle are noted in the provider modules, and are worth checking in that pilot: Cloudflare's after paging semantics, Mux ingest of Wistia .bin asset URLs, and Bunny libraries with embed token authentication.

Open decisions

  • Duplicate assets are reported, not deleted.

Companion docs prompt: muxinc/mux.com, branch docs/prompt-migrate-vimeo.

🤖 Generated with Claude Code

davekiss and others added 19 commits October 5, 2026 08:52
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…anifest provider

Covers the delivery step 1 contract: confirmation gating, exit-code
precedence, resumable state, duplicate prevention, event stream
reconciliation, directive attachment, and the manifest provider.
Modules are typed stubs until implemented.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…t provider

Adds the resumable run engine with duplicate prevention by
meta.external_id, event stream reconciliation, and directive
attachment; a bun:sqlite state store; a Mux client adapter that never
retries asset creation on timeouts or 5xx responses; and the CSV/JSON
manifest provider.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Covers JSON and human output, exit codes and next commands for run,
plan, status, retry, and export; recipe loading and duration parsing;
the mapping export; and the webhook event stream adapter.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Adds init, plan, run, status, export, and retry. Output follows the
migrate contract: newline-delimited JSON events from run, one JSON
document from the other commands, and stable error codes with hints
and next commands. Run follows the webhook event stream through a new
adapter that refreshes credentials and reports reconnects.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Checks each ready item's asset status, duration, caption tracks,
public playback, and directive runs; records the results for export;
re-queues items whose asset was deleted; and reports duplicate assets
that share an item's external ID.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Plan now reports item types, skip reasons, total duration and size,
expected fidelity, caption languages, configured directives, provider
warnings, and a pricing link, without resolving any source URL.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The shared client honors Retry-After, retries 429, 5xx, and network
failures with jittered backoff, spaces requests to a rate limit, and
maps failures to provider error codes. The Vimeo provider verifies the
video_files scope, follows paging.next, filters by processing status,
type, folder, and privacy, and prefers the source file.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…oviders

Cloudflare Stream generates downloads on demand and reports pending
until they are ready, signs downloads for signed-URL videos, and warns
that every item is a rendition. Bunny Stream prefers retained originals,
falls back to the highest MP4, signs CDN URLs when token authentication
is on, and detects direct-access blocking. Wistia prefers the original
file, guards against missing assets, and returns caption text inline
with BCP 47 language codes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ing sources

Adds a provider registry used by every command and by init, which now
lists the credentials each provider needs. Credentials come from the
environment, overridden by --credential NAME=value. Captions supplied
as text are uploaded to captions.host_bucket and removed once ingested,
or saved locally and reported with the command that attaches them.
Sources that need preparation are retried within the same run.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Adds a dependency-free SigV4 client covering presigned URLs, ListObjectsV2,
and object reads, writes, and deletes, verified against the AWS signature
examples. The bucket provider lists media by prefix, extension, and glob,
reads JSON and caption sidecars, and presigns each object just in time.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…ent migrate

Uploads caption text to the customer's bucket with a 24-hour presigned
URL when the recipe sets captions.host_bucket. Adds the migrate guide to
the README and aligns the specification with the provider behavior.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
- Retry starts a fresh attempt, so a replacement asset completes instead
  of being reported as a duplicate of the errored one.
- A source that fails to resolve, or captions that cannot be stored,
  error that item instead of stopping the run. Provider and Mux
  authentication failures stop the run once instead of erroring every
  item.
- External IDs longer than Mux's 128-character limit are hashed and
  mapped back, and passthrough values over 255 characters are rejected
  per item before creating an asset.
- Runs no longer wait forever on directives that never start a run, on
  sources that stay pending, or on items outside --ids.
- Background reconciles report failures as warnings.
- Uploaded captions are cleaned up after ingest finishes and for items
  that error, and every pending caption gets its own attach command.
- verify ignores errored assets and handles hashed external IDs.
- Cloudflare paging overlaps by a second so same-time videos are never
  skipped, and fails instead of looping. Bucket verify reports network
  failures. Bunny stores poster URLs unsigned and retries a failed CDN
  host lookup.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
The wait loop re-read every in-flight item on each state change, so rows
read grew with the square of the library (2 million for 2,000 items).
Counts now come from indexed SQL queries, --ids is a set, the external ID
index reads only IDs, and status uses limited queries. A 10,000-item run
reads 20,000 rows. verify stops its duplicate scan at assets created
before the migration started.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
engine.ts keeps the public API. A run is now composed of a shared
RunContext, AssetCreator (resolve and create), AssetLifecycle (adoption,
ready, errored, directive runs, duplicates), CaptionStage (staging and
cleanup), and Reconciler (stream events and catch-up), wired together by
MigrationRun. Behavior is unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…API settles

The Robots Directives API is changing, so v1 no longer attaches
directives or tracks directive runs. Removes --directive, --skip-robots,
the recipe directives field, the enriching state, and directive checks
in plan, verify, and export. A recipe that still lists directives is
rejected with a message explaining why. The specification keeps the
planned design under Robots enrichment as a fast follow.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Asset creation is limited to one per second for every token, and other
requests to one per second for low-priority tokens. The client now paces
creates and reads with token buckets sized to the low-priority limits.
Catching up after missed events and verify list assets 100 per request
instead of fetching each one, and plan reports the minimum creation time
as create_seconds. The docs recommend low-priority tokens for migrations.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
… act on

Duplicates found by run or verify are saved in the state file and listed
by status --json, with a delete command each, and by the mapping export.
plan checks recent assets for an earlier migration of the same library
and reports PREVIOUS_MIGRATION_FOUND with examples, which run repeats.
Nothing is deleted or blocked. run takes a lock on the state file so two
runs cannot create the same videos, taking over locks left by exited
processes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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