Skip to content

fix(#878): resolve phase diff stats against origin/<base>, not the stale local ref - #891

Merged
admarble merged 2 commits into
mainfrom
feature/878-fix-observability-phase-diff-stats-compare-aga
Aug 4, 2026
Merged

admarble merged 2 commits into
mainfrom
feature/878-fix-observability-phase-diff-stats-compare-aga

Conversation

@admarble

@admarble admarble commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

  • getGitDiffStats now resolves its base via a new resolveDiffBase (nearest-candidate between origin/<base> and the bare ref, preferring origin on a tie), so phase diff stats compare against the ref the worktree was actually created from instead of a possibly-stale local branch — no more phantom filesModified from already-merged upstream commits.
  • getCommitHash gains an optional baseRef and returns undefined when the branch never moved off its base, so an empty branch's phase log no longer records the base tip as its commit. Run-level start/end markers keep the bare behavior.
  • All 32 bare git diff main...HEAD in qa/SKILL.md → origin/main...HEAD across all three mirrors (byte-identical), plus — disclosed scope expansion, same root cause and same §7 gates — the 18 bare refs in qa's reference docs and the two gate scripts (semgrep-scan.ts, tautology-detector-cli.ts, now array-form execFileSync).
  • Real-git regression suite: worktree from origin/main with local main deliberately behind asserts zero files and no phase commit; also covers chain-mode local-ahead bases and remote-less fallback.

AC Verification

AC Description Status Evidence
AC-1 getGitDiffStats resolves base like resolveBaseRef ✅ Implemented src/lib/workflow/git-diff-utils.ts (resolveDiffBase), wired in batch-executor.ts
AC-2 getCommitHash undefined when no commits past base ✅ Implemented git-diff-utils.ts; run-level call sites deliberately unchanged
AC-3 Regression test with local base deliberately behind ✅ Implemented git-diff-utils.integration.test.ts (9 tests, real repos)
AC-4 32 bare refs in qa/SKILL.md origin-qualified, ×3 mirrors ✅ Implemented Counts: 43/43 origin-qualified, 0 bare, 0 doubled per mirror
AC-5 Mirrors byte-identical ✅ Implemented md5 equal ×3; check-skill-sync.ts 44/44 synced

Mutation verification (repo testing rules): reverting getGitDiffStats to the bare ref fails exactly the 2 diff-stat regression tests; disabling the getCommitHash zero-check fails exactly the AC-2 test. Both recorded in the QA comment on #878.

Out of scope: remaining bare-ref consumers (qa-cache.ts, worktree-manager.ts summaries, phase-executor.ts aider file-context, other skills' mirrors) → #890.

Test plan

  • Full suite: 4820 passed / 232 files
  • New integration suite (real git repos): 9/9
  • Both gate scripts executed end-to-end in the worktree (exit 0, correct file sets)
  • Build, lint, lint:skill-calls green

Fixes #878

🤖 Generated with Claude Code

…ale local ref

Worktrees are created from origin/<base> but getGitDiffStats diffed
against the local <base> ref, which nothing in the run path updates.
When local main lagged the remote, every phase log was attributed a
diff belonging to commits the run never made, and the bogus
filesModified flowed into run-reflect, merge-check, and sequant logs.

- Add resolveDiffBase: candidates are origin/<base> and the bare ref;
  pick the one nearest to HEAD (rev-list --count), preferring the
  origin-qualified form on a tie. Nearest-wins matches the worktree's
  creation point in both staleness directions (stale local default
  branch AND chain-mode local bases with unpushed commits). Falls back
  to the bare ref verbatim when no candidate resolves.
- getGitDiffStats resolves its base through resolveDiffBase.
- getCommitHash gains an optional baseRef and returns undefined when
  HEAD has no commits past it, so an empty branch never logs the base
  tip as its phase commit. Run-level start/end markers keep the bare
  behavior; a git error while counting fails open.
- batch-executor resolves the base once and feeds both calls.
- qa/SKILL.md: all 32 bare `git diff main...HEAD` -> origin/main...HEAD
  across all three mirrors (byte-identical); same for the 18 bare refs
  in the qa reference docs and the two gate scripts (semgrep-scan.ts,
  tautology-detector-cli.ts), which scanned merged code on the
  motivating run.
- Real-git regression tests: worktree from origin/main with local main
  deliberately behind asserts zero files and no phase commit.

Out of scope (follow-up): the same bare-ref pattern in qa-cache.ts,
worktree-manager.ts diff summaries, and phase-executor.ts:1114.

Fixes #878
… AC-3 test

QA-round fixes:
- semgrep-scan.ts / tautology-detector-cli.ts: array-form execFileSync
  instead of execSync template interpolation. Not exploitable today (the
  base ref is always a hardcoded candidate of "main"), but closes the
  latent shell surface if a future caller passes a non-literal base.
- Integration test: the standalone fixture-sanity test asserted only on
  git state (tautology detector correctly flagged it); its precondition
  assertions now live inside the AC-3 regression test.
@admarble
admarble merged commit 4dec46a into main Aug 4, 2026
8 checks passed
@admarble
admarble deleted the feature/878-fix-observability-phase-diff-stats-compare-aga branch August 4, 2026 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant