@series-inc/rundot-syncplay 6.0.0-rc.113 → 6.0.0-rc.114

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -36,7 +36,7 @@ export const physicsProfileWasmMetadata = Object.freeze({
36
36
  "sourceHash": "4ca971eb52456e0141b37c4700f877b15b776df4be327000ff7a42d0aef106e6",
37
37
  "wasmSha256": "4eb4d6848a74b25b5d21c377be92ad1a0d78f1f96f12934ddae683c99a7c0afc",
38
38
  "artifact": "profile",
39
- "packageVersion": "6.0.0-rc.113",
39
+ "packageVersion": "6.0.0-rc.114",
40
40
  "compilerFlags": [
41
41
  "-std=c++20",
42
42
  "-O3",
@@ -36,7 +36,7 @@ export const physicsWasmMetadata = Object.freeze({
36
36
  "sourceHash": "76bbbac134fa1abfc823dc6d324b663da3bcdb80bc09c28fc025736d2d9cc03f",
37
37
  "wasmSha256": "19d53336de18d53eed555cd80f25cdb5e9e43c6491c06e93f672be7683737ac7",
38
38
  "artifact": "production",
39
- "packageVersion": "6.0.0-rc.113",
39
+ "packageVersion": "6.0.0-rc.114",
40
40
  "compilerFlags": [
41
41
  "-std=c++20",
42
42
  "-O3",
@@ -50,7 +50,7 @@ export const physics2dWasmMetadata = Object.freeze({
50
50
  "sourceHash": "b4ae2139eb68bf6c797af143c07cec8b80e732662f9f9cda219bf76de63e0934",
51
51
  "wasmSha256": "633aeb98cb199b120cc7b5a855a620e01ab73d5cd8b6427cb7949eafecfdf1f0",
52
52
  "artifact": "production",
53
- "packageVersion": "6.0.0-rc.113",
53
+ "packageVersion": "6.0.0-rc.114",
54
54
  "compilerFlags": [
55
55
  "-std=c++20",
56
56
  "-O3",
@@ -98,6 +98,11 @@ export interface DeterministicAuthorityRoomConfig {
98
98
  readonly maxHydratedSnapshotBytes?: number;
99
99
  /** Snapshot acquisition telemetry: stored snapshots and rejected/abandoned transfers. */
100
100
  readonly onSnapshotEvent?: (event: AuthorityRoomSnapshotEvent) => void;
101
+ /** Reports a restored snapshot that exceeds the room wire limit. */
102
+ readonly onOversizeSnapshotRestore?: (warning: {
103
+ readonly size: number;
104
+ readonly limit: number;
105
+ }) => void;
101
106
  /**
102
107
  * Keep the confirmed-input history back to tick 0 even after a validated
103
108
  * snapshot is stored (G3 — replay-verified matches). Normally the snapshot
@@ -4,7 +4,7 @@ import { invariant } from './errors.js';
4
4
  import { createInputAuthority } from './input-authority.js';
5
5
  import { createBinaryDeterministicLocalAuthoritySnapshotChunkEnvelope, createBinaryDeterministicLocalAuthoritySnapshotCompleteEnvelope, createBinaryDeterministicLocalAuthoritySnapshotOfferEnvelope, createBinaryDeterministicLocalAuthoritySnapshotRefusalEnvelope, createBinaryDeterministicLocalAuthoritySnapshotRequestEnvelope, createDeterministicLocalAuthoritySnapshotChunkEnvelope, createDeterministicLocalAuthoritySnapshotCompleteEnvelope, createDeterministicLocalAuthoritySnapshotOfferEnvelope, createDeterministicLocalAuthoritySnapshotRefusalEnvelope, createDeterministicLocalAuthoritySnapshotRequestEnvelope, decodeBinaryDeterministicLocalAuthorityWireEnvelope, decodeDeterministicLocalAuthorityWireEnvelope, } from './local-authority-wire.js';
6
6
  import { DEFAULT_BINARY_SNAPSHOT_CHUNK_SIZE, snapshotHydratedByteLimit, DEFAULT_SNAPSHOT_CHUNK_SIZE, TEXT_COMPRESSED_SNAPSHOT_PREFIX, createBinarySnapshotTransferFromBytes, createSnapshotTransferCollector, createSnapshotTransferFromBytes, decodeDeterministicStateSnapshotInternal, encodeDeterministicStateSnapshot, encodeTextWrappedBinarySnapshot, deterministicRoomDescriptorHash, restampBinarySnapshotWitnesses, } from './session-snapshot.js';
7
- import { DEFAULT_MAX_SNAPSHOT_BYTES, MAX_SNAPSHOT_WIRE_BYTES, isPositiveSnapshotByteLimit } from './snapshot-limits.js';
7
+ import { DEFAULT_MAX_SNAPSHOT_BYTES, MAX_SNAPSHOT_WIRE_BYTES, isSnapshotWireByteLimit } from './snapshot-limits.js';
8
8
  import { MAX_KINETIX_SESSION_CONFIG_BYTES, MAX_SYNCPLAY_COMMAND_PAYLOAD_BYTES, MAX_SYNCPLAY_EPHEMERAL_PAYLOAD_BYTES, decodeDeterministicSessionMessage, encodeDeterministicSessionMessage, } from './session-wire.js';
9
9
  import { createSyncplaySecretAuthority, } from './secret-authority.js';
10
10
  import { DEFAULT_SEAT_POLICY, validateSeatPolicy, createInitialSeatControlState, allocatable, findAvailableSeat, applyTransition, expireSeatHolds, createSeatCheckpoint, restoreSeatControlState, } from './seat-control.js';
@@ -139,11 +139,11 @@ export function createDeterministicAuthorityRoom(transport, config) {
139
139
  }
140
140
  const sessionMsgType = config.sessionMsgType ?? DEFAULT_SESSION_MSG_TYPE;
141
141
  const binarySessionMsgType = config.binarySessionMsgType ?? `${sessionMsgType}-bin`;
142
- const storedSnapshotLimitBytes = config.maxSnapshotBytes ?? DEFAULT_MAX_SNAPSHOT_BYTES;
143
- // Low-level rooms and stored bundles can use a limit above the client maximum.
144
- const advertisedSnapshotLimitBytes = storedSnapshotLimitBytes === DEFAULT_MAX_SNAPSHOT_BYTES
145
- ? undefined
146
- : Math.min(storedSnapshotLimitBytes, MAX_SNAPSHOT_WIRE_BYTES);
142
+ const snapshotLimitBytes = config.maxSnapshotBytes === undefined ? DEFAULT_MAX_SNAPSHOT_BYTES : config.maxSnapshotBytes;
143
+ if (!isSnapshotWireByteLimit(snapshotLimitBytes)) {
144
+ throw new Error(`createDeterministicAuthorityRoom: maxSnapshotBytes must be an integer from 1 to ${MAX_SNAPSHOT_WIRE_BYTES}, received ${snapshotLimitBytes}`);
145
+ }
146
+ const advertisedSnapshotLimitBytes = snapshotLimitBytes === DEFAULT_MAX_SNAPSHOT_BYTES ? undefined : snapshotLimitBytes;
147
147
  const historyRetentionTicks = requireTickCount('historyRetentionTicks', config.historyRetentionTicks ?? DEFAULT_HISTORY_RETENTION_TICKS);
148
148
  // The ring keeps at least four redundancy windows, see createSessionAuthority.
149
149
  const historyRingTicks = Math.max(historyRetentionTicks, config.redundancyWindowTicks * 4);
@@ -160,13 +160,8 @@ export function createDeterministicAuthorityRoom(transport, config) {
160
160
  let seed = config.seed;
161
161
  let generation = config.restoreFrom?.generation ?? 0;
162
162
  invariant(Number.isInteger(generation) && generation >= 0, 'restored generation must be a non-negative integer', 'authority-room.restore-generation');
163
- if (config.maxSnapshotBytes !== undefined && !isPositiveSnapshotByteLimit(config.maxSnapshotBytes)) {
164
- throw new Error(`createDeterministicAuthorityRoom: maxSnapshotBytes must be a positive integer, received ${config.maxSnapshotBytes}`);
165
- }
166
- // With no explicit hydrated limit, the room must accept at least what its own wire limit allows.
167
- // The client uses the same floor, so the two sides agree.
168
163
  const snapshotDecodeLimits = config.maxHydratedSnapshotBytes === undefined
169
- ? { defaultHydratedByteFloor: storedSnapshotLimitBytes }
164
+ ? { defaultHydratedByteFloor: snapshotLimitBytes }
170
165
  : { maxHydratedBytes: config.maxHydratedSnapshotBytes };
171
166
  const maxHydratedSnapshotBytes = snapshotHydratedByteLimit(undefined, snapshotDecodeLimits);
172
167
  if (!Number.isInteger(maxHydratedSnapshotBytes) || maxHydratedSnapshotBytes < 1) {
@@ -525,6 +520,18 @@ export function createDeterministicAuthorityRoom(transport, config) {
525
520
  ...(restore.schemaHash === undefined ? {} : { schemaHash: restore.schemaHash }),
526
521
  },
527
522
  });
523
+ const size = restoredBinaryBytes?.byteLength ?? restore.snapshotBytes.length;
524
+ if (size > snapshotLimitBytes) {
525
+ const warning = { size, limit: snapshotLimitBytes };
526
+ if (config.onOversizeSnapshotRestore !== undefined) {
527
+ config.onOversizeSnapshotRestore(warning);
528
+ }
529
+ else {
530
+ console.warn('The restored snapshot exceeds the room wire limit.', {
531
+ event: 'syncplay_restore_snapshot_oversize', ...warning,
532
+ });
533
+ }
534
+ }
528
535
  // A restored room persists from the same snapshot tick, so the byte-accounting suffix
529
536
  // must start there rather than at the oldest retained frame.
530
537
  authority.setPersistedTailStart(decoded.snapshot.tick);
@@ -1926,13 +1933,12 @@ export function createDeterministicAuthorityRoom(transport, config) {
1926
1933
  }
1927
1934
  }
1928
1935
  const isBinaryTransfer = collected.binarySnapshotBytes !== undefined;
1929
- const effectiveMaxSnapshotBytes = storedSnapshotLimitBytes;
1930
1936
  if (decoded.source.kind === 'raw-binary' || decoded.source.kind === 'wrapped-binary') {
1931
1937
  const rawBinary = decoded.source.binarySnapshotBytes;
1932
1938
  const binarySnapshotBytes = snapshot.v === 3
1933
- ? restampBinarySnapshotWitnesses(rawBinary, frozenReporters.length)
1939
+ ? restampBinarySnapshotWitnesses(rawBinary, frozenReporters.length, snapshotLimitBytes)
1934
1940
  : rawBinary;
1935
- if (binarySnapshotBytes.byteLength > effectiveMaxSnapshotBytes) {
1941
+ if (binarySnapshotBytes === undefined || binarySnapshotBytes.byteLength > snapshotLimitBytes) {
1936
1942
  failPendingTransfer('snapshot-too-large');
1937
1943
  return;
1938
1944
  }
@@ -1954,7 +1960,7 @@ export function createDeterministicAuthorityRoom(transport, config) {
1954
1960
  const snapshotBytes = snapshot.v === 3
1955
1961
  ? encodeDeterministicStateSnapshot({ ...snapshot, witnesses: frozenReporters.length })
1956
1962
  : decoded.source.rawJsonText;
1957
- if (snapshotBytes.length > effectiveMaxSnapshotBytes) {
1963
+ if (snapshotBytes.length > snapshotLimitBytes) {
1958
1964
  failPendingTransfer('snapshot-too-large');
1959
1965
  return;
1960
1966
  }
@@ -2027,10 +2033,10 @@ export function createDeterministicAuthorityRoom(transport, config) {
2027
2033
  function refuseDonorTransfer(failed, reason) {
2028
2034
  const identity = { descriptorHash: roomDescriptorHash, configHash: failed.transferRequestId };
2029
2035
  if (transport.sendBinaryTo !== undefined && binaryCapablePlayers.has(failed.donorId)) {
2030
- transport.sendBinaryTo(failed.donorId, binarySessionMsgType, createBinaryDeterministicLocalAuthoritySnapshotRefusalEnvelope(nextWireSequence(), identity, reason, storedSnapshotLimitBytes));
2036
+ transport.sendBinaryTo(failed.donorId, binarySessionMsgType, createBinaryDeterministicLocalAuthoritySnapshotRefusalEnvelope(nextWireSequence(), identity, reason, snapshotLimitBytes));
2031
2037
  return;
2032
2038
  }
2033
- transport.sendTo(failed.donorId, sessionMsgType, createDeterministicLocalAuthoritySnapshotRefusalEnvelope(nextWireSequence(), identity, reason, storedSnapshotLimitBytes));
2039
+ transport.sendTo(failed.donorId, sessionMsgType, createDeterministicLocalAuthoritySnapshotRefusalEnvelope(nextWireSequence(), identity, reason, snapshotLimitBytes));
2034
2040
  }
2035
2041
  /**
2036
2042
  * Start a snapshot transfer to the best target that has a donor left. A
@@ -2081,7 +2087,7 @@ export function createDeterministicAuthorityRoom(transport, config) {
2081
2087
  minFrame: tick + 1,
2082
2088
  startedAt: now,
2083
2089
  timeoutTicks: transferTimeoutTicks,
2084
- collector: createSnapshotTransferCollector({ maxSnapshotBytes: storedSnapshotLimitBytes }),
2090
+ collector: createSnapshotTransferCollector({ maxSnapshotBytes: snapshotLimitBytes }),
2085
2091
  isRetry,
2086
2092
  targetTick: tick,
2087
2093
  generation,
@@ -99,7 +99,7 @@ export declare function encodeBinaryDeterministicStateSnapshot(snapshot: BinaryD
99
99
  * Rewrites `witnesses` on a `v: 3` `SYNSNP04` binary snapshot without
100
100
  * decompressing or re-compressing the runtime payload slice.
101
101
  */
102
- export declare function restampBinarySnapshotWitnesses(binarySnapshotBytes: Uint8Array, witnesses: number): Uint8Array;
102
+ export declare function restampBinarySnapshotWitnesses(binarySnapshotBytes: Uint8Array, witnesses: number, maxSnapshotBytes: number): Uint8Array | undefined;
103
103
  export type InternalDeterministicSnapshotSource = {
104
104
  readonly kind: 'legacy-json';
105
105
  readonly rawJsonText: string;
@@ -146,7 +146,7 @@ export function encodeBinaryDeterministicStateSnapshot(snapshot, options = {}) {
146
146
  * Rewrites `witnesses` on a `v: 3` `SYNSNP04` binary snapshot without
147
147
  * decompressing or re-compressing the runtime payload slice.
148
148
  */
149
- export function restampBinarySnapshotWitnesses(binarySnapshotBytes, witnesses) {
149
+ export function restampBinarySnapshotWitnesses(binarySnapshotBytes, witnesses, maxSnapshotBytes) {
150
150
  if (!isBinaryDeterministicStateSnapshot(binarySnapshotBytes)) {
151
151
  throw new Error('Expected SYNSNP04 binary snapshot');
152
152
  }
@@ -167,6 +167,10 @@ export function restampBinarySnapshotWitnesses(binarySnapshotBytes, witnesses) {
167
167
  ...headerObj,
168
168
  witnesses,
169
169
  }));
170
+ if (updatedHeaderBytes.byteLength > MAX_BINARY_SNAPSHOT_METADATA_BYTES
171
+ || BINARY_SNAPSHOT_HEADER_BYTES + updatedHeaderBytes.byteLength + payloadLen > maxSnapshotBytes) {
172
+ return undefined;
173
+ }
170
174
  const payloadSlice = binarySnapshotBytes.subarray(BINARY_SNAPSHOT_HEADER_BYTES + headerLen, BINARY_SNAPSHOT_HEADER_BYTES + headerLen + payloadLen);
171
175
  const out = new Uint8Array(BINARY_SNAPSHOT_HEADER_BYTES + updatedHeaderBytes.byteLength + payloadSlice.byteLength);
172
176
  out[0] = SNP_B0;
@@ -38,7 +38,8 @@ export type SyncplayRemovedSnapshotRoomConfigKey = keyof typeof SYNCPLAY_REMOVED
38
38
  * - `'accept-stored'`: for a stored bundle only. The room server uses it at
39
39
  * bundle load and at room creation, so a game published before rc.99 with
40
40
  * the old keys keeps starting rooms. Each key keeps its rc.95 meaning: a
41
- * positive safe integer is used as is, also outside the block ranges; any
41
+ * positive safe integer is used as is outside the block ranges, except that
42
+ * the snapshot wire limit is capped at 6,000,000 bytes. Any
42
43
  * other value falls back to the default (rc.95 ignored a value that is not
43
44
  * a number, and the engine cannot run with zero, a negative, a fraction or
44
45
  * NaN); `maxHydratedSnapshotBytes` has no effect, as rc.95 never passed it
@@ -60,11 +61,12 @@ export interface SyncplayStoredBundleSnapshotKey {
60
61
  readonly replacement: SyncplaySnapshotConfigKey | null;
61
62
  /**
62
63
  * - `applied`: the room uses the value, as rc.95 did.
64
+ * - `clamped`: the old snapshot limit exceeds the wire maximum.
63
65
  * - `invalid`: rc.95 ignored the value, or the engine cannot run with it; the room uses the default.
64
66
  * - `overridden`: `deterministic.snapshots` sets the replacement, and the block value wins.
65
67
  * - `ignored`: rc.95 never passed this key to the room, so it has no effect.
66
68
  */
67
- readonly outcome: 'applied' | 'invalid' | 'overridden' | 'ignored';
69
+ readonly outcome: 'applied' | 'clamped' | 'invalid' | 'overridden' | 'ignored';
68
70
  }
69
71
  /** How a deterministic room serves a joiner that needs a full catch-up. */
70
72
  export type SyncplayJoinSnapshotMode = 'fresh' | 'stored';
@@ -171,6 +171,7 @@ function rejectRemovedRoomConfigKeys(roomConfig) {
171
171
  * Read the removed keys of a stored bundle with their rc.95 meaning. rc.95
172
172
  * passed a key to the engine when it was a number; the engine needs a
173
173
  * positive integer, so any other value falls back to the default here.
174
+ * Cap the old wire limit at the maximum that clients can receive.
174
175
  * A key whose replacement the block sets is reported but not used.
175
176
  */
176
177
  function readStoredBundleKeys(roomConfig, block) {
@@ -190,8 +191,9 @@ function readStoredBundleKeys(roomConfig, block) {
190
191
  outcome = 'overridden';
191
192
  }
192
193
  else if (typeof value === 'number' && Number.isSafeInteger(value) && value >= 1) {
193
- ticks[key] = value;
194
- outcome = 'applied';
194
+ const clamped = key === 'maxSnapshotBytes' && value > MAX_SNAPSHOT_WIRE_BYTES;
195
+ ticks[key] = clamped ? MAX_SNAPSHOT_WIRE_BYTES : value;
196
+ outcome = clamped ? 'clamped' : 'applied';
195
197
  }
196
198
  else {
197
199
  outcome = 'invalid';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@series-inc/rundot-syncplay",
3
- "version": "6.0.0-rc.113",
3
+ "version": "6.0.0-rc.114",
4
4
  "description": "Kinetix orchestration, rollback, replay, late-join, and deterministic networking for RUN.game",
5
5
  "repository": {
6
6
  "type": "git",