Concurrent deploys of identical source produce duplicate artifact entities
Summary
When two apps are deployed concurrently from the same source directory, the resulting image has the same content-addressed digest. Both deploy paths race to register an artifact entity for that digest, creating duplicates. Subsequent lookups fail with:
error locating artifact by digest sha256:779c4e...: conflict in entity: more than one entity found
How we found this
While working on running blackbox tests in parallel (#724), TestDeployGoServer and TestEnvSetGetList both deploy testdata/go-server concurrently. They produce the same image digest and both builds fail.
Reproduction
Any two concurrent miren deploy commands against the same source will hit this. The blackbox tests are a convenient repro — just add t.Parallel() to any two tests that use the same testdata.
Root cause
Artifact entity registration appears to be insert-only with a uniqueness assumption on digest. When two deploys race, both inserts succeed, leaving two entities with the same digest. The lookup-by-digest path then finds two and returns an error rather than picking one.
Suggested fix
Artifact registration should be idempotent — if an entity with the same digest already exists, return the existing one rather than creating a duplicate. This is the standard pattern for content-addressed stores.
Impact
- Doesn't affect serial usage (one deploy at a time)
- Blocks running blackbox tests in parallel (#724)
- Likely to affect real users running concurrent deploys of the same source — e.g., CI pipelines spinning up review apps where multiple PRs trigger deploys close together