Skip to content

feat(bin): support GitLab merge requests end to end - #7243

Open
gh0stwin wants to merge 16 commits into
kunchenguid:mainfrom
gh0stwin:fm/track-firstmate-upstream-pr-7226
Open

gh0stwin wants to merge 16 commits into
kunchenguid:mainfrom
gh0stwin:fm/track-firstmate-upstream-pr-7226

Conversation

@gh0stwin

@gh0stwin gh0stwin commented Oct 13, 2026 •

Copy link
Copy Markdown

Intent

The public PR carrying the GitLab forge support to the firstmate repo - #7226 - failed its CI. The captain asked why it failed, ruled the fix work belongs to a worker ("Why didn't you port this to a worker?"), ruled the worker must run the full no-mistakes validation because firstmate did not run it after the branch merge with main, and ruled the validation must check only our modifications - upstream main's own breakage is not this task's scope. The PR must end up green-or-explained: our regressions fixed, the re-raise compliant, main's inherited failures named rather than fixed.

The maintainer commented on PR 7226 asking for live evidence: "drive one real GitLab path end-to-end (or the pieces you can safely run) - e.g. arm/refuse-draft on a real MR, a fresh refs/merge-requests//head review fetch, and the teardown landed-work proof - and post the evidence (or fold it into a no-mistakes re-raise)". Perhaps we can create an empty public repo on gitlab then create an MR and post the link on the PR.

Relaunch the 'upstream-pr-7226' worker and resolve the conflicts with firstmate github's main.

Upstream main moved again past the last rebase (now d22640f), the re-raised PR conflicts once more and its CI was cancelled without a verdict: "can we resolve the conflicts on our firstmate pr and then run no-mistakes again?"

There are also new conflicts on the PR (#7243) - can you fix them? And run no-mistakes again?

Can you also pull main and resolve the conflicts on our firstmate's PR?

What Changed

  • Add a forge=gitlab value to the closed forge= registry binding: bin/fm-project-mode.sh accepts it (keeping +yolo available, since a GitLab merge is not an attributed human approval), bin/fm-forge-detect.sh proposes it for a gitlab.com origin at intake, and it is the one forge that accepts a per-task base branch; generated ship briefs and Definitions of done send gitlab workers to open merge requests and to read back and clear draft state with glab-axi instead of gh-axi.
  • Harden the GitLab merge-request lifecycle: arming through bin/fm-pr-check.sh reads one JSON view of the merge request when jq is present, refuses a work_in_progress draft, and records the head sha as pr_head=; bin/fm-pr-merge.sh adds a live merge-time draft refusal; bin/fm-review-diff.sh compares against a freshly fetched refs/merge-requests/<iid>/head instead of warning down to the local branch; and bin/fm-teardown.sh proves a recorded merge request landed from the merged state plus that ref.
  • Bind every merge-request head fetch to a worktree origin that resolves to the recorded URL's GitLab host and project (fm_pr_gitlab_origin_matches in bin/fm-pr-lib.sh), so a same-numbered merge request of another project can never authorize review or cleanup; record the head-recording evidence and a live end-to-end pass (draft refusal, fresh review fetch, squash merge, teardown proof) in docs/gitlab-merge-watch.md, align the remaining forge docs, and pin the new behavior across ten test files.

Risk Assessment

⚠️ Medium: A large GitLab-forge feature port touching merge-authorization and cleanup-authorization paths; every traced path (origin-URL identity binding, merge-time draft refusal, arm-time draft/head recording, review fresh-head fetch, DoD/brief rendering, registry plumbing) behaves correctly with behavioral test coverage and all recorded rulings implemented, leaving only one informational dead-code residue.

Testing

Every scenario the maintainer's live-evidence request named was driven end-to-end against real gitlab.com in a marked disposable lab home: arm/refuse-draft on a real MR (refused while draft, armed with a glab-read head once ready), a fresh refs/merge-requests/<iid>/head review fetch (fresh head beat both stale signals, and refused to cross projects), merge-time draft refusal plus a real verified merge, and the teardown landed-work proof including its open-MR, stale-head, and cross-project-same-number refusals plus two full teardown successes (one load-bearing on the MR proof alone). Forge detection was verified across URL spellings. Transcripts for all nine live drives are in the evidence directory with an index, and the merged MR trail remains public on gitlab.com for the PR thread. Targeted regression suites for the changed files show zero failures; the only anomaly is a suite hang in tests/fm-captain-hold-lifecycle.test.sh that reproduces on the base commit (upstream main's own breakage, named per intent), while this change's two new tests in that suite pass in isolation. No source changes were needed; the worktree is clean and all disposable fixtures (lab home, clones, tmux servers, twin repo) were torn down. UI-screenshot note: this change's surfaces are CLI/script paths, so the evidence is command transcripts and forge state, not images.

  • Live validation: ✅ go - 9 of 9 scenarios driven live against the product
Scenario Result Live Evidence
Arm a task on a real gitlab.com MR: fm-pr-check refuses the draft MR and records nothing, then arms and records pr=+pr_head from glab's one JSON view once marked ready ✅ pass live s1-arm-draft-refusal.err + s1-arm-ready.out in evidence dir (rc=1 refusal with nothing recorded, then rc=0 armed with pr= and pr_head=44f21f9d… after glab mr update --ready)
Review a recorded GitLab MR: fm-review-diff compares against a freshly fetched refs/merge-requests/1/head even when the task branch and recorded pr_head are both stale ✅ pass live s2-review-diff.out (diff includes followup.txt; refs/fm-review/mr/1/head resolved to 64d742dc in the worktree)
Review head stays project-bound: fm-review-diff refuses to fetch another project's same-numbered MR head when the worktree origin names a different project (adversarial twin) ✅ pass live s2b-review-diff-crossproject.err/.out (warning + local-branch diff of cb-local.txt only; no refs/fm-review/mr/1/head created in that worktree)
Merge-time draft refusal: fm-pr-merge refuses a GitLab MR re-marked draft after arming, listing the new work_in_progress guard, and the MR stays unmerged ✅ pass live s3-merge-draft-refusal.err (rc=1, refusal lists detailed_merge_status=draft_status AND 'the merge request is a draft'; glab showed state=opened, merged_at=null afterwards)
Real merge: fm-pr-merge verifies live GitLab state and merges the ready MR with head binding and pipeline waiver ✅ pass live s4-merge.out (verified line naming head 64d742dc… then ✓ Merged!; glab read-back state=merged, merge_commit 2b9ac5f3; meta pr_head refreshed)
Teardown landed-work proof on a real MR: an open MR whose head ref carries the worktree HEAD is refused, and the same task tears down cleanly once that MR is really merged ✅ pass live s5c-teardown-open-mr-refuses.err (rc=1 REFUSED, state retained) and s5e-teardown-merged-mr-lands.out (rc=0 complete, window killed, backlog note 'GitLab merge request …/merge_requests/3')
Teardown safety twins on real merged MRs: a later local-only commit refuses, and a merged MR with contained head lands the full flow (backlog closed with the GitLab MR note) ✅ pass live s5a-teardown-stale-refuses.err (rc=1, 'work not on any remote and not landed', meta retained) and s5d-teardown-merged-lands.out (rc=0, backlog note 'GitLab merge request …/merge_requests/1')
Teardown cross-project origin binding (greptile-P1 attack): a merged MR URL in project A must not authorize cleanup through project B's same-numbered MR head that contains the worktree HEAD (adversari… ✅ pass live s5b-teardown-crossproject-refuses.err (rc=1 REFUSED 'work not on any remote and not landed', meta retained, backlog in_flight)
Forge detection at project intake: fm-forge-detect proposes forge=gitlab for gitlab.com origins in https, scp-like, and ssh:// spellings, and stays forge=none for self-hosted or non-GitLab hosts ✅ pass live s6-forge-detect.log (three spellings → forge=gitlab with evidence; self-hosted and github controls → forge=none)
Evidence: Live GitLab validation index (all scenarios + kept gitlab.com evidence links)

