Skip to content

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

Merged
shikanime merged 2 commits into
mainfrom
fix/gitlab-create-commit-idempotent
Sep 8, 2026
Merged

fix(server-nestjs): make GitLab repo create and commit idempotent#2624
shikanime merged 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 2 times, most recently from 951ed7f to acae553 Compare September 1, 2026 11:42
@shikanime shikanime modified the milestones: 10.0.0, 9.26.0 Sep 1, 2026
@shikanime shikanime added the bug Something isn't working label Sep 1, 2026
StephaneTrebel
StephaneTrebel previously approved these changes Sep 7, 2026
@shikanime shikanime added the preview Deploy preview app with Argo-cd label Sep 7, 2026
@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

🤖 Hey !

A preview of the application is available at : https://console-pr-2624.dso.cpin-hp.numerique-interieur.fr

Please be patient, deployment may take a few minutes.

@shikanime
shikanime force-pushed the fix/gitlab-create-commit-idempotent branch from acae553 to 5e2352d Compare September 7, 2026 16:03
shikanime and others added 2 commits September 7, 2026 18:05
…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
@cloud-pi-native-sonarqube

Copy link
Copy Markdown

@shikanime
shikanime enabled auto-merge September 7, 2026 16:13
@StephaneTrebel
StephaneTrebel self-requested a review September 8, 2026 15:36
@shikanime
shikanime added this pull request to the merge queue Sep 8, 2026
Merged via the queue into main with commit 0cf3ffb Sep 8, 2026
34 checks passed
@shikanime
shikanime deleted the fix/gitlab-create-commit-idempotent branch September 8, 2026 16:23
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 preview Deploy preview app with Argo-cd

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants