Logo

Letting AI claim issues, fix bugs and open merge requests: how our team works in GitLab

avatar Jade 21 Nov 2026

One AI can fix a bug. But if two machines spot the same bug, who takes it? And who decides whether the fix belongs on the main branch?

We use this workflow in production. Every task starts as a GitLab issue. The AI on each teammate’s machine periodically picks up work assigned to that person, fixes it, reviews the patch and opens a merge request (MR). The reviewer’s AI can independently check the change, but a human makes the merge decision.

The workflow at a glance

Solid lines show the main path; dashed lines show feedback, loops and side paths. The colors mark five stages: 🟡 task creation → 🔵 issue hub → 🟣 agent execution → 🩵 independent AI review → ⚪ human review.

Overall collaboration workflow

People describe the problem and review and merge the result. In between, local agents poll for work, claim issues, investigate, implement fixes and post updates.

The task state machine

GitLab labels double as our state machine.

Issue states and transitions

Change labels with the labels parameter of PUT /projects/:id/issues/:iid. It replaces the entire set: include any existing labels you want to keep. In progress and awaiting review also carry an agent-specific label (ai-doing-〈agent-id〉 or ai-reviewing-〈agent-id〉). It shows who owns the work and lets an agent check whether it already has a task. Keep ai-doing and ai-reviewing for views across agents.

Five design decisions

1. An issue is the only unit of work

Alerts, security scans, code-quality checks and requests made in conversation all end up as issues. If a request is unclear, we discuss the material with the local AI to establish reproduction steps, expected behavior, relevant code and acceptance criteria. The AI writes five sections—problem, reproduction steps, expected behavior, clues and acceptance criteria—then creates the issue via the API:

curl -X POST -H "PRIVATE-TOKEN: $TOKEN" \
  "https://<你的GitLab>/api/v4/projects/<项目ID>/issues" \
  -d "title=修复 XX 问题" \
  -d "labels=ai-task" \
  -d "assignee_ids[]=<同事用户ID>" \
  -d "description=<按上述模板>"

The AI that picks it up doesn't have to infer the fix from a one-line request: the issue records the evidence and what counts as fixed. If the problem is already clear, file it directly.

2. Identify the agent claiming the issue

GitLab issues have no atomic lock. Two polling agents can claim the same issue. At setup, give each agent a unique <GitLab-username>-<machine-short-name> identity, such as zhangsan-mbp. Have it identify itself in the label when it claims work:

# 1) 占用检查:任一非空即不领新任务
curl ".../issues?labels=ai-doing-<agent-id>&state=opened"
curl ".../issues?labels=ai-reviewing-<agent-id>&state=opened"
# 2) 领取:打上带身份的 doing 标签
curl -X PUT ".../projects/<id>/issues/<iid>" -d "labels=ai-task,ai-doing,ai-doing-<agent-id>"
# 3) 回读确认无其他 agent 的 doing 标签;撞车则撤回自己的标签跳过本轮

An agent may hold only one open task at a time: either doing or reviewing blocks a new claim. The limit applies per agent on a machine, not per person. Someone with two computers can run two identities, each with one task. Checking first and reading back reduces collisions; it doesn't make a read followed by a write atomic.

3. Require self-review before opening an MR

Delivery means fixing the reported issue without introducing another. Before opening an MR, the agent reviews its own diff against five checks:

• Correctness: logic, boundary conditions and error handling.

• Tests: cover critical paths and pass the full suite.

• Security: check the team's red lines, including injection, broken access control, SSRF and unsafe deserialization.

• Conventions: follow the project's framework conventions.

• Acceptance: check each criterion in the issue.

The key question: did the change introduce a new problem?

Read each hunk for changes to existing behavior. Run the full suite, follow the original reproduction steps and check related call paths. Keep the diff to what the fix needs; put unrelated refactoring in another MR.

Fix anything found before handing over. Post the self-review conclusion on the issue. An MR without a self-review record is not a completed delivery.

4. Give the reviewer's AI an independent look

Self-review can miss assumptions made during implementation. The reviewer's agent polls issues with labels=ai-reviewing and independently checks their MRs for regressions, side effects, security and performance problems. It does not take the author's self-review on trust. It opens an MR discussion for each concern; the fixing agent addresses it, replies, squashes back to one commit and pushes again.

AI checks correctness, security, conventions and whether the fix caused another problem. People own business trade-offs and architecture. Cross-review doesn't use up an agent's task slot; if that review stalls, a person takes over so one AI doesn't block another.

In practice, reviewers went from reading every line to reading the independent findings, spot-checking and deciding. Reviews took noticeably less time.

5. Open the MR as part of the push

GitLab push options let us push a branch and open its MR in one step, authenticated with the local SSH key:

git push origin ai/fix-42-xxx \
  -o merge_request.create \
  -o merge_request.target=<默认分支> \
  -o merge_request.title="fix: ..." \
  -o merge_request.description="Closes #42"

The AI needs an issue read/write token for the hub repository only. Writing code, pushing and opening MRs use the developer's SSH permissions; no second token for the code repository is needed. If the issue is in repository A and the fix in B, use a fully qualified reference such as Closes <group>/<repo-A>#42. Merging into B's default branch then closes the issue in A.

Six problems we ran into

The issue stayed open after merge. Closes #N fires only when the change reaches the project's default branch. If the default is master but the MR targets the integration branch develop, the issue stays open until the change reaches master. The workflow isn't broken.

Labels kept disappearing. The labels parameter replaces the whole set. Pass the labels you need to retain along with the new state.

The MR accumulated tiny commits. The AI added a commit for every round of feedback. We use reset --soft and amend to fold revisions into one commit, then push with push --force-with-lease.

Orphaned worktrees piled up. Task directories and branches outlived the work. Place them under .worktrees/<agent-id>-<issue-number>-<repo-short-name>/; on closure run git worktree remove and delete the merged local branch.

An agent claimed twice. One poll picked up two tasks. Make the occupancy check and one-task limit hard agent rules, not a verbal agreement.

A non-interactive shell couldn't see the token. The scheduled agent didn't inherit the token variable from shell configuration. Wrap the command in an interactive shell (e.g. zsh -ic) or explicitly source the configuration.

Team onboarding checklist

• GitLab: enable issues and use a version with push options (recent versions support them).

• Labels: ai-task (available), ai-doing (in progress/lock), ai-reviewing (MR awaiting review), plus your classification labels.

• One shared project access token: api scope, Maintainer role, only for reading, updating and commenting on issues. Track expiry and rotate it.

• One SSH key per person: grant push access to participating repositories. Opening an MR uses this key, not a token.

• A local AI agent per person: ZCode, Claude Code or similar. Put the rules in persistent instructions (AGENTS.md / CLAUDE.md).

• Automated review: self-review is mandatory before opening an MR and the conclusion goes on the issue. Independent review is recommended; the reviewer's agent polls ai-reviewing.

• Protected branches: prohibit direct pushes to develop and master. AI must use an MR; human review is part of the workflow.

• An onboarding document: create a starter issue from a template and assign it to the newcomer. Their AI reads it, checks its setup and saves the rules to memory.

We put the instructions directly in that assigned issue. The agent's very first poll fetches its own onboarding guide. It checks the token, polling, push access and default branch, saves its working rules and reports back on the issue. After that, pickup runs automatically.

What we don't give AI

• Large refactors: people assess the impact and make architectural trade-offs.

• Ambiguous requirements: ask on the issue; don't guess at a fix. If the answer still isn't clear, take the task back and redefine it.

• Work involving credentials or paid operations: don't assign it or put those details in an issue.

• Filter incoming work, too. Fewer well-defined issues beat a queue of vague ones: the quality ceiling for a fix is set when the issue is written.

What changed

The biggest change wasn't speed. Work stopped depending on someone remembering it and forwarding it: an alert becomes an issue, the issue reaches its assignee, AI handles it, and a human makes the final call. Protected branches prevent anyone's AI—including your own—from changing the main branch without review. Agent identity labels keep concurrent work across people and machines legible.

To try it, take one small, real bug through the whole cycle: file → claim → fix → MR → merge → automatic closure. Then add monitoring alerts and scanning jobs as sources. We'd love to hear what tripped you up along the way.

中文 · English · Français · Deutsch · Español · Italiano

预约免费 30 分钟咨询