SQLite's last_insert_rowid() only updates on actual INSERTs, not
ON CONFLICT DO UPDATE. When pushing a second tag for an existing
manifest digest, the upsert fires the conflict branch (no new row),
so LastInsertId() returns a stale ID from a previous insert. This
caused manifest_blobs and tags to reference the wrong manifest,
producing a 500 on the PUT manifest response.
Replace LastInsertId() with a SELECT id WHERE repository_id AND
digest query within the same transaction.
Security: manifest_blobs and tag foreign keys now always reference
the correct manifest.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>