Skip to content

[DO NOT MERGE] feat(sdk): hydration FSM — deterministic late-join and reconnect convergence - #1520

Draft
cyaiox wants to merge 1 commit into
stack/02-foundationsfrom
stack/03-hydration-fsm
Draft

[DO NOT MERGE] feat(sdk): hydration FSM — deterministic late-join and reconnect convergence#1520
cyaiox wants to merge 1 commit into
stack/02-foundationsfrom
stack/03-hydration-fsm

Conversation

@cyaiox

@cyaiox cyaiox commented Aug 5, 2026

Copy link
Copy Markdown
Member

Phase 1 of the authoritative-server network refactor. Fixes the core
divergence class ('some players see it, some don't'):

  • network/hydration.ts: pure state machine (DISCONNECTED → CONNECTED →
    REQUESTING_STATE → SYNCED) replacing the loose booleans in
    message-bus-sync; a stray RES_CRDT_STATE from a non-server peer is
    unrepresentable as an FSM event (unique-symbol constructor), so the
    retry-halt bug is structurally impossible
  • REQ_CRDT_STATE responder is server-gated: clients no longer hand out
    their partial world view to late joiners
  • re-hydration reconciliation: a full state dump now removes local
    NetworkEntity-tagged entities it omits (ghost cleanup after
    reconnect); multi-chunk dumps accumulate before reconciling; tag is
    dropped before removal so cleanup never broadcasts deletions
  • SERVER_ANNOUNCE (additive CommsMessage 10): the server names its run
    generation on ready and per state request; clients seeing a new
    generation re-hydrate, so a server restart converges automatically
  • comms arriving before the isServer role resolves is buffered and
    replayed in order (capped, loud on overflow) instead of being
    misrouted down the client path
  • isStateSyncronized() is now true on a ready server
  • RealmInfo observed on the injected engine, not the global singleton

Red defect tests #1, #2, #6, #7, #9, #14 flip to passing; #3, #4, #8,
#10, #11, #12, #13 verified still red. Two QUIRK pins migrated from the
characterization suite to the red suite per the TDD discipline. New
specs: hydration-fsm (25 unit tests, no engine), late-join-hydration,
reconnect-convergence — all ending in the cross-engine convergence
oracle.

Claude-Session: https://claude.ai/code/session_01Kzo6zwrn1CA79S4RN1dgsU

🤖 Generated with Claude Code

https://claude.ai/code/session_01Kzo6zwrn1CA79S4RN1dgsU


📚 Stack (splits #1505 — merge top-down within each stack)

Network layer (each PR is one self-contained, independently-green commit):

  1. test(sdk): characterization baseline for the network layer refactor #1518 test harness — characterization baseline + red defect suite (this stack's root)
  2. [DO NOT MERGE] refactor(sdk): network layer foundations — break cycles, single isServer, logging discipline #1519 foundations — cycle break, single isServer, logging discipline
  3. [DO NOT MERGE] feat(sdk): hydration FSM — deterministic late-join and reconnect convergence #1520 hydration FSM — late-join/reconnect correctness
  4. [DO NOT MERGE] feat(sdk): default-deny server validation, fixed correction path, O(1) entity lookup #1521 validator — default-deny, correction path, entity index
  5. [DO NOT MERGE] refactor(sdk): unify CRDT codec into a parse-once pipeline #1522 codec — parse-once pipeline (wire goldens byte-identical)
  6. [DO NOT MERGE] feat(sdk): clients target the authoritative server; registry collisions; players dedupe #1523 topology — targeted sends, registry collisions, players dedupe
  7. [DO NOT MERGE] refactor(sdk): parameterize network boot, document the host contract #1524 boot + host-conformance doc
  8. [DO NOT MERGE] refactor(sdk): ponytail sweep — delete what the refactor no longer needs #1525 simplification sweep (−95 lines)

sdk-commands (independent of the stack above):

After a parent squash-merges, the child needs git rebase --onto origin/auth-server <old-parent> <child> — ping the session and it gets restacked.

…ergence

Phase 1 of the authoritative-server network refactor. Fixes the core
divergence class ('some players see it, some don't'):

- network/hydration.ts: pure state machine (DISCONNECTED → CONNECTED →
  REQUESTING_STATE → SYNCED) replacing the loose booleans in
  message-bus-sync; a stray RES_CRDT_STATE from a non-server peer is
  unrepresentable as an FSM event (unique-symbol constructor), so the
  retry-halt bug is structurally impossible
- REQ_CRDT_STATE responder is server-gated: clients no longer hand out
  their partial world view to late joiners
- re-hydration reconciliation: a full state dump now removes local
  NetworkEntity-tagged entities it omits (ghost cleanup after
  reconnect); multi-chunk dumps accumulate before reconciling; tag is
  dropped before removal so cleanup never broadcasts deletions
- SERVER_ANNOUNCE (additive CommsMessage 10): the server names its run
  generation on ready and per state request; clients seeing a new
  generation re-hydrate, so a server restart converges automatically
- comms arriving before the isServer role resolves is buffered and
  replayed in order (capped, loud on overflow) instead of being
  misrouted down the client path
- isStateSyncronized() is now true on a ready server
- RealmInfo observed on the injected engine, not the global singleton

Red defect tests #1, #2, #6, #7, #9, #14 flip to passing; #3, #4, #8,
#10, #11, #12, #13 verified still red. Two QUIRK pins migrated from the
characterization suite to the red suite per the TDD discipline. New
specs: hydration-fsm (25 unit tests, no engine), late-join-hydration,
reconnect-convergence — all ending in the cross-engine convergence
oracle.

Claude-Session: https://claude.ai/code/session_01Kzo6zwrn1CA79S4RN1dgsU
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying js-sdk-toolchain with  Cloudflare Pages  Cloudflare Pages

Latest commit: f3e9e79
Status: ✅  Deploy successful!
Preview URL: https://cbf46408.js-sdk-toolchain.pages.dev
Branch Preview URL: https://stack-03-hydration-fsm.js-sdk-toolchain.pages.dev

View logs

@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Test this pull request

  • The @dcl/sdk package can be tested in scenes by running

    npm install "https://sdk-team-cdn.decentraland.org/@dcl/js-sdk-toolchain/branch/stack/03-hydration-fsm/dcl-sdk-7.25.1-31013689119.commit-5819885.tgz"
  • The @dcl/js-runtime package can be tested in scenes by running

    npm install "https://sdk-team-cdn.decentraland.org/@dcl/js-sdk-toolchain/branch/stack/03-hydration-fsm/@dcl/js-runtime/dcl-js-runtime-7.25.1-31013689119.commit-5819885.tgz"
  • To test with npx init

    export SDK_COMMANDS="https://sdk-team-cdn.decentraland.org/@dcl/js-sdk-toolchain/branch/stack/03-hydration-fsm/dcl-sdk-commands-7.25.1-31013689119.commit-5819885.tgz"
    npx $SDK_COMMANDS init
  • The /changerealm command to test test in-world

    /changerealm https://sdk-team-cdn.decentraland.org/ipfs/stack/03-hydration-fsm-e2e
    
  • You can preview this build entering:
    https://playground.decentraland.org/?sdk-branch=stack/03-hydration-fsm

@cyaiox cyaiox changed the title feat(sdk): hydration FSM — deterministic late-join and reconnect convergence [DO NOT MERGE] feat(sdk): hydration FSM — deterministic late-join and reconnect convergence Aug 5, 2026
@cyaiox
cyaiox marked this pull request as draft August 5, 2026 14:24
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