Add AR client bulk_delete_manifests
What does this MR do and why?
This MR adds #bulk_delete_manifests to the Artifact Registry (AR) HTTP client in ee/lib/artifact_registry/client.rb. This is Step 5 of the artifact delete surface plan. The method deletes a chosen list of manifests of one Docker or OCI image in a single request.
#bulk_delete_manifests(slug:, repository_name:, format:, image_id:, digests:) sends a POST with {"digests": [...]} to .../{format}/images/{image_id}/manifests/bulk_delete. Only Docker and OCI are accepted (IMAGE_FORMATS).
The method reuses guard_batch! (ArtifactRegistry::Guards) and nested_bulk_delete_path (ArtifactRegistry::Paths), added with #bulk_delete_versions in !256212 (merged), so both methods share the same refusal rule. An empty list or a list of more than 1000 entries raises ArgumentError without making a request, and a list of exactly 1000 entries is sent. As monolith/S14 requires, the method sends only the subset branch of the contract and has no delete_all: keyword. No surface sends the whole-collection branch, and no confirmation design exists for it. A whole-collection permanent delete that anyone can reach with a direct call is the same exposure monolith/S05 closes for its repository clear.
How it behaves against AR:
- POST is not in
RETRY_OPTIONS[:methods], so the transport never replays a batch. A 503 means AR recorded no job, so the caller can safely resubmit the same list. - A 413 means the body's size in bytes went over AR's per-route limit. This is a different limit from the 1000-entry count.
- The client checks only the count. AR's 400 response handles digest syntax. Repeated entries are sent as given, because AR counts them toward the cap and applies the list as a set.
- A 202 has no body, and the method returns nil. Any other 2xx raises
UnavailableErroras contract drift. - A 404 raises
ApiErrorand does not become nil. A delete that never happened must not look like a success. - AR skips a listed manifest if an index outside the batch still references it, and it does not report the skip. So a 202 does not mean every listed manifest is gone. The method comment says so.
This ships dark behind the artifact_registry_ui feature flag, with no GraphQL surface yet, so there is no changelog trailer.
Size: 135 lines added and 56 removed. client.rb has 20 added. client_spec.rb has 115 added and 56 removed, because the versions and manifests blocks now share one example.
Merge order: !256212 (merged) (Step 4) has merged, and this MR now targets master on its own.
Changes since the earlier draft
- Rebased onto the reworked !256212 (merged).
- Removed
#bulk_delete_container_tagsentirely. The spec has no bulk tag surface, because the manage-tags modal removes one tag per action. The contract's tags bulk route stays without a client method until something needs it. - Removed
delete_all:from the manifests method. - Replaced the shared example with a direct describe block. The shared example only made sense when there were two methods.
- Carried over the review round 1 changes from !256212 (merged):
guard_batch!,raise_unexpected_successwith onlyslug:, 401 and 403 pinned asAuthorizationError, table-shaped refusal and AR-answered examples, and the corrected retry comment. - Carried over review round 2: the refusal rows are labelled with
case_name, and the over-cap row is one digest repeated 1001 times, so no example is named after 1001 digests. - The branch name still says "tags", because renaming it would orphan the MR.
The plan's Step 5 still lists #bulk_delete_container_tags. On this point the spec replaces the plan. The plan fix is a separate docs(plans) follow-up listed in gitlab-org/ops/artifact-registry!2798 (merged), and it does not block this MR.
References
- Closes #627395 (closed)
- The work item is titled for manifests and tags. The spec drops the tag half, so this MR is all that remains of it. GitLab closes it only after the change reaches master.
- Tracking issue for the delete surface: #627172
- Plan (Step 5): https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/plans/monolith/2026-09-01-artifact-delete-surface.md
- Spec monolith/S14, "The bulk selector": https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/monolith/S14-version-list.md#the-bulk-selector
- Spec monolith/S14, "Ruby client": https://gitlab.com/gitlab-org/ops/artifact-registry/-/blob/main/docs/specs/monolith/S14-version-list.md#ruby-client
- Spec MR that set this shape (merged 2026-10-05): gitlab-org/ops/artifact-registry!2798 (merged)
- Step 4 (merged): !256212 (merged)
Screenshots or screen recordings
Not applicable: a Ruby client method with no caller yet, no UI change.
How to set up and validate locally
The script starts a throwaway local stand-in for AR on a random port, points the client at it, and prints OK or FAIL for each check. It needs no running AR and changes no data. Paste it into bin/rails console on this branch.
require 'socket'
# A throwaway local AR stand-in. It records every request and answers by repository name:
# 'oci-repo' accepts with 202, 'no-such-repo' answers 404, and a malformed digest answers 400.
requests = []
server = TCPServer.new('127.0.0.1', 0)
port = server.addr[1]
thread = Thread.new do
loop do
socket = server.accept
method, path = socket.gets.split
length = 0
while (line = socket.gets) && line != "\r\n"
length = line.split(':', 2).last.to_i if line.downcase.start_with?('content-length:')
end
body = length > 0 ? socket.read(length) : ''
requests << { method: method, path: path, body: body }
status, payload =
if path.include?('/no-such-repo/') then [404, { error: { code: 'not_found', message: 'repository not found' } }]
elsif body.include?('sha256:nope') then [400, { error: { code: 'invalid_argument', message: 'bad entry' } }]
else [202, nil]
end
json = payload ? payload.to_json : ''
socket.write("HTTP/1.1 #{status} X\r\nContent-Type: application/json\r\n" \
"Content-Length: #{json.bytesize}\r\nConnection: close\r\n\r\n#{json}")
socket.close
end
end
token_exchange = Struct.new(:token) { def token_for(*) = token }.new('per-user-token')
client = ArtifactRegistry::Client.new(base_url: "http://127.0.0.1:#{port}", current_user: User.first,
token_exchange: token_exchange)
check = ->(label, ok) { puts "#{ok ? 'OK ' : 'FAIL'} #{label}" }
refused = lambda do |&blk|
before = requests.size
blk.call
false
rescue ArgumentError => e
requests.size == before && e.message
end
digests = ["sha256:#{'a' * 64}", "sha256:#{'b' * 64}"]
base = { slug: 'gdk', repository_name: 'oci-repo', format: 'oci', image_id: 'img-1' }
digest_at = ->(i) { format('sha256:%064x', i) }
check.('a subset delete returns nil on 202', client.bulk_delete_manifests(**base, digests: digests).nil?)
sent = requests.last
check.('it POSTs to the nested manifests bulk route',
sent[:method] == 'POST' && sent[:path].end_with?('/oci-repo/oci/images/img-1/manifests/bulk_delete'))
check.('the body is the digests list and nothing else', sent[:body] == { digests: digests }.to_json)
check.('a 1000-entry list is sent', client.bulk_delete_manifests(**base,
digests: Array.new(1000) { |i| digest_at.(i) }).nil?)
check.('an empty list is refused before any request', refused.call { client.bulk_delete_manifests(**base, digests: []) })
check.('a 1001-entry list is refused before any request', refused.call do
client.bulk_delete_manifests(**base, digests: Array.new(1001) { |i| digest_at.(i) })
end)
check.('delete_all is not accepted', refused.call do
client.bulk_delete_manifests(**base, digests: digests, delete_all: true)
end.to_s.include?('unknown keyword: :delete_all'))
check.('a package format is refused before any request', refused.call do
client.bulk_delete_manifests(**base, format: 'maven', digests: digests)
end)
check.('there is no bulk tag delete method', !client.respond_to?(:bulk_delete_container_tags))
begin
client.bulk_delete_manifests(**base, digests: ['sha256:nope'])
check.('a digest AR rejects surfaces the 400', false)
rescue ArtifactRegistry::Client::ApiError => e
check.('a digest AR rejects surfaces the 400', e.status == 400)
end
begin
client.bulk_delete_manifests(**base, repository_name: 'no-such-repo', digests: digests)
check.('an unknown repository surfaces the 404, not nil', false)
rescue ArtifactRegistry::Client::ApiError => e
check.('an unknown repository surfaces the 404, not nil', e.status == 404)
end
check.('no request body ever carried delete_all', requests.none? { |r| r[:body].include?('delete_all') })
puts "#{requests.size} requests reached the stand-in"
thread.kill
server.closeExpected output: twelve OK lines followed by "4 requests reached the stand-in".
Tests and live check
Tests: client_spec.rb defines one shared example, 'a bulk subset delete', that both #bulk_delete_versions and #bulk_delete_manifests use, so the subset bulk-delete contract is written once. Each method keeps its own blank-segment and path-encoding examples. Each method has 24 examples, including the happy path for both of its formats, and the full ee/spec/lib/artifact_registry/ folder passes (1459 examples). I mutation-checked both methods. Each of these changes fails at least one example for either method:
- a wrong body key
- skipping the count guard
- re-adding
delete_all: - narrowing the format guard to
docker - re-raising a 401 or 403 as
ApiError
Live check: I ran the client against the same real local AR, built from AR main (commit e6e3e7deb) in development mode.
- Pushed three OCI artifacts to one image with oras. A subset delete of two digests returned nil, and the manifest list afterwards showed only the third.
- A malformed digest came back as AR's 400.
- An unknown repository came back as 404 ("repository not found").
- An empty list, a
delete_all:keyword, and a maven format were refused locally. respond_to?(:bulk_delete_container_tags)is false.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.