Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(play): stop false 'session expired' kick on world entry

fudjia537f22e41b81
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 38b087ec0..53fe4d973 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ Public history for [three.ws](https://three.ws), newest first. New pages come fr
- **A live 3D avatar in the GitHub README, and readme-3d: an open toolkit for 3D in markdown** — The three.ws GitHub README now opens with the platform mascot as a real, draggable 3D model that GitHub renders natively (no image, no video: an interactive viewer in plain markdown). The pipeline that made it is now an open-source package, readme-3d: a CLI and library that converts any GLB, glTF, OBJ, or STL into the ASCII-STL markdown blocks GitHub renders, simplifies meshes to fit GitHub's 512 KB markdown limit, and size-checks your files so they never silently stop rendering. It ships with five tutorials, live examples, a docs site, a Claude Code skill, and copy-paste agent prompts, and pairs with the free Forge text-to-3D API so anyone can go from a one-line prompt to a 3D model in their README in five minutes. `[feature, docs, sdk]`
- **A live 3D avatar in the GitHub README, and readme-3d: an open toolkit for 3D in markdown** — The three.ws GitHub README now opens with the platform mascot as a real, draggable 3D model that GitHub renders natively (no image, no video: an interactive viewer in plain markdown). The pipeline that made it is now an open-source package, readme-3d: a CLI and library that converts any GLB, glTF, OBJ, or STL into the ASCII-STL markdown blocks GitHub renders, simplifies meshes to fit GitHub's 512 KB markdown limit, and size-checks your files so they never silently stop rendering. It ships with five tutorials, live examples, a docs site, a Claude Code skill, and copy-paste agent prompts, and pairs with the free Forge text-to-3D API so anyone can go from a one-line prompt to a 3D model in their README in five minutes. (`https://github.com/nirholas/three.ws/tree/main/packages/readme-3d`) `[feature, docs, sdk]`
+- **Fixed: entering a /play world no longer kicks you out with a false 'session expired'** — Joining any coin world briefly showed the world and then bounced you back to the lobby with a 'your session expired' message, even though signing in was never required. The real cause was a version mismatch between the game client and the world server: the client asked for a newer feature the deployed server did not recognise, the server dropped the connection with a generic error code, and the client misread that code as a login-expiry eviction. Worlds now tolerate version differences in both directions: the server ignores messages it does not understand instead of dropping the player, and the client only shows the sign-in gate when the server actually says the session ended. Agent desks inside worlds are also back for everyone: they now load the platform's most recently active public agents instead of a signed-in-only list that failed silently for guests. (`/play`) `[fix]`
- **Paid API clients are no longer rate-limited for paying** — The per-IP budget on every paid three.ws endpoint used to count each payment attempt the same whether it succeeded or failed, which capped a paying client at 20 calls a minute. That is backwards for the market-data API, where the whole point is pulling many individual data points at a fraction of a cent each: a buyer fetching 50 metrics got rejected partway through despite paying for every one. The budget now counts failures instead of attempts. A settled payment costs a single token against a much larger allowance (300 calls a minute), while an invalid-payment flood, the abuse this guard exists to stop, drains the allowance quickly and is still cut off before it can cost us anything. Bulk buyers get the throughput they are paying for, and the abuse protection is unchanged. `[fix, improvement]`
## 2026-07-12
diff --git a/data/changelog.json b/data/changelog.json
index e300e5aab..bf660eaf4 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -1,6 +1,15 @@
{
"$comment": "Curated changelog entries for three.ws — the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security. `link` is optional and must be a live three.ws path.",
"entries": [
+ {
+ "date": "2026-07-13",
+ "title": "Fixed: entering a /play world no longer kicks you out with a false 'session expired'",
+ "summary": "Joining any coin world briefly showed the world and then bounced you back to the lobby with a 'your session expired' message, even though signing in was never required. The real cause was a version mismatch between the game client and the world server: the client asked for a newer feature the deployed server did not recognise, the server dropped the connection with a generic error code, and the client misread that code as a login-expiry eviction. Worlds now tolerate version differences in both directions: the server ignores messages it does not understand instead of dropping the player, and the client only shows the sign-in gate when the server actually says the session ended. Agent desks inside worlds are also back for everyone: they now load the platform's most recently active public agents instead of a signed-in-only list that failed silently for guests.",
+ "tags": [
+ "fix"
+ ],
+ "link": "/play"
+ },
{
"date": "2026-07-13",
"title": "Paid API clients are no longer rate-limited for paying",
diff --git a/multiplayer/src/room-compat.js b/multiplayer/src/room-compat.js
new file mode 100644
index 000000000..3d0d46ac0
--- /dev/null
+++ b/multiplayer/src/room-compat.js
@@ -0,0 +1,52 @@
+// Cross-version message compatibility for every room.
+//
+// Colyseus's default behavior for a message type with no registered handler is
+// to close the connection with WS_CLOSE_WITH_ERROR (4002). During a rolling
+// deploy the static frontend and this game server are never updated in the
+// same instant, so a newer client speaking one new message type ("profileReq")
+// to an older room build would get its whole session killed — and, worse, the
+// pre-2026-07-13 client misread that 4002 as a play-pass eviction and bounced
+// the player to a "session expired" sign-in gate (the /play kick-loop bug).
+//
+// Registering a wildcard handler replaces that kill-the-connection fallback:
+// unknown message types are logged (rate-limited per session) and ignored, so
+// a version-skewed client degrades to a missing feature instead of a dead
+// session. Real handlers registered via onMessage(type, …) always win — the
+// wildcard only sees types nothing else claimed.
+
+/**
+ * Install a tolerant fallback for unregistered message types on a room.
+ * Call once in onCreate, after (or before — order is irrelevant, the wildcard
+ * is only consulted when no named handler matches) the room's onMessage set.
+ *
+ * @param {import('@colyseus/core').Room} room
+ * @param {string} label room name used in the log line, e.g. 'walk_world'
+ */
+export function installUnknownMessageGuard(room, label) {
+ const seen = new Map(); // sessionId → Set of already-logged unknown types
+ room.onMessage('*', (client, type) => {
+ const key = client.sessionId;
+ let types = seen.get(key);
+ if (!types) {
+ // Bound the ledger for rooms that outlive thousands of sessions (StageRoom
+ // never auto-disposes) — losing dedup history is fine, leaking memory isn't.
+ if (seen.size >= 500) seen.clear();
+ types = new Set();
+ seen.set(key, types);
+ }
+ // Log each unknown type once per session — enough to spot a skewed or
+ // misbehaving client in the logs without letting it flood them.
+ if (types.size < 16 && !types.has(String(type))) {
+ types.add(String(type));
+ console.warn(`[${label}] ignoring unknown message type "${String(type).slice(0, 64)}" from ${key} (client build ahead of or behind this server)`);
+ }
+ });
+}
+
+// Close code for an active play-pass eviction (pass expired without a refresh
+// or the wallet fell below the token floor). Deliberately NOT 4002 — that is
+// Colyseus's own WS_CLOSE_WITH_ERROR and overloading it made real server
+// errors look like session expiry. The client keys on the close REASON
+// ('play_pass_required'), so this code is informational; it just has to stay
+// clear of Colyseus's reserved codes (4000, 4002, 4201, 4202).
+export const PLAY_PASS_EVICT_CODE = 4402;
diff --git a/multiplayer/src/rooms/AgoraRoom.js b/multiplayer/src/rooms/AgoraRoom.js
index 8a249a889..7d3fa5200 100644
--- a/multiplayer/src/rooms/AgoraRoom.js
+++ b/multiplayer/src/rooms/AgoraRoom.js
@@ -17,6 +17,7 @@ import { Room } from '@colyseus/core';
import { Schema, MapSchema, defineTypes } from '@colyseus/schema';
import { Player } from '../schemas.js';
import { cleanAvatarUrl } from '../avatar-url.js';
+import { installUnknownMessageGuard } from '../room-compat.js';
const MAX_CLIENTS = 50; // the server's proven per-room ceiling (WalkRoom)
const PATCH_RATE_HZ = 15;
@@ -88,6 +89,8 @@ export class AgoraRoom extends Room {
this.setState(new AgoraState());
this.setPatchRate(PATCH_RATE_MS);
this.autoDispose = true;
+ // Unknown message types are ignored, never a session kill (room-compat.js).
+ installUnknownMessageGuard(this, 'agora_world');
this.onMessage('move', (client, payload) => this._handleMove(client, payload));
this.onMessage('rename', (client, payload) => this._handleRename(client, payload));
diff --git a/multiplayer/src/rooms/ClashRoom.js b/multiplayer/src/rooms/ClashRoom.js
index 6c31d4761..19ee0f0fa 100644
--- a/multiplayer/src/rooms/ClashRoom.js
+++ b/multiplayer/src/rooms/ClashRoom.js
@@ -21,6 +21,7 @@ import { ClashMatch, ClashPhase, CLASH_DEFAULTS } from '../clash.js';
import { selectTarget } from '../combat.js';
import { verifyHolderPass } from '../holder-pass.js';
import { verifyPlayPass } from '../play-pass.js';
+import { installUnknownMessageGuard } from '../room-compat.js';
import { cleanAvatarUrl } from '../avatar-url.js';
import { reportBattle } from '../war-report.js';
@@ -81,6 +82,8 @@ export class ClashRoom extends Room {
this.setPatchRate(PATCH_RATE_MS);
this.maxClients = MAX_CLIENTS;
this.autoDispose = true;
+ // Unknown message types are ignored, never a session kill (room-compat.js).
+ installUnknownMessageGuard(this, 'clash');
// The two communities are fixed at creation from the matchKey's options. The
// engine owns the authoritative match; the schema mirrors it for clients.
diff --git a/multiplayer/src/rooms/IrlRoom.js b/multiplayer/src/rooms/IrlRoom.js
index b504cbd1b..c1e5f8116 100644
--- a/multiplayer/src/rooms/IrlRoom.js
+++ b/multiplayer/src/rooms/IrlRoom.js
@@ -22,6 +22,7 @@ import { Room } from '@colyseus/core';
import { IrlViewer, IrlState } from '../irl-schemas.js';
import { encodeGeohash, decodeGeohash } from '../geohash.js';
+import { installUnknownMessageGuard } from '../room-compat.js';
import {
isReactionType,
reactionAllowed,
@@ -69,6 +70,8 @@ export class IrlRoom extends Room {
this.state.geocell = this.geocell;
this.setPatchRate(PATCH_RATE_MS);
this.autoDispose = true;
+ // Unknown message types are ignored, never a session kill (room-compat.js).
+ installUnknownMessageGuard(this, 'irl');
// D3 — a viewer interacted with a pin in this cell. Fan an ambient `reaction`
// to everyone here so the agent visibly emotes for bystanders. This is the
diff --git a/multiplayer/src/rooms/StageRoom.js b/multiplayer/src/rooms/StageRoom.js
index 50aa0a307..5c0ffffd9 100644
--- a/multiplayer/src/rooms/StageRoom.js
+++ b/multiplayer/src/rooms/StageRoom.js
@@ -29,6 +29,7 @@ import { StageState, StageAudience, StageTipper } from '../stage-schemas.js';
import { ShowDirector, BEAT } from '../stage-show.js';
import { registerStage, unregisterStage } from '../stage-registry.js';
import { signStageRequest } from '../presence-token.js';
+import { installUnknownMessageGuard } from '../room-compat.js';
const PATCH_RATE_MS = 100; // 10 Hz — snappy enough for the tip ticker + captions
const MAX_CLIENTS = 200; // a busy venue; bound so a flood degrades gracefully
@@ -71,6 +72,8 @@ export class StageRoom extends Room {
this.state.phase = 'preshow';
this.setPatchRate(PATCH_RATE_MS);
this.autoDispose = false; // a scheduled show outlives an empty crowd between beats
+ // Unknown message types are ignored, never a session kill (room-compat.js).
+ installUnknownMessageGuard(this, 'stage');
this._director = new ShowDirector({ stageId: this.stageId });
diff --git a/multiplayer/src/rooms/WalkRoom.js b/multiplayer/src/rooms/WalkRoom.js
index 16b8d60de..78a4cb97a 100644
--- a/multiplayer/src/rooms/WalkRoom.js
+++ b/multiplayer/src/rooms/WalkRoom.js
@@ -30,6 +30,7 @@ import { verifyHolderPass } from '../holder-pass.js';
import { socialHub } from '../social-hub.js';
import { verifyPresenceTicket } from '../presence-token.js';
import { verifyPlayPass } from '../play-pass.js';
+import { installUnknownMessageGuard, PLAY_PASS_EVICT_CODE } from '../room-compat.js';
import {
restoreProfile, serializeProfile, profileSnapshot,
addItem, hasRoomFor, resolveSlot, grantXp, consumeSlot,
@@ -489,6 +490,10 @@ export class WalkRoom extends Room {
this.setState(new WalkState());
this.setPatchRate(PATCH_RATE_MS);
this.autoDispose = true;
+ // Version-skew tolerance: a message type this build doesn't know must be
+ // ignored, never close the session (Colyseus's default 4002 kill looked
+ // like "session expired" to pre-fix clients). See room-compat.js.
+ installUnknownMessageGuard(this, 'walk_world');
// The first client to land in this coin's instance seeds its identity.
this.state.coin = cleanCoin(options?.coin);
@@ -675,7 +680,7 @@ export class WalkRoom extends Room {
for (const client of this.clients) {
const exp = client.userData?.playExp;
if (typeof exp === 'number' && exp < nowS) {
- try { client.leave(4002, 'play_pass_required'); } catch {}
+ try { client.leave(PLAY_PASS_EVICT_CODE, 'play_pass_required'); } catch {}
}
}
}, 60_000);
diff --git a/public/changelog.json b/public/changelog.json
index 6edf4aa07..763b142a8 100644
--- a/public/changelog.json
+++ b/public/changelog.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-07-13T07:44:21.397Z",
+ "generated_at": "2026-07-13T23:16:23.828Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json",
"site": {
"name": "three.ws",
@@ -30,6 +30,16 @@
"sdk"
]
},
+ {
+ "date": "2026-07-13",
+ "type": "update",
+ "title": "Fixed: entering a /play world no longer kicks you out with a false 'session expired'",
+ "summary": "Joining any coin world briefly showed the world and then bounced you back to the lobby with a 'your session expired' message, even though signing in was never required. The real cause was a version mismatch between the game client and the world server: the client asked for a newer feature the deployed server did not recognise, the server dropped the connection with a generic error code, and the client misread that code as a login-expiry eviction. Worlds now tolerate version differences in both directions: the server ignores messages it does not understand instead of dropping the player, and the client only shows the sign-in gate when the server actually says the session ended. Agent desks inside worlds are also back for everyone: they now load the platform's most recently active public agents instead of a signed-in-only list that failed silently for guests.",
+ "link": "/play",
+ "tags": [
+ "fix"
+ ]
+ },
{
"date": "2026-07-13",
"type": "update",
diff --git a/public/changelog.xml b/public/changelog.xml
index b33a787d3..7382eb85e 100644
--- a/public/changelog.xml
+++ b/public/changelog.xml
@@ -22,6 +22,14 @@
<category>feature</category>
<description>The three.ws GitHub README now opens with the platform mascot as a real, draggable 3D model that GitHub renders natively (no image, no video: an interactive viewer in plain markdown). The pipeline that made it is now an open-source package, readme-3d: a CLI and library that converts any GLB, glTF, OBJ, or STL into the ASCII-STL markdown blocks GitHub renders, simplifies meshes to fit GitHub's 512 KB markdown limit, and size-checks your files so they never silently stop rendering. It ships with five tutorials, live examples, a docs site, a Claude Code skill, and copy-paste agent prompts, and pairs with the free Forge text-to-3D API so anyone can go from a one-line prompt to a 3D model in their README in five minutes.</description>
</item>
+ <item>
+ <title>Fixed: entering a /play world no longer kicks you out with a false 'session expired'</title>
+ <link>https://three.ws/play</link>
+ <guid isPermaLink="false">2026-07-13:Fixed: entering a /play world no longer kicks you out with a false 'session expired'</guid>
+ <pubDate>Mon, 13 Jul 2026 12:00:00 GMT</pubDate>
+ <category>fix</category>
+ <description>Joining any coin world briefly showed the world and then bounced you back to the lobby with a 'your session expired' message, even though signing in was never required. The real cause was a version mismatch between the game client and the world server: the client asked for a newer feature the deployed server did not recognise, the server dropped the connection with a generic error code, and the client misread that code as a login-expiry eviction. Worlds now tolerate version differences in both directions: the server ignores messages it does not understand instead of dropping the player, and the client only shows the sign-in gate when the server actually says the session ended. Agent desks inside worlds are also back for everyone: they now load the platform's most recently active public agents instead of a signed-in-only list that failed silently for guests.</description>
+ </item>
<item>
<title>Paid API clients are no longer rate-limited for paying</title>
<link>https://three.ws/changelog</link>
diff --git a/public/features.json b/public/features.json
index 72f7a9587..f41c41f67 100644
--- a/public/features.json
+++ b/public/features.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-07-13T07:44:21.378Z",
+ "generated_at": "2026-07-13T23:16:23.815Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json",
"site": {
"name": "three.ws",
diff --git a/src/game/coincommunities.js b/src/game/coincommunities.js
index b1ec22614..fe7602801 100644
--- a/src/game/coincommunities.js
+++ b/src/game/coincommunities.js
@@ -1292,12 +1292,15 @@ export class CoinCommunities {
ui: this.ui,
coin,
});
- // Agent desks — visible in every world. Fetches the world's top registered
- // agents from /api/agents and seats them at working desks with live
- // CanvasTexture monitors streaming their real activity. Players can walk up
- // and press E (or tap) to open the full 2D watch view.
+ // Agent desks — visible in every world. Seats the platform's most recently
+ // ACTIVE public agents (the same ranking as the /agents-live wall) at
+ // working desks with live CanvasTexture monitors streaming their real
+ // activity. Players can walk up and press E (or tap) to open the full 2D
+ // watch view. Must be the public directory, not /api/agents: that route
+ // lists the CALLER'S OWN agents and 401s for the anonymous players who make
+ // up most of /play, which silently left every world deskless.
this._agentDesks = [];
- fetch(`/api/agents?limit=3`, { credentials: 'include' })
+ fetch(`/api/agents/public?sort=live&limit=3`)
.then((r) => r.ok ? r.json() : null)
.then((d) => {
const agents = d?.agents || d?.data || [];
@@ -1307,7 +1310,6 @@ export class CoinCommunities {
const desk = createAgentDesk(this.scene, {
agentId: a.id,
agentName: a.name || 'Agent',
- avatarUrl: a.avatar_glb_url || a.avatar_model_url || '',
}, {
position: offsets[i],
rotationY: rotations[i],
diff --git a/src/game/community-net.js b/src/game/community-net.js
index ab035727b..723b329a9 100644
--- a/src/game/community-net.js
+++ b/src/game/community-net.js
@@ -452,13 +452,20 @@ export class CommunityNet {
this.worldTime = Number(this.room.state.worldTime) || 0;
$state?.listen?.('worldTime', (v) => { this.worldTime = Number(v) || 0; this._emit('worldtime', this.worldTime); });
- this.room.onLeave((code) => {
+ this.room.onLeave((code, reason) => {
this._setStatus('offline');
- // 4002: the server evicted us because our play pass expired without a
- // refresh (the wallet may have dropped below the token floor). Reconnecting
- // would just fail onAuth again — surface it as a terminal denial so the
- // scene routes the player back to the sign-in gate.
- if (code === 4002) { this._setStatus('denied', 'play_pass_required'); this._emit('denied', 'play_pass_required'); return; }
+ // A play-pass eviction (the server dropped us because our pass expired
+ // without a refresh — the wallet may have fallen below the token floor) is
+ // terminal: reconnecting would just fail onAuth again, so surface it as a
+ // denial and route the player back to the sign-in gate. Detect it by the
+ // server's close REASON, never by the bare close code: the legacy eviction
+ // code 4002 is also Colyseus's own WS_CLOSE_WITH_ERROR, which the server
+ // sends for any internal error (e.g. a message type this room build doesn't
+ // know) — treating those as "session expired" kicked healthy players to a
+ // sign-in gate that wasn't even enabled. Anything else non-consented is a
+ // connection fault: reconnect with backoff.
+ if (/play_pass/i.test(reason || '')) { this._setStatus('denied', 'play_pass_required'); this._emit('denied', 'play_pass_required'); return; }
+ if (code === 4002) log.warn('[community-net] server closed with error:', reason || '(no reason)');
if (!this._destroyed && code !== 1000) this._scheduleReconnect();
});
this.room.onError((code, message) => log.warn('[community-net] room.onError', code, message));
diff --git a/tests/irl-room-no-pins.test.js b/tests/irl-room-no-pins.test.js
index f6131c4da..fa3739706 100644
--- a/tests/irl-room-no-pins.test.js
+++ b/tests/irl-room-no-pins.test.js
@@ -61,8 +61,9 @@ describe('IrlRoom message surface — exactly presence + reactions, never a pin
it('registers exactly the three privacy-clean handlers — and nothing that could publish a pin', () => {
// If a future edit adds onMessage('publish', …) / onMessage('pin', …) to re-open
// a pin broadcast, this set changes and the test fails. The room's whole socket
- // surface is these three types; none of them transports a coordinate roster.
- expect(booted.messageTypes.slice().sort()).toEqual(['heartbeat', 'interaction', 'set_ghost']);
+ // surface is these three types plus the '*' compat fallback (room-compat.js),
+ // which ignores unknown types and can never publish anything.
+ expect(booted.messageTypes.slice().sort()).toEqual(['*', 'heartbeat', 'interaction', 'set_ghost']);
// Defensive: no message type even mentions a pin/publish/window concept.
for (const t of booted.messageTypes) {
expect(/pin|publish|window|roster|feed/i.test(t)).toBe(false);
diff --git a/tests/room-compat.test.js b/tests/room-compat.test.js
new file mode 100644
index 000000000..6188cae66
--- /dev/null
+++ b/tests/room-compat.test.js
@@ -0,0 +1,65 @@
+// room-compat — the version-skew guard that keeps an unknown message type from
+// killing a live session (the 2026-07-13 /play "session expired" kick-loop:
+// a newer client sent 'profileReq' to an older room build, Colyseus closed the
+// socket with its generic 4002, and the client misread 4002 as a play-pass
+// eviction). These tests pin the contract: a '*' fallback is registered, it
+// never disconnects the client, it logs each unknown type once per session,
+// and the real eviction code stays clear of Colyseus's reserved codes.
+import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
+import { installUnknownMessageGuard, PLAY_PASS_EVICT_CODE } from '../multiplayer/src/room-compat.js';
+
+function fakeRoom() {
+ const handlers = {};
+ return { handlers, onMessage: (type, cb) => { handlers[type] = cb; } };
+}
+
+function fakeClient(sessionId) {
+ return { sessionId, leave: vi.fn(), error: vi.fn() };
+}
+
+describe('installUnknownMessageGuard', () => {
+ let warn;
+ beforeEach(() => { warn = vi.spyOn(console, 'warn').mockImplementation(() => {}); });
+ afterEach(() => { warn.mockRestore(); });
+
+ it("registers the '*' fallback Colyseus consults before its kill-the-connection default", () => {
+ const room = fakeRoom();
+ installUnknownMessageGuard(room, 'walk_world');
+ expect(typeof room.handlers['*']).toBe('function');
+ });
+
+ it('never disconnects or errors the client for an unknown type', () => {
+ const room = fakeRoom();
+ installUnknownMessageGuard(room, 'walk_world');
+ const client = fakeClient('abc');
+ room.handlers['*'](client, 'profileReq', {});
+ expect(client.leave).not.toHaveBeenCalled();
+ expect(client.error).not.toHaveBeenCalled();
+ });
+
+ it('logs each unknown type once per session, so a chatty skewed client cannot flood the logs', () => {
+ const room = fakeRoom();
+ installUnknownMessageGuard(room, 'walk_world');
+ const client = fakeClient('abc');
+ for (let i = 0; i < 5; i++) room.handlers['*'](client, 'profileReq', {});
+ room.handlers['*'](client, 'questReq', {});
+ expect(warn).toHaveBeenCalledTimes(2);
+ // A different session gets its own dedup ledger.
+ room.handlers['*'](fakeClient('other'), 'profileReq', {});
+ expect(warn).toHaveBeenCalledTimes(3);
+ });
+
+ it('caps per-session unknown-type logging at 16 distinct types', () => {
+ const room = fakeRoom();
+ installUnknownMessageGuard(room, 'walk_world');
+ const client = fakeClient('abc');
+ for (let i = 0; i < 40; i++) room.handlers['*'](client, `nope-${i}`, {});
+ expect(warn.mock.calls.length).toBeLessThanOrEqual(16);
+ });
+});
+
+describe('PLAY_PASS_EVICT_CODE', () => {
+ it("avoids Colyseus's reserved close codes — especially WS_CLOSE_WITH_ERROR (4002)", () => {
+ expect([1000, 4000, 4002, 4201, 4202]).not.toContain(PLAY_PASS_EVICT_CODE);
+ });
+});