Skip to content

feat(id): signed game save points, handoffs, and forks (#6161) - #8552

Merged
dezren39 merged 1 commit into
mainfrom
queue/14876-6161-savepoint-handoff-fork
Nov 11, 2026
Merged

dezren39 merged 1 commit into
mainfrom
queue/14876-6161-savepoint-handoff-fork

Conversation

@dezren39

@dezren39 dezren39 commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

What

Implements issue #6161 in pkgs/id/src/boards.rs only, following the existing GamePost / GameChallengeAcceptance / GameTurn conventions: signed objects in the board graph, scoped validation at insert, deterministic queries, and replication-closure coverage.

  • GameSavePoint — signed by an assigned participant; names the game post's exact pinned package (hash + version — a mismatch is rejected), the frontier turn (must be a turn of the same game), and the SHA-256 hash of the replayed state at that frontier. Blobs stay content-addressed references; the record carries hashes only.
  • GameHandoff + GameHandoffAcceptance — only the save point's author may hand off, only to an assigned participant, and only the named recipient may accept. Acceptance is authorization, not just a marker (Codex P1, fixed in f2a4bf8): leg_recipients walks a prospective turn's prior chain to the deepest save point on it, and a base-line turn on a governed line may be signed by the accepted recipient under the seat role rotation assigns — the recipient's leg, per design id: design: ID boards v1 #2054 section 4 ("the recipient's acceptance begins their leg"). Replay resolves a leg turn to that seat by role, so legs replay deterministically. Competing handoffs are kept as signed history; game_main_line_head selects the social main line from accepted chains, never by arrival order and never by deleting alternatives.
  • GameFork — a signed citation of a save point that starts an alternate instance (Codex P1, fixed in f2a4bf8): the fork carries its own participant list (its author must hold an assignment), and GameTurn gains an optional fork_ref (serde-defaulted; base-line objects serialize exactly as before). A fork turn must build on the fork's cited frontier or on another turn of the same fork, and its signer resolves against the fork instance's participants by fork-turn position; replay resolves fork turns against the fork list as well, so a third-party fork proceeds and replays independently. (Board-level BoardFork is untouched — different feature, per the packet's scope exclusion.)

Queries: game_save_points, game_handoffs, game_handoff_acceptances, game_forks, game_main_line_head. All four object kinds are wired through kind names, board scoping, shape validation, insert-time link validation, and the board_object_set replication closure (turns also pull their fork record into the closure).

Tests (oracle: the #6161 acceptance criteria and design #2054 section 4)

cargo test --lib boards:: in pkgs/id — 56 passed, 0 failed (pre-existing suites stay green, including the generated replication-convergence and replay-oracle property tests), including twelve new tests:

  • game_save_handoff_accept_and_continue_selects_main_line — a three-participant tic-tac-toe line is saved, handed to a named recipient, accepted, and continued by that recipient; a competing handoff stays visible and unaccepted handoffs do not move the main line.
  • game_handoff_acceptance_begins_the_recipients_leg — the Codex round-1 example: after turn 1 of the two-player wasm game, the creator hands the save to the opponent; the opponent's turn 2 under the creator's x seat is rejected before acceptance and accepted after it (under their own o role it stays rejected), and the leg lineage replays deterministically.
  • game_save_point_handoff_and_fork_rejections — bad signer (non-participant save), package version mismatch, package hash mismatch, bad frontier (not a turn / unresolvable), handoff by a non-author, handoff citing an unresolvable save point, acceptance by a non-recipient, and a fork citing an unresolvable save point are each rejected.
  • game_fork_from_save_point_replays_both_lines_independently — two third authors fork from one save point (both records visible); the forker signs the fork instance's opening turn under the fork's own participants (a base-line turn by the forker, and an out-of-rotation fork turn, are rejected); source and fork lines replay through the pinned tic-tac-toe wasm to different states, deterministically, with lineage attribution intact. The save point's state hash is the real replayed snapshot hash, recomputed in the test.

rustfmt clean for the touched file (pre-existing fmt drift in unrelated id-core files is not touched).

Refs #6161.

  • game_handoff_chain_keeps_earlier_legs_authorized — chained handoffs (A to B, then B saves and hands back to A): the earlier leg stays authorized (union semantics, monotone in the evidence; Codex round-2 P1).
  • game_fork_preserves_the_saved_states_seat_phase — a save taken mid-rotation forks with seating phase-aligned to the absolute turn index (Codex round-2 P1).
  • game_leg_evidence_travels_with_a_board_fork_citation — a BoardFork citing a leg turn pulls its save/handoff/acceptance evidence into the replication set and replicates to Complete (Codex round-2 P2). Round 2 also brought: replay resolving leg turns to the scheduled seat (shared-role safe) and the rotation short-circuit so ordinary turns never pay the handoff ancestry search.

Round 3/4 additions: save points on a fork line authorize against the fork's participants (game_save_point_on_a_fork_line_uses_fork_participants); forks must preserve the saved instance's seat layout — same seats, same role per seat, authors may change (game_fork_must_preserve_the_saved_seat_layout); accepted handoffs govern fork instances in validation and replay (game_handoff_leg_inside_a_fork_instance).

Round 5 additions: handoff recipients resolve against the saved frontier's instance (game_handoff_recipient_resolves_against_the_saved_instance), and leg authorization is instance-scoped — a source-line handoff never governs inside a fork (game_source_line_handoff_does_not_govern_a_fork).

Round 6 addition: base-line turns may only build on base-line turns — instance continuity in the common predecessor check (game_base_turn_cannot_build_on_a_fork_turn).

Summary by CodeRabbit

  • New Features
    • Added signed save points so games can be resumed from a saved state.
    • Added participant handoffs, including recipient acceptance and continued play under the scheduled seat.
    • Added game forks that allow play to continue from a saved point with a separate participant rotation.
    • Game turns now retain compatibility with existing games, and the main game line reflects the latest accepted save point.
  • Bug Fixes
    • Improved replay attribution and replication validation for forked games and handoff-authorized turns.

@dezren39
dezren39 requested a review from a team as a code owner November 11, 2026 05:57
@coderabbitai

coderabbitai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown

Explain Change →

Walkthrough

The board graph adds signed game save points, handoffs, acceptances, and forks. Turns can identify fork instances, and validation and replay account for instance participants and accepted handoff recipients. Graph queries expose saved records and the accepted main-line head. Replication includes dependencies for these records.

Changes: Game history and turn authorization

Layer / File(s) Summary
Define and validate saved game records
pkgs/id/src/boards.rs
Adds save-point, handoff, acceptance, and fork objects. Validation checks their links, signatures, recipients, package references, and participant layouts.
Authorize and replay instance turns
pkgs/id/src/boards.rs
Adds optional fork_ref to turns. Turn authorization and replay use fork participants and accepted handoff recipients; base-line turns cannot continue fork turns.
Query and replicate game history
pkgs/id/src/boards.rs
Adds queries for game records and the accepted main-line head. Replication includes save, handoff, acceptance, and fork dependencies.

Estimated code review effort: 4 (Complex) | ~60 minutes

Change: Feature

Possibly related issues

Possibly related PRs

  • developing-today/code#6158 — This PR extends the GamePackageRef, GameParticipant, and GamePost board contract that PR #6158 introduced.
Merge Risk: Moderate · up to 9bfe8

The new game save, handoff and fork feature can report a fork's frontier as the source game's main line. Its tests also fail the repository's Clippy check, which would break CI. Long saved games may authorize and replay slowly. Resolve these before merging.

Pre-merge checks: Passed 2

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely identifies the main changes: signed game save points, handoffs, and forks.
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Warning

Some tools did not complete. Review the errors below.

Clippy (1.99.1)

Clippy execution timed out

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-11T07:32:09.052107Z 9bfe86b New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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: 2d57b0d422

ℹ️ 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 thread pkgs/id/src/boards.rs
Comment on lines +277 to +283
pub struct GameFork {
/// Board root hash.
pub board: ArtifactHash,
/// Hash of the immutable `BoardObject::GamePost` this fork belongs to.
pub game_post: ArtifactHash,
/// Hash of the `BoardObject::GameSavePoint` the fork cites.
pub save_point: ArtifactHash,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Connect fork records to independently authorized continuations

When an author outside the original participant list creates a GameFork, the record is accepted, but that author cannot play their continuation: GameTurn validation still resolves every signer against the original immutable GamePost.participants. The fork also has no instance or continuation reference that turns can name, so the graph cannot associate subsequent branches with either of two concurrent fork records. The new fork test masks this by signing both continuations with the original creator rather than either forker. Introduce a fork-specific continuation identity and participant resolution so a third-party fork can actually proceed independently, as specified in doc/2026-11-01_design_id2054.md:78–79.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in f2a4bf8. GameFork now carries its own participants list (the fork author must hold one of the assignments), and GameTurn gains an optional fork_ref naming the fork instance it belongs to (serde-defaulted, so base-line objects are byte-identical to before). A fork turn must build on the fork's cited save-point frontier or on another turn of the same fork, and its signer resolves against the fork instance's participants by fork-turn position; replay_game_lineage resolves fork turns against the fork's participant list too, so a third-party fork proceeds and replays independently — the reworked test game_fork_from_save_point_replays_both_lines_independently now has the forker (key 73, not a game-post participant) sign the fork's opening turn, a base-line turn by the forker is rejected, and an out-of-rotation fork turn is rejected. Fork records are also wired into the replication closure via fork_ref.

Comment thread pkgs/id/src/boards.rs
Comment on lines +1091 to +1094
ensure!(
handoff_body.recipient == author,
"a game handoff can be accepted only by its named recipient"
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Apply handoff acceptance to continuation authorization

For an accepted handoff whose recipient is not the next participant in the original rotation, acceptance does not let the recipient continue the saved line. For example, after turn 1 of a two-player game, the creator can hand the save to the opponent and the opponent can accept, but their turn 2 is rejected because GameTurn validation still requires the creator's signature. Nothing in continuation validation or replay consults the accepted handoff; the new test succeeds only by choosing a third participant whose turn was already next without any handoff. Bind continuation authorization to the accepted handoff so acceptance actually begins the recipient's leg, rather than merely affecting the main-line query.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in f2a4bf8. Continuation authorization now consults the accepted handoff: BoardGraph::leg_recipients walks a prospective base-line turn's prior chain to the deepest save point on it and returns the recipients of its accepted handoffs. A base-line turn is authorized when it is signed by the rotation participant for its index, OR by a governing accepted-handoff recipient under the seat role rotation assigns — the recipient's leg, playing the seat (design #2054 section 4: "the recipient's acceptance begins their leg"). Replay resolution matches: a leg turn signed by the recipient resolves to the seat by role, so the leg replays deterministically. New test game_handoff_acceptance_begins_the_recipients_leg uses exactly your example: after turn 1 of the two-player wasm game the creator hands the save to the opponent; the opponent's turn 2 under the creator's x seat is rejected before acceptance and accepted after it, under their own o role it stays rejected, and the leg lineage replays. The three-participant flow in game_save_handoff_accept_and_continue_selects_main_line also still passes.

@dezren39
dezren39 force-pushed the queue/14876-6161-savepoint-handoff-fork branch from 2d57b0d to f2a4bf8 Compare November 11, 2026 06:15

@chatgpt-codex-connector chatgpt-codex-connector Bot 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: f2a4bf88c3

ℹ️ 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 thread pkgs/id/src/boards.rs Outdated
Comment on lines +1049 to +1053
let position = value
.turn_index
.checked_sub(frontier_body.turn_index.saturating_add(1))
.context("a fork turn's index does not follow the fork frontier")?;
let acting = &fork_body.participants[usize::try_from(position)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve the saved state's seat rotation when starting a fork

When a save is taken partway through the participant rotation, subtracting the frontier index resets the fork to participant zero without resetting the replayed game state. For example, save after turn 0 of tic-tac-toe and fork with [third:x, opponent:o]: this authorizes the third author to sign turn 1 as X, but replay executes that move as O because apps/tic-tac-toe/program/main.roc:25–32 derives the mark from the existing move count and ignores the participant ID. The state changes, so replay's unchanged-state check does not detect the misattribution. Preserve the saved state's seat alignment when resolving fork participants; the added test only covers a frontier after a complete rotation.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in f660f57. Fork seating is now phase-aligned to the absolute turn index: a fork turn's seat is participants[turn_index % len] against the fork's own list, not a rotation reset at the frontier. The saved state's move count and the seat schedule can no longer drift: in your example the fork turn after turn 0 belongs to fork participant 1 (the o seat), and the forker signing it as x is rejected. New test game_fork_preserves_the_saved_states_seat_phase covers the mid-rotation save (frontier after turn 0 only); the existing fork test's frontier sits at a complete rotation and still passes under the aligned rule.

Comment thread pkgs/id/src/boards.rs Outdated
Comment on lines +1409 to +1410
if !recipients.is_empty() {
return recipients;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Bind handoff authorization to immutable continuation evidence

Accepting a later handoff can invalidate previously accepted continuation turns because this early return discards authorization from earlier handoffs. In a two-player game, let A hand the save after turn 1 to B, then let B sign turns 2/X, 3/O, and 4/X. If B subsequently saves turn 2 and hands it to A, A's acceptance makes leg_recipients return only A for turn 4. replay_game_lineage then rejects B's previously valid turn 4 because B is not assigned X in the original post. A peer receiving the newer acceptance before turn 4 also rejects that turn during insertion, so the same signed history can reconstruct differently by arrival order. Record which accepted handoff authorizes a continuation rather than recomputing historical authorization from the current deepest accepted save.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in f660f57. leg_recipients now returns the UNION of recipients of every accepted handoff whose save point's frontier lies on the turn's prior chain, instead of only the deepest accepted save's recipients. Authorization is therefore monotone in the evidence: a later acceptance can add a recipient but never revokes a leg an earlier accepted handoff began, so verdicts converge in any arrival order. New test game_handoff_chain_keeps_earlier_legs_authorized walks your exact chain (A to B at turn 1, B legs turns 2-3, B saves turn 2 and hands back to A, A accepts) and B's turn 4 under the x seat stays authorized and replays.

Comment thread pkgs/id/src/boards.rs
Comment on lines 1953 to +1955
let mut dependencies = vec![body.board.clone(), body.game_post.clone()];
dependencies.extend(body.prev_turn.iter().cloned());
dependencies.extend(body.fork_ref.iter().cloned());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Export handoff authorization dependencies for cited game turns

When a board-level BoardFork.source_frontier cites a source-board game turn authorized by an accepted handoff rather than ordinary rotation, this dependency closure exports its ancestry and challenge acceptance but omits the handoff acceptance, handoff, and save point needed to authorize it. Those sibling records are not included by the fork board's scope-based seed either. Consequently, replicate_board_from into a fresh graph cannot insert the cited turn and stalls, even though the source graph accepted every exported object. Include the handoff authorization evidence in the game turn's dependency closure; exporting the entire source board happens to mask this omission.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in f660f57. The GameTurn arm of board_object_set now also pulls every save point, handoff, and handoff acceptance of the same game into the dependency closure, alongside the challenge acceptances it already carried. New test game_leg_evidence_travels_with_a_board_fork_citation builds a BoardFork whose source frontier cites a handoff-authorized leg turn and asserts the fork board's set contains the save point, handoff, and acceptance, and that replicate_board_from into a fresh graph completes with the cited turn insertable.

Comment thread pkgs/id/src/boards.rs Outdated
Comment on lines +1067 to +1072
let leg_authorized = acting.role == value.role
&& post_body
.participants
.iter()
.any(|participant| participant.author == author)
&& self.leg_recipients(value).contains(author);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Skip handoff ancestry searches for rotation-authorized turns

For every ordinary valid base-line turn, the role and participant checks are true, so leg_recipients is evaluated even when rotation_authorized already authorizes the signature. With no save points at all, that helper walks every ancestor and calls game_save_points at each step, which scans the entire object map. This introduces quadratic work per insertion and cubic work to construct or replicate a long game history, including games that never use handoffs. Short-circuit the handoff lookup when ordinary rotation succeeds so the new feature does not impose this cost on all async games.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in f660f57. The base-line authorization now short-circuits: leg_authorized is computed only when rotation_authorized is false (the handoff ancestry search is behind the negated flag in the && chain), so ordinary rotation turns never pay the leg_recipients walk. Replay's leg resolution is likewise only consulted when the direct signer resolution is not already the scheduled seat.

Comment thread pkgs/id/src/boards.rs Outdated
}
None => &post_body.participants,
};
let position = participants

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve handoff replay to the scheduled participant seat

When different participants share a role, which validate_game_participants permits, resolving the replay participant by signer or role does not identify the seat authorized by rotation. For [A:player, B:player], an accepted A-to-B handoff after turn 1 permits B to sign turn 2 as player, substituting for A's scheduled seat. This lookup instead finds B's original assignment and passes participant ID 2 to the guest rather than ID 1; the role-only fallback is likewise ambiguous when several seats share a role. Participant-aware packages, such as examples/territory/main.roc:196–203, consequently apply the action to the wrong player's state. Resolve baseline handoff turns using the scheduled seat index rather than the recipient's original assignment or the first matching role.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in f660f57. Replay now resolves a base-line leg turn to the SCHEDULED seat: seat = participants[turn_index % len], used when the signer is a governing handoff recipient signing under the seat's role. The ambiguous role-only fallback is gone, so with shared roles ([A:player, B:player]) B's leg turn 2 executes under participant ID 1 (A's scheduled seat), not B's own assignment. The direct signer resolution remains for ordinary turns, which resolve to the same seat through their signer.

@dezren39
dezren39 force-pushed the queue/14876-6161-savepoint-handoff-fork branch from f2a4bf8 to f660f57 Compare November 11, 2026 06:32

@chatgpt-codex-connector chatgpt-codex-connector Bot 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: f660f57a88

ℹ️ 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 thread pkgs/id/src/boards.rs Outdated
Comment on lines +1126 to +1129
post_body
.participants
.iter()
.any(|participant| participant.author == author),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Authorize saves against the frontier's fork participants

When a third-party author creates and plays an independently seated fork, their turns are authorized using GameFork.participants, but saving that continuation still checks only the original GamePost.participants. Consequently, even a fork whose participants can successfully play and replay their turns cannot record a save point without an original participant's intervention, preventing its users from creating further save-based forks. Resolve save authorization against the frontier's fork participants when its turn has a fork_ref, retaining the original participant check for base-line saves.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in the amended head. Save-point authorization now resolves against the frontier's line: when the frontier turn carries a fork_ref, the signer must hold an assignment in that fork's participants (with the fork's game checked against the save's game); base-line frontiers keep the post-participant check. A fork's players can therefore save their continuation — and fork it again — without an original participant, and symmetrically a base-line participant with no fork seat can no longer save the fork line. New test game_save_point_on_a_fork_line_uses_fork_participants covers both directions.

@dezren39
dezren39 force-pushed the queue/14876-6161-savepoint-handoff-fork branch from f660f57 to ee60088 Compare November 11, 2026 06:44

@chatgpt-codex-connector chatgpt-codex-connector Bot 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: ee60088402

ℹ️ 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 thread pkgs/id/src/boards.rs
Comment on lines +1224 to +1228
ensure!(
value
.participants
.iter()
.any(|participant| participant.author == author),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve the saved instance's seat layout when creating a fork

When a fork changes the participant count, absolute-index seating no longer preserves the saved state's rotation. For example, after tic-tac-toe turn 0, a fork with the single assignment [C:x] passes this validation and authorizes C's turn 1 as X because 1 % 1 == 0. Replay nevertheless executes that move as O: pkgs/id/apps/tic-tac-toe/program/main.roc:25–32 ignores the participant ID and derives the mark from the saved move count. The state changes, so the replay guard does not detect the misattribution. Fresh evidence beyond the earlier phase-alignment finding is that unrestricted fork cardinality defeats the absolute-index fix. Validate that fork assignments preserve the saved instance's seat layout while allowing authors to change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in the amended head. Fork creation now validates the seat layout against the saved instance: the fork's participant list must have the same number of seats as the instance the cited save point belongs to (the post's list for a base-line save, the source fork's list for a fork-line save), with the same role at each seat — only the assigned authors may change. Your one-seat [C:x] fork of the two-seat game is now rejected at fork creation, so absolute-index seating can no longer be defeated by cardinality. New test game_fork_must_preserve_the_saved_seat_layout covers the one-seat fork, a role-swapped two-seat fork (both rejected), and a re-authored layout-preserving fork (accepted).

Comment thread pkgs/id/src/boards.rs Outdated
Comment on lines +1071 to +1073
ensure!(
acting.author == author && acting.role == value.role,
"a fork turn must be signed by the fork participant its fork-turn position names, under that participant's assigned role"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Apply accepted handoffs to fork-instance continuations

For a save on a fork line, an accepted handoff still cannot begin the recipient's leg because this authorization branch requires the scheduled fork participant and never consults handoff evidence. For example, let a fork assign [C:x, B:o], with B also an original-post participant. C can save after fork turn 1, hand that save to B, and obtain B's acceptance, but B's fork turn 2 under X is rejected here. The base-line handoff fix does not cover this Some(fork_ref) branch; dropping fork_ref instead loses the independent continuation identity. Apply accepted-handoff authorization within the saved fork instance, including the corresponding replay seat resolution.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in the amended head. Accepted handoffs now govern fork instances exactly as they govern the base line: the fork-turn branch computes leg authorization (recipient of an accepted handoff whose save frontier is on the turn's chain, signing under the scheduled seat's role) alongside rotation, and replay resolves a fork leg turn to the scheduled fork seat via the same seat-resolution path the base line uses — leg_recipients already walked fork chains unchanged, since fork turns link into the saved frontier's chain. New test game_handoff_leg_inside_a_fork_instance walks your example (fork [C:x, B:o], B plays turn 1, C saves and hands to B): B's fork turn 2 as x is rejected before acceptance, accepted after it, and replays as X.

@dezren39
dezren39 force-pushed the queue/14876-6161-savepoint-handoff-fork branch from ee60088 to fe215b0 Compare November 11, 2026 07:05

@chatgpt-codex-connector chatgpt-codex-connector Bot 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: fe215b02e5

ℹ️ 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 thread pkgs/id/src/boards.rs Outdated
Comment on lines +1209 to +1212
post_body
.participants
.iter()
.any(|participant| participant.author == value.recipient),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve handoff recipients against the saved fork's participants

For an independently seated fork [C:x, D:o] of an original game [A:x, B:o], C and D can play and save their continuation, but C cannot hand that save to D: this check still searches the original post's participants. Conversely, handing it to B passes this check even though B cannot continue that fork because fork-turn authorization requires membership in the fork. The fresh evidence beyond the earlier fork-handoff finding is that the added continuation test explicitly uses a recipient who is also an original participant, leaving third-party fork recipients blocked. Resolve the recipient against the saved frontier's instance, as save-point authorization already does.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in the amended head. Handoff recipient validation now resolves against the saved frontier's instance — the fork's participants for a fork-line save, the post's for a base-line save — mirroring save-point authorization. In your example C can hand the fork-line save to D, and B (no fork seat) is rejected as a recipient for it. New test game_handoff_recipient_resolves_against_the_saved_instance covers the independent fork [C:x, D:o] of [A:x, B:o] in both directions, plus the base-line non-participant control.

Comment thread pkgs/id/src/boards.rs
Comment on lines +1518 to +1519
for (save_hash, save) in self.game_save_points(&turn.game_post) {
if !chain.contains(&save.frontier) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Scope handoff authorization to the continuing fork instance

When a fork starts from a save with an accepted source-line handoff, this ancestry-only check imports that handoff's authority into the independent fork. For example, in the original game [A:x, B:o], save after turn 1, accept an A-to-B handoff, then create a fork assigning [C:x, B:o]. B can immediately sign fork turn 2 as X: the fork authorization branch calls leg_recipients, which finds the source save and authorizes B despite the fork assigning that seat to C and having no handoff of its own. Require authorizing save frontiers to belong to the continuing instance so source-line handoffs cannot override independent fork assignments.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in the amended head. leg_recipients is now instance-scoped: a handoff governs a prospective turn only when its save point's frontier belongs to the turn's own instance (frontier fork_ref equals the turn's fork_ref). A fork's chain still walks back through the source line for lineage, but source-line handoffs no longer authorize inside the fork — in your example B's fork turn 2 as X is rejected (the seat is C's; the fork has no handoff of its own), while C's own turn 2 stands. The scoping is a no-op for base-line turns, whose chains only contain base-line frontiers. New test game_source_line_handoff_does_not_govern_a_fork covers it; the round-4 fork-leg test (handoff created inside the fork) still passes.

@dezren39
dezren39 force-pushed the queue/14876-6161-savepoint-handoff-fork branch from fe215b0 to 74fa92f Compare November 11, 2026 07:19

@chatgpt-codex-connector chatgpt-codex-connector Bot 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: 74fa92fbb8

ℹ️ 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 thread pkgs/id/src/boards.rs
Comment on lines +1093 to +1096
None => {
let acting = &post_body.participants[usize::try_from(value.turn_index)
.unwrap_or(usize::MAX)
% post_body.participants.len()];

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Reject fork-instance predecessors for base-line turns

When a turn omits fork_ref, this branch authorizes it against the original post without requiring its predecessor to belong to the base line. For example, with original participants [A:x, B:o] and fork participants [C:x, D:o], A can append turn 2 directly to D's fork turn 1 by omitting fork_ref. The common predecessor checks accept this because they check only the game and consecutive index, and replay also succeeds. This lets an author outside the fork's roster continue its state while silently switching authorization back to the original roster, without an explicit fork or handoff. Require a base-line turn's predecessor to have fork_ref: None; instance transitions should use the explicit fork path.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Fixed in the amended head. The common predecessor check now enforces instance continuity: a base-line turn (no fork_ref) may only build on a base-line turn. Appending a base-line turn onto a fork turn — continuing the fork instance's state under the original roster with no fork record or handoff — is rejected; crossing instances takes the explicit fork path, whose branch already validates fork turns' predecessors against their own fork. New test game_base_turn_cannot_build_on_a_fork_turn covers your example (original creator appending turn 2 onto D's fork turn 1).

@dezren39
dezren39 force-pushed the queue/14876-6161-savepoint-handoff-fork branch from 74fa92f to 9bfe86b Compare November 11, 2026 07:29
@dezren39
dezren39 merged commit 3a691f3 into main Nov 11, 2026
0 of 7 checks passed
@dezren39
dezren39 deleted the queue/14876-6161-savepoint-handoff-fork branch November 11, 2026 07:33
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