Skip to content

room-node: fix CkptIndex wrap slot collision, zero caps, miss LRU bump, and clear clock - #443

Open
Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/ckpt-index-slot-wrap-and-zero-cap
Open

Pybsama wants to merge 1 commit into
Nehanth:mainfrom
Pybsama:fix/ckpt-index-slot-wrap-and-zero-cap

Conversation

@Pybsama

@Pybsama Pybsama commented Dec 4, 2026

Copy link
Copy Markdown

Problem

Four edge cases in packages/room-node/ckpt.js (CkptIndex) could corrupt or mismanage checkpoint slots:

  1. nextKey() wrapped (this.n % 65534) + 1 without checking whether the slot number was still live in this.ix.items. On a long-running host, wrapping past 65,534 reuses slot 1 and overwrites a still-pinned system prompt checkpoint (or a slot scheduled for eviction whose dp rides after sv).
  2. plan() clamped cap with Math.max(1, pin ? this.pins : this.answers). When pins === 0 (which roomnode.js explicitly configures for 1-slot Flash rooms via { answers: 1, pins: 0 }) or answers === 0, plan() still allocated and saved a slot, exceeding the room's checkpoint reserve.
  3. best(ids, reused) delegated to this.ix.best(ids), which bumped item.t = ++clock even when b.n <= reused caused CkptIndex.best() to reject the checkpoint and count a miss — keeping unused pinned checkpoints artificially fresh.
  4. clear() emptied this.ix.items without resetting GreedyDual clock this.L back to 0.

Changes

  • Skip currently indexed slot keys in CkptIndex.nextKey() (throwing if all 65,534 slots are simultaneously live).
  • Honor zero caps in CkptIndex.plan() by returning { skip: true, key: null } without dropping existing checkpoints or advancing this.L, and allocate key before advancing this.L.
  • Scan strict prefixes longer than reused directly in CkptIndex.best() so touch() only runs on actual hits.
  • Reset this.L = 0 in CkptIndex.clear().
  • Added regression tests in packages/room-node/test/ckpt_test.mjs.

Verification

  • node --check packages/room-node/ckpt.js packages/room-node/test/ckpt_test.mjs: OK
  • node --test packages/room-node/test/ckpt_test.mjs: 14 passed, 0 failed
  • npm run test:packages: 217 passed, 6 skipped, 0 failed
  • npm run test:runtime: PASS (6/6 checks, 172 frames)

@Pybsama
Pybsama requested a review from Nehanth as a code owner December 4, 2026 17:38
@vercel

vercel Bot commented Dec 4, 2026

Copy link
Copy Markdown

@Pybsama is attempting to deploy a commit to the nehanth's projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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