1
0
Fork 0

fix(minigames): end Bomperator WS jitter with ack-sized envelope and rate-limited trims

Prod telemetry (bompDebug, 783 snapshots): ping RTT of 3-24ms shrank the
correction envelope to ~0.75 cells while the real gap noise floor sat at
p95 1.0, so 13% of snapshots trimmed and each trim closed its whole
excess in one frame - constant micro-teleports.

- size the envelope from transport RTT plus the server-side component of
  measured input-to-ack latency (tick queue + snapshot turnaround),
  which ping/pong cannot see; HTTP behavior stays near the v0.12.6 tuning
- rate-limit trims to 0.35 cells per snapshot (a run-speed glide); the
  >2.5-cell ease branch remains the fallback for genuine divergence
- harness mirror updated: maxJump now capped at 0.35 across all 12
  scenarios, prod-trace pulls 162 -> 47, zero teleports throughout
This commit is contained in:
Jason Fraley 2026-10-20 02:02:00 -04:00
parent 1883a1aabe
commit d15beb8e35
2 changed files with 49 additions and 11 deletions

View file

@ -455,6 +455,16 @@ export function BomperatorGame({
const lastAckedDirRef = useRef<Dir | null>(null);
const lastVersionSeenRef = useRef(-1);
const rttAvgRef = useRef(100);
/**
* Input-to-ack latency EMA: measured from send time until the server's
* snapshot confirms the input. Unlike the transport RTT (ping/pong on WS,
* POST timing on HTTP), it includes the server tick queue and snapshot
* turnaround - the full loop delay prediction must tolerate. The envelope
* sizes itself from this; production telemetry showed ping-only RTT (3-24ms)
* shrinking the envelope below the natural gap noise floor, so ~13% of
* snapshots trimmed and each trim read as a micro-teleport.
*/
const ackLatRef = useRef(100);
const dbgRef = useRef<{ ring: DbgRow[]; lastAt: number; remoteSnaps: number; lastRs: number } | null>(
null,
);
@ -774,6 +784,9 @@ export function BomperatorGame({
while (pending.length > 0) {
const head = pending[0];
if (!head || head.seq > ack) break;
// Sample input-to-ack latency for the envelope (see ackLatRef).
const lat = now - head.sentAt;
if (lat > 0 && lat < 2000) ackLatRef.current = ackLatRef.current * 0.8 + lat * 0.2;
ackedDir = head.dir;
pending.shift();
}
@ -820,16 +833,23 @@ export function BomperatorGame({
// unattended past the snap threshold and discharged as the
// reported "teleported back to where the server saw me". Now:
// gaps inside the envelope ride untouched, anything beyond is
// trimmed a little on EVERY snapshot, and even large gaps close
// at a capped rate (2.5x run speed) instead of teleporting.
// Verified against the recorded production latency trace plus
// server-stall replay in tests/int/bomperator-prediction.int.
// spec.ts: zero corrections over 1.5 cells (old policy: instant
// 2.6-cell jumps). Round resets still snap via the ack-backwards
// branch.
// trimmed toward the envelope on EVERY snapshot, and even large
// gaps close at a capped rate (2.5x run speed) instead of
// teleporting. Verified against the recorded production latency
// trace plus server-stall replay in tests/int/bomperator-prediction.
// int.spec.ts. Round resets still snap via the ack-backwards branch.
// Sizing uses transport RTT plus the SERVER-SIDE component of
// the measured input-to-ack loop (tick queue + snapshot
// turnaround), which ping/pong RTT does not see: prod telemetry
// over the WS arena showed ping RTT (3-24ms) understating the
// real input->effect delay, so the envelope sat below the
// natural gap noise floor (p95 1.0 cells) and every held run
// trimmed visibly. On HTTP the ack loop minus POST RTT is just
// the snapshot wait, so this stays near the v0.12.6 tuning.
const rttEnv = Math.min(300, Math.max(rtt, ackLatRef.current - rtt));
const envelope = Math.max(
PRED_DEADZONE,
(me.speed * (rtt / 2 + TICK_MS / 2 + PRED_ENVELOPE_BUDGET_MS)) / 1000,
(me.speed * (rttEnv / 2 + TICK_MS / 2 + PRED_ENVELOPE_BUDGET_MS)) / 1000,
);
if (gap > 2.5) {
const maxStep = (me.speed * 2.5 * dtMs) / 1000;
@ -838,7 +858,14 @@ export function BomperatorGame({
pred.y += (est.y - pred.y) * easeT;
facingRef.current = facing;
} else if (gap > envelope) {
const k = Math.min(gap - envelope, gap * 0.5) / gap;
// Rate-limited trim: close at most 0.35 cells per snapshot
// (~7 cells/s at 20Hz, i.e. a run-speed glide, not a jump).
// The old policy closed the whole excess in one frame; once
// trims got frequent on the WS arena that read as constant
// micro-teleports (the reported jitter), and slower
// proportional convergence let sustained divergence stack
// past the ease threshold in trace replay.
const k = Math.min(gap - envelope, 0.35) / gap;
pred.x += (est.x - pred.x) * k;
pred.y += (est.y - pred.y) * k;
}

View file

@ -251,6 +251,9 @@ function runScenario(cfg: ScenarioConfig): Telemetry {
let lastAck = 0;
let lastAckedDir: Dir | null = null;
let rttAvg = cfg.rttTrueMs;
// Mirror of ackLatRef: input-to-ack latency EMA (includes the tick queue
// and snapshot turnaround); sizes the correction envelope.
let ackLat = cfg.rttTrueMs;
let clientView: SimSnapshot | null = null;
let lastVersionSeen = -1;
let seqCounter = 0;
@ -520,6 +523,8 @@ function runScenario(cfg: ScenarioConfig): Telemetry {
while (pending.length > 0) {
const head = pending[0];
if (!head || head.seq > ack) break;
const lat = now - head.sentAt;
if (lat > 0 && lat < 2000) ackLat = ackLat * 0.8 + lat * 0.2;
ackedDir = head.dir;
pending.shift();
}
@ -554,9 +559,10 @@ function runScenario(cfg: ScenarioConfig): Telemetry {
// lead, tick quantization, estimator error) ride inside the envelope
// untouched; anything beyond is genuine divergence, corrected a little
// on EVERY snapshot so offsets can never stack into a teleport.
const rttEnv = Math.min(300, Math.max(rttAvg, ackLat - rttAvg));
const envelope = Math.max(
PRED_DEADZONE,
(me.speed * (rttAvg / 2 + TICK_MS / 2 + PRED_ENVELOPE_BUDGET_MS)) / 1000,
(me.speed * (rttEnv / 2 + TICK_MS / 2 + PRED_ENVELOPE_BUDGET_MS)) / 1000,
);
const predBefore = { x: pred.x, y: pred.y };
if (gap > 2.5) {
@ -589,7 +595,12 @@ function runScenario(cfg: ScenarioConfig): Telemetry {
: gap > envelope
) {
const floor = cfg.policy === "v123" ? PRED_DEADZONE : envelope;
const k = Math.min(gap - floor, gap * 0.5) / gap;
// v123: instant close to floor. Envelope policy: rate-limited trim
// (max 0.35 cells per snapshot, a glide not a jump).
const k =
cfg.policy === "v123"
? Math.min(gap - floor, gap * 0.5) / gap
: Math.min(gap - floor, 0.35) / gap;
pred.x += (est.x - pred.x) * k;
pred.y += (est.y - pred.y) * k;
tel.pulls += 1;