Skip to content

fix(bin): converge GitLab notes and close state - #9

Merged
eyevanovich merged 3 commits into
mainfrom
fm/firstmate-gitlab-workitem-note-id
Jul 23, 2026
Merged

eyevanovich merged 3 commits into
mainfrom
fm/firstmate-gitlab-workitem-note-id

Conversation

@eyevanovich

Copy link
Copy Markdown
Owner

Intent

Autofix the remaining live GitLab WorkItem completion bug after PR #7. Issue 146 is a trusted self-owned WorkItem whose exact authenticated completion note appears three times because WorkItem noteable_id is a separate opaque positive identity from the legacy Issues API .id. Through the trusted issue-notes endpoint, reuse any existing exact authenticated non-system WorkItem note without comparing its opaque noteable_id to the issue API ID and never POST another duplicate; preserve strict comparable identity checks for legacy Issue and MergeRequest notes, exact body and author matching, pagination, malformed-ID rejection, and field-name-only mismatch diagnostics. Also make issue-close converge both new and already-closed self-owned issues to closed with all execution/workflow labels removed while preserving unrelated labels and ownership, without repeating an already-landed state transition; enforce the directly equivalent MR close invariant. Keep all fixes and tests within WorkItem note identity/deduplication and issue/MR close-state convergence, and do not broaden the public API.

What Changed

  • Reuse exact authenticated non-system GitLab WorkItem notes without comparing their opaque noteable_id to the legacy issue ID, while preserving strict Issue and MergeRequest identity checks and malformed-ID rejection.
  • Make issue and merge-request close operations remove workflow labels, preserve unrelated metadata, and converge already-closed resources without repeating the close transition.
  • Expand mutation coverage for note deduplication, endpoint-scoped identity validation, field-only mismatch diagnostics, malformed note IDs, and idempotent close cleanup.

Risk Assessment

✅ Low: Captain, the prior correctness findings are resolved and the only remaining issue is an unused private helper.

Testing

The previously completed full baseline passed, the focused GitLab mutation suite passed twice, and its captured CLI/API trace directly demonstrates WorkItem note reuse, strict legacy identity handling, malformed-ID rejection, and idempotent issue/MR close-state convergence; no UI surface was changed, so visual evidence was not applicable.

Evidence: GitLab end-user flow evidence
137:+ out='{"resource":"issue","note":{"id":501,"body":"Live work-item note.\nSecond line: \"quoted\" & UTF-8 café.\n","author":"mate","already":true}}'
172:+ out='{"resource":"issue","note":{"id":501,"body":"Live work-item note.\nSecond line: \"quoted\" & UTF-8 café.\n","author":"mate","already":true}}'
202:+ out='{"resource":"issue","note":{"id":551,"body":"Legacy issue note.\n","author":"mate","already":true}}'
210:+ jq -cn --argjson exact '{"id":651,"body":"Legacy MR note.\n","author":{"id":42,"username":"mate"},"system":false,"noteable_id":8005,"noteable_type":"MergeRequest","project_id":314,"noteable_iid":5}' $'[\n    ($exact | .id=649 | .noteable_type="WorkItem" | .noteable_iid=null),\n    ($exact | .id=650 | .noteable_iid=6),\n    $exact\n  ]'
227:+ out='{"resource":"mr","note":{"id":651,"body":"Legacy MR note.\n","author":"mate","already":true}}'
257:+ jq -cn --rawfile body /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/repo/malformed-existing-note.md $'\n    [{id:0,body:$body,author:{id:42,username:"mate"},system:false,\n      noteable_id:77146,noteable_type:"WorkItem",project_id:314,noteable_iid:null}]'
459:+ out='{"resource":"issue","note":{"id":501,"body":"Worker update.\n","author":"mate","already":true}}'
483:+ jq -e $'.issue.state == "closed" and .issue.labels == ["bug"]\n    and .issue.assignees == ["mate"]'
484:++ count_log '"state_event":"close"'
485:++ local 'pattern="state_event":"close"'
486:++ grep -c -- '"state_event":"close"' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/glab.log
504:++ count_log '"state_event":"close"'
505:++ local 'pattern="state_event":"close"'
506:++ grep -c -- '"state_event":"close"' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/glab.log
525:++ jq -r .issue.state
595:+ jq -e $'.issue.state == "closed" and .issue.labels == ["bug"]\n    and .issue.assignees == ["mate"]'
596:+ assert_no_grep '"state_event":"close"' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/glab.log 'issue close retry repeated an already-landed state transition'
597:+ grep -F -- '"state_event":"close"' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/glab.log
644:+ jq -e $'.mr.state == "closed" and .mr.labels == ["backend"]\n    and .mr.assignees == []'
645:+ assert_no_grep '"state_event":"close"' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/glab.log 'merge-request close retry repeated an already-landed state transition'
646:+ grep -F -- '"state_event":"close"' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/glab.log
757:++ count_log 'input={"add_labels":"docs","remove_labels":"bug"}'
758:++ local 'pattern=input={"add_labels":"docs","remove_labels":"bug"}'
759:++ grep -c -- 'input={"add_labels":"docs","remove_labels":"bug"}' /var/folders/j_/g4b3__rs5j95fq6xf9fb17sc0000gn/T//fm-forge-mutations-tests.fstRVI/glab.log
1297:+ out='{"resource":"mr","note":{"id":601,"body":"MR update.\n","author":"mate","already":true}}'
1323:+ jq -e '.mr.state == "closed" and .mr.labels == ["docs"]'
1341:++ jq -r .mr.state
Evidence: Targeted mutation-suite transcript
ok - issue claim sends explicit JSON media type and preserves array encoding
ok - live work-item note shape verifies exact resource and suppresses duplicates
ok - note list matching and read-back share strict endpoint-scoped identity
ok - malformed created note IDs cannot pass read-back verification
ok - malformed matching note IDs fail closed without duplicate posts
ok - issue creation validates labels, optional claim, identity, and canonical read-back
ok - issue claim, status, note, close, reopen, and release converge safely
ok - close retries remove workflow labels without repeating landed transitions
ok - already-correct issue claims, statuses, and label deltas are no-ops
ok - issue release can return self-owned work to the ready queue without clobbering labels
ok - issue mutations cannot steal or bypass exact ownership
ok - missing, archived, and malformed label metadata blocks mutations
ok - malformed targets, labels, usernames, and non-regular note files are rejected
ok - issue API identity rejects foreign, mismatched, and malformed work-item URLs
ok - untrusted projects and API failures never report a successful mutation
ok - issue and note mutations require deterministic matching read-back
ok - merge-request claim, status, labels, notes, lifecycle, and release converge safely
ok - merge-request workflow labels require status and release commands
ok - merge-request mutations preserve project, author, branch, head, and API guards
ok - issue creation and comments surface API and verification failures

Pipeline

Updates from git push no-mistakes

✅ **intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 info
  • 🚨 bin/fm-forge.sh:591 - The intent requires “never POST another duplicate” and preserving “malformed-ID rejection.” find_matching_note silently skips an otherwise exact authenticated non-system note whose .id is malformed; if no valid duplicate follows, post_note falls through to POST. Reject this case with an id-only diagnostic instead of posting.
  • ⚠️ bin/fm-forge.sh:1117 - The close path now changes workflow labels, but the script header still states that workflow labels are changed only by claim, status, and release commands. Update that safety contract to include close cleanup.
  • ℹ️ bin/fm-forge.sh:1117 - Issue and MR close duplicate workflow-label removal, expected-label calculation, idempotence, and payload construction. Extract the shared close-state calculation so these directly equivalent invariants cannot drift.

🔧 Fix: Fix note deduplication and close-state convergence
1 info still open:

  • ℹ️ bin/fm-forge.sh:575 - note_identity_valid() is now unused; matching and required verification both call note_identity_mismatches() directly. Remove this dead wrapper to simplify the identity helper surface.
✅ **Test** - passed

✅ No issues found.

  • command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
  • Pre-run baseline: command -v tmux >/dev/null || { echo "tmux is required for e2e tests" >&2; exit 1; }; tmux -V; rc=0; for t in tests/*.test.sh; do echo "== $t =="; bash "$t" || rc=1; done; exit "$rc"
  • bash tests/fm-forge-mutations.test.sh
  • bash -x tests/fm-forge-mutations.test.sh with filtered CLI-response and mutation evidence captured to gitlab-user-flow-evidence.txt
  • Verified the testing run left the git worktree clean with git status --short
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

Ivan Miles Piesh added 3 commits July 22, 2026 19:41
WorkItem note IDs are opaque and can differ from the legacy issue API
ID. Match exact authenticated notes by their trusted issue endpoint fields
so retries reuse existing notes instead of posting duplicates.

Closing issues and merge requests now also clears workflow labels,
including recovery from a state transition that landed before label
cleanup.
@eyevanovich
eyevanovich merged commit 3a8f505 into main Jul 23, 2026
@eyevanovich
eyevanovich deleted the fm/firstmate-gitlab-workitem-note-id branch July 23, 2026 03:19
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.

1 participant