Skip to content

fix(rules,dg,web): ref forced back to an earlier tip, and PR bases that do not exist (D-600, D-501) - #65

Merged
PastaPastaPasta merged 4 commits into
masterfrom
fix/ref-rule-and-pr-base
Sep 27, 2026
Merged

PastaPastaPasta merged 4 commits into
masterfrom
fix/ref-rule-and-pr-base

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Owner

Fixes two S1 defects from QA wave 1: D-600 and D-501.

D-600: force-pushing back to an earlier tip made the ref read as deleted

A push sequence of A → B → git push --force A made the ref resolve as unborn in every client. The Mirror Action wiped a mirror's default branch this way (evidence: integrations/T-ABA, T-IMP/44-45).

Cause. resolve_ref let a prevOid match supersede an update regardless of the clock, on the assumption that tip chains are acyclic. But a prevOid names a commit, not a document, and a ref can hold the same commit twice. The old A → B update's prevOid (A) equals the newest tip, so each of the two updates superseded the other. That left zero heads, which reads as Unborn.

Fix. The fix is in the shared rules, in Rust (forge-core::rules) and TypeScript (forge-web/lib/rules/resolveRef.ts).

  • Updates are folded in consensus-clock order. $createdAt is block time and is required on both ref types.
  • The prevOid chain orders updates only inside one block (causal_order / causalOrder): Kahn's sort by $id, with a chain cycle broken at its smallest-$id member.
  • Supersession only looks forward, so a ref whose newest update names a commit is never unborn.

