Skip to content

fix(#534): treat null QA verdict and zero-diff exec as phase failure - #536

Merged
admarble merged 3 commits into
mainfrom
feature/534-fix-orchestrator-treat-null-qa-verdict-and-zer
Apr 19, 2026
Merged

admarble merged 3 commits into
mainfrom
feature/534-fix-orchestrator-treat-null-qa-verdict-and-zer

Conversation

@admarble

Copy link
Copy Markdown
Contributor

Summary

  • Harden the run orchestrator's post-success mapping so it no longer treats two clear failure modes as success:
    • QA phase with null/unparseable verdict → returns success: false with "QA completed without a parseable verdict" (sessionId and stderr/stdout tails preserved).
    • Exec phase with zero file changes → returns success: false with "exec produced no changes (no commits, no uncommitted work)" after checking git diff --quiet origin/main..HEAD AND git status --porcelain in the worktree.
  • Extract mapAgentSuccessToPhaseResult (pure, @internal-exported) so the post-success logic is directly unit-testable without the full executePhase machinery.
  • Add hasExecChanges(cwd) helper that fails open on git errors to avoid false phase failures when origin/main isn't fetched.

Test plan

  • npm run build — tsc clean
  • npm run lint — 0 warnings
  • npm test src/lib/workflow/phase-executor.test.ts — 88/88 pass (16 new)
  • npx vitest run src/lib/workflow/ — 713/713 pass across 27 files
  • Synthetic reproducer via tsx -e confirmed both guards fire against an empty mktemp repo and a null-verdict QA result
  • CI passes on push

Closes #534

The orchestrator's post-success mapping in phase-executor.ts silently passed
two clear failure modes through as success:

1. QA phase with a null verdict (empty or unparseable agent output) — the
   `verdict &&` short-circuit meant `parseQaVerdict() === null` fell through
   to the success branch.
2. Exec phase regardless of whether any commits or uncommitted work were
   produced. An agent session returning `subtype: "success"` on an empty
   worktree was reported as a successful exec.

Combined, an empty worktree could progress spec → exec → qa and only fail at
PR creation with "No commits between main and feature/…".

This change adds:

- `hasExecChanges(cwd)` — internal helper that runs `git diff --quiet
  origin/main..HEAD` and `git status --porcelain`, failing open on git
  errors so a missing origin ref does not regress normal runs.
- `mapAgentSuccessToPhaseResult(...)` — extracts the success-to-PhaseResult
  mapping into a pure, unit-testable function. It now returns failure for:
  - qa phase with `parseQaVerdict(output) === null`, with error message
    "QA completed without a parseable verdict";
  - exec phase when `hasExecChanges(cwd)` is false, with error message
    "exec produced no changes (no commits, no uncommitted work)".
  Session id, stderr/stdout tails, and exit code are preserved in both
  failure paths.

Tests cover the full matrix: QA verdict variants (including NEEDS_VERIFICATION
and AC_NOT_MET), null/empty output, exec with commits, exec with uncommitted
work, exec zero-diff, and no-op for non-qa/non-exec phases. Synthetic
reproducer confirms both guards fire against an empty worktree.
Follow-up to the pushed commit: the AC-specified check
`git diff --quiet origin/main..HEAD` has a false-positive on stale
branches. `git diff A..B` reports differences in either direction, so
once `origin/main` advances past HEAD the two-dot diff exits 1 (the
inverse diff is non-empty) and `hasExecChanges` would falsely report
"has commits" — exactly the bug #534 is trying to fix.

Switch to `git rev-list --count origin/main..HEAD`, which counts only
commits reachable from HEAD but not from origin/main. Zero-progress
runs on stale branches now correctly report `success: false`.

Added regression tests:
- hasExecChanges: stale-base scenario returns false
- hasExecChanges: non-numeric rev-list output treated as zero
- mapAgentSuccessToPhaseResult: exec phase fails on stale-base zero diff

CHANGELOG updated to reflect the `rev-list` semantic.
…strator-treat-null-qa-verdict-and-zer

# Conflicts:
#	CHANGELOG.md
@admarble
admarble merged commit 032b241 into main Apr 19, 2026
5 checks passed
@admarble
admarble deleted the feature/534-fix-orchestrator-treat-null-qa-verdict-and-zer branch April 19, 2026 00:06
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.

fix(orchestrator): treat null QA verdict and zero-diff exec as failure, not success

1 participant