Skip to content

netcode: confirm the ticks a save makes final - #242

Merged
SandroMaglione merged 3 commits into
mainfrom
claude/project-thread-vlhuzg
Nov 22, 2026
Merged

SandroMaglione merged 3 commits into
mainfrom
claude/project-thread-vlhuzg

Conversation

@SandroMaglione

@SandroMaglione SandroMaglione commented Nov 21, 2026 •

Copy link
Copy Markdown
Member

Requested by Sandro · project thread

Rebased on main after #241 (one message per frame). The protocol is now version 6, and #241's changeset says so too.

What was wrong

After a save (a page that loads again, a hidden page back under "resync-on-return", any resync()), confirmed events went missing. They did not go missing on the page the save seated: in 280 seeded matches (2 to 8 seats, lossy link, hitches, adaptive delay), that page confirmed every tick from the save on, exactly once. The losses were on the other pages, the host included, in the ticks just before the save.

A save is the host's world as it ran, including its guesses of other seats' input. Every peer withdrew the ticks it had run but not yet confirmed (ledger.reset()), and never confirmed them. Under rollback that is up to maxRollback ticks per page per save. When a page reloads mid-race, the others run on guesses of its seat until it is back. With Tabletop Champions' settings that is 48 ticks (0.8 s), so a lap, a checkpoint, or a sound from that stretch never reached any page, and nothing said so. Lockstep was not affected.

A second bug: a peer ahead of the host can confirm the save's own tick and inputDelay more. The ledger kept one tick fewer of what it had handed out, so lost() missed one replaced tick after a resync.

The fix

  • The host confirms every tick it ran before its own save.
  • The sync message carries ranFrom and ran: the canonical keys of the inputs each of the host's last ticks ran with. A peer confirms the ticks it ran with the same inputs, from a tick both had confirmed. What predicted() handed out for those ticks stands.
  • Every other tick before the save is reported by lost() with a new reason, "save": ticks this peer ran otherwise, confirmed otherwise, or never ran. Their predictions are withdrawn. A page the save seats for its first match (one that loaded again) is told nothing of the ticks before the save.
  • resyncReach is now saveDelay + 1.
  • The run keys are kept under rollback only.

Breaking (types only): EventsLost["reason"] is now "unread" | "resync" | "save". The changeset has the fix.

Tests

  • test/Saved.test.ts covers:

    • a page that loads again, and a hidden page under "resync-on-return"
    • rollback (2, 3, 8 seats) and lockstep (2, 3), over a lossy link
    • five seeded matches with hitches and an adaptive delay

    The host must confirm every tick it ran. Every other peer must confirm each tick once, as the host ran it, or report it through lost(). The seated page must confirm every tick from its save on.

  • On main (after netcode: one message per link per frame, and lighter ones #241), 14 of these 15 fail. With only the resyncReach fix reverted, one seeded case fails.

  • Events.test.ts: predicted ticks before the save are now confirmed. Only ticks from the save on are withdrawn.

  • integration/netcode: the resync test now sees "save" reports on seat 1, which main dropped silently. They are recorded, and the host has none.

Checks

After the rebase:

  • pnpm run check passes.
  • pnpm --dir website build passes.
  • Netcode bench, against main on the same machine:
    • Time: noise.
    • Lockstep frame allocations: unchanged.
    • Rollback frame allocations: +6.6% (one key string per tick), under the 10% gate.
  • bench:check against the recorded baseline shows +33% time on the rollback frame, but main itself measures the same on this machine, so that is the machine, not this PR.

🤖 Generated with Claude Code

https://claude.ai/code/session_01HendNe1CC9Z9F2bcbgrbaD

A save is the host's world as it ran, guesses of other seats' input
included. Every peer, the host too, withdrew the ticks it had run before
the save but not confirmed yet, and never confirmed them: under rollback,
up to maxRollback ticks of events vanished on every page at each save (a
page reloading mid-match lets the others run on guesses of its seat until
it is back). The page the save seated was not affected.

- The host confirms every tick it ran before its save.
- The save carries the inputs its last ticks ran with (protocol version
  5); a peer confirms the ticks it ran with the same inputs, from a tick
  both confirmed.
- The rest before the save (run otherwise, confirmed otherwise, or not
  run) is reported by lost() with the new reason "save".
- A peer ahead of the host confirms the save's tick and inputDelay more:
  the ledger kept one tick fewer, so lost() missed one after a resync.

Tests cover a page that loads again and a hidden page under
"resync-on-return", rollback and lockstep, two to eight seats, a lossy
link, hitches, and an adaptive delay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HendNe1CC9Z9F2bcbgrbaD
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HendNe1CC9Z9F2bcbgrbaD
Lockstep runs nothing on a guess, so a save names none of its ticks: it
allocates nothing more per tick than before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HendNe1CC9Z9F2bcbgrbaD
@SandroMaglione
SandroMaglione force-pushed the claude/project-thread-vlhuzg branch from e9e897c to e8bfe10 Compare November 22, 2026 00:08
@SandroMaglione
SandroMaglione merged commit ae9428b into main Nov 22, 2026
5 checks passed
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.

2 participants