Skip to content

fix(ci): raise principal-review max-turns and salvage verdict on crash - #299

Closed
libravault-pipeline-bot[bot] wants to merge 1 commit into
devfrom
fix/principal-review-max-turns-and-crash-verdict
Closed

libravault-pipeline-bot[bot] wants to merge 1 commit into
devfrom
fix/principal-review-max-turns-and-crash-verdict

Conversation

@libravault-pipeline-bot

Copy link
Copy Markdown
Contributor

What

principal-review.yml's "Run principal review agent" step is capped at
--max-turns 40, which routinely brushes against the agent's actual turn
count (observed 41-turn near-misses on 4 same-day PRs: #257, #264, #281,
and flagged once before on #279). When it hits, steps.agent.outcome
reports failure, and the "Advance PR based on review verdict" step
discarded principal-verdict.txt unconditionally on that outcome — even
though the agent's last action before ending is writing that exact file,
so a valid verdict is very often already on disk when the crash happens.

Fix

  • Raised --max-turns from 40 to 70 — real headroom above the
    observed 41-turn near-misses, without going as high as dev-agent.yml's
    90 (that workflow does substantially more: editing, running builds).
  • Changed the crash branch in "Advance PR based on review verdict" to read
    principal-verdict.txt even when steps.agent.outcome == 'failure'. If
    it holds a valid verdict (auto-merge or human-merge), that verdict is
    used and the PR gets a comment noting the run crashed right after
    writing it (visibility, per the issue's ask) — labels/auto-merge/
    human-merge routing all proceed exactly as a normal run. Only truly
    unusable state (no file, or a crash before any file exists) still routes
    to status:needs-info, unchanged from before.

Closes #297

Risk

This touches .github/workflows/**, one of agent-policy.yml's
sensitive_paths, so classify_pr_risk.py will force risk:high on this
diff regardless of size — flagging that explicitly here so the principal
review agent doesn't have to rediscover it. The change is scoped to a
single workflow file and does not touch agent-policy.yml or any other
sensitive path.

Testing

No local emulator/CI harness exists for a workflow file's embedded run:
bash, so I extracted the exact "Advance PR" script via a small Python/YAML
snippet, substituted realistic values for every ${{ }} expression, and
ran it against a mocked gh CLI to exercise all 5 relevant paths:

  1. Agent crashes, no principal-verdict.txt at all → routes to
    status:needs-info (unchanged behavior, verified still intact).
  2. Agent crashes, but principal-verdict.txt contains auto-merge →
    verdict is used, status:approved-auto-merge applied, crash-visibility
    comment posted.
  3. Agent crashes, principal-verdict.txt contains human-merge → same,
    routes to status:needs-human-merge.
  4. Agent finishes normally with auto-merge → unchanged behavior.
  5. Agent finishes normally with no verdict file → still defaults to
    human-merge (unchanged behavior).

Also ran bash -n and shellcheck over the extracted script (the only
shellcheck findings are expected false positives on GitHub Actions'
${{ }} expression syntax, not real issues) and validated the full YAML
file parses with python3 -c "import yaml; yaml.safe_load(...)".

The agent's last action before a normal finish is writing
principal-verdict.txt, so hitting --max-turns one turn later than usual is
common, not rare. Raise the cap from 40 to 70 for headroom above the
observed 41-turn near-misses, and make the crash-handling branch in
"Advance PR based on review verdict" check principal-verdict.txt for a
valid verdict before discarding it — only fall back to status:needs-info
when there's truly no usable verdict on disk.

Closes #297
@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

@github-actions github-actions Bot added the risk:high Touches a sensitive path or exceeds diff-size threshold — always human merge label Aug 19, 2026
@libravault-pipeline-bot libravault-pipeline-bot Bot added the status:needs-qa PR open, awaiting qa-agent verification label Aug 19, 2026
@claude

claude Bot commented Aug 19, 2026

Copy link
Copy Markdown
Contributor

QA verification — PR #299 vs issue #297

Issue type: bug report, no explicit checklist — criteria used: (a) the reported crash-discards-valid-verdict pattern no longer reproduces, (b) a regression check proves it.

What I did

This is a workflow-YAML-only diff (single file, .github/workflows/principal-review.yml, no app code), so ./gradlew testDebugUnitTest is not relevant — no JVM/Android/iOS code changed, and this repo has no automated harness for workflow run: scripts (confirmed against precedent, e.g. commit 6e130cd, which also shipped workflow-only fixes with no test files, just PR-description manual verification). Instead I independently reproduced the PR's own testing methodology rather than trusting its claims:

  • Extracted the exact "Advance PR based on review verdict" run: script via python3 -c "import yaml; ...", substituted realistic values for every ${{ }} expression, and ran it for real against a mocked gh CLI on $PATH.
  • ✅ Crash + valid auto-merge verdict on disk → verdict is used, status:approved-auto-merge applied, crash-visibility comment posted referencing issue principal-review.yml: --max-turns 40 is too tight and a crash discards a valid verdict #297. Confirmed via actual gh call log.
  • ✅ Crash + valid human-merge verdict (mixed case, padded whitespace: " Human-Merge ") → correctly normalized and routed to status:needs-human-merge. Confirms the tr lowercase/whitespace-strip handles sloppy agent output.
  • ✅ Crash + no verdict file at all → unchanged behavior, routes to status:needs-info, verdict=crashed. Confirms the fix doesn't regress the pre-existing case.
  • bash -n on the extracted script: clean. shellcheck: only SC2296/SC2193 on the ${{ }} GitHub Actions expressions, which are expected false positives (not real syntax), matching what the PR description claims.
  • python3 -c "import yaml; yaml.safe_load(...)" on the full file: parses cleanly.

--max-turns raised 40→70: reasonable headroom above the observed 41-turn near-misses cited in the issue (#257/#264/#281), below dev-agent.yml's 90. The issue didn't pin an exact number so this is a judgment call, not a contract violation.

⚠️ Coordination flag for the human merger (not a defect in this PR's code)

PR #298 (fix/principal-review-turn-cap-crash-verdict, human-authored, opened ~22s before this one) fixes the same issue #297 with a functionally equivalent change to the same block of principal-review.yml (cap raised to 65 instead of 70, same crash-salvage logic). It's currently sitting at status:needs-info — as expected, since any PR touching principal-review.yml itself always trips this workflow's own OIDC anti-tampering drift check (workflow-drift step, issue #254) and gets routed straight to a human rather than reviewed by the agent. That's pre-existing, intended behavior, not something either PR introduces or can avoid.

Only one of #298/#299 should actually be merged — a human should pick one and close the other, or they'll conflict on the same lines. Flagging explicitly since neither PR's own pipeline can detect the duplicate.

AGENTS.md conventions

Commit hygiene: single conventional commit (fix(ci): ...), Closes #297 present. Branch naming follows fix/<slug>. Branch is 3 commits behind dev (unrelated: #260, #261, #262) — doesn't affect this diff or the drift check (which only compares principal-review.yml itself against dev), but worth a rebase before merge per "keep dev clean." Non-blocking.

Verdict

Logic verified by direct execution against a mocked gh CLI (not just trusting the PR description), all 3 crash-path scenarios behave correctly, no regression to the pre-existing no-verdict crash path, conventions followed. The duplicate-PR situation is a merge-coordination call for a human, not a code defect.

QA verdict: PASS

@github-actions github-actions Bot removed the status:needs-qa PR open, awaiting qa-agent verification label Aug 19, 2026
@libravault-pipeline-bot libravault-pipeline-bot Bot added the status:needs-review QA passed, awaiting principal-review-agent label Aug 19, 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 19, 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: Update on the duplicate-PR situation QA flagged above (05:03:03Z comment).

PR #298 (the other fix for #297) has since merged — 2026-08-19T05:48:39Z, raising principal-review.yml's --max-turns to 65 and adding the crash-verdict-salvage logic. dev's copy of principal-review.yml now already contains this exact fix.

That means this PR is now fully redundant, not just a same-day duplicate risk — its changes are already live on dev. It's also not eligible for this routine's automated stale-branch rebase-and-retry (it touches .github/workflows/principal-review.yml itself, a sensitive_paths entry), so it's just going to keep tripping the OIDC workflow-drift check every time someone re-labels it.

Recommend a human close this PR without merging rather than rebasing it — a rebase would just make it a no-op diff against dev.


Generated by Claude Code

@libravault-xyz

Copy link
Copy Markdown
Collaborator

Superseded by #298, which already merged the same fix (raised principal-review.yml's --max-turns and made the crash branch read principal-verdict.txt even on failure) for the same issue (#297). This PR and #298 were opened independently around the same time — closing this one rather than resolving the now-inevitable conflict with dev. No action needed on the underlying issue, it's done.

@libravault-xyz
libravault-xyz deleted the fix/principal-review-max-turns-and-crash-verdict branch August 19, 2026 08:09
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

Development

Successfully merging this pull request may close these issues.

principal-review.yml: --max-turns 40 is too tight and a crash discards a valid verdict

1 participant