Skip to content

feat: FORGE_RULES_V2 client rules and the event/authorEvent contract split - #9

Merged
PastaPastaPasta merged 9 commits into
masterfrom
feat/forge-rules-v2
Sep 25, 2026
Merged

PastaPastaPasta merged 9 commits into
masterfrom
feat/forge-rules-v2

Conversation

@PastaPastaPasta

Copy link
Copy Markdown
Owner

PR "B" of the forge-v2 client migration: the pure FORGE_RULES_V2 client rules in Rust and TypeScript, their conformance vectors, and one contract change. The rules contain no SDK or network code.

Contract change: event split into event + authorEvent

event in forge-collab used to be gated by ownerRefersTo anyOf[maintainer, writer, issue-author, patch-author]. A reader could not tell which operand admitted an event: a maintainer who authored a PR and was later revoked left merges that the author path might have admitted, and the author path does not allow merges.

  • event: ownerRefersTo anyOf[maintainer lookup, writer lookup] only. It still carries every kind.
  • new authorEvent: ownerRefersTo anyOf[issue author lookup + propertyAgreement, patch author lookup + propertyAgreement] (the author operands event had before). kind is an integer 1..2 (close, reopen), so consensus refuses any other kind. The type is immutable and non-deletable, with indexes target (targetId, $createdAt) and feed (repoId, $createdAt).

Why a new registration, not an update. tools/contract-validate gains --previous <registered schema>, which runs rs-dpp's validate_update under protocol 14. It refuses the split, because removing ownerRefersTo operands is an incompatible change. It also refuses adding an index to an existing type. So forge-collab was re-registered on devnet moutai:

current forge-collab CbsaT6oxuoESYhWuoJuPW9QikvAP7RS2x8NGQAYiwsMq (nonce 4), enrolled in group 23iVLZABbVQ5a4heSa6GLVbVqSWr74JTSESSMTEYNd6o
cost 0.555523 DASH (55,552,297,710 credits); transition 12,149 B (59.3% of 20,480); 11 types / 23 indexes
superseded 9fCcSGF3UmajGCNHuuDGz2ou3Gm3EXhrwB3SRS9ocm4Y (the four-operand event) and 6tm5ehZGoNSwenkCZkXjUm97Vt2bdXfFFsfh9KZ5N43W (the split, before review added the authorEvent feed index; 0.545473 DASH)
forge-core unchanged, GdZYaEntYPiW9dvUGCHyeqN7H7qEocbSkuj81n341i3L

deploy-v2.mjs gains three things:

  • --only collab: register forge-collab alone, against the recorded forge-core and group.
  • --force-new: supersede the recorded forge-collab with a new id.
  • schemaHash on every record: sha256 of the substituted schema, backfilled on the existing records.

--force-new supersedes only a registered contract whose hash differs from the current schema. Rerunning the command after success or after a crash therefore registers nothing, and I checked this on moutai. A rerun warns when a recorded contract was registered from a different schema. negative.sh adds four authorEvent mutations, and all 21 are refused. docs/contracts/forge-v2.md §2, §3, §7 and §8 are updated.

FORGE_RULES_V2 (crates/forge-core/src/rules/v2.rs, forge-web/lib/rules/v2.ts)

RoleOracle::{role_at(&self, identity, at) -> Option<Role>, member_at(..) -> bool, current_role(identity) -> Option<Role>}
fold_issue_state_v2(events: &[Event], author_events: &[Event], target_author: &str) -> IssueState
fold_pr_state_v2(events, author_events, target_author, base_tip: Option<&str>, is_ancestor: impl Fn(&str,&str)->bool) -> PrState
number_ceiling(count: u64) -> u64
allocate_number(count: u64, taken_numbers_desc: &[u32]) -> Option<u32>
order_pack_copies(copies: &[PackCopy]) -> Vec<&PackCopy>
select_pack_copy(copies: &[PackCopy]) -> Option<&PackCopy>
pack_read_order(copies: &[PackCopy]) -> Vec<PackPick>
count_approvals(reviews: &[Review], oracle: &RoleOracle, head_oid: &str) -> Approvals
is_well_formed(doc: &ContentDoc, visibility: Visibility) -> bool
is_valid_repo_name(name: &str) -> bool / normalize_repo_name(input: &str) -> Option<String>

The TypeScript names are the same in camelCase.

  • Fold. Every event applies, because its existence proves a member wrote it and a later revocation does not undo that. An authorEvent applies only if it is a close or reopen by the target's author. Both types fold as one log in v1's ($createdAt, $id) order with v1's per-kind effects. A merge applies only if its oid is reachable from the base tip, and a merged PR cannot be reopened.
  • Numbering. ceiling = min(2n + 100, 2³² − 1); base = the largest taken number ≤ ceiling (or 0); claim the first free number above base. The caller's ascending query must be paged to the end of the contiguous run. The exact semantics are in forge-v2.md §6.
  • Pack copies. Copies are tried current maintainers first, then writers, then others, each group by createdAt then id; the first verified copy is read. A supersedes list is honoured only from the selected, verified copy. Superseded packs are read after the rest as a fallback, not dropped.
  • Approvals. Input is filtered by is_well_formed first. Only reviews on the current head count, and only from a reviewer with a current membership document created at or before the review. The newest approve or request-changes review per reviewer stands; comment and unknown verdicts are ignored.
  • Well-formed. In a public repo a document has no enc and has its kind's required plaintext field; a review has none, since its content is the verdict and commitOid. In a private repo it has a non-empty enc, an epoch, and no plaintext fields. This covers issue, patch, comment, review, ref update and config.
  • Repo names. A name must fully match ^[a-z0-9][a-z0-9._-]{0,62}$. Normalization lowercases ASCII A–Z only.
  • String order. Strings compare by code point (UTF-8 byte order). The TypeScript port uses a shared compareStrings instead of <, which compares UTF-16 code units and disagrees with Rust on astral characters. The v1 TypeScript orderings now use it too.

Two v1 behaviours are kept and documented: an author may reopen what a member closed, and a member's approval counts on their own PR. v1 rules are otherwise unchanged; the v1 per-kind effects, merge reachability and event order became shared helpers that v2 reuses.

Conformance vectors

Vectors take an optional "rules": "v1" | "v2" field; absent means v1. All 74 existing vectors are unchanged, and 118 v2 vectors are added:

case count
fold_issue_v2__* 17
fold_pr_v2__* 15
allocate_number__* 12
pack_copies__* 12
approvals__* 15
role_oracle__* 4
well_formed__* 29
repo_name__* 14

Both harnesses (the Rust test at the bottom of rules.rs, and forge-web/lib/rules/conformance.test.ts) dispatch on rules, refuse unknown input keys at every depth, and assert that at least 70 v1 and 110 v2 vectors ran. To confirm the new vectors actually run, I made one temporary change at a time; each was reverted:

temporary break result
wrong expected value in allocate_number__far_squatter_ignored both harnesses fail
authorEvent labels allowed to apply both fail
a misspelt nested key (copies[1].supersede) both fail
TS ordering switched back to UTF-16 < the two code-point vectors fail

Gates

  • cargo fmt --all -- --check, cargo clippy --locked --workspace --all-targets -- -D warnings, cargo test --locked --workspace: pass (conformance_vectors: 74 v1 + 118 v2 vectors green)
  • forge-web: pnpm install --frozen-lockfile, pnpm typecheck, pnpm lint, pnpm test: pass (325 passed, 3 skipped)
  • tools/contract-validate (cargo +1.98.1): both contracts valid under protocol 14; negative.sh: all mutations refused

🤖 Generated with Claude Code

PastaPastaPasta and others added 9 commits September 25, 2026 02:08
…rEvent

event is now gated by maintainer or writer only; the issue/patch author path moves to a new authorEvent type whose kind is limited to close (1) and reopen (2) by the schema. A reader can now tell which gate admitted each document, so a revoked maintainer who authored a PR no longer leaves ambiguous merges.

contract-validate gains --previous, which runs rs-dpp validate_update against the registered schema: removing the ownerRefersTo operands is refused as an incompatible change, so the split ships as a new registration. negative.sh covers the authorEvent lookup.

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

deploy-v2.mjs gains --only collab (register forge-collab alone against the recorded forge-core and group) and --force-new (supersede the recorded forge-collab with a new id). The new forge-collab is 6tm5ehZGoNSwenkCZkXjUm97Vt2bdXfFFsfh9KZ5N43W (nonce 3, 0.545473 DASH); 9fCcSGF3UmajGCNHuuDGz2ou3Gm3EXhrwB3SRS9ocm4Y is recorded as superseded.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
--force-new now supersedes only a record whose status is registered. A broadcasting record is the new contract of an interrupted run, which registerContract completes or retries, so rerunning the same command after a crash cannot register a third copy.

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

forge-core::rules::v2 and forge-web/lib/rules/v2.ts: RoleOracle over current membership documents; issue/PR fold over event + authorEvent (event existence is authorization, authorEvent is close/reopen by the author only, merge needs a reachable oid); allocate_number with the 2n+100 ceiling; pack copy ordering, selection and supersedes-aware read order; count_approvals; is_well_formed; repo name validation and normalization. v1 fold effects are factored into shared helpers that v2 reuses, with v1 behaviour unchanged.

Vectors gain an optional rules field (absent means v1); both harnesses dispatch on it, refuse unknown input keys, and assert 74 v1 + 93 v2 vectors ran.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
… and well-formedness rules

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

Every deployment record now carries schemaHash, the sha256 of the substituted schema JSON. --force-new supersedes only a registered forge-collab whose hash differs from the current schema, so rerunning it after success or a crash registers nothing. A rerun warns when a recorded contract was registered from a different schema, and a dry-run forge-core step is no longer checked against a leftover record.

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

authorEvent gains (repoId, $createdAt) so the repo activity feed reads both event types. Adding an index is refused on update, so forge-collab was re-registered on devnet moutai as CbsaT6oxuoESYhWuoJuPW9QikvAP7RS2x8NGQAYiwsMq (nonce 4, 0.555523 DASH); 6tm5ehZGoNSwenkCZkXjUm97Vt2bdXfFFsfh9KZ5N43W joins the superseded records. schemaHash is backfilled on every record from the schema it was registered from.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
TypeScript now orders every string by code point (compareStrings, UTF-8 byte order, as Rust does) instead of UTF-16 code units, in the event order, sorted sets and overlay paths. is_well_formed treats a review's body as optional (its content is the verdict and commitOid) and adds config; count_approvals documents that its input is filtered by is_well_formed first. TS allocateNumber rejects a count that is not a non-negative integer, and both ports state that the ascending query must be paged to the end of the contiguous run.

Both harnesses now refuse unknown keys at every depth and gain a role_oracle case. 25 vectors added (118 v2 total): code-point ordering, role oracle, same-key stability, non-author reopen, base-at-ceiling gap, supersedes chain and cycle, review and config well-formedness, and the kept design choices (author reopen after member close, self-approval).

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

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

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown

Important

Review skipped

Too many files!

This PR contains 132 files, which is 32 over the limit of 100.

To get a review, reduce the PR to 100 files or fewer by splitting it into smaller PRs or changing its base branch.

Upgrade to a paid plan to raise the limit.

This review couldn't start because sufficient usage credits or metered capacity aren't available. Add credits or update usage-based reviews in the billing tab, then retry.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: b249c635-a0d8-4a43-bf2b-4374399cd750

📥 Commits

Reviewing files that changed from the base of the PR and between 406c984 and 6b97e71.