Vectors. New resolve_ref__ vectors:

  • ref_force_back_to_earlier_tip
  • ref_force_back_then_forward_again (A→B→A→B)
  • ref_force_back_to_first_of_three
  • ref_force_back_without_prev
  • ref_force_back_then_repush_same_tip (the mirror's real history)
  • ref_deleted_then_recreated_at_earlier_tip
  • ref_same_createdat_mutual_chain_uses_id
  • ref_same_createdat_chain_breaks_tie
  • ref_same_createdat_cycle_placed_before_its_downstream

There is also an exhaustive property test: a ref is unborn exactly when its causally newest update is a deletion, and the result does not depend on input order. It fails on the old code.

D-501: a PR against a nonexistent base could be "merged" by creating that base

  • Rule. A new shared rule, pr_base_tips / prBaseTips: a base that had no valid tip when the PR was opened has no tips, so no merge into it ever counts. Readers use it: forge-core patch_view and forge-web readPull. Vectors pr_base_tips__* and fold_pr_v2__merge_into_base_{created_after_open_inert,present_at_open_counts}. This applies to merge events already on chain: a PR that read as merged only because its merge created its base now reads open.
  • dg pr create refuses a --base that is not a live branch of the target (E102, nothing written). That covers a branch that was never pushed, a typo, and a deleted branch.
  • dg pr merge refuses a base that was missing when the PR was opened, and refuses to push to a deleted base, which would re-create it. --event-only can still record a merge into a base deleted since.
  • Web, new-PR page. A base that is not a branch (from ?base= or a kept draft) is blocked with the reason. The same goes for a repo with no branches.
  • Web, C2 browser merge (feat(web): merge pull requests in the browser (fast-forward and disjoint merges) #61). The merge panel built on pullBase's tip, which falls back to the PR's historical tip when the base is deleted. So the browser merge could re-create a deleted base, or merge into a base that was missing when the PR was opened. mergeBaseTip now passes only the live branch tip, and '' (refused by mergeRefProblem) in both cases.
  • Docs. docs/contracts/forge-v2.md §6 documents the clock-order fold and the base-at-open rule.

Tests

  • Failing first: the new vectors and the property test fail on master in both ports (on master, 7 of the first 8 resolve_ref vectors fail in TS and the Rust vector run fails).
  • CLI e2e scenario 17, 17-ref-force-back-and-pr-base.sh, run live on moutai as a freshly minted identity:
    • The candidate build fails at "force back to A" with ref did not converge to pushed tip.
    • This branch passes all 12 checks: A→B→force A→B shows each pushed tip in ls-remote and a fresh clone; pr create refuses a missing or deleted base; pr merge refuses and leaves the deleted base unrecreated.
  • Playwright pr-base.spec.ts (read-only, moutai fixture): fails against the old build (the button stays live, no alert) and passes on this branch.
  • Unit: mergeBaseTip cases.
  • The full Rust suites for forge-core, dg, forge-import and forge-relay pass, as do all web vitest tests and clippy -D warnings.
  • Live D-501 before/after: with the old dg, pr create --base d501/before-does-not-exist was accepted, and pr merge pushed refs/heads/d501/before-does-not-exist and marked the PR merged.

Evidence: dash-forge-qa/evidence/impl/fix-ref-rule-and-pr-base/.

Notes

  • The code-review-validator approved with suggestions. Its valid findings are fixed here: cycle breaking, the provisional-tip definition in tipOidOf, stale comments, and a per-iteration array copy.
  • Deferred: data-contracts.md is the historical v1 design record and was left unchanged. The fold uses the patch's original base, so a retargeted PR still merges against it; that was already the case, and it is now documented.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Sep 27, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 33 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: 9d88a36e-9559-4bb8-9f0c-798c01a4e1fe

📥 Commits

Reviewing files that changed from the base of the PR and between c47a954 and 5b339f9.

📒 Files selected for processing (36)
  • crates/dg/src/pr.rs
  • crates/forge-core/src/collab/v2.rs
  • crates/forge-core/src/refs.rs
  • crates/forge-core/src/rules.rs
  • docs/contracts/forge-v2.md
  • e2e/README.md
  • e2e/cli/run.sh
  • e2e/cli/scenarios/17-ref-force-back-and-pr-base.sh
  • forge-contracts/vectors/fold_pr_v2__merge_into_base_created_after_open_inert.json
  • forge-contracts/vectors/fold_pr_v2__merge_into_base_present_at_open_counts.json
  • forge-contracts/vectors/pr_base_tips__base_created_in_the_opening_block_counts.json
  • forge-contracts/vectors/pr_base_tips__base_deleted_after_open_keeps_history.json
  • forge-contracts/vectors/pr_base_tips__base_deleted_at_open_has_no_tips.json
  • forge-contracts/vectors/pr_base_tips__base_missing_at_open_has_no_tips.json
  • forge-contracts/vectors/pr_base_tips__base_present_at_open_keeps_history.json
  • forge-contracts/vectors/resolve_ref__ref_deleted_then_recreated_at_earlier_tip.json
  • forge-contracts/vectors/resolve_ref__ref_force_back_then_forward_again.json
  • forge-contracts/vectors/resolve_ref__ref_force_back_then_repush_same_tip.json
  • forge-contracts/vectors/resolve_ref__ref_force_back_to_earlier_tip.json
  • forge-contracts/vectors/resolve_ref__ref_force_back_to_first_of_three.json
  • forge-contracts/vectors/resolve_ref__ref_force_back_without_prev.json
  • forge-contracts/vectors/resolve_ref__ref_same_createdat_chain_breaks_tie.json
  • forge-contracts/vectors/resolve_ref__ref_same_createdat_cycle_placed_before_its_downstream.json
  • forge-contracts/vectors/resolve_ref__ref_same_createdat_mutual_chain_uses_id.json
  • forge-web/components/repo/new-pull-content.tsx
  • forge-web/components/repo/pull-merge.tsx
  • forge-web/e2e/pr-base.spec.ts
  • forge-web/lib/repo/issues.test.ts
  • forge-web/lib/repo/issues.ts
  • forge-web/lib/repo/refs.ts
  • forge-web/lib/rules/conformance.test.ts
  • forge-web/lib/rules/index.ts
  • forge-web/lib/rules/resolveRef.ts
  • forge-web/lib/view/pull-actions.test.ts
  • forge-web/lib/view/pull-actions.ts
  • forge-web/lib/view/refs.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 and others added 4 commits September 27, 2026 06:15
…en no tips

D-600: a prevOid names a commit, not a document, so a ref that revisits a tip (A -> B -> force A) let the stale A -> B update supersede the newest one while the newest superseded it back, and the ref read as deleted in every client. resolve_ref now folds in the consensus clock order, with the prevOid chain ordering only updates inside one block, and supersession only looks forward, so a non-null newest update is always a head. Rust and TS ports, eight resolve_ref vectors and an exhaustive property test.

D-501: pr_base_tips (Rust) / prBaseTips (TS) give a base that was no branch when the PR was opened no tips, so a merge into a branch created later never counts. Vectors pr_base_tips__* and fold_pr_v2__merge_into_base_*.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…e it on merge

D-501: dg pr create --base naming a branch the target does not have (never pushed, a typo, or deleted) is refused with E102 before anything is written, and the web's new-PR page blocks it with the reason. dg pr merge refuses a base that was no branch when the PR was opened, and refuses to push to a deleted base (it would re-create it). Readers (forge-core patch_view, forge-web readPull) fold the base through pr_base_tips, so a PR 'merged' by creating its base reads open.

CLI e2e scenario 16 (A -> B -> force A -> B, and the base checks) and the Playwright spec pr-base.spec.ts. forge-v2.md documents the clock-order ref fold (D-600) and the base-at-open rule.

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

The e2e scenario ran ls-remote inside a command substitution, so a failure or flake only left the subshell and read as a wrong tip; it now runs at the top level. Renumbered to 17 (16 is taken by the private-repo branch). causal_order uses chunk_by and drops a redundant guard (both ports); read_merge_base takes the PR's open time and calls pr_base_tips directly; the conformance harnesses share one merge/pr base-tips arm; resolve_head returns a PrHead struct.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…erge needs a live base

Review follow-up: when every same-block update waits on a chain cycle, causal_order now picks the smallest-id update that lies on the cycle, not one merely downstream of it (which then sorted before its own predecessor). Both ports, vector resolve_ref__ref_same_createdat_cycle_placed_before_its_downstream. tipOidOf takes heads[0] so the provisional tip has one definition.

D-501 against C2's browser merge: the merge panel built on pullBase's tip, which falls back to the PR's historical tip for a deleted base, so a browser merge could push to and re-create a deleted base, or merge into a base missing when the PR was opened. mergeBaseTip gives the live branch tip only, and '' (refused by mergeRefProblem) in both cases.

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