The browser scenario of the import page runs on isolated API fixtures, so
nothing checked the page with the real handlers, the background worker and
the publisher together. tests/browser-library-import-live.cjs seeds a few
library tracks on a fresh disposable instance, uploads a Spotify export
ZIP built in the test and checks that only the playlist files are sent,
the statistics after the worker finishes, the private playlists in source
order without repeats, the filters, a manual choice published by the next
pass, the export flagged as already imported, Retry unmatched, history
deletion that keeps the playlists and the page at phone width.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Only each peer catalogue was limited to 4 MiB, so one lookup of up to 16
untrusted owners could bring hundreds of thousands of made-up tracks, and
the pass kept 64 such lookups. A lookup now keeps at most 5,000 tracks; a
catalogue whose new tracks do not fit counts as lost (too large). The pass
remembers 8 lookups, enough for folded spellings and collaboration parts.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
REQ §11 repeats the search in the library and the federation for both
unmatched and ambiguous entries, but only unmatched ones waited for the
network stage, so an entry with a weak local candidate (a remaster, a
compilation) never asked a peer, not even on Retry. With the user's
consent an ambiguous entry now waits too, with its candidates. A peer's
match decides it only when no stored candidate is Strong or Exact, as
deciding over both would; otherwise the catalogue candidates are added.
When the search fails, the node is off or the budget is used up, the
entry is ambiguous again with its candidates.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An upload was buffered by an untagged enum, built into a JSON tree,
serialized again and parsed into a second tree, so a 32 MiB body of tiny
entries took gigabytes, and nothing limited parallel uploads. The file
JSON is now kept as written (serde_json raw values) and passed to the
adapter, which borrows each playlist and entry from the bytes and parses
them one at a time. An upload may hold at most 200,000 entries and as many
playlists, more are refused with 413, and only two uploads are read and
parsed at a time. The same body now peaks below 90 MB.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The concurrent sync test passed even when the playlist row was written
after the register committed, because nothing held the window open. Row
and table locks now park a removal and an addition between the two
writes, and the register must still show the old state. Consistency
checks also look at every library track in the playlist, not only at
registers that name a local track.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Applying an item now changes its register and playlist row in one
transaction, register first. Library cleanup and metadata fixes delete
playlist rows before they detach registers, so the two could deadlock and
the sync exchange failed with the operation already journaled. A deadlock
or serialization failure now runs the item again, up to three times, from
its register. Reordering the locks would instead conflict with the import
publisher, which locks registers before writing playlist rows.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The publisher reads the targets once per phase. When the user deleted a
target and asked to recreate it while another playlist was publishing,
the worker reached it with its old view and paused it again, undoing the
request it had already confirmed. A pause now applies only while the
target is still the one the worker read; otherwise the requested rerun
publishes into a new target.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both took any POST, so a form of a sibling site that receives the
SameSite=Lax session cookie could cancel or requeue an import. Like every
other change of an import they now need application/json, which a form
cannot send without a preflight; the player already sends it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Deleting an import cascades to its receipts once per entry, and deleting
any playlist sets the import targets that point at it to NULL. Without an
index on the referencing columns each of these scanned the whole table.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The skeleton had four cells in five columns while the statistics have six;
it now inherits the statistics grid on every width. The Russian notice
after Retry promised that the tracks would be found.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The wizard dialog leaves the DOM without close(), so focus fell to the
page body. Closing it now returns focus to the button that opened it, or
to New import, unless it closes to navigate, and each new step focuses the
dialog title. Leaving the details clears a pending entry search, and
entries are not loaded without an import, so /api/imports/null/items is
never requested.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A stored entry is copied by its compressed size, so a record that declares
an original size of zero could still bring hundreds of megabytes, once per
central directory record that points at it. Each extracted file is now
charged the larger of its sizes, a stored entry must declare equal sizes,
and unknown methods and duplicate names are refused.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Import library sits between Followed and Settings in the account menu and
opens #imports: the sources, the history with statistics and links to the
created playlists, and #imports/N with progress, per-playlist results, a
deleted-playlist notice with Create again, and the entries with status and
playlist filters, search, paging and the candidates of doubtful entries to
choose from. Retry unmatched (with the federated search consent), Cancel,
Delete history and a new Spotify sign-in for waiting imports call the
existing /api/imports endpoints. The page polls every 3 s while an import
runs. It follows the player's views, skeletons, dialogs, switches and
phrase table in English and Russian.
The New import wizard picks a source, then the data export or the Spotify
sign-in, then the playlists: imported ones cannot be selected, similar ones
need an explicit confirmation, and federated search is off until the user
turns it on. A ZIP export is opened in the browser with fflate 0.8.2,
vendored with its MIT licence and served at /vendor/fflate-0.8.2.js only
when an archive is picked. Only Playlist*.json and YourLibrary.json are
extracted; archives over 256 MiB, with more than 2,000 entries, more than
256 playlist files or more than 32 MiB declared for them are refused before
anything is decompressed, and a request over 32 MiB is not sent.
Federated tracks can now be removed from a playlist in edit mode:
DELETE /api/player/tracks/content/playlist checks the owner and records the
existing PlaylistTrackRemoved operation. The body-level dialogs get an
Alpine root, which also makes Get app open again.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each source playlist gets an ordinary private playlist, created with its
PlaylistCreated operation in one transaction even when nothing matched.
Matched entries follow in source order, at most 200 per transaction: the
playlist row, the item register, the existing PlaylistTrackAdded operation
and a receipt are written together, so fed_sync_ops serves as the outbox
and an interrupted batch leaves nothing behind. Locks are taken in a fixed
order (per-user advisory lock, import lease, playlist, fed-device identity,
registers). Registers are only inserted; an item the playlist has or had,
a removal committed to the journal but not yet applied, a repeat or a
receipt keep the publisher from adding it again. A deleted target pauses
publication until POST .../playlists/{pid}/recreate; POST .../resync
retries unmatched entries and appends new matches at the end.
Before each batch the outgoing Device Sync line is measured by serializing
the same parts the exchange sends. Tracks and new playlists are published
while the music snapshot stays within library_import_sync_budget (2 MiB)
and the whole line within 7 MiB; the rest waits as deferred_sync_limit.
Device Sync gets local helpers only: create_owned_playlist_tx is extracted
from the playlist handler, append_in_transaction takes an explicit
position, the two operations have in-transaction variants on
append_local_op, and applying a playlist item writes its register under an
atomic last-writer-wins condition and its playlist row in the same
transaction, so concurrent operations cannot make them diverge. The
protocol and its formats are unchanged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With the user's consent and federation enabled, entries that the local
library and known federated tracks do not match wait for resolver stage 3.
It looks up each artist group by its original name, its spelling without
Latin diacritics and, if those find nothing, its collaboration parts, and
decides the entries against the federated tracks of the catalogues.
The new artist_catalogs_bounded in the federation client asks at most 16
owners, a given number at a time, in a JoinSet owned by one task; dropping
the stream aborts the search and every catalogue request. The player's
stream_artist_catalogs keeps its behaviour and shares the owner parsing.
Imports search two groups at a time process-wide, give a group 60 s, retry
failed searches after 2/4/8 s, stop after 500 groups or 30 minutes per pass
and cancel running lookups on cancellation or lease loss. Lost catalogues
are counted in the statistics.
POST /api/imports/{id}/items/{item_id}/match takes a stored candidate of
an ambiguous entry for its owner after checking it again, and queues a
finished import so that the choice is published.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the matcher and the first two resolver stages of the library import.
The matcher is pure: titles are split into a core, featured artists and
version tags, taken from the album title too, so a remaster or concert
album counts like a marker in the track title. Hard tags (live, remix,
edit and similar) must be equal; remaster, mono, stereo, explicit and
clean never match automatically. A match without a comparable duration
needs the same album, and a single candidate is not a match by itself.
Collaborations are split only into known artists, so "Tyler, The Creator"
stays one artist.
The resolve_local phase matches pending entries by artist group against
the library, then against federated tracks this server already knows from
searches and from the owner's synced likes and playlists, and stores
matched, ambiguous (with up to five candidates) or unmatched decisions
under the lease. A local match without a cached content id is hashed with
ensure_local_content_id from agent_storage_dir, so local imports are
publishable with federation disabled. The network is reached only through
a FederationAccess trait and only with the user's consent.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the Spotify adapter to the library import. The data export path parses
Playlist*.json and YourLibrary.json sent by the browser, tolerates missing
and unexpected keys, keeps the source order and repeats, and stores episodes,
audiobooks, local files and unreadable entries as unsupported instead of
dropping them. The bundled export fixture is synthetic and must be joined by
an anonymized real export before acceptance.
POST /api/imports/preview lists the playlists of an upload and marks those
already imported or similar to an earlier import; POST /api/imports stores
the selected playlists with every entry in one transaction and starts the
worker. Requests are JSON-only and limited to 32 MiB (413). Re-import is
detected per source playlist: a repeat is refused with 409, and a changed
playlist with the same title needs confirm_similar.
The Spotify Web API is optional and enabled by an administrator's client ID
(and redirect URI behind a proxy) in the settings. Sign-in uses PKCE with the
state, verifier and waiting import kept in the session; access tokens stay
only in an in-memory vault for at most 30 minutes. The worker fetches the
selected playlists one by one, honors Retry-After and backs off on server
errors. A missing or expired token parks the import as needs_reauth; signing
in again with the same account continues the same import and skips the
playlists already fetched.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the library_import subsystem core: migration m_0065 with the import,
playlist, item, publication-receipt and attempt tables, the provider-neutral
import model, the adapter trait and the storage layer.
The library_import job claims imports under a two-minute lease that a
heartbeat renews, checks cancellation between phases and resumes an
interrupted import from its stored phase. Matching and publication phases
are placeholders for the following changes. At boot, imports of the previous
process are requeued; a sweeper starts a worker whenever an import waits
without one, so a worker that stops without a server restart is replaced
once its lease expires.
The /api/imports endpoints list the user's imports, show one import with
its playlists and paged entries, cancel it and delete its history while
keeping the created playlists. Every request is scoped to the owner.
GET /imports redirects to the player view.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>