Source: Live GitLab validation index (all scenarios + kept gitlab.com evidence links)

Full live-validation index: lab-home contract, real gitlab.com repos/MRs, per-scenario transcripts, kept evidence links, and targeted-suite results.

# Live GitLab validation — firstmate GitLab forge port (branch fm/track-firstmate-upstream-pr-7226)

All scenarios below ran against **real gitlab.com** through the machine's existing
glab login (user gh0stwin), in a disposable firstmate lab home created with
`bin/fm-lab-home.sh` (marked lab home — no gate bypass; every fm-teardown run
printed `fm-gate-refuse: gate agent lifecycle permitted only against lab home`).
Only third-party tools outside this change's scope were stubbed on PATH, exactly
like the repo's own test fixtures: `treehouse` (no-op) and `no-mistakes` (no-op).
Everything else — glab, git, tmux (lab socket), tasks-axi — was real.

Evidence kept on gitlab.com (public, for the PR thread):
- Repo: https://gitlab.com/gh0stwin/fm-live-7243-a (kept)
  - MR !1 (merged, the main flow): https://gitlab.com/gh0stwin/fm-live-7243-a/-/merge_requests/1
  - MR !2 (merged, same-numbered twin for the cross-project attack): https://gitlab.com/gh0stwin/fm-live-7243-a/-/merge_requests/2
- Cross-project twin repo fm-live-7243-b (MR !1 open, MR !2 closed-with-head-ref,
  MR !3 squash-merged) was deleted after the run (gitlab renamed it
  `fm-live-7243-b-deletion_scheduled-*`).

## S1 — arm refuses a draft GitLab MR, arms after ready (s1-*)
`bin/fm-pr-check.sh task-x1 <MR !1 url>` on a real draft MR (created with
`glab mr create --draft`):
- s1-arm-draft-refusal.err: refusal "is a draft merge request ... mark it ready
  for review and arm again", rc=1, and the meta recorded nothing (no pr=).
- After `glab mr update 1 --ready`: rc=0, `armed: state/task-x1.check.sh`, meta
  gained `pr=<canonical url>` and `pr_head=44f21f9d…` read from glab's single
  JSON view.

## S2 — review diff uses a freshly fetched refs/merge-requests/1/head (s2-review-diff.*)
A follow-up commit was pushed to the MR branch from a *different* clone, so the
task worktree branch AND the recorded pr_head both lagged the live MR head
(64d742dc). `bin/fm-review-diff.sh task-x1` fetched
`refs/merge-requests/1/head` from gitlab.com and diffed both feature.txt and
followup.txt; `refs/fm-review/mr/1/head` in the worktree resolved to 64d742dc.

## S2b — review diff refuses another project's same-numbered head (s2b-*)
Worktree origin = fm-live-7243-b, recorded pr= names fm-live-7243-a MR !1.
Output: `warning: PR head unavailable; diff may lag the open PR (using local
branch fm/task-x2)` and a diff containing ONLY cb-local.txt — none of
fm-live-7243-b MR !1's head content (b-marker.txt / secret-mr1.txt), and no
`refs/fm-review/mr/1/head` ref was fetched into that worktree.

## S3 — merge-time draft refusal (s3-merge-draft-refusal.err)
After arming, the MR was re-marked draft and
`bin/fm-pr-merge.sh task-x1 <url> --allow-no-pipeline` refused (rc=1) listing
BOTH `detailed_merge_status is "draft_status", not mergeable` AND
`the merge request is a draft` (the new work_in_progress guard). The MR stayed
open/unmerged. Also shows the recorded-vs-live head disagreement notice
(44f21f9d vs 64d742dc) and the FM_PR_CHECK_MERGE=1 re-record path.

## S4 — real merge through fm-pr-merge (s4-merge.*)
`bin/fm-pr-merge.sh task-x1 <url> --allow-no-pipeline` verified live state
("open and mergeable at head 64d742dc…, with no head pipeline, waived by
--allow-no-pipeline") and merged MR !1 on gitlab.com (state=merged,
merge_commit 2b9ac5f3); meta pr_head refreshed to the live head.

## S5 — teardown landed-work proof and its refusals (s5a–s5e)
- s5a stale head: merged MR !1 + a later local-only commit → REFUSED
  ("work not on any remote and not landed"), meta/backlog/worktree retained.
- s5b cross-project (the greptile-P1 attack): recorded URL = fm-live-7243-a
  MR !2 (glab says merged), origin = fm-live-7243-b whose own same-numbered
  refs/merge-requests/2/head == the worktree HEAD → REFUSED, state retained.
- s5c open MR: recorded URL = fm-live-7243-b MR !3 (open), origin matches,
  head ref carries the wt HEAD → REFUSED.
- s5d merged lands (full flow): fm/task-x1 branch deleted + pruned so the
  merged MR is the landing proof → rc=0, meta removed, backlog closed with
  note `GitLab merge request <MR !1 url>` (real tasks-axi).
- s5e merged lands, MR proof uniquely load-bearing: MR !3 was squash-merged
  with --remove-source-branch, so the wt HEAD was unreachable from any
  remote-tracking ref; teardown read merged state through glab, fetched
  refs/merge-requests/3/head, proved containment, killed the real lab tmux
  window (server gone afterwards), synced the project, closed the backlog
  (`GitLab merge request <MR !3 url>`).

## S6 — forge detection on real clones (s6-forge-detect.log)
`bin/fm-forge-detect.sh` on clones with origins:
https://gitlab.com/… → `forge=gitlab evidence=… is on gitlab.com`;
[email protected]:… and ssh://[email protected]/… → forge=gitlab;
https://gitlab.internal.corp/… → forge=none; github.com control → forge=none.

## Targeted regression suites (gate worktree)
fm-forge-detect, fm-brief, fm-dod-lib, fm-project-mode, fm-task-delivery,
fm-pr-check-security, fm-review-diff: full pass. fm-pr-merge: 0 failures
(covered across two runs — the suite outran a single timeout budget).
fm-teardown: 81 oks, 0 failures, all GitLab delta tests green, cut by the
time budget. fm-captain-hold-lifecycle: the two GitLab delta tests pass in
isolation; the suite itself hangs in `test_hold_origins_follow_backend_holds`
— reproduced on the BASE commit (69023626), i.e. upstream main's own breakage.
Evidence: S1 arm-time draft refusal on a real gitlab.com MR

Source: S1 arm-time draft refusal on a real gitlab.com MR

error: https://gitlab.com/gh0stwin/fm-live-7243-a/-/merge_requests/1 is a draft merge request; a draft cannot be merged, so merge monitoring would wait for an event that cannot occur - mark it ready for review and arm again, or declare a wait instead of done if the draft is deliberate

error: https://gitlab.com/gh0stwin/fm-live-7243-a/-/merge_requests/1 is a draft merge request; a draft cannot be merged, so merge monitoring would wait for an event that cannot occur - mark it ready for review and arm again, or declare a wait instead of done if the draft is deliberate
Evidence: S2 fresh MR-head review fetch (worktree branch and pr_head both stale)

Source: S2 fresh MR-head review fetch (worktree branch and pr_head both stale)

diff base: origin/main feature.txt | 1 + followup.txt | 1 + (followup.txt existed only in the freshly fetched refs/merge-requests/1/head, not in the local branch or recorded pr_head)

diff base: origin/main
 feature.txt  | 1 +
 followup.txt | 1 +
 2 files changed, 2 insertions(+)

diff --git a/feature.txt b/feature.txt
new file mode 100644
index 0000000..3fe0868
--- /dev/null
+++ b/feature.txt
@@ -0,0 +1 @@
+live-gitlab-arm
diff --git a/followup.txt b/followup.txt
new file mode 100644
index 0000000..60a2efb
--- /dev/null
+++ b/followup.txt
@@ -0,0 +1 @@
+follow-up pushed from the project copy, not the task worktree
Evidence: S2b review-diff cross-project origin-binding refusal

Source: S2b review-diff cross-project origin-binding refusal

warning: PR head unavailable; diff may lag the open PR (using local branch fm/task-x2) — the other project's MR head was never fetched; diff showed only cb-local.txt

WARNING: watcher still down (same stale episode; last beat: 298s ago, grace 300s) - full banner already printed this episode.
warning: PR head unavailable; diff may lag the open PR (using local branch fm/task-x2)
Evidence: S3 merge-time draft refusal (new work_in_progress guard)

Source: S3 merge-time draft refusal (new work_in_progress guard)

error: refusing to merge … - detailed_merge_status is "draft_status", not mergeable - the merge request is a draft (MR stayed open and unmerged; recorded-vs-live head disagreement notice above it)

●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
●  WATCHER DOWN - SUPERVISION IS OFF
●  2 task(s) in flight, but no watcher has a fresh beacon (last beat: 317s ago, grace 300s).
●  Trust the emitted supervision protocol for this harness; do not use shell & for watcher repair.
●  This is a supervision warning only; the guarded operation WILL still run.
●  repair a missing or failed watcher cycle with the Pi tool fm_watch_arm_pi, or restart Pi with -e {run-worktree}/.pi/extensions/fm-primary-turnend-guard.ts -e {run-worktree}/.pi/extensions/fm-primary-pi-watch.ts if the extensions are not loaded.
●━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
notice: recorded head 44f21f9d5c4f3e5c59b7260945c91d8e0504750f disagrees with the live head 64d742dc2b1c6f92237d0b7c6340ed1119038d2d; verifying the live head
error: refusing to merge https://gitlab.com/gh0stwin/fm-live-7243-a/-/merge_requests/1
  - detailed_merge_status is "draft_status", not mergeable
  - the merge request is a draft
Evidence: S4 real merge through fm-pr-merge

Source: S4 real merge through fm-pr-merge

verified: … is open and mergeable at head 64d742dc…, with no head pipeline, waived by --allow-no-pipeline / ✓ Merged! (state=merged, merge_commit 2b9ac5f3)

armed: state/task-x1.check.sh
! No pipeline running on fm/task-x1
✓ Merged!
https://gitlab.com/gh0stwin/fm-live-7243-a/-/merge_requests/1
Evidence: S5b teardown cross-project refusal (greptile-P1 attack)

Source: S5b teardown cross-project refusal (greptile-P1 attack)

REFUSED: worktree … has work not on any remote and not landed. unpushed commits: 3c34a0b feat: task work that lives only in B MR !2 head — recorded URL names merged A MR !2 while origin is project B whose same-numbered head contains the worktree HEAD; refused and state retained

fm-gate-refuse: gate agent lifecycle permitted only against lab home /tmp/fm-lab.60l2Hy/home
WARNING: watcher still down (same stale episode; last beat: 3s ago, grace 300s) - full banner already printed this episode.
WARNING: queued wakes pending - drain them with bin/fm-wake-drain.sh before anything else.
REFUSED: worktree /tmp/fm-lab.60l2Hy/repo-b-wt has work not on any remote and not landed.
unpushed commits:
3c34a0b feat: task work that lives only in B MR !2 head
Push the branch, land its PR, or get the captain's explicit OK to discard, then --force.
Evidence: S5e teardown merged-lands success (MR proof uniquely load-bearing)

Source: S5e teardown merged-lands success (MR proof uniquely load-bearing)

teardown task-x4 complete (window firstmate:fm-task-x4, worktree …) / Backlog: task-x4 is closed — done against a squash-merged MR whose branch commits were unreachable from any remote-tracking ref, with the lab tmux window actually killed

/tmp/fm-lab.60l2Hy/repo-b-cc: synced f3319ec..591babe
teardown task-x4 complete (window firstmate:fm-task-x4, worktree /tmp/fm-lab.60l2Hy/repo-b-cc-wt)
Backlog: task-x4 is closed in /tmp/fm-lab.60l2Hy/home/data/backlog.md. Run bin/fm-tasks-axi.sh ready for dependency-cleared candidates, check date gates, and dispatch only work whose blockers are gone and date is due.
Evidence: S6 forge detection on real clone configs

Source: S6 forge detection on real clone configs

forge=gitlab evidence=origin remote https://gitlab.com/… is on gitlab.com (also git@ and ssh:// spellings); self-hosted gitlab.internal.corp and github.com controls → forge=none

== https origin:
forge=gitlab evidence=origin remote https://gitlab.com/gh0stwin/fm-live-7243-a.git is on gitlab.com
== scp-like ssh origin:
forge=gitlab evidence=origin remote [email protected]:gh0stwin/fm-live-7243-a.git is on gitlab.com
== ssh:// origin:
forge=gitlab evidence=origin remote ssh://[email protected]/gh0stwin/fm-live-7243-b.git is on gitlab.com
== self-hosted gitlab-looking host:
forge=none
== github control:
forge=none
Evidence: Kept live evidence: merged MR trail on gitlab.com

Source: Kept live evidence: merged MR trail on gitlab.com

MR !1: draft→refused→ready→armed→fresh-head-reviewed→re-draft→merge-refused→merged→teardown landed-work proof; MR !2: merged same-numbered twin used by the cross-project refusal.

# Live GitLab validation — firstmate GitLab forge port (branch fm/track-firstmate-upstream-pr-7226)

