Skip to content

fix(ci): add deterministic backstop for PRs opened outside the pipeline - #225

Merged
libravault-xyz merged 2 commits into
devfrom
fix/pr-intake-backstop
Aug 17, 2026
Merged

libravault-xyz merged 2 commits into
devfrom
fix/pr-intake-backstop

Conversation

@libravault-xyz

@libravault-xyz libravault-xyz commented Aug 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Related to #223 / #224, not closing either — this is a pipeline-infra fix
prompted by what happened on them, not a change to either.

While addressing issue #223's comment thread,
I found that PR #224 — the actual fix for #223 — was opened by a Claude
Code session directly, not by the dev-agent.yml workflow — and as a result
it carried no risk:*/status:* label at all and nothing downstream
would ever have picked it up. I had to hand-classify it and manually
apply risk:low/status:needs-qa to get it moving through the pipeline.

Root cause

dev-agent.yml's risk-classification + status:needs-qa handoff only
runs as the last step of its own triage-and-implement job — i.e. only
for PRs it opens itself, via the pipeline App token, in that same job
run. The workflow's own comment on why PR creation doesn't need the App
token explicitly assumed this away: "PR creation itself doesn't trigger
any workflow this pipeline cares about (ours all trigger on labeled,
not opened)" — true for pipeline-opened PRs, but it meant any PR opened
another way (a human, or a session working an issue directly rather than
through status:ready-for-dev) falls through every trigger in the
pipeline and sits unlabeled indefinitely.

Fix

Adds pr-intake.yml, a deterministic backstop (no agent):

  • Triggers on pull_request: opened/reopened.
  • Skips PRs authored by libravault-pipeline-bot[bot] (already handled
    synchronously by dev-agent.yml itself — confirmed live via the API
    that pipeline-opened PRs carry that exact login).
  • Skips PRs that already carry any pipeline status label (idempotent
    against reopened re-firing, and against a PR a human/QA/review round
    has already moved along).
  • Skips PRs with no linked issue (Closes #N etc.) — not a pipeline PR.
  • Respects status:blocked on the linked issue, same as dev-agent.yml.
  • Runs the exact same classify_pr_risk.py + App-token status:needs-qa
    step dev-agent.yml's own tail runs for its own PRs.

Documents the gap and the fix in docs/agent-team-pipeline.md (new "PR
intake backstop" section, right after "Cross-workflow triggering").

Risk

Touches .github/workflows/**, a sensitive path per agent-policy.yml
— will classify as risk:high and land on human-merge regardless, as
intended for pipeline-config changes.

Test plan

  • python3 -c "import yaml; yaml.safe_load(open('.github/workflows/pr-intake.yml'))" — valid YAML.
  • Manually walked the if conditions and guard-step logic against real
    API data pulled from PR fix(reader): make ReaderTopBar icon button sizes consistent #221 (pipeline-opened: author.login == "libravault-pipeline-bot[bot]", type: "Bot") and PR feat(ios): add vault deletion to Manage Vaults #224
    (session-opened: author.login == "libravault-xyz", is_bot: false)
    to confirm the exclusion condition discriminates correctly between the
    two cases this backstop needs to tell apart.
  • No way to fire a real pull_request: opened event pre-merge without
    opening a throwaway PR against dev — deferred to the first real PR
    that lands this way after merge; flagged here rather than silently
    assumed to work.

Edit history

Reworded the sentence above that used to read "PR #224 (which fixes
#223)" — that incidental phrasing was itself a real closing-keyword match
(confirmed via closingIssuesReferences in the GitHub GraphQL API), so
this PR was on track to automatically close issue 223 a second time on
merge despite having nothing to do with it. Root-caused as issue #228,
fixed there. qa-agent.yml also independently caught the resulting
issue/PR pairing mismatch live and flagged it — see this PR's own
comments. (Deliberately spelling out "issue 223" instead of "#223" in
this paragraph so this explanation doesn't itself retrigger the exact
bug it's describing.)

🤖 Generated with Claude Code

Co-Authored-By: Claude Sonnet 5 noreply@anthropic.com

dev-agent.yml's risk-classification + status:needs-qa handoff only runs
as the tail of its own triage-and-implement job, i.e. only for PRs it
opens itself via the pipeline App token in that same job run. A PR
opened any other way (a human, or a Claude Code session working an
issue directly rather than through status:ready-for-dev) never enters
that job, so it carries no risk:*/status:* label and nothing downstream
ever picks it up.

Confirmed live: issue #223's actual fix, PR #224, was opened this way
by a session outside the pipeline and sat unlabeled until a human
noticed and hand-applied risk:low/status:needs-qa manually.

Adds pr-intake.yml: triggers on pull_request opened/reopened, skips
PRs authored by libravault-pipeline-bot[bot] (already handled
synchronously by dev-agent.yml) and PRs already carrying a pipeline
status label (idempotent against reopened re-firing), then runs the
same deterministic classify-and-label step dev-agent.yml's tail runs
for its own PRs. Runs no agent - pure backstop, not a fourth triage
path. Documents the gap and fix in docs/agent-team-pipeline.md.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@github-actions github-actions Bot added the risk:high Touches a sensitive path or exceeds diff-size threshold — always human merge label Aug 17, 2026
@libravault-pipeline-bot libravault-pipeline-bot Bot added the status:needs-qa PR open, awaiting qa-agent verification label Aug 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR was opened outside the automated pipeline (author isn't libravault-pipeline-bot[bot]), so dev-agent.yml's own end-of-run classification step never ran for it — it would otherwise have sat with no risk/status label and nothing downstream would pick it up (see issue #223's actual history). This deterministic backstop (pr-intake.yml) classified its risk and applied status:needs-qa to route it into the normal pipeline from here.

@github-actions

Copy link
Copy Markdown
Contributor

📱 iOS Build Status: PASSED

✅ iOS Simulator Build & Unit Tests - success
✅ Android Core Modules - success

iOS UI tests run in a separate, informational job and are not reflected above — check "iOS UI Tests (informational)" for those.

View run details

@claude

claude Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

QA verification — PR #225

⚠️ Issue/PR pairing mismatch (read this first)

I was asked to verify this PR against issue #223's acceptance criteria
(iOS vault deletion in Manage Vaults). That checklist has nothing to do
with this PR:

So there's no acceptance-criteria checklist to score this PR against.
Flagging this prominently for a human to look at — it suggests whatever
dispatched this QA pass paired the wrong PR/issue, not that anything is
wrong with the PR itself. I evaluated PR #225 on its own stated root
cause/fix instead of forcing an irrelevant checklist onto it.

What I checked instead

Diff scope: git diff origin/dev...HEAD --stat → only
.github/workflows/pr-intake.yml (new, 134 lines) and
docs/agent-team-pipeline.md (+25 lines). No Kotlin/Swift/JVM source
touched.

  • ✅ YAML validity: python3 -c "import yaml; yaml.safe_load(open('.github/workflows/pr-intake.yml'))" → parses clean.
  • ✅ Logic trace vs. its stated twin (dev-agent.yml's own tail
    classify+label step, lines ~460-500): same classify_pr_risk.py
    invocation pattern, same App-token-only-for-status:needs-qa
    separation (risk labels stay on GITHUB_TOKEN, matching the documented
    rationale in agent-team-pipeline.md's "Cross-workflow triggering"
    section), same idempotency intent. Uses origin/$BASE_REF (dynamic)
    vs. dev-agent's hardcoded origin/dev — correct, since this workflow
    must handle PRs targeting any base, not just PRs the pipeline itself
    always opens against dev.
  • ✅ Trust boundary: pull_request: opened/reopened fires for fork
    PRs with zero permission required, so the job gates on
    head.repo.full_name == github.repository — same-repo-only, identical
    boundary dev-agent.yml already relies on for its own
    pull_request: labeled trigger. Verified this isn't a new attack
    surface: same-repo branch push already requires collaborator access.
  • ✅ Reuses shared script (resolve_linked_issue.sh) rather than
    reimplementing issue-link parsing — avoids the drift risk the script's
    own header comment calls out.
  • ✅ Idempotency guard: skips if the PR already carries any pipeline
    status label, so a reopened re-fire (or a PR a human/QA has already
    moved along) won't get relabeled. Confirmed the later unconditional
    --add-label status:needs-qa is safe given this guard already
    guarantees no existing status label at that point.
  • ✅ status:blocked respected on the linked issue, matching
    persona/pipeline convention (checklist item 0).
  • ✅ Correctly excludes libravault-pipeline-bot[bot]-authored PRs
    (already handled synchronously by dev-agent.yml's own tail).
  • ✅ Docs update (agent-team-pipeline.md) accurately describes the gap
    and the fix; no factual drift from the workflow file itself.
  • ✅ Real test suite: ran ./gradlew testDebugUnitTest --continue in
    full (not skipped) — BUILD SUCCESSFUL in 6m 34s, 415 actionable tasks,
    no failures. Expected/irrelevant-but-confirms-no-regression, since this
    diff touches no JVM source.
  • AGENTS.md test-coverage rule: this repo has no existing precedent
    for unit/lint-testing .github/workflows/*.yml or .github/scripts/*
    (no actionlint/yamllint config, no bats/pytest harness for the
    existing scripts either — dev-agent.yml, qa-agent.yml, etc. were
    themselves added without that kind of test). PR fix(ci): add deterministic backstop for PRs opened outside the pipeline #225's test plan (YAML
    validity + manual condition trace against real PR fix(reader): make ReaderTopBar icon button sizes consistent #221/feat(ios): add vault deletion to Manage Vaults #224 API data)
    matches that existing bar for this file category. The PR itself is
    upfront that it couldn't fire a real pull_request: opened event
    pre-merge and defers that to the first real PR landing this way after
    merge — a disclosed, reasonable limitation given no such test harness
    exists in this repo, not a hidden gap.
  • Ironic but minor note, not a defect: by its own scope (no linked
    issue via closing keyword), pr-intake.yml would not have picked up
    PR fix(ci): add deterministic backstop for PRs opened outside the pipeline #225 itself — it needed the same manual labeling PR feat(ios): add vault deletion to Manage Vaults #224 needed
    before this backstop existed. That's consistent with its stated design
    (issue-linked pipeline PRs only), not a bug, but worth a human's
    awareness.
  • No regressions found in related areas — checked for other workflows
    triggering on pull_request events that could race with this one;
    qa-agent.yml/principal-review.yml/dev-agent.yml all trigger on
    labeled, not opened, so there's no double-fire/race on PR creation.
  • Commit hygiene: single commit, Conventional Commits subject
    (fix(ci): ...), one concern.
  • risk:high already correctly applied (touches .github/workflows/**,
    a sensitive_paths glob in agent-policy.yml) — always lands on human
    merge regardless of this verdict.

Verdict rationale

Setting aside the mismatched pairing (flagged above for a human), the PR
as written is a sound, well-scoped, minimal-risk infra fix: logic mirrors
its documented precedent correctly, reuses shared tooling, respects
existing trust/idempotency conventions, and its test plan matches this
repo's actual bar for CI-config changes. I'm not withholding a pass over
"probably fine" — the code-level trace and full JVM test run give solid,
not partial, confidence in the change itself. The only real open item is
the issue/PR pairing question, which is a process signal for a human, not
something the dev agent can act on by revising this PR.

QA verdict: PASS

@github-actions github-actions Bot removed the status:needs-qa PR open, awaiting qa-agent verification label Aug 17, 2026
@libravault-pipeline-bot libravault-pipeline-bot Bot added the status:needs-review QA passed, awaiting principal-review-agent label Aug 17, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Principal review — PR #225

Risk label: risk:high (correctly applied — the PR touches .github/workflows/pr-intake.yml, matching sensitive_paths: .github/workflows/** in agent-policy.yml; diff is well under the 400-line auto-merge threshold otherwise). No commits landed after the label was last set (single commit 8342be6), so the label is current — re-running classify_pr_risk.py locally reproduces risk:high for the same reason. Per policy this routes to human-merge regardless of findings below.

CI: Verified against the actual check runs, not the PR's own claims — JVM Tests, iOS build, QA Agent verify, and PR Intake intake all show SUCCESS; UI Tests (Emulator) is SKIPPED, consistent with a workflow/docs-only diff. Nothing red.

Finding (CONFIRMED, live-verified)

resolve_linked_issue.sh's closing-keyword regex mismatches prose in this PR's own body, and it's not a hypothetical — it actually fired that way on this exact PR.

The PR's guard step ("Check whether this PR needs intake") is supposed to skip PRs with no linked issue. Pulling the real run log for this PR (gh run view 31994594534 --log, run for PR #225 itself) shows the guard step never printed the "doesn't link an issue" skip path — it went straight through to risk classification, meaning resolve_linked_issue.sh returned a non-empty issue number for PR #225's body.

The PR body opens with "Related to #223 / #224, not closing either" — but later contains "PR #224 (which fixes #223)", describing PR #224, not this PR. resolve_linked_issue.sh's regex (\b(close[sd]?|fix(e[sd])?|resolve[sd]?) #[0-9]+) has no way to distinguish "this PR fixes #N" from prose describing what another PR fixed — it matched "fixes #223" and returned 223 as "the linked issue," directly contradicting the PR's own explicit statement that it doesn't close anything.

In this specific run it's inconsequential — I checked issue #223 (gh issue view 223) and it doesn't carry status:blocked, so the guard proceeded and labeled correctly. But the mechanism is real and will recur, and it's a materially bigger problem for pr-intake.yml than it ever was for dev-agent.yml/qa-agent.yml's existing use of the same script:

  • dev-agent.yml only ever runs this against its own agent-generated PR bodies, which always contain a literal templated Closes #N line — there's essentially no ambiguous prose for the regex to misfire against.
  • pr-intake.yml is specifically built for the opposite case — arbitrary human/session-authored bodies. Referencing other issues/PRs by number in prose (exactly as this PR itself does) is completely normal PR-writing style, not an edge case.

The failure mode this produces is silent and hard to notice: if the guard step resolves to an unrelated issue that does carry status:blocked, it sets skip=true and exits — no PR comment, just a line in the Actions run's stderr — leaving an otherwise-legitimate, unrelated PR sitting with no risk/status label. That's a reoccurrence of the exact bug this PR exists to fix (see #223/#224's history in the PR description), just triggered by an incidental word match instead of "author isn't the pipeline bot."

Suggest before merge: make the guard step's "linked issue resolved to #N but that issue is blocked" path visibly distinct from a genuine no-op (e.g. leave a PR comment naming which issue it matched and why it's skipping), so a human can catch a bad match instead of it disappearing into workflow logs. Tightening the regex itself (e.g. requiring the keyword phrase to be on its own line, closer to how GitHub's own auto-link UI treats it) would also reduce false positives, though a comment-on-skip is probably the more robust fix since prose will always be somewhat ambiguous.

Everything else checked

  • No new networking dependency/call (the pip install pyyaml + gh/API calls all mirror the existing pattern dev-agent.yml's tail already uses).
  • No other agent-policy.yml sensitive_paths touched (.claude/agents/**, agent-policy.yml itself, vault/crypto, billing, versions.toml all untouched) — and the one sensitive path that is touched (.github/workflows/**) is explicitly flagged in the PR's own "Risk" section, as the persona requires.
  • Verified PIPELINE_APP_ID/PIPELINE_APP_PRIVATE_KEY App-token usage, permissions block, fork-exclusion (head.repo.full_name == github.repository), and pipeline-bot exclusion (user.login != 'libravault-pipeline-bot[bot]') all match the equivalent, already-proven logic in dev-agent.yml's own tail step — cross-checked field-for-field, including confirming via gh api repos/.../pulls/221 that the raw REST user.login value for a pipeline-bot PR really is "libravault-pipeline-bot[bot]" (the gh pr view --json author CLI wrapper displays it differently, as app/libravault-pipeline-bot, which could otherwise look like a mismatch).
  • YAML validated independently (python3 -c "import yaml; yaml.safe_load(...)") — valid.
  • docs/agent-team-pipeline.md additions accurately describe what the workflow actually does; no drift between prose and implementation.
  • This PR's own pr-intake.yml addition self-exercised live on PR #225 (same-repo pull_request runs use the workflow file from the PR's own branch) and did correctly apply risk:high — so the PR's "Test plan" claim that there's "no way to fire a real pull_request: opened event pre-merge" undersells what actually happened; it was live-tested by virtue of being opened as a same-repo PR. Worth noting only because it means the finding above isn't theoretical either — it's drawn from this PR's own real run.

Verdict

risk:high alone already mandates human-merge. Combined with the CONFIRMED finding above (real, reproducible, not blast-radius-zero for future PRs even though harmless on this one), routing to a human with the full write-up rather than a bare comment.

@github-actions github-actions Bot added status:needs-human-merge Principal review done, requires human merge decision and removed status:needs-review QA passed, awaiting principal-review-agent labels Aug 17, 2026
libravault-xyz added a commit that referenced this pull request Aug 17, 2026
…nce (#230)

Live on PR #225: qa-agent.yml tried to verify it against issue #223's
acceptance criteria, completely unrelated (#225 is a CI pipeline-infra
fix; #223 is a separate feature closed by the separate PR #224). Root
cause: PR #225's own body mentioned, in passing prose, "PR #224 (which
fixes #223)" - background context, not PR #225's own closing keyword -
and the shared regex matched it anyway. qa-agent caught the mismatch
itself and evaluated the PR on its own merits, but flagged it as a
process signal.

Confirmed via the GitHub GraphQL API (closingIssuesReferences) that
this isn't just our script being loose - GitHub's own real
closing-keyword parser is exactly this naive too: it had linked PR #225
as a genuine closing reference for issue #223, meaning merging it would
have auto-closed the wrong issue a second time. That's a footgun in
GitHub's parser this script can't fix, but resolve_linked_issue.sh's
actual job (telling dev-agent/qa-agent/principal-review which issue's
acceptance criteria a PR should be judged against) is a stricter
question than "what would GitHub technically auto-close" - matching
GitHub's looser behavior here isn't worth keeping.

Anchors the keyword to the start of its (trimmed) line, stripping
optional markdown list/heading/blockquote markers first - matches how
every real PR in this pipeline already writes it ("Closes #N" alone on
its own line) and rejects mid-sentence mentions. Verified against real
PR bodies: #224 still resolves to 223, #229 still resolves to 227, #221
(pre-existing pipeline PR) still resolves to 4, #225 now correctly
resolves to nothing.

Also cleaned up PR #225's own body to stop tripping this (both the
original phrasing and, ironically, an early draft of this explanation
itself re-triggered the same match).

Closes #228

Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
libravault-xyz added a commit that referenced this pull request Aug 17, 2026
Rebased on top of #230, which already fixed #228's core bug (line-start
anchoring instead of a bare \b match). This adds what #230 didn't cover:

- resolve_linked_issue.sh now explicitly rejects PR bodies with more
  than one distinct closing-issue line, instead of silently taking the
  first match via `head -1` — every downstream caller only supports a
  single linked issue, so ambiguity now fails loudly (consistent with
  the script's existing "fail loudly, don't guess" stance on gh
  failures) rather than picking one guess and dropping the other.
- Refactors the matching logic into resolve_from_body() so it can be
  tested without a live `gh` call; adds test_resolve_linked_issue.sh
  (13 cases: the real PR #225 false-positive, #230's synthetic cases
  bullet/heading/indented/blockquote, mid-sentence rejection, the
  disclosed/enclosed substring guard, and the new ambiguity rejection).
  No bats/pytest harness exists for .github/scripts/* in this repo —
  #230's own PR body noted the same gap — so this is a standalone
  script matching how the sibling scripts here are invoked.
- Updates dev-agent.md's PR-body guidance and the two "Could not
  resolve..." operator-facing messages in dev-agent.yml/qa-agent.yml to
  say the closing line must stand on its own, so future dev-agent PRs
  don't unknowingly write it in prose and fall through to "no linked
  issue" (safe, just misses the automatic QA/review advance).

Closes #228
libravault-xyz added a commit that referenced this pull request Aug 17, 2026
…#232)

Rebased on top of #230, which already fixed #228's core bug (line-start
anchoring instead of a bare \b match). This adds what #230 didn't cover:

- resolve_linked_issue.sh now explicitly rejects PR bodies with more
  than one distinct closing-issue line, instead of silently taking the
  first match via `head -1` — every downstream caller only supports a
  single linked issue, so ambiguity now fails loudly (consistent with
  the script's existing "fail loudly, don't guess" stance on gh
  failures) rather than picking one guess and dropping the other.
- Refactors the matching logic into resolve_from_body() so it can be
  tested without a live `gh` call; adds test_resolve_linked_issue.sh
  (13 cases: the real PR #225 false-positive, #230's synthetic cases
  bullet/heading/indented/blockquote, mid-sentence rejection, the
  disclosed/enclosed substring guard, and the new ambiguity rejection).
  No bats/pytest harness exists for .github/scripts/* in this repo —
  #230's own PR body noted the same gap — so this is a standalone
  script matching how the sibling scripts here are invoked.
- Updates dev-agent.md's PR-body guidance and the two "Could not
  resolve..." operator-facing messages in dev-agent.yml/qa-agent.yml to
  say the closing line must stand on its own, so future dev-agent PRs
  don't unknowingly write it in prose and fall through to "no linked
  issue" (safe, just misses the automatic QA/review advance).

Closes #228
@github-actions

Copy link
Copy Markdown
Contributor

📱 iOS Build Status: PASSED

✅ iOS Simulator Build & Unit Tests - success
✅ Android Core Modules - success

iOS UI tests run in a separate, informational job and are not reflected above — check "iOS UI Tests (informational)" for those.

View run details

@libravault-xyz
libravault-xyz merged commit 737b0dc into dev Aug 17, 2026
7 checks passed
@libravault-xyz
libravault-xyz deleted the fix/pr-intake-backstop branch August 18, 2026 19:32
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-human-merge Principal review done, requires human merge decision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant