Skip to content

feat(ci): sweep both status:needs-human-merge and status:needs-info every 4h - #335

Merged
libravault-xyz merged 3 commits into
devfrom
feature/human-merge-sweep-routine
Aug 20, 2026
Merged

libravault-xyz merged 3 commits into
devfrom
feature/human-merge-sweep-routine

Conversation

@libravault-xyz

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

Copy link
Copy Markdown
Collaborator

What

Every 4 hours, clears both places docs/agent-team-pipeline.md's state machine parks work on a human:

  • status:needs-human-merge — re-verify each PR is still current, run a genuine second review, merge what's clean, close what's gone stale/conflicting/superseded.
  • status:needs-info — a deliberately more conservative task, added after the original PR here was already reviewed once (see commit history). Most status:needs-info items are a real question only a human can answer (scope, product intent, anything security-sensitive) — the sweep never guesses at those. It only acts when the label was applied because the pipeline itself got stuck (a crashed run, workflow-file drift) rather than because there's an actual open question: in that case it retries the stage that crashed, once, and leaves a comment explaining why. Everything else either already has a clear explanation for the human, or gets one added if it didn't. Anything also labeled security/release-blocker (agent-policy.yml's sensitive_issue_labels) gets zero autonomous action, not even investigation.

This was requested directly, same as the original scope: the human-merge gate is correct by design, but in practice both backlogs only got cleared when a human noticed and asked for a manual pass — which is what happened this session for PRs #327 and #324 (merge backlog) plus this exact addition for the info backlog.

What's here

  • human-merge-sweep.yml — unchanged trigger/auth from the original PR (schedule every 4h + workflow_dispatch, plain GITHUB_TOKEN). --max-turns raised 120→160 for the extra backlog.
  • human-merge-sweep-agent.md — new Part 3 (needs-info), described above. Parts 1-2 (merge backlog + general staleness sweep) unchanged from the original review.
  • human-merge-sweep-log.md — broadened to cover needs-info retries alongside merges/closes (column renamed PR → Item); plain clarifying comments don't get a log row since they change nothing and are already visible in place.
  • docs/agent-team-pipeline.md addendum updated to describe both backlogs.

Hard-coded limits (not left to judgment) — unchanged plus new ones for Part 3

  • Never merges anything touching .github/workflows/**, .github/agent-policy.yml, or .claude/agents/**.
  • Never merges/force-pushes outside dev; never deletes a branch other than one it just merged.
  • Respects status:blocked and the repo-wide AGENTS_PAUSED kill switch.
  • Caps at 15 items per backlog per run, flagging the volume itself if exceeded.
  • New: Part 3 never merges, closes, or approves anything — only a label-based retry (at most once per item, only for a detected pipeline failure, never a real question) and posting a clarifying comment. Never resolves a product/scope/security decision on the human's behalf, under any circumstance.

Risk

Same as before, restated because it's still true after this addition: this PR is exactly the kind of change its own agent is hard-coded to never touch. .github/workflows/** and .claude/agents/** are both sensitive_paths entries, classify_pr_risk.py will force risk:high, and this session will not self-merge it even if CI is green.

🤖 Generated with Claude Code

…cklog

docs/agent-team-pipeline.md's state machine ends most risk:high PRs at
status:needs-human-merge — correct by design, but until now that backlog
only got cleared when a human noticed it and manually asked Claude Code to
review + merge each one (as happened this session for PRs #327 and #324,
plus closing #292 and #326 as stale/superseded along the way).

This adds a new, separate workflow that automates the noticing, not the
judgment:

- human-merge-sweep.yml: schedule-triggered (every 4 hours) +
  workflow_dispatch for manual testing. Plain GITHUB_TOKEN — merging/
  closing PRs isn't blocked by this repo's "Actions can't create/approve
  PRs" setting the way *opening* one is (principal-review.yml's own
  auto-merge step already proves this), so no App-token minting needed.
- human-merge-sweep-agent.md: the actual review persona. Re-verifies each
  status:needs-human-merge PR is still current (stale/conflicting PRs get
  closed with an explanation if genuinely superseded, left alone if
  ambiguous), does a real second review (reads the whole diff, cross-
  checks claims against ground truth, checks for vacuous tests) before
  merging, and separately sweeps ALL open PRs for the same staleness
  pattern regardless of label. Hard rule, not a judgment call: never
  merges anything touching .github/workflows/**, .github/agent-policy.yml,
  or .claude/agents/** — that class of change always needs a human
  directly, however clean it looks.
- human-merge-sweep-log.md: audit trail, same spirit as auto-merge-log.md
  but for this human-merge-routed path instead of the risk:low auto-merge
  path.

This PR itself is exactly the kind of change its own new agent is
hard-coded to never touch (.github/workflows/**, .claude/agents/**) — by
design, flagging it plainly rather than leaving that as an implicit
assumption: needs a human's own read, this session will not self-merge it
even if CI is green.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@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

Copy link
Copy Markdown
Collaborator Author

Automated pipeline health check: This PR needs a human look — it doesn't match any of the 5 known failure patterns, and it's also a case where self-healing is hard-blocked regardless.

  • Opened 2026-08-19T19:56 by this account. pr-intake.yml's backstop never applied a status:* label (matches the same "PR opened outside/around the normal dev-agent PR-creation path never gets classified" shape seen on feat(ui): show an explicit "No cover art" placeholder instead of a generated cover #170/docs(android): document Firebase App Distribution tablet install issue #217/feat(ios): implement Encrypted Vaults auth UI (create/unlock/list) #334, each a distinct root cause but the same visible symptom), and no dev-agent.yml/qa-agent.yml/principal-review.yml run has ever fired for it — only the informational iOS/Android build-status check has run (currently green).
  • More importantly, this PR adds new files under .github/workflows/** and .claude/agents/** (human-merge-sweep.yml, human-merge-sweep-agent.md) — both on this repo's sensitive_paths list. This routine's hard rules say never touch a sensitive path directly and never force-push/merge/requeue around one, so even if it did have a routing gap worth self-healing, this PR is explicitly out of scope for that. The PR author's own description already flags this plainly and asks for direct human review rather than pipeline auto-merge.

Not self-healing (no safe action applies here either way) — flagging so a human applies the appropriate label and reviews it directly, same as recommended for #170/#217/#334.


Generated by Claude Code

status:needs-human-merge isn't the only place the pipeline parks work on
a human — status:needs-info (issue triage that's underspecified, or a
PR whose QA/review run crashed or hit workflow-file drift) blocks on a
human just as silently, and was out of scope for the sweep as first
built.

Adds Part 3 to human-merge-sweep-agent.md, deliberately more conservative
than Parts 1-2 given how different the task is — "is this safe to
merge/close" is a mechanical check, "does this actually need a human" is
not:

- Detects when status:needs-info was applied because the *pipeline*
  crashed (turn budget exhausted, workflow-file drift) rather than
  because there's a real open question, and retries the stage that
  crashed — at most once per item, logged to human-merge-sweep-log.md
  same as a merge.
- For everything else — the default assumption, not an edge case — never
  answers, never changes a label, never invents scope. Only ever ensures
  a clear comment exists naming the actual open question, so a human can
  answer faster.
- Hard-excludes anything labeled security/release-blocker
  (agent-policy.yml's sensitive_issue_labels) from all autonomous action,
  including investigation.

Bumped --max-turns 120→160 (three backlogs to work per run now, not two)
and broadened human-merge-sweep-log.md's scope/column naming (PR → Item)
to cover issues and retries alongside merges/closes.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@libravault-xyz libravault-xyz changed the title feat(ci): add every-4h human-merge sweep for the needs-human-merge backlog feat(ci): sweep both status:needs-human-merge and status:needs-info every 4h Aug 20, 2026
@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

Copy link
Copy Markdown
Collaborator Author

Principal review — PR #335 (feature/human-merge-sweep-routine → dev)

Verdict: request-changes / human-merge. I confirmed classify_pr_risk.py against origin/dev...origin/feature/human-merge-sweep-routine myself: risk:high (.claude/agents/human-merge-sweep-agent.md matches .claude/agents/**; .github/workflows/human-merge-sweep.yml also matches .github/workflows/**). Note for the record: the PR currently carries no risk:* label at all — pr-intake.yml's guard skips PRs with no linked issue (Closes #N), and this PR doesn't reference one, so the deterministic classifier never ran on GitHub. I'm treating my own local run of the script as authoritative per the review instructions rather than trusting an (absent) label. This alone forces human-merge regardless of anything else below, and the PR description itself correctly anticipates that.

Beyond the risk tier, I found two CONFIRMED functional bugs that mean the workflow, as written, would not do what its own description/persona claim:

CONFIRMED — 1. Missing id-token: write permission breaks the agent step on every run

.github/workflows/human-merge-sweep.yml:32-35:

permissions:
  contents: write
  pull-requests: write
  issues: write

Every other workflow in this repo that invokes anthropics/claude-code-action@v1 (dev-agent.yml:23-32, qa-agent.yml:25-29, principal-review.yml:44-48) carries id-token: write, with an identical comment citing a real prior failure: "claude-code-action requests an OIDC ID token as part of its own auth/telemetry setup. Without this, actions/core's OidcClient can't find ACTIONS_ID_TOKEN_REQUEST_URL... the step fails after 3 retries with 'Could not fetch an OIDC token' — confirmed via a real failed run (issue #158)." human-merge-sweep.yml omits it entirely, and did so from the very first commit (3e92fe2e) unchanged through the second (8a378826) — this isn't new-commit drift, it's a bug that survived the PR's own claimed prior review. Given the identical, already-diagnosed precedent for the identical action in this same repo, I'm calling this CONFIRMED rather than plausible: the "Run human-merge sweep agent" step will fail with the OIDC token error on every scheduled invocation. Because the step has continue-on-error: true (human-merge-sweep.yml:64), this failure is silently swallowed — the job reports overall success, "Report outcome" prints the generic "crashed or exhausted its turn budget" line, and the workflow will appear to run every 4 hours while doing nothing at all. This is exactly the continue-on-error-masks-a-real-failure pattern the review mindset calls out explicitly.

CONFIRMED — 2. Part 3's label-based "retry" cannot actually trigger the downstream stage

.claude/agents/human-merge-sweep-agent.md:143-150 has the agent, on a detected transient pipeline failure, "remove status:needs-info and re-add whichever label restarts the stage that actually crashed (status:ready-for-dev… status:needs-qa… status:needs-review…)". The whole job runs under plain GITHUB_TOKEN (human-merge-sweep.yml:59, workflow header comment lines 18-23) — there is no App-token-minting step anywhere in either new file (grep-confirmed).

docs/agent-team-pipeline.md's own "Cross-workflow triggering" table (lines 174-214) states plainly that a label add capable of crossing phases — i.e., firing a different workflow — must use the libravault-pipeline-bot App token, because GitHub does not fire new workflow runs for events produced by the built-in GITHUB_TOKEN. It names exactly the three labels this PR's retry logic re-applies as needing the App token: status:needs-qa (→ qa-agent.yml), status:needs-review (→ principal-review.yml), and by the same trigger shape status:ready-for-dev on an issue (→ dev-agent.yml, triggered by issues: labeled). pr-intake.yml is the live, working precedent for this exact distinction: it explicitly mints and uses an App token (APP_GH_TOKEN) solely to apply status:needs-qa (pr-intake.yml:101-133), with a comment explaining a plain-GITHUB_TOKEN add would not trigger qa-agent.yml.

The workflow's own auth-justification comment ("principal-review.yml's own 'Auto-merge if approved' step already proves GITHUB_TOKEN can merge; the same is true here") is correct for Parts 1/2 (merge/close are terminal actions, exactly like principal-review.yml's own outcomes) but does not extend to Part 3, which needs to cross phases — and nothing in either file accounts for that gap. As implemented, a Part 3 "retry" will: remove status:needs-info, add e.g. status:needs-qa, post a comment saying it retried, log a row to docs/human-merge-sweep-log.md — and then nothing further ever happens, because qa-agent.yml is never actually invoked. The item silently falls out of every backlog query in the pipeline (no longer needs-info, never actually re-enters needs-qa processing) and is worse off than before the "fix": a human skimming the log or the label would reasonably believe it's back in the pipeline, when it's actually orphaned.

PLAUSIBLE / design gaps worth a human's explicit sign-off (not independently blocking, but real)

  • Item 3's "hard rule" (never merge .github/workflows/**/.claude/agents/**/agent-policy.yml) has no deterministic backstop — it's LLM-prompt-adherence only; nothing in human-merge-sweep.yml mechanically checks changed paths before allowing the merge call. This mirrors an existing accepted pattern in principal-review.yml (its auto-merge step also fully trusts the agent-written verdict file with no independent path check), so it isn't a novel flaw this PR introduces — but this agent's Part 1 scope is broader (any status:needs-human-merge PR, unattended, on a timer, no per-PR human trigger) than principal-review.yml's single-PR-per-invocation shape, so I'd flag it explicitly rather than wave it through on "same as before."
  • The retry-once dedup mechanism is fragile even setting aside bug test(reader): Readium 3 instrumentation tests + emulator CI #2: "grep the comment history for human-merge-sweep-agent retry text" (human-merge-sweep-agent.md:141-143) has no canonical, fixed marker string defined anywhere for the comment the agent posts when retrying — free-text LLM-generated comments across separate runs/models are a weak thing to grep reliably for exact-once semantics. Given bug test(reader): Readium 3 instrumentation tests + emulator CI #2 likely means items never even loop back to status:needs-info a second time in practice, this may not manifest often, but it's a real latent gap in the "at most once" guarantee.

Verified as correct

  • sensitive_issue_labels exclusion (human-merge-sweep-agent.md:126-127) — security/release-blocker — matches .github/agent-policy.yml verbatim.
  • Auth claim for Parts 1/2 (plain GITHUB_TOKEN sufficient to merge/close PRs) — verified true by reading principal-review.yml's "Auto-merge if approved" step (gh pr merge under plain GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}, lines 381-524).
  • No new networking dependency/call introduced.
  • docs/agent-team-pipeline.md and docs/human-merge-sweep-log.md updates are real, present, and consistent with the PR's description.
  • CI is green as of head commit 8a378826 (JVM Tests pass, Build Android App pass, iOS Build & Test pass, iOS UI Tests informational pass, Compose UI Tests skipped as normal); mergeable: MERGEABLE, mergeStateStatus: CLEAN. (I did not execute the workflow itself — no way to locally run a scheduled Actions job — so bugs fix: Readium Kotlin Toolkit 3.0.0-beta.2 API migration #1/test(reader): Readium 3 instrumentation tests + emulator CI #2 above are static-review findings, backed by identical, already-diagnosed precedent elsewhere in this repo, not by an observed failing run.)

Bottom line

Correctly self-classified as needing a human regardless of how clean it looks — and it isn't fully clean: two CONFIRMED bugs would leave the sweep either doing nothing (bug #1) or silently orphaning retried items (bug #2) if merged as-is. I would not merge this even by hand until at least id-token: write is added and Part 3's retry either mints an App token for the three cross-phase labels or is scoped back to something that doesn't need to (e.g., just posting a comment asking a human to re-apply the label).

Two CONFIRMED findings from principal review of PR #335's own diff:

- permissions: was missing id-token: write. Every sibling workflow
  invoking claude-code-action carries this with an identical comment
  citing issue #158 ("Could not fetch an OIDC token" after 3 retries) —
  missed here, and continue-on-error: true on the agent step would have
  swallowed the failure silently, forever, every 4 hours.
- Part 3's retry action re-applies status:ready-for-dev/needs-qa/
  needs-review to restart a crashed pipeline stage — that label change
  must trigger the corresponding workflow, which a plain GITHUB_TOKEN
  cannot do (see docs/agent-team-pipeline.md's "Cross-workflow
  triggering"; pr-intake.yml already mints an App token for exactly this
  reason). Fixed by minting the same pipeline App token and passing it to
  the agent step as a distinctly-named PIPELINE_APP_TOKEN, with explicit
  instructions (both in the workflow prompt and the persona file) that
  it's used for that one action only — everything else stays on the
  default GH_TOKEN, unchanged.

Also tightened the retry-dedup check flagged as a plausible weak point:
"grep the comment history for retry text" is now "grep for an exact
<!-- human-merge-sweep-retry --> marker, always the first line of the
retry comment" — an exact string match instead of a fuzzy read.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@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

Copy link
Copy Markdown
Collaborator Author

Principal review (round 2) — verifying fix commit decd452 for PR #335

Re-reviewed the fix commit against the two CONFIRMED bugs and the PLAUSIBLE weak point from the prior round. All three are genuinely fixed, not just claimed — verified by diffing against the exact sibling files they're supposed to match, not by trusting the commit message.

Risk tier: still no risk:* label on the PR (confirmed again: pr-intake.yml skips it because the PR body has no Closes #N, so the deterministic classifier never runs on GitHub for this PR at all — this is a pre-existing pipeline gap for issue-less/meta PRs, not something this commit introduced). Re-ran .github/scripts/classify_pr_risk.py origin/dev pr-335-check locally: risk:high (.claude/agents/human-merge-sweep-agent.md matches .claude/agents/**, .github/workflows/human-merge-sweep.yml matches .github/workflows/**). Same result as the prior round. This alone requires human-merge regardless of the findings below.

CONFIRMED #1 (missing id-token: write) — RESOLVED

Now present in human-merge-sweep.yml's permissions: block, with the same issue #158 citation and near-identical wording to dev-agent.yml's own comment (OIDC token fetch failure after 3 retries). Matches the sibling pattern.

CONFIRMED #2 (retry using the wrong token) — RESOLVED, verified correct not just present

  • New "Mint pipeline App token (Part 3 retries only)" step uses actions/create-github-app-token@v2 with app-id: ${{ vars.PIPELINE_APP_ID }} / private-key: ${{ secrets.PIPELINE_APP_PRIVATE_KEY }} — byte-for-byte the same shape as pr-intake.yml's "Mint pipeline App token" step.
  • I independently re-verified (not trusting the earlier claim) that both exist on this repo: gh variable list -R LibraVault/reader shows PIPELINE_APP_ID, gh secret list -R LibraVault/reader shows PIPELINE_APP_PRIVATE_KEY.
  • The minted token is wired into the agent step's env: as PIPELINE_APP_TOKEN (distinct name from GH_TOKEN, deliberately not the default).
  • Cross-checked human-merge-sweep.yml's prompt text against human-merge-sweep-agent.md's Part 3 instructions for drift — they agree: PIPELINE_APP_TOKEN is scoped to exactly one action (the status:needs-info → status:ready-for-dev/needs-qa/needs-review label swap), everything else stays on default GH_TOKEN. No inconsistency between the two files.

PLAUSIBLE (retry-dedup marker) — RESOLVED

<!-- human-merge-sweep-retry --> is now specified as a literal, verbatim string in both directions in human-merge-sweep-agent.md: the dedup search ("search its comments... for the exact literal marker") and the emit instruction ("Post a gh issue comment/gh pr comment starting with the <!-- human-merge-sweep-retry --> marker on its own first line"). Same string, both places — dedup is no longer a fuzzy free-text match.

New findings from this commit

None blocking. YAML re-parses cleanly (python3 -c "import yaml; yaml.safe_load(...)"). Permissions block is unchanged in scope beyond the required id-token: write addition — no escalation. App-token minting is unconditional (no early-exit guard like pr-intake.yml has), which is fine here since this workflow has no skip-guard step to gate it on.

CI / mergeable state (checked directly, not taken on faith)

All real checks pass on head commit decd452: Build & Test iOS (Simulator) pass, Build Android App pass, Unit & Integration Tests (JVM) pass, iOS UI Tests (informational) pass, Report Build Status pass. Compose UI Tests shows skipping (consistent across all three commits on this PR, not a masked failure). mergeStateStatus: CLEAN, mergeable: MERGEABLE.

No new networking dependency/call. No sensitive path touched beyond what the PR description already discloses and self-flags (.github/workflows/**, .claude/agents/**).

Verdict

human-merge (risk:high, self-declared and independently re-confirmed by re-running the classifier — not due to any remaining CONFIRMED finding, all three prior findings are genuinely resolved). The change itself is clean as of decd452. No local Actions runner available — this is a static/diff verification, not an execution test of the scheduled job itself, consistent with the prior round's caveat.

Recommend a human merges this by hand once satisfied with the above.

@libravault-xyz
libravault-xyz merged commit 8f11263 into dev Aug 20, 2026
6 checks passed
@libravault-xyz
libravault-xyz deleted the feature/human-merge-sweep-routine branch August 20, 2026 06:30
libravault-xyz pushed a commit that referenced this pull request Aug 20, 2026
…344)

Previously a manually-opened PR with no resolvable "Closes #N" line
exited pr-intake.yml's guard early with no risk:*/status:* label
applied at all, requiring a human to notice and hand-label it (as
happened for PRs #326, #335, #342). Now it still runs
classify_pr_risk.py and routes into the pipeline — status:needs-qa
when an issue is linked (unchanged), status:needs-review when it
isn't, since qa-agent.yml hard-stops on a missing linked issue (no
acceptance criteria to check) while principal-review.yml already
tolerates one gracefully.

Closes #343

Co-authored-by: claude[bot] <41898282+claude[bot]@users.noreply.github.com>
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