📒 Files selected for processing (132)
  • crates/forge-core/src/rules.rs
  • crates/forge-core/src/rules/v2.rs
  • docs/contracts/forge-v2.md
  • forge-contracts/contracts/forge-collab.json
  • forge-contracts/deployments/devnet-moutai.json
  • forge-contracts/scripts/deploy-v2.mjs
  • forge-contracts/vectors/allocate_number__base_at_ceiling_with_gap.json
  • forge-contracts/vectors/allocate_number__dense.json
  • forge-contracts/vectors/allocate_number__empty.json
  • forge-contracts/vectors/allocate_number__far_squatter_ignored.json
  • forge-contracts/vectors/allocate_number__gap_not_filled.json
  • forge-contracts/vectors/allocate_number__last_number.json
  • forge-contracts/vectors/allocate_number__order_not_relied_on.json
  • forge-contracts/vectors/allocate_number__probe_steps_over_squatters_above_ceiling.json
  • forge-contracts/vectors/allocate_number__saturated.json
  • forge-contracts/vectors/allocate_number__squatter_at_ceiling_counts.json
  • forge-contracts/vectors/allocate_number__squatter_just_above_ceiling_ignored.json
  • forge-contracts/vectors/allocate_number__squatter_just_ahead_one_retry.json
  • forge-contracts/vectors/approvals__author_self_approval_counts.json
  • forge-contracts/vectors/approvals__comment_does_not_clear_verdict.json
  • forge-contracts/vectors/approvals__latest_verdict_wins.json
  • forge-contracts/vectors/approvals__member_approval_counts.json
  • forge-contracts/vectors/approvals__non_member_ignored.json
  • forge-contracts/vectors/approvals__non_member_request_changes_ignored.json
  • forge-contracts/vectors/approvals__readded_member_old_review_ignored.json
  • forge-contracts/vectors/approvals__reapproval_clears_request_changes.json
  • forge-contracts/vectors/approvals__review_at_membership_time_counts.json
  • forge-contracts/vectors/approvals__review_before_membership_ignored.json
  • forge-contracts/vectors/approvals__revoked_reviewer_no_longer_counts.json
  • forge-contracts/vectors/approvals__same_timestamp_tiebreak_by_id.json
  • forge-contracts/vectors/approvals__stale_head_ignored.json
  • forge-contracts/vectors/approvals__unknown_verdict_ignored.json
  • forge-contracts/vectors/approvals__writer_and_maintainer_both_count.json
  • forge-contracts/vectors/fold_issue_v2__issue_author_event_by_non_author_inert.json
  • forge-contracts/vectors/fold_issue_v2__issue_author_event_close_reopen.json
  • forge-contracts/vectors/fold_issue_v2__issue_author_event_close_valid.json
  • forge-contracts/vectors/fold_issue_v2__issue_author_event_label_kind_inert.json
  • forge-contracts/vectors/fold_issue_v2__issue_author_event_reopen_by_non_author_inert.json
  • forge-contracts/vectors/fold_issue_v2__issue_author_reopen_after_member_close_valid.json
  • forge-contracts/vectors/fold_issue_v2__issue_default_open.json
  • forge-contracts/vectors/fold_issue_v2__issue_event_by_since_revoked_member_valid.json
  • forge-contracts/vectors/fold_issue_v2__issue_event_ids_ordered_by_code_point.json
  • forge-contracts/vectors/fold_issue_v2__issue_labels_sorted_by_code_point.json
  • forge-contracts/vectors/fold_issue_v2__issue_member_assign_unassign.json
  • forge-contracts/vectors/fold_issue_v2__issue_member_close_author_reopen.json
  • forge-contracts/vectors/fold_issue_v2__issue_member_label_valid.json
  • forge-contracts/vectors/fold_issue_v2__issue_pr_only_kinds_ignored.json
  • forge-contracts/vectors/fold_issue_v2__issue_same_key_event_before_author_event.json
  • forge-contracts/vectors/fold_issue_v2__issue_same_key_events_keep_input_order.json
  • forge-contracts/vectors/fold_issue_v2__issue_same_timestamp_tiebreak_by_id_across_types.json
  • forge-contracts/vectors/fold_pr_v2__pr_author_close_member_reopen.json
  • forge-contracts/vectors/fold_pr_v2__pr_author_event_close_valid.json
  • forge-contracts/vectors/fold_pr_v2__pr_author_event_draft_retarget_label_inert.json
  • forge-contracts/vectors/fold_pr_v2__pr_author_event_merge_kind_inert.json
  • forge-contracts/vectors/fold_pr_v2__pr_default_open.json
  • forge-contracts/vectors/fold_pr_v2__pr_event_by_since_revoked_member_merge_valid.json
  • forge-contracts/vectors/fold_pr_v2__pr_illegal_retarget_inert.json
  • forge-contracts/vectors/fold_pr_v2__pr_member_draft_retarget_ready_label.json
  • forge-contracts/vectors/fold_pr_v2__pr_merge_oid_equals_base_tip_valid.json
  • forge-contracts/vectors/fold_pr_v2__pr_merge_unreachable_oid_inert.json
  • forge-contracts/vectors/fold_pr_v2__pr_merge_without_base_tip_inert.json
  • forge-contracts/vectors/fold_pr_v2__pr_merge_without_oid_inert.json
  • forge-contracts/vectors/fold_pr_v2__pr_merged_cannot_be_reopened_by_author.json
  • forge-contracts/vectors/fold_pr_v2__pr_unreachable_merge_then_reachable_merge.json
  • forge-contracts/vectors/fold_pr_v2__pr_writer_merge_reachable_valid.json
  • forge-contracts/vectors/pack_copies__first_verified_wins.json
  • forge-contracts/vectors/pack_copies__maintainers_then_writers_then_others.json
  • forge-contracts/vectors/pack_copies__none_verified.json
  • forge-contracts/vectors/pack_copies__read_order_by_created_at_then_hash.json
  • forge-contracts/vectors/pack_copies__self_supersede_ignored.json
  • forge-contracts/vectors/pack_copies__supersedes_chain.json
  • forge-contracts/vectors/pack_copies__supersedes_cycle.json
  • forge-contracts/vectors/pack_copies__supersedes_honoured_when_verified.json
  • forge-contracts/vectors/pack_copies__supersedes_ignored_when_unverified.json
  • forge-contracts/vectors/pack_copies__supersedes_only_from_selected_copy.json
  • forge-contracts/vectors/pack_copies__tie_break_created_at_then_id.json
  • forge-contracts/vectors/pack_copies__writer_copy_when_no_maintainer_copy_verifies.json
  • forge-contracts/vectors/repo_name__dots_underscores_digits.json
  • forge-contracts/vectors/repo_name__empty.json
  • forge-contracts/vectors/repo_name__kelvin_sign_not_folded.json
  • forge-contracts/vectors/repo_name__leading_dash.json
  • forge-contracts/vectors/repo_name__leading_dot.json
  • forge-contracts/vectors/repo_name__max_length_63.json
  • forge-contracts/vectors/repo_name__non_ascii.json
  • forge-contracts/vectors/repo_name__simple.json
  • forge-contracts/vectors/repo_name__single_char.json
  • forge-contracts/vectors/repo_name__slash.json
  • forge-contracts/vectors/repo_name__space.json
  • forge-contracts/vectors/repo_name__too_long_64.json
  • forge-contracts/vectors/repo_name__trailing_newline.json
  • forge-contracts/vectors/repo_name__uppercase_normalizes.json
  • forge-contracts/vectors/role_oracle__both_roles_same_time.json
  • forge-contracts/vectors/role_oracle__maintainer_outranks_writer.json
  • forge-contracts/vectors/role_oracle__other_identity_ignored.json
  • forge-contracts/vectors/role_oracle__readded_member_starts_again.json
  • forge-contracts/vectors/well_formed__private_comment_plaintext_body.json
  • forge-contracts/vectors/well_formed__private_config_empty_patterns_enc.json
  • forge-contracts/vectors/well_formed__private_config_plaintext_patterns.json
  • forge-contracts/vectors/well_formed__private_issue_both.json
  • forge-contracts/vectors/well_formed__private_issue_empty_enc.json
  • forge-contracts/vectors/well_formed__private_issue_enc.json
  • forge-contracts/vectors/well_formed__private_issue_enc_without_epoch.json
  • forge-contracts/vectors/well_formed__private_issue_neither.json
  • forge-contracts/vectors/well_formed__private_issue_plaintext_title.json
  • forge-contracts/vectors/well_formed__private_patch_enc.json
  • forge-contracts/vectors/well_formed__private_patch_plaintext_base_ref_name.json
  • forge-contracts/vectors/well_formed__private_patch_plaintext_source_ref_name.json
  • forge-contracts/vectors/well_formed__private_ref_update_enc.json
  • forge-contracts/vectors/well_formed__private_ref_update_plaintext_ref_name.json
  • forge-contracts/vectors/well_formed__private_review_enc.json
  • forge-contracts/vectors/well_formed__private_review_plaintext_body.json
  • forge-contracts/vectors/well_formed__private_review_without_enc.json
  • forge-contracts/vectors/well_formed__public_comment_without_body.json
  • forge-contracts/vectors/well_formed__public_config_plaintext.json
  • forge-contracts/vectors/well_formed__public_issue_empty_title.json
  • forge-contracts/vectors/well_formed__public_issue_plaintext.json
  • forge-contracts/vectors/well_formed__public_issue_with_enc.json
  • forge-contracts/vectors/well_formed__public_issue_without_title.json
  • forge-contracts/vectors/well_formed__public_patch_plaintext.json
  • forge-contracts/vectors/well_formed__public_ref_update_plaintext.json
  • forge-contracts/vectors/well_formed__public_ref_update_without_ref_name.json
  • forge-contracts/vectors/well_formed__public_review_body.json
  • forge-contracts/vectors/well_formed__public_review_with_enc.json
  • forge-contracts/vectors/well_formed__public_review_without_body.json
  • forge-web/lib/rules/conformance.test.ts
  • forge-web/lib/rules/fold.ts
  • forge-web/lib/rules/index.ts
  • forge-web/lib/rules/oid.ts
  • forge-web/lib/rules/overlay.ts
  • forge-web/lib/rules/v2.ts
  • tools/contract-validate/negative.sh
  • tools/contract-validate/src/main.rs

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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 322d96b into master Sep 25, 2026
3 checks passed
PastaPastaPasta added a commit that referenced this pull request Sep 25, 2026
…mirror lies

Review #2/#4/#9: requests are limited to 4 per origin and a pack's URLs are raced 3 at a time; the 15 s deadline covers the response starting and then each gap between chunks, not the time spent queued; a URL that timed out gets one sequential retry before the pack is declared unavailable; URLs that failed outright are remembered for the session; range reads use the same list; a Platform pack failing cancels the external downloads; a partial clone is reused for 60 s, not the session, so a later view retries the mirrors. Review #8: a mirror serving bytes that fail the sha256 is shown as 'served bad data' and recorded separately in the ledger and trust detail. Review #5: a REF_DELTA whose base is in a skipped pack names that pack instead of failing with a bare indexer error.

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