All scenarios below ran against **real gitlab.com** through the machine's existing
glab login (user gh0stwin), in a disposable firstmate lab home created with
`bin/fm-lab-home.sh` (marked lab home — no gate bypass; every fm-teardown run
printed `fm-gate-refuse: gate agent lifecycle permitted only against lab home`).
Only third-party tools outside this change's scope were stubbed on PATH, exactly
like the repo's own test fixtures: `treehouse` (no-op) and `no-mistakes` (no-op).
Everything else — glab, git, tmux (lab socket), tasks-axi — was real.

Evidence kept on gitlab.com (public, for the PR thread):
- Repo: https://gitlab.com/gh0stwin/fm-live-7243-a (kept)
  - MR !1 (merged, the main flow): https://gitlab.com/gh0stwin/fm-live-7243-a/-/merge_requests/1
  - MR !2 (merged, same-numbered twin for the cross-project attack): https://gitlab.com/gh0stwin/fm-live-7243-a/-/merge_requests/2
- Cross-project twin repo fm-live-7243-b (MR !1 open, MR !2 closed-with-head-ref,
  MR !3 squash-merged) was deleted after the run (gitlab renamed it
  `fm-live-7243-b-deletion_scheduled-*`).

## S1 — arm refuses a draft GitLab MR, arms after ready (s1-*)
`bin/fm-pr-check.sh task-x1 <MR !1 url>` on a real draft MR (created with
`glab mr create --draft`):
- s1-arm-draft-refusal.err: refusal "is a draft merge request ... mark it ready
  for review and arm again", rc=1, and the meta recorded nothing (no pr=).
- After `glab mr update 1 --ready`: rc=0, `armed: state/task-x1.check.sh`, meta
  gained `pr=<canonical url>` and `pr_head=44f21f9d…` read from glab's single
  JSON view.

## S2 — review diff uses a freshly fetched refs/merge-requests/1/head (s2-review-diff.*)
A follow-up commit was pushed to the MR branch from a *different* clone, so the
task worktree branch AND the recorded pr_head both lagged the live MR head
(64d742dc). `bin/fm-review-diff.sh task-x1` fetched
`refs/merge-requests/1/head` from gitlab.com and diffed both feature.txt and
followup.txt; `refs/fm-review/mr/1/head` in the worktree resolved to 64d742dc.

## S2b — review diff refuses another project's same-numbered head (s2b-*)
Worktree origin = fm-live-7243-b, recorded pr= names fm-live-7243-a MR !1.
Output: `warning: PR head unavailable; diff may lag the open PR (using local
branch fm/task-x2)` and a diff containing ONLY cb-local.txt — none of
fm-live-7243-b MR !1's head content (b-marker.txt / secret-mr1.txt), and no
`refs/fm-review/mr/1/head` ref was fetched into that worktree.

## S3 — merge-time draft refusal (s3-merge-draft-refusal.err)
After arming, the MR was re-marked draft and
`bin/fm-pr-merge.sh task-x1 <url> --allow-no-pipeline` refused (rc=1) listing
BOTH `detailed_merge_status is "draft_status", not mergeable` AND
`the merge request is a draft` (the new work_in_progress guard). The MR stayed
open/unmerged. Also shows the recorded-vs-live head disagreement notice
(44f21f9d vs 64d742dc) and the FM_PR_CHECK_MERGE=1 re-record path.

## S4 — real merge through fm-pr-merge (s4-merge.*)
`bin/fm-pr-merge.sh task-x1 <url> --allow-no-pipeline` verified live state
("open and mergeable at head 64d742dc…, with no head pipeline, waived by
--allow-no-pipeline") and merged MR !1 on gitlab.com (state=merged,
merge_commit 2b9ac5f3); meta pr_head refreshed to the live head.

## S5 — teardown landed-work proof and its refusals (s5a–s5e)
- s5a stale head: merged MR !1 + a later local-only commit → REFUSED
  ("work not on any remote and not landed"), meta/backlog/worktree retained.
- s5b cross-project (the greptile-P1 attack): recorded URL = fm-live-7243-a
  MR !2 (glab says merged), origin = fm-live-7243-b whose own same-numbered
  refs/merge-requests/2/head == the worktree HEAD → REFUSED, state retained.
- s5c open MR: recorded URL = fm-live-7243-b MR !3 (open), origin matches,
  head ref carries the wt HEAD → REFUSED.
- s5d merged lands (full flow): fm/task-x1 branch deleted + pruned so the
  merged MR is the landing proof → rc=0, meta removed, backlog closed with
  note `GitLab merge request <MR !1 url>` (real tasks-axi).
- s5e merged lands, MR proof uniquely load-bearing: MR !3 was squash-merged
  with --remove-source-branch, so the wt HEAD was unreachable from any
  remote-tracking ref; teardown read merged state through glab, fetched
  refs/merge-requests/3/head, proved containment, killed the real lab tmux
  window (server gone afterwards), synced the project, closed the backlog
  (`GitLab merge request <MR !3 url>`).

## S6 — forge detection on real clones (s6-forge-detect.log)
`bin/fm-forge-detect.sh` on clones with origins:
https://gitlab.com/… → `forge=gitlab evidence=… is on gitlab.com`;
[email protected]:… and ssh://[email protected]/… → forge=gitlab;
https://gitlab.internal.corp/… → forge=none; github.com control → forge=none.

