Repository navigation
Description
Summary
Worktrees are created from origin/<base>, but the run's diff statistics are computed against the local <base> ref. When the local branch lags the remote — routine, since nothing in the run path updates it — every phase log is attributed a diff belonging to commits the run did not make.
src/lib/workflow/worktree-manager.ts:743 creates the branch from the remote:
: `origin/${detectedDefault}`;src/lib/workflow/git-diff-utils.ts:137 compares against the local ref:
const diffRef = `${baseBranch}...HEAD`; // "main...HEAD", not "origin/main...HEAD"The same file's getCommitHash (line 110) records a bare git rev-parse HEAD, so a branch with no commits of its own logs the base tip as if it were the phase's commit.
Note phase-executor.ts:723 (resolveBaseRef, added by #537) already normalizes to origin/... for exactly this reason. git-diff-utils.ts predates it and was never migrated.
Evidence
Dogfood run of sequant run 765 in matcha-maps, 2026-07-29 (run log run-2026-07-30T03-30-56-05473c99-cf2d-49d0-83b8-59b722e41d1d.json).
Reflog timeline:
| time (CDT) | event |
|---|---|
| 22:22 | local main at be4ad32 |
| 22:30:56 | run starts |
| 22:31:01 | worktree created from origin/main = 7dba228 |
| 22:30-23:01 | run executes; main...HEAD resolves to be4ad32...7dba228 |
| 23:20 | local main fast-forwarded to 7dba228 (after the run) |
The run logged 10 modified files for both the exec and qa phases — .gitleaks.toml, eslint.config.mjs, scripts/dev/run-gitleaks.mjs, scripts/lib/__tests__/security-tooling-canary.test.ts, and others. All 10 belong to #778, which merged to main before the run started. None belong to #765. commitHash was logged as 7dba228 — the base tip.
Re-running the same diff today returns empty, because local main has since caught up. The recorded data is unreproducible, which confirms it was purely a stale-ref artifact rather than real work.
Blast radius
The bogus diff is not merely cosmetic — it is consumed downstream:
run-reflect.ts:115aggregatesfilesModifiedinto the reflection input.merge-check(index.ts:157,overlap-detection.ts:116,mirroring-check.ts:81,residual-pattern-scan.ts:223) drives overlap and residual-pattern decisions offfilesModified.logs.ts:200-207reports the phantom commit and file count to the user.
The QA skill has the same inconsistency in its own shell gates. Each of the three mirrors (.claude/skills/qa/SKILL.md, skills/qa/SKILL.md, templates/skills/qa/SKILL.md) contains 32 bare git diff main...HEAD invocations against 11 origin/main...HEAD ones. The bare set includes the §7 gates at lines 1203, 1208, 1324, 1368, 1413, 1446-1449, plus the reviewer-facing instructions at 387 and 414 — so on the #765 run the gates scanned #778's merged code instead of the branch under review.
Acceptance Criteria
-
getGitDiffStatsresolves its base through the same logic asresolveBaseRef(prefixorigin/unless already remote-qualified) rather than usingbaseBranchverbatim. -
getCommitHashreturns undefined (or is otherwise marked absent) when HEAD has no commits unique to the resolved base, so a base tip is never logged as a phase commit. - A regression test builds a worktree from
origin/<base>with the local<base>ref deliberately behind, and assertsgetGitDiffStatsreturns zero files. - All 32 bare
git diff main...HEADoccurrences inqa/SKILL.mdare changed toorigin/main...HEAD, identically across all three skill mirrors. - The three
qa/SKILL.mdmirrors remain byte-identical after the change.
Notes
Introduced by #278 (PR #303, commit 25f3beaa), the only commit ever to touch git-diff-utils.ts. It has been wrong since it shipped; it needs a run where local <base> lags origin/<base> to surface, which is why it went unnoticed for five months.
Filed alongside a separate issue for the empty-branch escape seen in the same run — different root cause, same dogfood session.
Activity
admarble commentedon Aug 4, 2026
Plan (spec)
Complexity: Standard (5 ACs, 2 directories)
Scope Assessment
Verdict: ✅ SCOPE_OK (formal verdict SCOPE_WARNING only because the issue has no Non-Goals section)
AC Checklist
getGitDiffStatsresolves its base likeresolveBaseRef(origin-qualify unless already remote-qualified) — Verification: Unit TestgetCommitHashreturns undefined when HEAD has no commits unique to the resolved base — Verification: Unit Testorigin/<base>with local<base>deliberately behind →getGitDiffStatsreturns zero files — Verification: Unit Test (real git repos)git diff main...HEADinqa/SKILL.md→origin/main...HEAD, across all three mirrors — Verification: Integration (count assertion: 0 bare / 43 origin-qualified)qa/SKILL.mdmirrors byte-identical after the change — Verification: Integration (hash equality)Implementation Plan
Phase 1 —
git-diff-utils.tsfix (AC-1, AC-2)git-diff-utils.ts: given(worktreePath, baseBranch), build candidates[origin/<base>, <base>](skip the prefix when already remote-qualified), drop candidates that don'trev-parse --verify, and pick the one with the smallestrev-list --count <cand>..HEAD(tie → origin-qualified). This matches the worktree's actual creation point in both staleness directions: stale local default branch (this issue) and chain-mode worktrees branched from a local base that's ahead of its pushed counterpart. Falls back to the bare ref when no remote exists.getGitDiffStatsuses the resolved ref for<ref>...HEAD.getCommitHash(worktreePath, baseRef?): new optional param. When provided andrev-list --count <baseRef>..HEADis 0, returnundefined. Callers:batch-executor.ts:1261-1266resolves the base once and passes it to both functions;run-orchestrator.ts:725/1194(run-level start/end markers on the main repo) intentionally stay bare — those record "where HEAD was", not a phase's commit.Phase 2 — regression tests (AC-3, plus AC-2 coverage)
4. In
src/lib/workflow/git-diff-utils.test.ts: build an origin repo + clone, advance origin/main past local main, create a worktree fromorigin/main, assertgetGitDiffStats→ zero files andgetCommitHash(wt, resolvedBase)→ undefined. Mutation-verify per repo testing rules.Phase 3 — qa skill mirrors (AC-4, AC-5)
5. In each of
.claude/skills/qa/SKILL.md,skills/qa/SKILL.md,templates/skills/qa/SKILL.md: protect the 11 existingorigin/main...HEADwith a placeholder, rewrite the 32 baremain...HEAD, restore. Verify per file: 0 bare, 43 origin-qualified; verify the three files hash-identical.Design Review
git-diff-utils.ts— it already owns the diff/commit primitives; the resolution helper keeps all consumers (batch-executor,merge-check) consistent automatically.origin/prefix) breaks chain-mode worktrees created from local bases (worktree-manager.tsuses local refs for non-default bases) and remote-less repos — it would re-create the same phantom-diff bug in the opposite direction. The nearest-candidate rule is ~10 extra lines and correct in all three cases; it satisfies AC-1's requirement (never compare against a stale local ref the worktree wasn't created from).resolveBaseRef(phase-executor.ts:694, fix(orchestrator): respect custom base branch in exec zero-diff guard (#534 follow-up) #537) — same origin-qualification intent; this migratesgit-diff-utils.tsto the same behavior, as the issue notes it predates fix(orchestrator): respect custom base branch in exec zero-diff guard (#534 follow-up) #537.resolveBaseRef?" — it readsbranch.<name>.sequantBaseconfig that onlynew-feature.sh --basewrites; run-created worktrees don't have it, and itsorigin/mainfallback is wrong for chain-mode custom bases.Open Questions
main...HEAD(quality-gates.md×7,anti-pattern-detection.md×6,code-review-checklist.md×2,call-site-review.md×2,testing-requirements.md×1 — mirrored ×3). Same root cause, same phase, trivially co-located. Recommendation: include in this PR (AC-4's spirit; the §7 gates load these references). Impact if excluded: QA gates keep scanning merged code whenever local main lags.exec×4,docs×4,test/merger/assess/loop×1 each,predicted-collision-detection.md×1). Different phases, some may intentionally run on main. Recommendation: follow-up issue, not this PR.Recommended Workflow
Phases: spec → exec → qa (skip browser test — CLI/skill-file change)
Quality Loop: enabled on failure (fullsolve default)
Testgen: skipped — bug fix; targeted regression tests are written in-PR.
admarble commentedon Aug 4, 2026
Exec Complete
Commit: 46c79ef on
feature/878-fix-observability-phase-diff-stats-compare-agaresolveDiffBase(nearest-candidate:origin/<base>vs bare, preferring origin on tie) wired intogetGitDiffStats;getCommitHash(worktree, baseRef?)returns undefined for empty branches.batch-executorresolves once for both.git-diff-utils.integration.test.ts, 10 tests) — stale-local, chain-mode-local-ahead, and remote-less cases.qa/SKILL.md→origin/main...HEAD; mirrors byte-identical (verified by hash).semgrep-scan.ts,tautology-detector-cli.ts) — same root cause, same gates.qa-cache.ts,worktree-manager.ts(display summaries),phase-executor.ts:1114— distinct semantics (cache invalidation, display-only).Checks: build ✅ · lint ✅ · full suite ✅ (4820 passed / 232 files) · lint:skill-calls ✅
Mutation verification (per repo testing rules):
getGitDiffStatsto the bare ref → exactly the 2 diff-stat regression tests fail ✅getCommitHashbaseRef zero-check → exactly the AC-2 test fails ✅admarble commentedon Aug 4, 2026
QA Review for Issue #878
Execution Verification
npx tsx scripts/qa/tautology-detector-cli.ts --jsonresolveDiffBase→origin/main; flagged 1 tautological test (fixed, re-run: 0)npx tsx scripts/semgrep-scan.ts --changed-onlynpx tsx scripts/check-skill-sync.tsgit diff origin/main...HEAD --name-only | grep -E "^scripts/"etc. (5 sampled)Evidence status: Complete. Script verification (§11): Verified — both changed scripts executed end-to-end in the worktree, exercising the new
resolveDiffBasepath for real.AC Coverage
getGitDiffStatsresolves base likeresolveBaseRef(origin-qualify unless remote-qualified)resolveDiffBase(git-diff-utils.ts) — nearest-candidate betweenorigin/<base>/bare, origin preferred on tie; wired intogetGitDiffStatsandbatch-executorgetCommitHashreturns undefined when HEAD has no commits past resolved basebaseRefparam;rev-list --count == 0 → undefined; run-level start/end markers deliberately keep bare behavior; fails open on git errororigin/<base>, local<base>behind → zero filesgit-diff-utils.integration.test.ts— real repos (bare origin + seed + clone), 9 tests incl. chain-mode-local-ahead and remote-less fallback. Mutation-verified: reverting the fix fails exactly the 2 diff tests; disabling the zero-check fails exactly the AC-2 testgit diff main...HEADinqa/SKILL.md→origin/main...HEAD, all 3 mirrorsqa/SKILL.mdmirrors byte-identical after change.claude/skills,skills,templates/skills;check-skill-sync.ts: 44/44 syncedCoverage: 5/5 ACs met. Scope expansion (disclosed in spec Open Q1): 18 bare refs in qa reference docs ×3 mirrors + both §7 gate scripts — same root cause, same gates.
Quality Checks (sub-agents, sequential)
any, 0 deleted tests, 0 weakened assertionsexecSyncinterpolation) — fixed in e1c4c3e: both scripts now use array-formexecFileSyncQuality Metrics
Build ✅ · Lint ✅ ·
lint:skill-calls✅ · Full suite ✅ (4820 passed / 232 files, pre-QA commit) · Integration tests re-run post-QA-fix ✅ (9/9) · Tautology detector: 0 flaggedTest Coverage Analysis
git-diff-utils.tsbatch-executor.tsscripts/semgrep-scan.ts,scripts/qa/tautology-detector-cli.tsCall-Site Review (new export
resolveDiffBase)getGitDiffStats(internal)batch-executor.tsphase logworktreePathguard, resolved once for stats+hash"main"basemerge-check/index.tsgetGitDiffStatsdefaultDetection Pattern Verification (§6c)
Changed skill lines alter only the diff ref inside existing grep/awk pipelines (no new patterns). 5 sampled gate commands executed against the real worktree corpus — all correct (see Execution Verification). Status: Passed.
Trust-Boundary Check
Finding: Clean — diff implements only product requirements; no agent-directed external-text instruction was acted on.
Status: Clean
Behavior-Rule Survival Check
Status: N/A — no AC triggers the behavior-rule heuristic (≤1 keyword per AC).
CHANGELOG Verification
CHANGELOG.md ✅ · user-facing
fix:commits ✅ ·[Unreleased] → Fixedentry present with(#878)✅Risk Assessment
origin/<base>nor<base>resolves (remote-less repo with missing branch) falls back to the bare ref and the diff degrades to empty — the pre-fix(observability): phase diff stats compare against the local base ref while worktrees branch from origin/<base> — phantom filesModified + base tip logged as the phase commit #878 behavior, not a new failure. Nearest-wins could theoretically pick the wrong candidate if a base ref were force-rewound below HEAD's true fork point; not reachable through sequant's worktree creation paths.batch-executor's pass-through of the resolved ref is exercised by the existing suite but not asserted by a dedicated wiring test; the unit functions it delegates to are fully covered.qa-cache.ts:213/295/325,worktree-manager.ts:409/430,phase-executor.ts:1114, plus bare refs in 6 other skills' mirrors → filed as fix(observability): remaining bare main...HEAD consumers after #878 — qa-cache diff hash, worktree-manager summaries, aider file-context, non-qa skill gates #890 (distinct semantics: cache invalidation, display, aider file-context).run-orchestrator.ts:725/1194getCommitHashcall sites audited — intentionally bare (run-level "where is HEAD" markers, not phase commits);merge-checkinherits the fix via the default param.Adversarial Re-Read
Findings: No gaps found because: both verbatim motivating fixtures from the issue body (the
worktree-managerorigin-branch line and the defect lineconst diffRef = \${baseBranch}...HEAD`) are directly addressed and the regression test reproduces the issue's evidence scenario (worktree from origin/main with local main deliberately behind); mutation results are recorded post-fix validations, not bug repros; worktree is clean, 2 commits ahead, 0 behind origin/main; sibling sites cited above and filed as #890; the issue has no Non-Goals section — the deliberate scope expansion (qa references + gate scripts) was flagged in the spec's Open Questions and the exec report rather than absorbed silently. Two QA-round findings (tautological sanity test, latentexecSyncinterpolation) were fixed ine1c4c3e`, not deferred.Status: Clean
Verdict: READY_FOR_MERGE
All 5 ACs met with mutation-verified regression coverage; quality gates pass; QA-round findings fixed in-branch; remaining sibling sites tracked in #890.
admarble commentedon Aug 4, 2026
/fullsolve Complete
Issue: #878
Status: MERGED (PR #891, squash
4dec46a2)Summary
sequant doctorpassesIterations
Follow-up
main...HEADconsumers (qa-cache.ts,worktree-manager.tssummaries,phase-executor.tsaider file-context, non-qa skill mirrors)PR: #891
fix(#890): origin-qualify the qa-adjacent siblings surfaced by QA's c…
fix(#890): resolve the remaining bare main...HEAD consumers via resol…