Step 2 of docs/same-name-merges.md. PUT / onto a key another item holds used
to answer 200 with that item and drop the app's uuid, so the app's next
request by its uuid (a move, most often) got item_not_found for good.
Now, when the upload is the same kind of item (two books, or two containers)
under a uuid with no active row of its own, it merges into the item already
there: that item keeps its uuid, the uploaded uuid is recorded as a pointer to
it (which PR 1's lookups follow), the upload's listening state replaces the
survivor's only when it was played later, and the reply lists the merge as
conflicts: [{ key, uuid }], the shape POST /uuids already answers with and both
apps already apply. A row from before uuids takes the uploaded uuid of the same
kind, as POST /uuids does. A book against a container, or a uuid that has an
active row elsewhere, keeps today's behaviour. POST /uuids records no pointer:
the apps already adopt its conflicts, and it carries no item kinds.
putObject now returns { content, conflicts }; every PUT / answers conflicts,
empty unless it merged.
Step 2 of docs/same-name-merges.md:
PUT /records merges. Builds on #66, which made every lookup by uuid follow a merge pointer.Why
PUT /onto a key another item already holds answers 200 with that item and drops the app's uuid. Neither app reads the uuid in that reply, so its next request by its own uuid (a/move, most often) getsitem_not_foundand holds its sync queue for good. It happens when the same book, or a same-named folder, is added on two devices before either has synced.What changes
LibraryService.mergeUploadIntoOccupant, called whenPUT /finds its key taken:POST /uuidsalready doeslibrary_item_merges(a retry re-records it); the upload's listening state replaces the survivor's only when it was played later; the reply lists the mergeThe reply is now
{ content, conflicts }.conflictsuses thePOST /uuidsshape,[{ key: <uuid as sent>, uuid: <survivor's uuid> }], which both apps already decode and apply to their library and queued tasks. It is empty unless the upload merged, and today's apps ignore it. Until the apps read it, the pointer keeps them working, and their weekly missing-items pass moves them to the survivor's uuid.POST /uuidsrecords no pointer (decided with the maintainer): both apps already switch to the uuid its conflicts name, so nothing would use one, and it is sent paths without item kinds, so it could record a book-vs-folder pointer.Supporting changes:
LibraryDB.adoptUuidIfMissing,recordMerge(upsert) andsetItemProgress;putObjectreturnsPutObjectResult;docs/same-name-merges.mdandCLAUDE.mddescribe the reply.Testing
src/__tests__/services/LibraryServiceUploadMerge.test.ts, 11 cases:content.🤖 Generated with Claude Code