## Targeted regression suites (gate worktree)
fm-forge-detect, fm-brief, fm-dod-lib, fm-project-mode, fm-task-delivery,
fm-pr-check-security, fm-review-diff: full pass. fm-pr-merge: 0 failures
(covered across two runs — the suite outran a single timeout budget).
fm-teardown: 81 oks, 0 failures, all GitLab delta tests green, cut by the
time budget. fm-captain-hold-lifecycle: the two GitLab delta tests pass in
isolation; the suite itself hangs in `test_hold_origins_follow_backend_holds`
— reproduced on the BASE commit (69023626), i.e. upstream main's own breakage.
  • Outcome: ⚠️ 1 info across 1 run (2h37m30s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

🔧 **Rebase** - 1 issue found → auto-fixed ✅
  • ⚠️ docs/scripts.md - merge conflict rebasing onto origin/main

🔧 Fix applied.
✅ Re-checked - no issues remain.

⚠️ **Review** - 1 info
  • ℹ️ bin/fm-dod-lib.sh:705 - The fm_dod_block refactor left two variables dead: contract_forge is declared (bin/fm-dod-lib.sh:552) and interpolated at the fm_dod_manual_pr_block call (bin/fm-dod-lib.sh:705) but never assigned anymore (the old contract_forge=&#39; forge=forgejo&#39; assignment was dropped in favor of forge_token), and forge_cli is now always the default gh-axi since the forgejo forge_cli=tea assignment was dropped. This is behavior-preserving only because fm_pr_text_valid refuses pr=manual on every forge!=none, so the manual block can only render for forge=none where both values were already the defaults; if pr=manual is ever allowed on gitlab/forgejo, the manual block would silently tell the worker to publish with gh-axi and drop the forge token from its Delivery contract line. Simplification: drop the two dead parameters from fm_dod_manual_pr_block (or keep the per-forge assignments) so the reachable-value invariant is stated in code rather than left implicit.
⚠️ **Test** - 1 info
  • ℹ️ tests/fm-captain-hold-lifecycle.test.sh:4502 - Pre-existing suite hang, not introduced by this change: tests/fm-captain-hold-lifecycle.test.sh hangs in test_hold_origins_follow_backend_holds (bin/fm-captain-hold.sh verify spins at ~100% CPU). Reproduced on the base commit 6902362 with a fresh git archive snapshot (full suite rc=124 after 600s with only 2 oks), so this is upstream main's own breakage; per the branch intent it is named, not fixed. The two GitLab tests this change adds to that suite (test_answer_before_cleanup_replay_notes_a_retained_gitlab_merge_request, test_teardown_retains_a_gitlab_captain_call_with_its_mr_url) pass when invoked in isolation (rc=0) from an unmodified copy of the current test file.
  • Live validation: ✅ go - 9 of 9 scenarios driven live against the product
Scenario Result Live Evidence
Arm a task on a real gitlab.com MR: fm-pr-check refuses the draft MR and records nothing, then arms and records pr=+pr_head from glab's one JSON view once marked ready ✅ pass live s1-arm-draft-refusal.err + s1-arm-ready.out in evidence dir (rc=1 refusal with nothing recorded, then rc=0 armed with pr= and pr_head=44f21f9d… after glab mr update --ready)
Review a recorded GitLab MR: fm-review-diff compares against a freshly fetched refs/merge-requests/1/head even when the task branch and recorded pr_head are both stale ✅ pass live s2-review-diff.out (diff includes followup.txt; refs/fm-review/mr/1/head resolved to 64d742dc in the worktree)
Review head stays project-bound: fm-review-diff refuses to fetch another project's same-numbered MR head when the worktree origin names a different project (adversarial twin) ✅ pass live s2b-review-diff-crossproject.err/.out (warning + local-branch diff of cb-local.txt only; no refs/fm-review/mr/1/head created in that worktree)
Merge-time draft refusal: fm-pr-merge refuses a GitLab MR re-marked draft after arming, listing the new work_in_progress guard, and the MR stays unmerged ✅ pass live s3-merge-draft-refusal.err (rc=1, refusal lists detailed_merge_status=draft_status AND 'the merge request is a draft'; glab showed state=opened, merged_at=null afterwards)
Real merge: fm-pr-merge verifies live GitLab state and merges the ready MR with head binding and pipeline waiver ✅ pass live s4-merge.out (verified line naming head 64d742dc… then ✓ Merged!; glab read-back state=merged, merge_commit 2b9ac5f3; meta pr_head refreshed)
Teardown landed-work proof on a real MR: an open MR whose head ref carries the worktree HEAD is refused, and the same task tears down cleanly once that MR is really merged ✅ pass live s5c-teardown-open-mr-refuses.err (rc=1 REFUSED, state retained) and s5e-teardown-merged-mr-lands.out (rc=0 complete, window killed, backlog note 'GitLab merge request …/merge_requests/3')
Teardown safety twins on real merged MRs: a later local-only commit refuses, and a merged MR with contained head lands the full flow (backlog closed with the GitLab MR note) ✅ pass live s5a-teardown-stale-refuses.err (rc=1, 'work not on any remote and not landed', meta retained) and s5d-teardown-merged-lands.out (rc=0, backlog note 'GitLab merge request …/merge_requests/1')
Teardown cross-project origin binding (greptile-P1 attack): a merged MR URL in project A must not authorize cleanup through project B's same-numbered MR head that contains the worktree HEAD (adversari… ✅ pass live s5b-teardown-crossproject-refuses.err (rc=1 REFUSED 'work not on any remote and not landed', meta retained, backlog in_flight)
Forge detection at project intake: fm-forge-detect proposes forge=gitlab for gitlab.com origins in https, scp-like, and ssh:// spellings, and stays forge=none for self-hosted or non-GitLab hosts ✅ pass live s6-forge-detect.log (three spellings → forge=gitlab with evidence; self-hosted and github controls → forge=none)
  • Live: bin/fm-pr-check.sh task-x1 https://gitlab.com/gh0stwin/fm-live-7243-a/-/merge_requests/1 on a real draft MR (refused) and after glab mr update --ready (armed, pr=+pr_head recorded)
  • Live: bin/fm-review-diff.sh task-x1 with the MR head moved past both the local branch and the recorded pr_head (fresh refs/merge-requests/1/head fetched and used)
  • Live: bin/fm-review-diff.sh task-x2 with origin fm-live-7243-b vs recorded URL fm-live-7243-a (cross-project head fetch refused, warning + local-branch fallback)
  • Live: bin/fm-pr-merge.sh task-x1 &lt;MR1&gt; --allow-no-pipeline on a re-drafted MR (refused listing 'the merge request is a draft'; MR stayed open)
  • Live: bin/fm-pr-merge.sh task-x1 &lt;MR1&gt; --allow-no-pipeline on the ready MR (verified at head 64d742dc, merged on gitlab.com)
  • Live: bin/fm-teardown.sh task-x4 against an open B MR !3 (REFUSED, state retained) and again after glab mr merge 3 --squash --remove-source-branch (rc=0, window killed, backlog closed with the GitLab MR note)
  • Live: bin/fm-teardown.sh task-x1 with a later local commit (REFUSED) and at the merged MR head after branch deletion+prune (rc=0 full flow)
  • Live: bin/fm-teardown.sh task-x2 cross-project attack — merged A MR !2 URL vs B origin with same-numbered head containing wt HEAD (REFUSED)
  • Live: bin/fm-forge-detect.sh on real clone configs (https/ssh/scp gitlab.com → forge=gitlab; self-hosted + github → forge=none)
  • Suites: tests/fm-forge-detect.test.sh, tests/fm-brief.test.sh, tests/fm-dod-lib.test.sh, tests/fm-project-mode.test.sh, tests/fm-task-delivery.test.sh, tests/fm-pr-check-security.test.sh, tests/fm-review-diff.test.sh (full pass)
  • Suites: tests/fm-pr-merge.test.sh (0 failures across two runs: 112 oks then invocations 110-122 isolated, 15 oks) and tests/fm-teardown.test.sh (81 oks, 0 failures, all GitLab delta tests green, cut by time budget)
  • Isolation check: the two new GitLab tests in tests/fm-captain-hold-lifecycle.test.sh pass when invoked alone; full suite hang reproduced on base commit 69023626 via git-archive snapshot
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @gh0stwin — forge=gitlab as a registry binding (detect proposes only for gitlab.com; unbound homes unchanged) is the same opt-in forge pattern as gerrit/forgejo, with draft refuse / arm / review-fetch / teardown landed-proof and live evidence on a throwaway fixture.

Diff review: forge-detect, project-mode, brief, pr-check/lib, review-diff, teardown, backlog note label, docs + tests. Workflow-zero. No secret/RCE surface. Fork CI approved for tip 350b3831 (CI 38482955547; Require no-mistakes 38483876648 / 38483858887 / 38482955468).

Attestation: MATCH 350b383166d972f3c4c91d0d0e0f9cdaf30dfd25. Live claim 14/14 noted.

Contract-class: opt-in. Unconfigured runs do not gain GitLab behavior; only projects with an explicit forge=gitlab binding do.

VISION.md: one-interface / authority / scripts / restart / spine / vendor / scope all align (explicit binding; GitHub regression covered).

Main 7df545bf is still CI red (unrelated Pi types + remote-reply). No merge this wake. Once this tip is green and main is green, this is on the auto-merge path (opt-in). Nothing needed from you unless CI surfaces an author-owned failure.

@gh0stwin
gh0stwin force-pushed the fm/track-firstmate-upstream-pr-7226 branch from 350b383 to ca86a7a Compare October 14, 2026 05:06
@gh0stwin gh0stwin changed the title feat(bin): add the forge=gitlab binding for GitLab merge requests feat(bin): support GitLab as a forge via glab merge requests Oct 14, 2026
@gh0stwin gh0stwin closed this Oct 14, 2026
@gh0stwin gh0stwin reopened this Oct 14, 2026
@gh0stwin

Copy link
Copy Markdown
Author

@kunchenguid can you run CI checks again?

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @gh0stwin — re-checking tip ca86a7ab (was 350b3831 at the last stamp) after you asked to run CI again.

Diff review (re-verified): forge-detect proposes forge=gitlab only for gitlab.com; unbound homes unchanged; arm/refuse-draft / review-fetch / teardown landed-proof gated on the binding. No secret/RCE surface.

Contract-class: opt-in. Unconfigured runs do not gain GitLab behavior; only projects with an explicit forge=gitlab binding do. Unconfigured path re-checked on this tip — still unchanged.

Attestation: MATCH ca86a7ab. Live 11/11 noted.
CI/NM: re-approved fork workflows for this tip — CI 38516904006 + Require no-mistakes 38516904023 now queued. Tip is ahead of green main 8c9c67de, behind 0.

VISION: one-interface / authority / scripts / restart / spine / vendor / scope all align.

Main is green now. Once this tip's CI is green with MATCH, this lands on the auto-merge path (opt-in) under the merge lock. Nothing needed from you unless CI surfaces an author-owned failure.

@gh0stwin
gh0stwin force-pushed the fm/track-firstmate-upstream-pr-7226 branch from ca86a7a to ddf0933 Compare October 18, 2026 22:11
@gh0stwin gh0stwin changed the title feat(bin): support GitLab as a forge via glab merge requests feat(bin): support GitLab as a registered forge for merge-request tasks Oct 18, 2026
@gh0stwin

Copy link
Copy Markdown
Author

@kunchenguid Is anything blocking this PR?

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks for the nudge, @gh0stwin, and sorry for the wait. Two things were holding this, and neither one is your code being wrong.

1. CI never ran on your current tip. The ddf0933c push from Oct 18 left the fork workflows waiting for approval, and nobody approved them. I've reviewed the diff at this tip (24 files: forge-detect, project-mode, brief/DoD, pr-check/pr-lib, review-diff, teardown, spawn comment, docs, tests). There are no workflow edits and no secret or network surface beyond the existing glab reads, so I approved CI 39171170949 and Require no-mistakes 39171170945 / 39171286820. They're queued now. The attestation in the body matches ddf0933c.

2. I'm changing the contract-class from my earlier opt-in stamp to new-default. That's on me for not catching it sooner. The forge=gitlab registry binding itself is opt-in, because detect only proposes it and the captain confirms it. But several of the new paths key off the recorded MR URL, not the binding: the arm-time draft refusal in fm-pr-check.sh (PROVIDER=gitlab), the refs/merge-requests/<iid>/head review fetch in fm-review-diff.sh, and the GitLab landed-work proof in fm-teardown.sh. Main already merge-watches GitLab MRs without any forge token (docs/gitlab-merge-watch.md), so a home with no forge=gitlab binding that tracks a GitLab MR would now refuse a draft at arm, review a fetched MR head, and take a new teardown proof. GitHub and Forgejo paths are unchanged. These look like improvements, but they change what an unconfigured run does on an existing path, so this isn't an auto-merge. Once CI is green, it goes to Kun as a merge-or-leave decision.

VISION.md: one captain, one interface — aligns (no new captain-facing surface) · authority explicit — aligns for the binding; the URL-keyed arms change default behavior, which is why this needs the captain · scripts/agents — aligns (exact glab/jq reads, degrades without jq) · restart is a non-event — aligns (MR head/teardown proof from durable refs) · delegation with a spine — aligns (draft refusal, landed-work proof) · outlives any vendor — aligns (adds a forge; no GitHub coupling) · scope — aligns.

Nothing is needed from you unless CI comes back red on something in your diff. After that, this waits on the captain, not you.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks @gh0stwin. CI on head ddf0933c came back green apart from the usual serial 2 time-cap cancel, but main has moved since and GitHub now reports this PR as conflicting. Because I read it as new-default, I won't resolve the conflict here. When you can, please rebase onto current main and re-raise through git push no-mistakes so the attestation binds the new head. Once it's green and mergeable, it goes to Kun as a merge-or-leave decision. Waiting on you for the rebase.

@gh0stwin
gh0stwin force-pushed the fm/track-firstmate-upstream-pr-7226 branch from ddf0933 to 824fcbf Compare October 24, 2026 09:49
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks for the rebase, @gh0stwin. GitHub now reports this PR as mergeable on head 824fcbf5, and the no-mistakes attestation in the body is bound to that head.

I re-read the diff at this tip. It touches the same 24 files as before, there are no workflow edits, and the only new forge access is the existing glab reads plus the refs/merge-requests/<iid>/head fetch. So I approved the fork CI runs for this head: CI 40083500504 and Require no-mistakes 40083500491 / 40083570211.

My contract-class read is unchanged: new-default. The draft refusal at arm, the MR-head review fetch, and the GitLab teardown proof still key off the recorded MR URL (PROVIDER=gitlab), not the forge=gitlab binding. That means a home with no binding that already merge-watches a GitLab MR would pick up the new behavior. That isn't a flaw in your code. It just means Kun makes the call here, not auto-merge. Once CI comes back green on this head, it goes to him as a merge-or-leave decision. Right now this is waiting on CI, not on you.

@gh0stwin gh0stwin changed the title feat(bin): support GitLab as a registered forge for merge-request tasks feat(bin): support GitLab merge requests as a first-class forge Oct 24, 2026
@gh0stwin
gh0stwin force-pushed the fm/track-firstmate-upstream-pr-7226 branch from 824fcbf to 18020c2 Compare October 25, 2026 17:37
@gh0stwin gh0stwin changed the title feat(bin): support GitLab merge requests as a first-class forge feat(bin): add GitLab forge support for merge requests Oct 25, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks for the new push, @gh0stwin. I re-read the diff at 18020c23 against main abb81944. It's the same 24 files, still with no workflow edits, and the only forge access is still glab reads plus the refs/merge-requests/<iid>/head fetch. I found no security concerns. The no-mistakes attestation in the body is bound to 18020c23, the live GitLab evidence covers 6 of 7 scenarios, and the PR merges cleanly onto current main.

I've approved the fork CI runs for this head: CI 40217370192, plus body-compliance 40217370193 and 40217625823. They're queued now.

My contract-class read hasn't changed: new-default. The arm-time draft refusal and the teardown proof still key off the recorded MR URL (PROVIDER=gitlab, */-/merge_requests/*), not the forge=gitlab binding. Your code isn't wrong. It just means the merge is Kun's call. Once CI is green on this head, I'll send it to him as merge-or-leave. Right now this is waiting on CI, not on you.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thanks for your patience, @gh0stwin. The serial 1 rerun came back green, so all 19 checks now pass on 18020c23. The no-mistakes check passes and the attestation binds this head (live 6/7). The PR is CLEAN against main 2b46ed1f. Last pass I also ran the changed test files locally on main 2b46ed1f plus this PR, and they passed. The diff is the same 24 files with no workflow edits, and the only forge access is glab reads plus the refs/merge-requests/<iid>/head fetch. I found no security concerns.

My contract-class read is still new-default: the arm-time draft refusal and the teardown proof key off the recorded MR URL (PROVIDER=gitlab, */-/merge_requests/*), not the forge=gitlab binding. VISION.md aligns on every rule, so whether to take it is a product call for Kun.

Status: with Kun for a merge-or-leave decision. It's not waiting on you, and there's nothing more you need to do right now.

@gh0stwin gh0stwin changed the title feat(bin): add GitLab forge support for merge requests feat(bin): add forge=gitlab support for GitLab merge requests Nov 1, 2026
@greptile-apps

greptile-apps Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] No newly established issue blocks merging this PR.

Reviews (4) · Last reviewed commit: "no-mistakes(document): add work_in_progr..." · Reviewed by Greptile

Comment thread bin/fm-teardown.sh Resolved
Comment thread tests/fm-teardown.test.sh Resolved
@gh0stwin

gh0stwin commented Nov 1, 2026

Copy link
Copy Markdown
Author

Thanks - both findings are real, and both are being fixed in this validation round.

P1 (bin/fm-teardown.sh - Cleanup trusts another MR): Correct. The merged-state read is addressed through the recorded URL's host+project (fm_pr_url_parse -> fm_pr_gitlab_read_record), while the containment head is fetched from the worktree's origin remote keyed only by the MR number, so a recorded URL and an origin naming different projects could let a merged MR in one project authorize cleanup of work contained only in a same-numbered unmerged MR in the other. The fix landing in this round binds the two: the proof verifies the worktree's origin remote resolves to the same GitLab host+project as the recorded URL before trusting the origin-fetched head, and a mismatch refuses (falling back to the content check), pinned by an adversarial twin test.

P2 (tests/fm-teardown.test.sh - Test reuses an earlier fixture): Correct. make_case tasks-axi-close-gitlab is called by both close tests, so the second setup re-initializes an existing bare origin and clones into a populated directory (the two Git errors in the log) and then continues on the first test's leftover clone and worktree. The fix gives the second test its own fixture name so its case is built fresh.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @gh0stwin for the new round, and for the clear read on both Greptile findings. I agree with both. The teardown proof should only trust an origin that names the same GitLab host and project as the recorded MR URL, and the second close test needs its own fixture.

Waiting on you: push those two fixes, including the adversarial twin test you described, and re-raise through git push no-mistakes. Since the teardown landed-work proof changes, please include a short live run of that path on your throwaway GitLab repo: a matching origin is trusted and a mismatched origin falls back to the content check. Then resolve the two threads.

Two notes so nothing surprises you. GitHub reports the branch as conflicting with main e1a7a2ff, so CI hasn't started on 47c59caf. That conflict is ours to fix on a merge word, so please don't rebase for it. Also, this was with Kun as a merge-or-leave decision on 18020c23. The open P1 on the new head pauses that until your fix lands, and then it goes back to him. Contract-class: new-default (unchanged). VISION.md: unchanged, aligns on every rule.

@gh0stwin
gh0stwin force-pushed the fm/track-firstmate-upstream-pr-7226 branch from 47c59ca to a55d0b4 Compare November 2, 2026 00:34
@gh0stwin gh0stwin changed the title feat(bin): add forge=gitlab support for GitLab merge requests feat(bin): support GitLab as a registered forge end to end Nov 2, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @gh0stwin, this round covers everything we asked for. fm_pr_gitlab_origin_matches now binds both the teardown landed-work proof and the review fetch to the host and project in the recorded MR URL, and it compares the raw origin rather than the insteadOf-expanded one, which was a nice catch. The close test has its own fixture, both Greptile threads are resolved, and your live runs show both sides of the teardown path on your throwaway GitLab repo: a matching origin is allowed (r3-06), and a cross-project origin with the same MR number is REFUSED with its state kept (r3-07).

On a55d0b4d the no-mistakes attestation binds the head with every step run, live validation is 8 of 9 (the untested row is the unit-suite aggregate), and Greptile is at 5/5.

This is now waiting on Kun, not you. It's back with him as the merge-or-leave decision. GitHub reports the branch as conflicting with main b7d2533f, so CI hasn't run on this head. That conflict is ours to fix on a merge word, and we'll run fresh CI then, so please don't rebase for it.

Contract-class: new-default (unchanged). VISION.md: unchanged, aligns on every rule.

@gh0stwin
gh0stwin force-pushed the fm/track-firstmate-upstream-pr-7226 branch from a55d0b4 to 4e8212e Compare November 2, 2026 05:23
gh0stwin and others added 16 commits November 3, 2026 11:51
… arm

tasks-axi types a --pr link only as a GitHub or Forgejo pull request url,
so a GitLab merge request url made the teardown atomic close refuse (both
GitLab teardowns failed on it today). Extend the Gerrit note-rewrite
precedent to GitLab: fm_backlog_pr_note_label labels any untaken forge
url by its forge, and done, retain, and retained-artifact close record it
as a labeled note instead of refusing.

bin/fm-pr-check.sh now requires jq for a GitLab arm, names glab and jq
together when either is missing, reads one JSON view of the merge request
and refuses a work_in_progress draft exactly like the GitHub arm-time
draft refusal, and records the MR head sha as pr_head for teardown and
review consumers.

fm_pr_json_draft_state takes the field name so GitLab's work_in_progress
reads through the same helper. fm_pr_gitlab_read_record gains the
glab-axi fallback its GitHub twin already had, with the glab
implementation split out as fm_pr_gitlab_read_record_with_glab.
fm-review-diff.sh fetches the compare tip for a GitLab merge request
from refs/merge-requests/<iid>/head, the ref GitLab keeps for every
merge request, instead of warning down to the local branch; the one
fetch helper now takes the ref pair, so the GitHub pull ref and the
GitLab merge-request ref share one mechanism.

fm-teardown.sh proves a recorded GitLab merge request landed the same
way the GitHub path does: merged state through
fm_pr_gitlab_read_record, head fetched from
refs/merge-requests/<iid>/head, then the same ancestor-or-patch-id
containment proof. pr_ref_for_target picks the forge ref for a bare
number or either URL shape.

fm-pr-merge.sh merges a merge request with --squash when the caller
names no method, mirroring the GitHub default the header already
documents, because the fleet's recording and teardown machinery
reasons on squash merges.

The forge closed set gains gitlab: fm-project-mode.sh parses and
refuses it like gerrit, fm_forge_valid_for_mode accepts it for the
publishing modes, a direct-PR DoD block on gitlab tells the worker to
open its merge request with glab-axi and read its draft state back,
fm-brief.sh names glab-axi in a gitlab ship brief's tool rule, and
fm-forge-detect.sh proposes forge=gitlab from a gitlab.com origin.
yolo stays available on gitlab; a base branch stays refused on gerrit
publishes only, since a merge request targets any branch.

docs: architecture.md, gerrit-forge-integration.md, and
gitlab-merge-watch.md updated for the new behaviors, with dated
arm-time head-recording and jq-refusal evidence against the public
fixture. tests: arm-time head and draft, squash default, teardown MR
proof and MR-url close, review-diff MR head, gitlab forge rows,
detection proposals, DoD rendering, and the brief binding.
The fallback accepted the gh-twin spelling 'open' where GitLab's native
open state is 'opened', so a host without plain glab read every open
merge request as state unknown; it also rejected 'locked' as unreadable.
Accept the native spellings, passing 'locked' through the way the
plain-glab twin does, and pin the fallback with the tests it never had:
the fake-glab-axi state matrix, the rendered gitlab tool rule and forge
token in the ship brief, and the gitlab retain and retained-artifact
labels on the captain-held cleanup paths.

Findings and remedy from the adversarial review of the port
(data/fm-gitlab-port-adversarial-review/report.md, F1-F4).
The merge with main replaced the gitlab port's no-mistakes draft-readback
sentence with the forge-specific direct-PR wording, so a gitlab no-mistakes
brief told the worker to read the pipeline's own pull request back through
glab-axi. The readback is now scoped to the no-mistakes block: gh-axi for
none and gitlab, main's tea sentence for forgejo, whose pipeline-opened pull
request lives on the Forgejo forge.

Two unit pins that predate the gitlab forge value also broke under the port:
fm-brief's closed-set table and fm-project-mode's glabbed fixture both
refused forge=gitlab, which the port accepts. Both now pin the binding
positively, and the fm-brief forge test covers the gitlab Rule 3 line, the
delivery-contract line, and the pipeline-scoped draft readback.

Records the 2026-10-13 live end-to-end evidence in docs/gitlab-merge-watch.md
against a real public fixture merge request: the draft-refusal arm, a fresh
refs/merge-requests/<iid>/head review fetch that out-ranked a stale recorded
pr_head, the guarded squash merge with a successful head pipeline, and the
teardown landed-work proof after the merge.
…ebase

The rebase onto main composed main's FORGE_RULE_LINE refactor (from the
pr=manual feature) with the GitLab port's forge arms, but the ship heredoc
still expanded the port's old $RULE3 variable, which the composed block no
longer defines: every ship scaffold died on an unbound variable under set -u.
Render rule 3 from FORGE_RULE_LINE, whose gitlab arm the composition keeps,
so the glab-axi/tea/gh-axi rule lines reach the brief unchanged.
A GitLab landed-work proof read its merged state through the recorded
URL's host, path, and number (fm_pr_gitlab_read_record) but fetched its
containment head from the worktree's origin remote addressed by merge
request number alone, and bin/fm-review-diff.sh fetched its fresh review
head the same way. When the URL and the origin remote name different
projects, a merged merge request in one project could authorize cleanup
of - or review against - a same-numbered merge request of another
project the origin happens to serve.

Add fm_pr_gitlab_origin_matches to bin/fm-pr-lib.sh and call it at both
readers: gitlab_mr_is_merged refuses on mismatch (the caller falls back
to the content check, never trusting the origin-fetched head), and
resolve_pr_head's GitLab arm leaves the head unresolved so the offline
fallbacks apply. The check compares the raw configured origin URL -
never the insteadOf-expanded transport, which only says where the same
project is fetched from - after normalizing https/http/ssh/git and
scp-like spellings, with a case-insensitive host, a case-sensitive
project path, and a conventional trailing ".git" removed; a URL naming
no host and project never matches. The merged-lands teardown test now
pins both https and ssh spellings, and adversarial twins prove the
refusal: a cross-project origin leaves teardown REFUSED with state
retained, and a review whose origin names another project falls back to
the recorded pr_head instead of the other project's fresh head.

Also give test_teardown_closes_a_gitlab_task_with_its_mr_url_as_a_note
its own fixture (tasks-axi-close-gitlab-mr-note): it reused the earlier
close test's fixture, so make_case re-initialized an existing bare
origin and cloned into a populated directory, continuing on leftover
state with two Git setup errors per run.
… arm

The GitLab origin-mismatch arm added in 487f4f0d guards the merge-request
head fetch with fm_pr_gitlab_origin_matches, so on a mismatch the resolved
local is never assigned; under set -u the function then crashed at
[ -n "$resolved" ] before the recorded-pr_head fallback could run, printed
'line 185: resolved: unbound variable' to the user, and degraded the review
to the local branch instead of the recorded head the commit promises.

Initialize resolved empty. The cross-project unit twin now advances the
local branch past the recorded pr_head, asserts the recorded head wins over
the moved branch, and asserts the mismatch path leaves stderr clean; it
fails on 487f4f0d and passes with this fix (proven live against gitlab.com
in the evidence for this round).
bin/fm-pr-check.sh's header states that fm-pr-merge.sh records through
it with FM_PR_CHECK_MERGE=1 and skips the arm-time draft refusal
"because its own merge-time draft refusal is authoritative", but
gitlab_verify_mergeable never read work_in_progress, so a merge request
marked draft after arming reached `glab mr merge` with no
firstmate-side refusal while GitHub and Forgejo both refuse theirs.
Mirror those twins: read work_in_progress from the same one live view
of the merge request, refuse unless it reads false, and report
"the merge request is a draft" alongside every other failing condition,
so the header claim is authoritative on every forge.
@gh0stwin
gh0stwin force-pushed the fm/track-firstmate-upstream-pr-7226 branch from 4e8212e to dfeaa6a Compare November 3, 2026 15:03
@gh0stwin gh0stwin changed the title feat(bin): support GitLab as a registered forge end to end feat(bin): support GitLab merge requests end to end Nov 3, 2026
@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @gh0stwin for the new round. I read head dfeaa6a6. It now sits on current main 69023626 and merges cleanly. The one new piece is the merge-time draft refusal in fm-pr-merge.sh: work_in_progress is read from the same live view and refused unless it is false. It has its own tests and a live run (s3), and it brings GitLab in line with the GitHub and Forgejo merge paths. The attestation binds this head with every step completed, live validation is 9 of 9, and Greptile is 5/5 with both threads resolved. The diff has no workflow edits, so I approved the fork CI runs for this head.

This is still waiting on Kun, not you, as the merge-or-leave decision. Contract-class: new-default (unchanged). VISION.md: unchanged, it aligns on every rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants