Skip to content

fix(ci): open dev-agent's PR early as a checkpoint, not as its last step - #368

Merged
libravault-xyz merged 2 commits into
devfrom
fix/dev-agent-checkpoint-early
Aug 20, 2026
Merged

libravault-xyz merged 2 commits into
devfrom
fix/dev-agent-checkpoint-early

Conversation

@libravault-xyz

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

Copy link
Copy Markdown
Collaborator

Summary

Root cause of a real failure this session (issue #203, workflow run 32372682878): the dev agent exhausted its 90-turn budget one call short of gh pr create, having already committed and pushed ~1,700 lines of real, working implementation. The branch sat on origin with no PR at all — invisible to this workflow's own crash-recovery lookup (find_linked_pr.sh, which can only find a PR that already exists) — so all of that work was orphaned until a human happened to notice the pushed branch and manually opened a PR for it.

Fix: dev-agent now opens a --draft PR as soon as it has one coherent commit, keeps pushing to it as it continues, and marks it ready (gh pr ready) once actually done.

Why this is safe (verified, not assumed)

  • Both qa-agent.yml and principal-review.yml trigger only on pull_request: labeled, never on a PR existing or being in draft.
  • pr-intake.yml already excludes bot-authored PRs (user.login != 'libravault-pipeline-bot[bot]') — irrelevant to dev-agent's own PRs regardless.
  • dev-agent's own tail step is what labels its PRs (status:needs-qa), and that only fires once, after the agent step finishes (success or failure) — never earlier just because a PR is open.
  • The crash-recovery step already declines to advance an unconfirmed PR to status:needs-qa when the agent step itself failed (routes to status:needs-info instead) — this PR doesn't touch that logic, it only fixes the "no PR exists anywhere" case that logic can't help with.
  • find_linked_pr.sh already searches --state open, which includes drafts — finds an early-opened PR with zero changes needed there.

Update: addressed principal review's CHANGES_REQUESTED finding

Review correctly caught a real side effect I hadn't accounted for: opening the PR early and pushing several more commits to it before marking ready means jvm-tests.yml/ios-app-build.yml (default pull_request types) now fire a full run on every intermediate push, not just once at the end — real added CI cost, especially iOS build minutes (this pipeline's scarcest resource — I hit "pipeline at capacity" myself earlier this same session).

Fixed by gating both workflows' pull_request-triggered jobs on non-draft state, adding ready_for_review to their trigger types so marking ready still fires one real CI run against the finished diff, and gating ios-app-build.yml's report-status job the same way (a draft-skipped needs.*.result == 'skipped' would otherwise have tripped its fail-check and posted a false "FAILED" comment). Mirrors ui-tests.yml's own existing precedent for conditionally skipping a heavy job on dev PRs.

Other changes

  • Added a gh pr ready safety net to dev-agent's own tail step, for the case where a run reports success but the agent forgot to un-draft its own PR before finishing — harmless no-op (|| true) on the common path where it's already ready.
  • Persona doc: caps open-ended manual verification on platforms with no local build signal (iOS, no Xcode on the Linux runner) — a real contributor to turns burned in the [Feature] iOS Encrypted Vaults 4/6: per-format read/play integration (EPUB/PDF/audio) #203 run was open-ended swift -frontend -parse cross-referencing as a substitute for a compile signal the agent doesn't have, right up until the turn budget ran out. Time-boxed now; CI's real compiler is the actual verification, same as for any contributor without a Mac.

Review notes

  • Touches .github/workflows/** and .claude/agents/dev-agent.md (.claude/agents/**) — both sensitive_paths entries, risk:high/human-merge expected regardless of findings, per agent-policy.yml. (Per review nit: naming both explicitly here, not just the workflows directory.)
  • No behavior change to non-draft/non-crash paths on the label/status-machine side: a normal successful run still ends in exactly the same state.
  • Verified YAML parses (python3 -c "import yaml; yaml.safe_load(...)") and the tail step's embedded shell parses (bash -n) for every file touched — no way to exercise the actual claude-code-action step or a real crash scenario without live infra, so this is reviewed by inspection + the trigger-condition verification above, not a live test run.

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

Root cause of a real failure this session (issue #203, workflow run
32372682878): the dev agent exhausted its 90-turn budget one call short
of `gh pr create`, having already committed and pushed ~1,700 lines of
real, working implementation. The branch sat on origin with no PR at
all — invisible to this workflow's own crash-recovery lookup
(find_linked_pr.sh, which can only find a PR that already exists) — so
all of that work was orphaned until a human happened to notice the
pushed branch and manually opened a PR for it.

Fix: dev-agent now opens a --draft PR as soon as it has one coherent
commit, keeps pushing to it as it continues, and marks it ready
(`gh pr ready`) once actually done. This costs nothing on the success
path and loses nothing extra on a crash — the crash-recovery step
already declines to advance an unconfirmed PR to status:needs-qa when
the agent step itself failed (routes to status:needs-info instead); the
only thing this fixes is the "no PR exists anywhere" case, which
crash-recovery can't do anything about after the fact.

No pr-intake.yml/qa-agent.yml changes needed, verified before assuming
otherwise: both qa-agent.yml and principal-review.yml trigger only on
`pull_request: labeled`, never on a PR existing or being in draft, and
pr-intake.yml already excludes bot-authored PRs
(`user.login != 'libravault-pipeline-bot[bot]'`) entirely — dev-agent's
own tail step is what labels its PRs, and that only fires once, after
the agent step finishes (success or failure), regardless of when in the
run the PR was opened. find_linked_pr.sh also already searches
`--state open`, which includes drafts, so it finds an early-opened PR
correctly with zero changes needed there either.

Also adds a `gh pr ready` safety net to the tail step itself, for the
case where a run reports success but the agent forgot to un-draft its
own PR before finishing — harmless no-op on the common path.

Secondary fix in the persona doc: cap open-ended manual verification on
platforms with no local build signal (iOS, no Xcode on the Linux
runner) — a real contributor to turns burned in the #203 run was
open-ended `swift -frontend -parse` cross-referencing as a substitute
for a compile signal the agent doesn't have access to, right up until
the turn budget ran out. Time-box it and let CI's real compiler be the
actual verification, same as any other contributor without a Mac would.

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 20, 2026
@libravault-pipeline-bot libravault-pipeline-bot Bot added the status:needs-review QA passed, awaiting principal-review-agent label Aug 20, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR was opened outside the automated pipeline (author isn't libravault-pipeline-bot[bot]) and doesn't link an issue (no Closes #N-style line in its body), so there's no acceptance criteria for qa-agent.yml to verify against — it would otherwise sit with no risk/status label and nothing downstream would pick it up (see issue #223's actual history, and issue #343 for this issue-less case specifically). This deterministic backstop (pr-intake.yml) classified its risk and applied status:needs-review to route it straight to principal review.

@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 #368

Risk label sanity check: risk:high is current (single commit df7894c,
label applied after it; nothing landed since). Correctly triggered by
sensitive_paths matches on both .github/workflows/** and
.claude/agents/** — diff itself is only 87 changed lines, well under the
400-line size threshold, so size isn't a factor here.

Verified independently (not just taking the PR body's word for it):

  • qa-agent.yml and principal-review.yml both trigger only on
    pull_request: types: [labeled] (+ workflow_dispatch) — confirmed by
    reading both files. An early draft PR cannot prematurely fire either.
  • pr-intake.yml triggers on pull_request: types: [opened, reopened] but
    guards on user.login != 'libravault-pipeline-bot[bot]' — confirmed this
    correctly excludes dev-agent's own (App-token-authored) PRs regardless of
    draft state, so it won't double-label them.
  • find_linked_pr.sh uses gh pr list --state open, which does include
    drafts — confirmed by reading the script.
  • The new tail-step shell (gh pr ready "$PR_NUMBER" 2>/dev/null || true
    and surrounding block) parses cleanly (bash -n on the extracted run:
    block) and the workflow YAML loads with yaml.safe_load.
  • gh pr ready only needs pull_request: write, which GITHUB_TOKEN
    already has in this job — using the default token there (not the App
    token) is correct, since it's a state toggle, not something that needs to
    trigger a downstream workflow.

Finding (verified, not blocking on its own but not accounted for in the
PR's "why this is safe" section):

Opening the PR early — and continuing to push to it — makes jvm-tests.yml
(pull_request: branches: ["**"]) and ios-app-build.yml
(pull_request: branches: [...]), both using the GitHub Actions default
pull_request types (opened, synchronize, reopened), fire on every
subsequent commit the dev agent pushes while still working, not just once
at the end. Before this change, pushes to a branch with no open PR don't
fire pull_request events at all — only the final gh pr create fired
opened once, against the finished diff. Now, a session that makes several
commits before marking the PR ready will re-trigger full JVM test runs and
iOS builds several times over, against WIP/possibly-broken intermediate
states. cancel-in-progress: true on both (confirmed by reading the
concurrency: blocks) means these don't pile up and each superseded run
gets cut short, but each one still spins up a runner and does some real
work before being canceled — real, if bounded, added CI cost, and iOS
build minutes are usually the scarcest resource in a pipeline like this.
(ui-tests.yml's Compose/emulator job is unaffected — for PRs into dev
it only runs when a needs-emulator label is present, confirmed by reading
its if: condition, so it's already gated and not exposed to this.)

The PR's "Why this is safe" section only checks the pipeline-status
workflows (qa-agent.yml, principal-review.yml, pr-intake.yml) —
correctly — but doesn't mention this. The "Review notes" claim "No behavior
change to non-draft/non-crash paths: a normal successful run looks
identical from the outside except the PR exists earlier in its lifetime"
overstates it slightly — a normal successful run now also triggers CI
multiple times instead of once. This doesn't break anything (status-label
logic and the actual crash-recovery fix are unaffected and, verified above,
correct), so I'm not asserting the approach is wrong — just that this is a
real, verified side effect a human merging this should weigh (acceptable
cost for the reliability win, vs. e.g. gating those two workflows' heavy
jobs on non-draft like ui-tests.yml already does for its emulator job).

Minor nit: the PR description names .github/workflows/** as the
sensitive path touched but doesn't mention .claude/agents/dev-agent.md
also matches agent-policy.yml's .claude/agents/** entry. Doesn't change
the outcome (already risk:high either way) but per the persona's
"flag sensitive-path touches explicitly" expectation, the PR body should
name both.

Everything else: the actual fix (draft-then-ready checkpoint, safety-net
gh pr ready in the tail step, time-boxed iOS manual-verification guidance)
is sound, addresses a real documented failure (issue #203, run
32372682878), and the token/identity choices are correct per
docs/agent-team-pipeline.md's "Cross-workflow triggering" and
claude-code-action gotchas sections. No networking additions, no other
sensitive-path touches beyond the two already labeled.


risk:high already routes this to status:needs-human-merge regardless of
the above — flagging the CI-retrigger point via --request-changes so a
human explicitly weighs it (accept the cost, or gate those workflows on
draft state too) rather than it being buried in a plain 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 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

Addresses principal review's CHANGES_REQUESTED finding on this PR
(gh pr review 368): opening dev-agent's PR early, then pushing several
more commits to it before marking it ready, made both jvm-tests.yml and
ios-app-build.yml (default pull_request types: opened/synchronize/
reopened) fire a full run on every one of those intermediate pushes,
not just once at the end — real added CI cost, particularly for iOS
build minutes, this pipeline's scarcest resource (confirmed live this
session: a QA run got skipped outright for "pipeline at capacity").

Fix, mirroring ui-tests.yml's own existing needs-emulator-label
precedent for conditionally skipping a heavy job on `dev` PRs:
- Both workflows' pull_request trigger now explicitly includes
  ready_for_review (previously only implicit opened/synchronize/
  reopened) — needed so marking a draft ready fires a fresh, real CI
  run against the finished diff; without this a draft-opened PR could
  reach "ready" with no CI signal at all if no further push happens
  after gh pr ready.
- Every job in both workflows that's triggered by `pull_request` now
  skips while `draft: true`; `push` events (dev/main) are never gated,
  since they carry no pull_request context to check.
- ios-app-build.yml's report-status job (comment + fail-check) is
  gated the same way, not just the two jobs it depends on — without
  this, needs.*.result == 'skipped' would have tripped its "Fail if
  either build failed" step and posted a false "FAILED" comment on
  every draft-triggered run.

Drafts can't be merged regardless of check state, so gating on draft
here costs nothing at the point that actually matters (merge time) —
same reasoning ui-tests.yml's existing conditional-required-check
pattern on dev already relies on.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@libravault-xyz

Copy link
Copy Markdown
Collaborator Author

Addressed the CHANGES_REQUESTED finding — good catch, I'd only checked the pipeline-status workflows (qa-agent/principal-review/pr-intake) and missed that opening the PR early also changes how often `jvm-tests.yml`/`ios-app-build.yml` fire.

Pushed `ad1491c`: both workflows now skip their `pull_request`-triggered jobs while the PR is a draft (mirroring `ui-tests.yml`'s existing needs-emulator-label precedent), with `ready_for_review` added to their trigger types so marking a PR ready still produces exactly one real CI run against the finished diff — not zero, not one-per-push. `ios-app-build.yml`'s `report-status` job is gated the same way so a draft-skipped run doesn't trip its fail-check or post a false "FAILED" comment. Also fixed the PR description to name `.claude/agents/` alongside `.github/workflows/` per the minor nit.

`risk:high` already routes this to human-merge regardless of review outcome, so merging this myself now that the finding's addressed.

@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 0fb8f74 into dev Aug 20, 2026
6 checks passed
@libravault-xyz
libravault-xyz deleted the fix/dev-agent-checkpoint-early branch August 20, 2026 18:28
libravault-xyz added a commit that referenced this pull request Aug 20, 2026
…nding (#375)

Real finding from PR #368's own review went undocumented anywhere but
that PR's now-merged review thread: opening dev-agent's PR early would
re-trigger full JVM/iOS CI on every intermediate push, a real cost given
this pipeline's iOS build minutes are already its scarcest resource
(confirmed live, same session: PR #355's QA run got skipped outright for
"pipeline at capacity"). Fixed in the same PR before merge, but never
got the numbered-issue treatment this repo's own workflow comments lean
on everywhere else (`see issue #244`, `#254`, `#311`, ...) — filed
retrospectively as #373, closed with a link to the fix.

This codifies that as standard practice going forward: any finding at
CONFIRMED severity (the same bar that already forces human-merge) now
also gets filed as a GitHub issue, independent of whether it's fixed
inline in the same PR/round, needs separate follow-up, or a human
decides not to act on it. A review comment disappears from easy view
the moment its PR merges; a numbered issue doesn't.

`issues: write` is already granted to principal-review.yml's job — no
workflow changes needed, this is a persona-only addition, same shape as
#368's dev-agent fix turning out narrower than first assumed once the
actual permissions/triggers were checked instead of guessed at.

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