Skip to content

fix(rules,web): break same-block ref cycles upstream-first; refuse browser merge of retargeted PRs (D-600, D-501) - #73

Merged
PastaPastaPasta merged 4 commits into
masterfrom
fix/ref-cycle-and-retarget-merge
Sep 27, 2026
Merged

PastaPastaPasta merged 4 commits into
masterfrom
fix/ref-cycle-and-retarget-merge

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Owner

This fixes two bugs that a follow-up review found in #65's commits that nobody had reviewed. Both relate to D-600 and D-501.

1. A same-block chain cycle could place an update before its own predecessor (D-600 rule)

Within one block, resolve_ref orders updates by the prevOid chain: an update that recorded another's tip comes after it. When every remaining update waits on a cycle, one has to be placed anyway. #65 picked the smallest-$id update that lies on any cycle. If that cycle itself waited on another cycle, this could place an update before one it builds on.

Five updates in one block show it:

id prev → new
a A → C
b C → A
c B → A
d D → B
e B → D

These resolved to Diverged [e(D), c(A)] instead of Diverged [e(D), a(C)].

Fix. The change is in both ports: forge-core::rules::cycle_to_break and forge-web cycleToBreak.

  • Compute the strongly connected components of builds_on among the updates not yet placed, with an iterative Tarjan.
  • Place the smallest-$id update all of whose unplaced predecessors build back on it, so it waits on nothing outside its own cycle.
  • An update is then never placed before one it builds on unless that one builds back on it.
  • docs/contracts/forge-v2.md §6 and both doc comments describe the rule.

Tests.

  • New vector resolve_ref__ref_same_createdat_cycle_waits_on_upstream_cycle. It fails on master in both ports.
  • An exhaustive property test over every one-block history of five updates on four tips (12⁵ histories), in Rust and TypeScript. It asserts the invariant above. The Rust test fails on master's rule.

Reading histories already on chain. This changes how a ref is resolved when one block holds two chained push cycles, one waiting on the other. That needs several same-block pushes going back and forth, so real data is very unlikely to have it. It is listed in the release notes (BACKLOG).

2. The browser merge could move a retargeted PR's new base, for a merge that never counts (D-501 follow-up)

The fold checks a merge against the base the PR was opened with. For a retargeted PR, mergeBaseTip returned the new base's tip, so the browser merge moved that branch and posted a merge event the fold ignores.

Fix.

  • mergeBaseTip returns '' for a retargeted PR.
  • mergeRefProblem (both the panel and the runner) refuses it. openedBaseRefName is now required in the runner, so no caller can skip the check.
  • dg's refusal gave the same unworkable advice ("merge by hand, then dg pr merge --event-only"). That could not work: dg refuses a retargeted PR before --event-only, and the merge would not count anyway. Both dg and the web now say to open a new PR against the new base.
  • The pull-actions and runner tests fail on master and pass here.

Verification

  • CLI e2e scenario 17 re-run live on moutai with this build: 12 of 12 checks pass.
  • Rust tests for forge-core and dg pass, as do clippy -D warnings, all web vitest tests, tsc and lint.
  • The code-review-validator approved. Its findings are fixed here: the retarget advice, and requiring openedBaseRefName. It also suggested the TS property test, which is added.
  • read_private_merge_base is left as it is. feat(private): seal issues, pull requests, comments and reviews in the CLI #68 uses it and moves it to the D-501 rule on the private path.

🤖 Generated with Claude Code

PastaPastaPasta and others added 4 commits September 27, 2026 10:37
…other cycle

The fallback took the smallest-id update on any cycle, so a cycle downstream of another cycle could be broken first, placing an update before its own predecessor (five same-block updates resolved to Diverged [e, c] instead of [e, a]). cycle_to_break / cycleToBreak now take the smallest-id update all of whose unplaced predecessors build back on it (Tarjan SCCs, iterative). Vector resolve_ref__ref_same_createdat_cycle_waits_on_upstream_cycle and an exhaustive property test over one-block histories (fails on the previous rule).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
The fold checks a merge against the base the PR was opened with, so merging a retargeted PR moved the new base and recorded a merge that never counts. mergeBaseTip returns no tip for it, and mergeRefProblem (panel and runner) gives dg's guidance: merge by hand, then dg pr merge --event-only --merge-oid.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… rule in TS

Review follow-up: the retargeted-PR advice (merge by hand, then dg pr merge --event-only) could not work: dg refuses a retargeted PR before --event-only, and a merge into the new base never counts against the base the PR was opened with. Both dg and the web now say to open a new PR against the new base. The runner's openedBaseRefName is required, so no caller can skip the check. A TS port of the exhaustive causal-order property test.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
openedBaseRefName is now required on the merge runner's pull; #67's test built one without it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@coderabbitai

coderabbitai Bot commented Sep 27, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 26 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: 7df8b6d0-1d45-441a-abfc-2d65c3daab3a

📥 Commits

Reviewing files that changed from the base of the PR and between b82be64 and fd91db9.

📒 Files selected for processing (12)
  • crates/dg/src/pr.rs
  • crates/forge-core/src/rules.rs
  • docs/contracts/forge-v2.md
  • forge-contracts/vectors/resolve_ref__ref_same_createdat_cycle_waits_on_upstream_cycle.json
  • forge-web/components/repo/merge-panel.tsx
  • forge-web/lib/merge/runner.test.ts
  • forge-web/lib/merge/runner.ts
  • forge-web/lib/rules/resolveRef.test.ts
  • forge-web/lib/rules/resolveRef.ts
  • forge-web/lib/storage/storage.test.ts
  • forge-web/lib/view/pull-actions.test.ts
  • forge-web/lib/view/pull-actions.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@PastaPastaPasta
PastaPastaPasta merged commit 26866dc into master Sep 27, 2026
22 checks passed
PastaPastaPasta added a commit that referenced this pull request Sep 27, 2026
…al private edits

Private-repo edits of issues and comments now re-seal through #67's sealEdit and replace only enc/epoch (no plaintext ever leaves); without a seal context a private edit is still refused. The issue page and list use #68's privateComposeBlock / composeCost / SealedLimit. dg issue list reads private issues through readable_all (decrypted for members); the CLI edit still refuses private repos (no sealed CLI edit yet).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
PastaPastaPasta added a commit that referenced this pull request Sep 27, 2026
…chedDocument, open_for_write)

Rebased onto master after #67, #68, #72, #73 and #74: the settings sections use the AA text shades the contrast test requires; the test fixture fills FetchedDocument.updated_at_block_height; the archive check opens through Session::open_for_write so dg pr create stays within the line limit.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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.

1 participant