Skip to content

fix(ci): explicitly close linked issue on principal-review auto-merge - #404

Merged
libravault-xyz merged 2 commits into
devfrom
fix/close-issue-on-auto-merge
Aug 22, 2026
Merged

libravault-xyz merged 2 commits into
devfrom
fix/close-issue-on-auto-merge

Conversation

@libravault-pipeline-bot

Copy link
Copy Markdown
Contributor

What

principal-review.yml's auto-merge step now explicitly closes the PR's
linked issue (via resolve_linked_issue.sh, the same logic
dev-agent.yml/qa-agent.yml already share) right after a successful
gh pr merge --squash, instead of relying solely on GitHub's implicit
close-on-merge behaviour.

Why

Confirmed live: issue #178 (PR #264) and issue #314 (PR #316) both merged
via this exact auto-merge step, but were left open afterward carrying
stale status:ready-for-dev/status:in-progress labels — GitHub's
implicit close-on-merge silently didn't fire. Flagged by the pipeline
health-check routine at the time as "a new failure mode" but never
tracked until #402 filed it.

Approach

  • After a successful merge, resolve the linked issue number
    (resolve_linked_issue.sh, already used elsewhere in this same step for
    the audit-log entry — deduplicated into a single call now, computed once
    and reused).
  • If the issue is still OPEN, strip its stale pipeline status labels
    (status:triage/status:ready-for-dev/status:in-progress/
    status:needs-info) and gh issue close it with an explanatory comment.
  • If it's already closed (GitHub's implicit close did fire this time) or
    the issue can't be resolved/read, log why and move on — best-effort,
    never fails the run, matching the existing style of this step (e.g. the
    audit-log block right below it).

Risk

