Skip to content

fix(server-nestjs): make GitLab repo create and commit idempotent - #2624

Open
shikanime wants to merge 2 commits into
mainfrom
fix/gitlab-create-commit-idempotent
Open

fix(server-nestjs): make GitLab repo create and commit idempotent#2624
shikanime wants to merge 2 commits into
mainfrom
fix/gitlab-create-commit-idempotent

Conversation

@shikanime

@shikanime shikanime commented Aug 28, 2026

Copy link
Copy Markdown
Member

Issues liées

Quel est le comportement actuel ?

Deux trous d'idempotence dans GitlabClientService :

  • createGroupRepo appelle Projects.create sans tolérance de collision. Sous synchro concurrente, le perdant lève has already been taken.
  • maybeCreateCommit lit le fichier puis appelle Commits.create séparément. Deux synchros qui se chevauchent peuvent toutes deux voir le fichier absent, émettre une action create, et la seconde rencontre already exists (400) sans tolérance.

Comportement attendu

  • createGroupRepo recharge le dépôt existant (recherche dans Projects.all par nom) et le retourne en cas de collision.
  • maybeCreateCommit traite une erreur already exists / has already been taken (ou 400) comme un commit déjà appliqué, vérifie que le fichier existe désormais et continue sans lever.

Changements

  • createGroupRepo : enveloppe Projects.create et recharge le dépôt existant en cas de collision.
  • maybeCreateCommit : tolère un commit déjà appliqué (concurrence) et poursuit sans lever quand le fichier est présent.
  • Ajout de tests unitaires couvrant le rechargement après collision et le cas commit déjà existant.

@github-actions github-actions Bot added the built label Aug 28, 2026
@shikanime
shikanime force-pushed the fix/gitlab-create-commit-idempotent branch 2 times, most recently from 1447eff to c29170c Compare August 28, 2026 14:20
@shikanime
shikanime changed the base branch from main to fix/uniformize-error-guards August 28, 2026 14:22
Base automatically changed from fix/uniformize-error-guards to main August 28, 2026 15:54

@shikanime shikanime left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict : Changements demandés — la PR ne compile pas (PR propriétaire : commentaire bloquant, non request-changes).

  • gitlab-client.service.ts:355 — [🔴 Bloquant] GitbeakerRequestError est encore référencé (error instanceof GitbeakerRequestError) mais l import a été retiré (ligne 21 absente du diff ; l edit supprime import { GitbeakerRequestError }). tsc échouera. Suggestion : remettre import { GitbeakerRequestError } from "@gitbeaker/requester-utils" ou, mieux, ajouter un helper isGitbeakerBadRequest dans gitlab.utils.ts et l utiliser ici (cohérent avec isGitbeakerUnauthorized déjà sur main).
  • gitlab.utils.ts / nexus.utils.ts / vault.utils.ts — [🟠 Important] Les gardes isVaultNotFound, isVaultBadRequest, isNexusNotFound, isGitbeakerUnauthorized sont déjà fusionnées sur main (ec9c18a914). Cette PR les re-ajoute : rebasez sur main pour ne garder que la logique ensure*/maybeCreateCommit, sinon conflit (voir #2626 CONFLICTING).
  • gitlab-client.service.ts:352-366 — [✨ Éloge] ensureGroupRepo (reload par Projects.all + filtre name) et maybeCreateCommit (tolère 400 + vérifie la présence du fichier) ciblent exactement la course concurrente décrite. Bonne couverture de test (collision + fichier absent).

Rebasez sur main puis corrigez l import manquant avant de sortir du draft.

@shikanime
shikanime force-pushed the fix/gitlab-create-commit-idempotent branch from c29170c to 115d118 Compare August 31, 2026 11:44
@shikanime shikanime self-assigned this Sep 1, 2026
@shikanime shikanime added this to the 9.24.6 milestone Sep 1, 2026
@StephaneTrebel StephaneTrebel modified the milestones: 9.24.6, 9.25.0, 10.0.0 Sep 1, 2026
@shikanime
shikanime force-pushed the fix/gitlab-create-commit-idempotent branch 5 times, most recently from 9e91398 to 985cb46 Compare September 1, 2026 11:05
@shikanime
shikanime marked this pull request as ready for review September 1, 2026 11:06
@shikanime
shikanime requested a review from a team as a code owner September 1, 2026 11:06
@shikanime
shikanime force-pushed the fix/gitlab-create-commit-idempotent branch from 985cb46 to 951ed7f Compare September 1, 2026 11:30
shikanime and others added 2 commits September 1, 2026 13:42
…ection

Review feedback: // style comments, shorter util name, casts dropped where
inference suffices (Users.create already returns ExpandedUserSchema), and the
has-already-been-taken / already-exists / 400 collision check moved into an
isCommitAlreadyApplied guard used by maybeCreateCommit, with isGitbeakerRace
naming entity collisions for ensure. ensure takes a single options object.

Co-authored-by: Automata <automata@shikanime.studio>
Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: I728df0130286bfab2d599b9c6091731b6a6a6964
isGitbeakerRace predicate matrix, ensure create/reload/collision contract
(create called once, reload once, non-race rethrow), and a two-sync race
scenario proving maybeCreateCommit never emits a second commit for content
already synced. Rebased onto main; createGroupRepo rename adapted.

Co-authored-by: Automata <automata@shikanime.studio>
Signed-off-by: William Phetsinorath <william.phetsinorath-open@interieur.gouv.fr>
Change-Id: I6ee1064982cadefe1562f097751ce3f76a6a6964
@shikanime
shikanime force-pushed the fix/gitlab-create-commit-idempotent branch from 951ed7f to acae553 Compare September 1, 2026 11:42
@cloud-pi-native-sonarqube

Copy link
Copy Markdown

@shikanime shikanime added the bug Something isn't working label Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working built

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants