Skip to content

principal-review.yml's checkout leaves the working tree dirty relative to HEAD for unrelated files #386

Closed

Description

@libravault-xyz

What happened

During PR #375's principal-review run (workflow run 32414815714), the review agent's very first diagnostic command — before it had done anything else — found the working tree was dirty in a way that shouldn't be possible right after a checkout:

$ git branch --show-current; git log --oneline -3; git status; git diff HEAD -- .claude/agents/principal-review-agent.md | head -50
fix/principal-review-file-issues
557c679 fix(ci): principal-review-agent files an issue for every CONFIRMED finding
0fb8f74 fix(ci): open dev-agent's PR early as a checkpoint, not as its last step (#368)
60b398e fix(ios): verify and pin EPUB bookmark/locator compatibility with block model (#367)
On branch fix/principal-review-file-issues
Your branch is up to date with 'origin/fix/principal-review-file-issues'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   .claude/agents/dev-agent.md
	modified:   .claude/agents/human-merge-sweep-agent.md
	modified:   .claude/agents/principal-review-agent.md

HEAD (557c679, confirmed by git log) is PR #375's real tip, which does commit the "Documenting real findings" section this PR adds — but the working tree file did not have that section; git diff HEAD showed it as an unstaged removal. Same story for dev-agent.md/human-merge-sweep-agent.md: both files exist on disk with content that doesn't match what's actually committed at HEAD.

Sequence of events (from the run log)

  1. actions/checkout@v4 (fetch-depth: 0, no explicit ref:) — for a pull_request-family trigger this checks out GitHub's synthetic refs/pull/375/merge ref. Log line: Previous HEAD position was c9e0e29 Merge 557c679...into 0fb8f74... — i.e. a merge of PR fix(ci): principal-review-agent files an issue for every CONFIRMED finding #375's tip into 0fb8f74, the commit PR fix(ci): principal-review-agent files an issue for every CONFIRMED finding #375's branch was actually cut from (not necessarily current dev at run time).
  2. gh pr checkout 375 — log line: Switched to a new branch 'fix/principal-review-file-issues', tracking origin/fix/principal-review-file-issues. This reports success and looks like a clean branch switch.
  3. git fetch origin dev (the workflow-file-drift OIDC self-check, fetch only — doesn't touch the working tree).
  4. The agent's own first command (quoted above) already shows the dirty state — nothing the agent itself ran caused it; there's no git checkout/git reset/git stash anywhere earlier in its own command history.

So the dirty state exists immediately after step 2, despite gh pr checkout's own output claiming a clean switch.

Likely relevant context (not fully confirmed as root cause)

dev-agent.md and human-merge-sweep-agent.md were both modified by PRs that merged to dev shortly before this run (#381 at 20:21:46Z, #372 at 19:36:37Z) — after PR #375's branch (fix/principal-review-file-issues) was cut from dev at 0fb8f74 but before this review run's checkout at ~20:34:39Z. Whether that timing is actually why — e.g. some interaction between the initial merge-ref checkout and gh pr checkout's branch-switch not doing a full clean overwrite for files also touched on dev in the meantime — is a real hypothesis, not confirmed. I did not reproduce this deliberately or trace gh's actual checkout implementation; flagging the observed facts rather than asserting a mechanism I haven't verified.

Why this matters (and why it didn't cause a wrong outcome this time)

The review agent's actual verdict on PR #375 was correct — it used gh pr diff/gh pr view --json files (API-based, not local git state) as its real source of truth for what the PR contains, explicitly noted the dirty state as "not part of PR #375's actual diff," and didn't let it affect the outcome. That's the right instinct and it held here.

But principal-review.yml's own "Check for workflow-file drift (GitHub OIDC self-check)" step (see #254 for why it exists) does rely on local git diff --quiet origin/dev -- <workflow file> — the same kind of comparison that was wrong here, just for a different file. In this specific run that check happened to land on the right answer (principal-review.yml itself wasn't among the files reported dirty), but if this checkout inconsistency can affect an arbitrary file, it could in principle affect that self-check's own file too, undermining the anti-tampering guard it exists to provide. Same risk applies to any other automated step in this pipeline that trusts local git diff/git status against a freshly-checked-out PR branch (dev-agent.yml's equivalent revise-mode workflow-drift check is the other place this pattern is used).

Suggested next step

Not fixing this now — filing per the new "document CONFIRMED findings" policy (#375) since it's a real, verified anomaly with unclear root cause and potential (unconfirmed) implications for the workflow-drift anti-tampering checks. Worth a deliberate reproduction (e.g. trigger a review run on a PR whose branch predates a dev change to a file outside the PR's own diff, then inspect git status the same way) before deciding whether this needs a fix, or is an artifact specific to gh pr checkout's interaction with the default merge-ref checkout that's already known/documented upstream.

Activity

  1. added
    status:ready-for-dev
    status:in-progress
    on Aug 20, 2026
  2. libravault-xyz commented on Aug 22, 2026

    @libravault-xyz
    CollaboratorAuthor

    Automated pipeline health check: This issue's own status:ready-for-dev/status:in-progress labels are stale — its linked PR, #387, already exists and has advanced to status:escalated.

    Root cause (confirmed by reading .github/workflows/dev-agent.yml): the triage-and-implement step's success path only clears status:in-progress and labels the PR; it never revisits the originating issue's status labels once a PR is opened. Same signature confirmed on #401 (→PR #405), #402 (→PR #404), #403 (→PR #407) — a new, 6th failure mode not in the 5 this routine currently tracks. Not self-healing (label cleanup on an already-advanced issue isn't in this routine's authorized action set) — flagging for a human to file/fix.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:in-progressstatus:ready-for-dev

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions