Skip to content

fix(ledger): repair the branch review ledger and close the loop that corrupted it - #1310

Merged
BigSimmo merged 7 commits into
mainfrom
claude/branch-review-ledger-fixes-42575f
Jul 28, 2026
Merged

fix(ledger): repair the branch review ledger and close the loop that corrupted it#1310
BigSimmo merged 7 commits into
mainfrom
claude/branch-review-ledger-fixes-42575f

Conversation

@BigSimmo

Copy link
Copy Markdown
Owner

Why

docs/branch-review-ledger.md exists to stop repeat branch/PR reviews. It had drifted far enough that its own throttle no longer worked, and the guard was too weak to notice — every defect below landed CI-green.

What was wrong

Found across the ledger's 1113 records:

  • 146 mojibake lines from an append written through a non-UTF-8 shell — em/en dashes, arrows and ellipses became ??? and U+FFFD.
  • 46 duplicate records. The exact-duplicate guard missed them precisely because the mojibake made the corrupted twin differ from the clean original.
  • 21 rows that were not six cells — unescaped prose pipes (up to 12 cells) or a merged Scope+Outcome cell (5 cells). Every consumer reads cells by index.
  • 4 records written as a ## <date> heading + bullet list inside the table, which splits the table and hides the record from every row parser.
  • 137 HEADs recorded as see PR head, pending pushed head, or 8-character abbreviations. No git rev-parse lookup can match those, so the throttle silently never fired and branches were re-reviewed.

Tooling gaps behind it: sweep-branch-ledger.mjs split rows on a raw | (an escaped prose pipe shifted every later column) and compared HEADs by exact string; docs/branch-cleanup-guide.md prescribed a Select-String regex on the full SHA that could never match an abbreviated row.

What changed

Repair. 140 corrupted lines restored byte-exact from git history rather than guessed — an arrow and an en dash are not interchangeable in these records. 6 residual separators repaired, the 4 block records converted to rows, exact duplicates dropped, all 1067 rows normalised to six cells. No record's content or verdict was changed; no record removed except exact duplicates, which this file's contract has always allowed.

Root cause. Rows were hand-written. scripts/branch-review-ledger.mjs adds:

  • npm run ledger:lookup -- <ref> [--head <sha>] [--scope <text>] — resolves the HEAD, matches abbreviated SHAs and origin/x / `x` / PR #N / x spellings, prints ALREADY REVIEWED or NOT REVIEWED at this HEAD.
  • npm run ledger:append -- --ref --head --scope --outcome --checks — stamps the date, resolves the HEAD to a full SHA, escapes pipes, writes UTF-8, refuses exact and ref/HEAD/scope duplicates.

Guard.check-branch-review-ledger.mjs now also fails on mojibake, wrong cell width, heading-style records, impossible dates, and blank lines splitting the table. Records dated 2026-07-29 or later must additionally carry a resolvable HEAD and must not repeat a ref/HEAD/scope. The cutoff is the day after the repair, so no historical record is retroactively invalidated.

Docs.AGENTS.md, docs/codex-review-protocol.md, docs/branch-cleanup-guide.md, docs/README.md and 12 skill/agent files now point at the two commands instead of "search this file".

Risk

The repair rewrites 226 historical lines mid-file. Open PRs that merge origin/main afterwards take the repaired lines by ordinary 3-way merge; only a same-hunk conflict would let merge=union keep both copies. Tracked as #088 in docs/outstanding-issues.md — run npm run check:branch-review-ledger on the first few post-repair merges.

This branch already exercised it: merging origin/main (25 commits, ~30 new ledger records) auto-merged the ledger with no conflict. The merge did surface two blank lines inside the record table that main already carried — they split it into separate markdown tables, the old guard could not see them, and the new one blocked the merge until both were closed. Whitespace only; no record touched.

No retrieval, ranking, clinical, privacy, auth, or schema surface is touched.

Checks

npm run verify:pr-local PASS on the merged tree: runtime, installed-lock parity, format:changed, lint, typecheck, test (405 files / 4126 passed, 3 skipped), build (compiled in 3.7min), check:rag:fixtures.

npm run check:branch-review-ledger PASS — 1092 records, six cells each, union merge active, no conflict markers, mojibake, heading records, or duplicates. Twelve new unit tests in tests/repo-hygiene.test.ts.

No provider-backed check was run (no OpenAI, Supabase, or hosted-CI call).

🤖 Generated with Claude Code

BigSimmoand others added 4 commits July 28, 2026 11:10
…atch
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…corrupted it
The review ledger exists to stop repeat branch/PR reviews, but it had drifted
far enough that its own throttle no longer worked, and the guard was too weak
to notice.
Found in docs/branch-review-ledger.md (1113 records):
- 146 mojibake lines from an append written through a non-UTF-8 shell, which
turned em/en dashes, arrows and ellipses into "???" and U+FFFD.
- 46 duplicate records. The exact-duplicate guard missed them precisely because
the mojibake made the corrupted twin differ from the clean original.
- 21 rows that were not six cells: unescaped prose pipes (up to 12 cells) or a
merged Scope+Outcome cell (5 cells). Every consumer reads cells by index.
- 4 records written as a "## <date>" heading plus bullet list inside the table,
which splits the table and hides the record from every row parser.
- 137 HEADs recorded as "see PR head", "pending pushed head", or 8-character
abbreviations. No git rev-parse lookup can match those, so the throttle
silently never fired and branches were re-reviewed.
Repair: 140 corrupted lines restored byte-exact from git history rather than
guessed (an arrow and an en dash are not interchangeable in these records), 6
residual separators repaired, the 4 block records converted to rows, exact
duplicates dropped, all 1067 rows normalised to six cells. No record's content
or verdict was changed.
Root cause: rows were hand-written. scripts/branch-review-ledger.mjs adds
`npm run ledger:lookup` (resolves HEAD, matches abbreviated SHAs and
origin/x, `x`, "PR #N / x" spellings, prints an explicit verdict) and
`npm run ledger:append` (stamps the date, resolves the HEAD to a full SHA,
escapes pipes, writes UTF-8, refuses duplicates).
check-branch-review-ledger.mjs now also fails on mojibake, wrong cell width,
heading-style records, impossible dates, and blank lines splitting the table;
records dated 2026-07-29 or later must additionally carry a resolvable HEAD and
must not repeat a ref/HEAD/scope. The cutoff is the day after the repair so no
historical record is retroactively invalidated.
sweep-branch-ledger.mjs split rows on raw "|", so an escaped prose pipe shifted
every later column, and it compared HEADs by exact string, so an abbreviated
record never matched. Both fixed.
AGENTS.md, docs/codex-review-protocol.md, docs/branch-cleanup-guide.md,
docs/README.md and 12 skill/agent files now point at the two commands instead
of "search this file" and a Select-String regex that could not match.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Also corrects the #85 knip row: the finding was first seen in a worktree with
no node_modules of its own, which is the known condition under which knip
misreports, so it must be re-run after npm ci before anyone acts on it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…ledger-fixes-42575f
# Conflicts:
#	docs/outstanding-issues.md
@supabase

supabaseBot commented Jul 28, 2026

Copy link
Copy Markdown

This pull request has been ignored for the connected project sjrfecxgysukkwxsowpy because there are no changes detected in supabase directory. You can change this behaviour in Project Integrations Settings ↗︎.


Preview Branches by Supabase.
Learn more about Supabase Branching ↗︎.

@coderabbitai

coderabbitaiBot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in:18 minutes

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 08c8a434-3bd6-4684-8b43-c7fe5d7df8cd

📥 Commits

Reviewing files that changed from the base of the PR and between c9bec8f and 679aab6.

📒 Files selected for processing (23)
  • .agents/skills/review/SKILL.md
  • .claude/agents/clinical-governance-reviewer.md
  • .claude/agents/frontend-ui-reviewer.md
  • .claude/agents/ingestion-worker-reviewer.md
  • .claude/agents/pr-ci-fixer.md
  • .claude/agents/rag-retrieval-reviewer.md
  • .claude/agents/repo-auditor.md
  • .claude/agents/supabase-schema-guardian.md
  • .claude/skills/handoff/SKILL.md
  • .claude/skills/prlanded/SKILL.md
  • .claude/skills/run-pr/SKILL.md
  • .cursor/agents/pr-babysit.md
  • AGENTS.md
  • docs/README.md
  • docs/branch-cleanup-guide.md
  • docs/branch-review-ledger.md
  • docs/codex-review-protocol.md
  • docs/outstanding-issues.md
  • package.json
  • scripts/branch-review-ledger.mjs
  • scripts/check-branch-review-ledger.mjs
  • scripts/sweep-branch-ledger.mjs
  • tests/repo-hygiene.test.ts

Comment @coderabbitai help to get the list of available commands.

@BigSimmo

Copy link
Copy Markdown
OwnerAuthor

@cursoragent Inspect the PR and repository state, identify the root cause of every failing CI check, unresolved review comment, merge conflict, and related defect. Apply the smallest robust fix using existing project patterns and best practices, without unrelated changes. Run all relevant lint, type-check, test, build, and CI-equivalent commands, fix any issues found, then resolve only the review comments that are fully addressed. Summarise the root causes, changes made, validation results, and any remaining blockers. Also run Bugbot if not already done on this PR yet.

@cursor

cursorBot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

PR #1310 is mergeable with required CI green on the fix tip; all 3 Codex review threads are fixed and resolved.

Root causes

  • No failing required CI on the inspected tip — earlier CI cancel was concurrency from a newer push, not a product failure.
  • 3 Codex P2s in scripts/branch-review-ledger.mjs:
    1. Scope used substring match → branch-cleanup-deletion-pending could skip cleanup
    2. --supersede could append a same ref/HEAD/scope the guard rejects
    3. 40-char hex skipped git rev-parse → fake SHAs accepted
  • Hosted Bugbot never started: bugbot run / cursor review from cursor[bot] are ignored

Changes (7c870c13)

  • Exact scope match; --supersede mints distinct scope; full SHAs verified via git rev-parse
  • Also: ignore n/a-embedded hex and parenthetical prose as ref/HEAD tokens
  • Tests + cleanup-guide note; ledger closeout row at 679aab6b

Validation

  • Local: check:branch-review-ledger PASS; repo-hygiene 25/25; lint; typecheck; full vitest 4133 passed
  • Hosted on 7c870c13: PR required / Static / Unit / Build / Safety SUCCESS
  • Threads: 0 unresolved

Remaining blockers

  • Approving review still needed (mergeStateStatus: BLOCKED with no failing checks)
  • Hosted Bugbot: comment bugbot run or cursor review as a human on the PR (bot comments don’t trigger it). Local Bugbot-equivalent review already done; defects fixed.
Open in WebOpen in Cursor

@cursor

cursorBot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

bugbot run

@chatgpt-codex-connectorchatgpt-codex-connectorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit:3e405e8db9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment threadscripts/branch-review-ledger.mjs Outdated
Comment threadscripts/branch-review-ledger.mjs Outdated
Comment threadscripts/branch-review-ledger.mjs Outdated
@BigSimmo

Copy link
Copy Markdown
OwnerAuthor

@codex resolve actionable Codex review findings for this pull request and current head using the repository instructions. This is the pull request's single automatic repair pass: do not perform a fresh review, create new standalone findings, or request another review. Work only the existing unresolved Codex threads on the current head. Always fix P0 and P1 findings. For P2 and lower findings, fix only clear, scoped, low-risk issues; otherwise disposition them with a concise reason. After fixing or dispositioning a thread, reply in that thread with as the first line, followed by a concise summary; that marker authorizes the workflow to close that exact thread. If human input or new authorization is required, do not use the marker and leave the thread open with the blocker. Finish only after every actionable thread is fixed or dispositioned and closed, or explicitly left open for a human decision. Do not update the branch from main, address unrelated reviews, broaden scope, or create more than one scoped fix commit. Do not use external APIs, paid services, credentials, dependency changes, or broad refactors unless explicitly authorized. Add targeted tests where behavior changes and run the narrowest relevant validation.

@chatgpt-codex-connector

Copy link
Copy Markdown

Summary

Testing

  • npm run check:branch-review-ledger — passed; reported 1,105 records, six cells each, active union merge handling, and no conflicts, mojibake, heading records, or duplicates.
  • git diff --check
  • node scripts/branch-review-ledger.mjs --self-test
  • node scripts/check-branch-review-ledger.mjs --self-test
  • ⚠️npm test -- tests/repo-hygiene.test.ts — could not run because this checkout is missing node_modules/vitest/vitest.mjs; no dependency installation was performed because this repair pass prohibited dependency changes.

View task →

…pend
Codex P2s on PR #1310: lookup used substring scope matching (so
branch-cleanup-deletion-pending skipped cleanup), append --supersede
could write a ref/HEAD/scope the guard rejects, and 40-char hex was
accepted without git rev-parse. Also stop treating parenthetical prose
or n/a-embedded hex as ref/HEAD matches.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@cursor

cursorBot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

cursor review

Append-only review record for the Codex P2 fix pass and green hosted
PR-required aggregate.
Co-authored-by: BigSimmo <BigSimmo@users.noreply.github.com>
@BigSimmo
BigSimmo enabled auto-merge (squash) July 28, 2026 05:38
@BigSimmo
BigSimmo merged commit 422e43d into mainJul 28, 2026
20 checks passed
@BigSimmo
BigSimmo deleted the claude/branch-review-ledger-fixes-42575f branch July 28, 2026 05:43
Sign up for freeto 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.

2 participants

@BigSimmo@cursoragent