This touches .github/workflows/**, one of agent-policy.yml's
sensitive_paths — classify_pr_risk.py will force risk:high on this
PR regardless of diff size, and it will always land on
status:needs-human-merge, never auto-merge. Flagging explicitly per
AGENTS.md/the dev-agent persona rather than leaving it for the
principal reviewer to rediscover.

The change only adds calls after a merge has already succeeded
(MERGED=true) — it cannot affect whether a PR merges, only what happens
to the issue immediately afterward, and every new gh issue call is
non-fatal on failure (|| true / logged fallback), so it can't turn a
successful merge into a failed workflow run.

Cleanup

Manually closed #178 and #314 (both confirmed merged via #264/#316) as
requested in #402's "Cleanup needed" section, with a comment explaining
why they'd been sitting open.

Out of scope (flagging, not fixing here)

human-merge-sweep-agent.md's manual-merge path (status:needs-human-merge
→ gh pr merge --squash under the same GITHUB_TOKEN) is structurally the
same merge call and could plausibly hit the identical implicit-close gap —
but #402 only reports and asks for a fix on principal-review.yml's
auto-merge step, and .claude/agents/** is itself a sensitive_paths
entry requiring direct human edit/review in this environment (this
session isn't permitted to write to it). Worth a human's judgment on
whether to file a follow-up for that path.

Testing

  • .github/scripts/test_resolve_linked_issue.sh — pre-existing regression
    suite for the shared resolution logic this change calls into, still
    passes unchanged (this PR doesn't modify that script).
  • Validated the modified workflow file parses as valid YAML
    (yaml.safe_load) and the extracted "Auto-merge if approved" step's
    shell passes bash -n.
  • No local way to execute a GitHub Actions workflow step (gh issue close/gh issue edit calls against a real merge) outside of a real PR
    merge in this repo — CI on this PR is the first real signal on syntax/
    permissions (issues: write is already granted at job level), and an
    actual live exercise of the new logic only happens the next time some
    PR in this pipeline auto-merges cleanly.

Closes #402

GitHub's implicit close-on-merge doesn't reliably fire for PRs merged by
principal-review.yml's auto-merge step, leaving the originating issue open
with stale status:ready-for-dev/status:in-progress labels (confirmed live
on issues #178 and #314). Resolve the linked issue via
resolve_linked_issue.sh after a successful merge, clear its stale pipeline
labels, and close it explicitly instead of relying on GitHub's parser.

Closes #402
@github-actions
github-actions Bot marked this pull request as ready for review August 21, 2026 07:23
@github-actions github-actions Bot added the risk:high Touches a sensitive path or exceeds diff-size threshold — always human merge label Aug 21, 2026
@libravault-pipeline-bot libravault-pipeline-bot Bot added the status:needs-qa PR open, awaiting qa-agent verification label Aug 21, 2026
@claude

claude Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

QA verification — PR #404 vs issue #402

Root cause fix vs issue's suggested fix: PASS. principal-review.yml's
"Auto-merge if approved" step now calls resolve_linked_issue.sh right
after a successful gh pr merge --squash, and if the linked issue is
still OPEN, strips status:triage/status:ready-for-dev/
status:in-progress/status:needs-info and gh issue closes it with an
explanatory comment — exactly the fix issue #402 requested, not a
workaround.

Cleanup requested in #402 ("#178 and #314 should be manually closed"):
PASS, verified live via gh issue view:

What I ran:

  • python3 -c "yaml.safe_load(...)" on the modified workflow — parses
    clean (matches the PR's own claim).
  • Extracted the "Auto-merge if approved" step's run: block via
    yaml.safe_load and ran bash -n on it — no syntax errors (matches
    the PR's own claim).
  • bash .github/scripts/test_resolve_linked_issue.sh — 15/15 PASS,
    confirming the shared resolution logic this change calls into is
    unaffected (file untouched by this diff, confirmed via git diff origin/dev...HEAD --stat: only .github/workflows/principal-review.yml
    changed, +23/-1).
  • Traced set -euo pipefail semantics through every new line: all new
    gh issue * calls are guarded (|| true / || echo ... >&2 /
    wrapped in a $(... || echo "") substitution), so a transient gh
    failure here can't kill the step the way an earlier, unguarded
    MERGE_STATE=$(...) lookup in this same step once did (see commit
    a052940's second commit, caught by a prior QA round on this exact
    file) — no repeat of that failure mode.
  • Confirmed issues: write is already granted at job level (pre-existing,
    not part of this diff) — the new gh issue edit/gh issue close calls
    have the permission they need.
  • Confirmed the branch is current with dev (git merge-base HEAD origin/dev == origin/dev HEAD) — no rebase/conflict risk.
  • Commit message and branch name (fix/close-issue-on-auto-merge) follow
    repo convention; risk:high is correctly applied since this touches a
    sensitive_paths entry (.github/workflows/**).

Gap, not blocking: no automated regression test exercises the new
logic itself (only syntax validation + the unrelated pre-existing
resolve_linked_issue.sh suite). The PR is upfront about this — there's
no way to unit-test a live gh issue view/edit/close sequence without
extracting it into a mockable script the way resolve_linked_issue.sh is,
which this PR doesn't do. That said, this matches this exact step's own
established precedent: none of its prior fixes to this same "Auto-merge if
approved" block (e.g. the BEHIND/DIRTY retry logic in #247) shipped with
an automated test either — this class of change has always relied on
syntax checks + careful set -e tracing, with real validation coming from
the next live auto-merge. Worth flagging as a follow-up (extract this
block into a testable script, matching the resolve_linked_issue.sh
pattern) but not a reason to fail this PR on its own terms.

QA verdict: PASS

@github-actions github-actions Bot removed the status:needs-qa PR open, awaiting qa-agent verification label Aug 21, 2026
@libravault-pipeline-bot libravault-pipeline-bot Bot added the status:needs-review QA passed, awaiting principal-review-agent label Aug 21, 2026
@github-actions github-actions Bot added status:needs-info Dev/QA agent needs more detail before proceeding and removed status:needs-review QA passed, awaiting principal-review-agent labels Aug 21, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR's branch is stale relative to dev — specifically, .github/workflows/principal-review.yml differs between this branch and dev. GitHub Actions refuses to mint the OIDC token claude-code-action needs when a pull_request-triggered, id-token: write workflow's own file doesn't byte-match the base branch (its own anti-tampering check), so the principal review agent step was skipped rather than silently no-opping (see issue #254 for the full diagnosis). Rebase/merge dev into this branch and re-add status:needs-review to retry.

Copy link
Copy Markdown
Collaborator

Automated pipeline health check: Confirmed the stale-branch/workflow-validation diagnosis in the comment above is correct (#254 pattern — this branch's copy of .github/workflows/principal-review.yml differs from dev's, so the OIDC anti-tamper check refuses to mint a token and the principal-review agent step is skipped), but flagging why this routine isn't self-healing it automatically.

This PR's only changed file is .github/workflows/principal-review.yml, which is on .github/agent-policy.yml's sensitive-path list (.github/workflows/**). This routine's rules exclude sensitive-path PRs from the automatic rebase-and-retrigger self-heal, specifically so a workflow-file change doesn't get force-pushed and re-triggered without a human looking at it.

A human (or a differently-scoped agent) needs to rebase fix/close-issue-on-auto-merge onto dev and re-apply status:needs-review manually. No code/label changes made by this routine.


Generated by Claude Code

@github-actions

Copy link
Copy Markdown
Contributor

Human-merge sweep: not retrying this one, and flagging that the "rebase and re-apply status:needs-review" advice above is a dead end for this specific PR.

This PR's diff is entirely .github/workflows/principal-review.yml (confirmed via gh pr diff 404 --name-only) — the exact file the OIDC anti-tamper check compares against dev. Since modifying that file is this PR's whole content, its copy can never byte-match dev's copy no matter how current the branch is; a rebase would reproduce the identical "stale branch" failure immediately. This is the same self-referential-drift dead end already confirmed live on #382, #387, and #430 — not an infra fluke this sweep can retry away.

The actual fix for this class of failure is PR #405 (classify_workflow_drift.sh), which detects exactly this "self" case and routes straight to status:needs-human-merge instead of the dead-end retry loop — but #405 is itself sitting at status:needs-human-merge, blocked by this sweep's hard rule against merging anything touching .github/workflows/**.

Leaving this on status:needs-info for a human: either merge #405 (which will make this class of failure route correctly going forward) or manually rebase and re-trigger review, accepting it may bounce back here if #405 hasn't landed first.

@libravault-xyz

Copy link
Copy Markdown
Collaborator

Rebased onto current dev (clean merge, picks up #405's workflow-drift classifier + other pipeline fixes). This PR's own diff modifies principal-review.yml directly, so it'll never get a real automated review run (drift self-check, correctly). Reviewed the diff by hand — small, well-scoped fix for #402 (explicit issue-close instead of relying on GitHub's not-always-reliable close-on-merge), best-effort/non-fatal on failure. Merging directly.

@libravault-xyz
libravault-xyz merged commit f7ece41 into dev Aug 22, 2026
8 checks passed
@libravault-xyz
libravault-xyz deleted the fix/close-issue-on-auto-merge branch August 22, 2026 20:27
libravault-xyz pushed a commit that referenced this pull request Aug 22, 2026
…430)

Merged after manual rebase + review: same self-modifying-workflow situation as #404. Diff (extract_review_verdict.sh + hookup) is correct, has its own test coverage (all 7 cases verified passing), closes #426.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:high Touches a sensitive path or exceeds diff-size threshold — always human merge status:needs-info Dev/QA agent needs more detail before proceeding

Projects

None yet

1 participant