commit 309b9af3f77c050650fa0e5e2fa10c5da7531c8f
parent b2aca981600b7b9f29ed657a2fb768db7f26259d
Author: anon <anon@example.com>
Date: Tue, 3 Nov 2026 10:06:33 +0000
Retain bounded death and resurrection evidence in browser traces
Diffstat:
5 files changed, 102 insertions(+), 4 deletions(-)
diff --git a/DEVELOPERS.md b/DEVELOPERS.md
@@ -641,7 +641,13 @@ deduplicates transport replay across reconnects. A received packet is evidence
of receipt, not that native activation or server acceptance succeeded. Check the
resulting client state and, for significant transactions, independent server
state or persistence. The report retains 2048 events and 32 snapshots; `dropped`
-reports overwritten events. Save intermediate reports for long scenarios.
+reports overwritten events. Its separate `lifecycle` history keeps the latest
+64 CharacterAction99/152 and Resurrect packets, including their original actor,
+direction, navigation, stream, sequence and payload. `lifecycleDropped` reports
+overwritten lifecycle markers independently. Use that history when a large world
+replay evicts death/return evidence from `events`; save intermediate reports for
+long scenarios. Run `node tools/client/test_game_trace.mjs` for the bounded
+retention regression.
Extend the C snapshot at `client/runtime/browser_testing.c` when a new scenario
needs another native field. Keep object traversal on the game-owning thread;
diff --git a/TODO.md b/TODO.md
@@ -3510,7 +3510,7 @@ with payloads and known client/server provenance.
original pixels and retain earned progress/items without browser errors.
See icon provenance and
`local/favicon/native-20261102-004223/verified.json`.
-- [ ] [P1] Retain selected lifecycle evidence across large native world replays.
+- [x] [P1] Retain selected lifecycle evidence across large native world replays.
Check: death/resurrection markers, including CharacterAction152 and Resurrect,
survive ordinary trace rollover while memory remains bounded. The connected
level-2 run records native HP0 and automatic same-page return with conserved
@@ -3518,6 +3518,15 @@ with payloads and known client/server provenance.
The retained history starts after death; the resurrection sequence is no longer
in that bounded trace. Keep this evidence gap separate from a missing game
transition or native error. Captures: `local/todo-progression-play/runtime-level6/`.
+ The harness now retains the latest 64 CharacterAction99/152 and Resurrect
+ packets separately, with original context and an independent overwrite count.
+ Three Node regressions cover ordinary rollover, marker bounds and unrelated
+ inputs. A short controlled WASM death/reclaim and cold-recovery check retains
+ all three real markers after 2050 tagged synthetic trace records evict them
+ from ordinary history. All nine saved native reports are clean. This fixes
+ future capture; it cannot recover the old missing events. See
+ [browser tracing](DEVELOPERS.md#browser-game-testing) and
+ `local/lifecycle-trace/verification.json`.
- [x] [P1] Record visible inventory grid cells and scroll offset in browser
snapshots. Check: missing-icon audits identify the actual displayed cells and
verify coverage of every row rather than infer visual order from logical
diff --git a/tools/client/game_test.mjs b/tools/client/game_test.mjs
@@ -31,6 +31,8 @@ export class PacketStream {
export class GameTest {
events = [];
+ lifecycle = [];
+ lifecycleDropped = 0;
inputEvents = new EventEmitter();
errors = [];
snapshots = [];
@@ -108,6 +110,15 @@ export class GameTest {
this.readyActors.add(event.actor[1]);
const recorded = {time: Date.now(), navigation: this.navigation, ...event, sequence: ++this.sequence};
this.events.push(recorded);
+ // Preserve death, return requests and resurrection across large world replays.
+ if (event.kind === 'packet') {
+ const action = event.opcode === '5e477770' && event.hex.length >= 66 ?
+ Buffer.from(event.hex, 'hex').readUInt32BE(29) : 0;
+ if (event.opcode === '445f2a0b' || action === 99 || action === 152) {
+ this.lifecycle.push(recorded);
+ if (this.lifecycle.length > 64) { this.lifecycle.shift(); ++this.lifecycleDropped; }
+ }
+ }
if (event.kind === 'error') this.errors.push(recorded);
if (this.events.length > 2048) { this.events.shift(); ++this.dropped; }
if (event.kind === 'error' || event.kind === 'input' && event.stage === 'consumed')
@@ -325,7 +336,8 @@ export class GameTest {
async save(directory) {
await fs.mkdir(directory, {recursive: true});
await fs.writeFile(`${directory}/trace.json`, JSON.stringify({url: this.page.url(),
- dropped: this.dropped, errors: this.errors, events: this.events, snapshots: this.snapshots}, null, 2) + '\n');
+ dropped: this.dropped, lifecycleDropped: this.lifecycleDropped, lifecycle: this.lifecycle,
+ errors: this.errors, events: this.events, snapshots: this.snapshots}, null, 2) + '\n');
await this.page.screenshot({path: `${directory}/screen.png`});
}
}
diff --git a/tools/client/test_game_trace.mjs b/tools/client/test_game_trace.mjs
@@ -0,0 +1,56 @@
+import assert from 'node:assert/strict';
+import {test} from 'node:test';
+import {GameTest} from './game_test.mjs';
+
+function packet(opcode, action) {
+ const bytes = Buffer.alloc(49);
+ bytes.writeUInt32BE(parseInt(opcode, 16), 16);
+ bytes.writeUInt32BE(50000, 20);
+ bytes.writeUInt32BE(1, 24);
+ bytes.writeUInt32BE(action, 29);
+ return {kind: 'packet', direction: 'framereceived', actor: [50000, 1],
+ navigation: 1, stream: 'first', opcode, hex: bytes.toString('hex')};
+}
+
+test('death and resurrection survive ordinary trace rollover with their context', () => {
+ const game = new GameTest();
+ game.record(packet('5e477770', 99));
+ game.record({...packet('5e477770', 152), direction: 'framesent'});
+ game.record(packet('445f2a0b', 1));
+ const critical = [...game.events];
+
+ game.navigation = 2;
+ for (let index = 0; index < 3000; ++index) game.record({kind: 'position', position: [index, 0, 0]});
+
+ assert.deepEqual(game.lifecycle, critical);
+ assert.equal(game.lifecycleDropped, 0);
+ assert.equal(game.events.length, 2048);
+ assert.equal(game.events[0].sequence, 956);
+ assert.equal(game.dropped, 955);
+});
+
+test('lifecycle retention remains bounded and reports its own overwritten markers', () => {
+ const game = new GameTest();
+
+ for (let index = 0; index < 70; ++index) game.record(packet('5e477770', 99));
+
+ assert.equal(game.lifecycle.length, 64);
+ assert.equal(game.lifecycle[0].sequence, 7);
+ assert.equal(game.lifecycle[63].sequence, 70);
+ assert.equal(game.lifecycleDropped, 6);
+ assert.equal(game.events.length, 70);
+ assert.equal(game.dropped, 0);
+});
+
+test('unrelated actions and incomplete packets do not fill lifecycle retention', () => {
+ const game = new GameTest();
+
+ game.record(packet('5e477770', 3));
+ game.record(packet('46002f16', 99));
+ game.record({...packet('5e477770', 99), hex: '00'});
+
+ assert.deepEqual(game.lifecycle, []);
+ assert.equal(game.lifecycleDropped, 0);
+ assert.equal(game.events.length, 3);
+ assert.deepEqual(game.errors, []);
+});
diff --git a/tools/client/test_reclaim_weapon.mjs b/tools/client/test_reclaim_weapon.mjs
@@ -28,7 +28,7 @@ try {
const sequence = game.sequence;
assert.equal((await page.request.post(url + '/test-fatal-hit')).status(), 204);
await game.wait('same-playfield death return', snapshot => snapshot.localId === 1 && game.local(snapshot)?.stats[27] === 1 &&
- game.local(snapshot)?.inventory.length === 0 && game.events.some(event => event.sequence > sequence &&
+ game.local(snapshot)?.inventory.length === 0 && game.lifecycle.some(event => event.sequence > sequence &&
event.direction === 'framesent' && event.opcode === '5e477770' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 152), 30000);
await game.ready();
const dead = await state();
@@ -90,6 +90,21 @@ try {
assert.equal(stats.get(26), 13);
await game.key('KeyU');
await game.save(output + '/psychic');
+ if (phase === 'live') {
+ const lifecycle = game.lifecycle.filter(event => event.actor?.[1] === 1);
+ assert.deepEqual(lifecycle.map(event => [event.direction, event.opcode,
+ Buffer.from(event.hex, 'hex').readUInt32BE(29)]), [
+ ['framereceived', '5e477770', 99], ['framesent', '5e477770', 152], ['framereceived', '445f2a0b', 1],
+ ]);
+
+ // Controlled trace load isolates rollover from another gameplay replay.
+ for (let index = 0; index < 2050; ++index) game.record({kind: 'fixture-replay', index});
+ assert.equal(game.events.length, 2048);
+ assert(game.events.every(event => event.sequence > lifecycle[2].sequence));
+ assert.deepEqual(game.lifecycle, lifecycle);
+ assert.equal(game.lifecycleDropped, 0);
+ await game.save(output + '/lifecycle-rollover');
+ }
assert.equal(game.errors.length, 0);
console.log('PASS:', phase, 'reclaimed weapon, ammunition, recovered stats and exactly-once Psychic bonus');
} finally {