fix: marker_seen deletes commit with the wall change
A wall cause change (endpoint move, thickness/position, player_marker off, no longer window) committed the wall row in the FULL transaction while its marker_seen deletes rode the later NORMAL derived-memory transaction. A crash between them left the stale row, and restart restored the marker with the anchor recomputed from the NEW geometry, revealing a position the player never saw (DESIGN 5.8). updateWall now deletes the affected rows in the same FULL transaction as the replaced row, exactly as the composite FK cascade already does for wall.remove. The live del frames are unchanged and marker inserts stay in the derived transaction: wall+deletes commit, derived inserts, then ack. The marker cause signature moves to world.markerSig so the write-time delete and the online retraction cannot drift. Proof: a leakfault-only markerCrash hook quits between the wall commit and the derived write; tools/markers.test.mjs covers all four causes and restarts on a clean build, asserting no marker for the changed wall (no new anchor) and restoring the untouched window's marker as the positive control. Ref #60
This commit is contained in:
@@ -394,3 +394,98 @@ test('marker retraction is durable: delete and cascade survive a restart (#60)',
|
||||
fs.rmSync(stateDir, { recursive: true, force: true })
|
||||
}
|
||||
})
|
||||
|
||||
// -------------------------------------------------------------------------------------------------
|
||||
// #60 leak fix: a cause change and its `marker_seen` deletes are one commit.
|
||||
//
|
||||
// The bug: `wall.update` committed the wall row in its FULL transaction, but the retraction deletes
|
||||
// rode the later NORMAL derived-memory transaction. A crash in between left the stale row; on
|
||||
// restart `markers.restore` recomputed the anchor from the NEW wall, so a player who never saw the
|
||||
// new geometry got it handed to them in the full marker set. The fix puts the deletes in the wall
|
||||
// transaction, exactly as the FK cascade already does for `wall.remove`.
|
||||
//
|
||||
// The `LEAK_FAULT=markerCrash` hook (a `-d:leakfault` build only, never shipped) quits the process
|
||||
// immediately after the wall commit and before the derived write. Each case then restarts on a clean
|
||||
// build: the changed wall's old marker must not come back, while an untouched window's marker must
|
||||
// be restored unchanged (the positive control, so the harness can fail).
|
||||
async function waitProcessExit(handle, timeoutMs = 5000) {
|
||||
const deadline = Date.now() + timeoutMs
|
||||
while (handle.child.exitCode === null && handle.child.signalCode === null &&
|
||||
Date.now() < deadline) {
|
||||
await sleep(20)
|
||||
}
|
||||
assert.ok(handle.child.exitCode !== null || handle.child.signalCode !== null,
|
||||
'the markerCrash fault did not kill the server')
|
||||
}
|
||||
|
||||
async function markerCrashCase({ cause, patch, newAnchor, reEarns }) {
|
||||
const stateDir = makeStateDir()
|
||||
const gmKey = gmKeyOf(stateDir)
|
||||
let alice
|
||||
let s = await startServer({ stateDir, defines: ['leakfault'],
|
||||
env: { LEAK_FAULT: 'markerCrash' } })
|
||||
let winMarker
|
||||
let keepMarker
|
||||
try {
|
||||
const gm = await gmConnect(s.origin, gmKey)
|
||||
// Two marked windows in the subject's sight: one is edited into a cause change, the other is
|
||||
// untouched and is the positive control across the restart.
|
||||
const changed = await addWall(gm, { preset: 'window', a: [200, 500], b: [200, 700] })
|
||||
await addWall(gm, { preset: 'window', a: [400, 300], b: [400, 400] })
|
||||
alice = await namedPlayer(gm, s.origin, `Crash ${cause}`)
|
||||
await addSightToken(gm, alice, [300, 320])
|
||||
const seen = await alice.conn.ws.waitFor(m => m.t === 'marker' && m.set.length === 2)
|
||||
winMarker = seen.set.find(e => e.pos[0] === 200).id
|
||||
keepMarker = seen.set.find(e => e.pos[0] === 400).id
|
||||
|
||||
// Fire the wall write by hand (no awaited ack): the fault kills the process inside the handler,
|
||||
// after the wall+delete commit and before the derived transaction that used to carry the delete.
|
||||
gm.ws.sendText(JSON.stringify({ t: 'wall.update', scene: gm.scene, id: changed.id,
|
||||
...patch, reqId: 9001 }))
|
||||
await waitProcessExit(s)
|
||||
assert.equal(alice.conn.ws.messages.some(m => m.t === 'marker' &&
|
||||
(m.del ?? []).includes(winMarker)), false,
|
||||
`${cause}: the process died before the live del was sent`)
|
||||
} finally {
|
||||
try { alice.conn.ws.close() } catch {}
|
||||
await stopServer(s)
|
||||
}
|
||||
|
||||
s = await startServer({ stateDir })
|
||||
try {
|
||||
const again = await openAs(s.origin, alice.key)
|
||||
await again.ws.waitText('hello')
|
||||
const full = await again.ws.waitFor(m => m.t === 'marker' && m.full === true)
|
||||
const kept = full.set.find(e => e.pos[0] === 400 && e.pos[1] === 350)
|
||||
assert.equal(kept?.id, keepMarker,
|
||||
`${cause}: positive control, the untouched window's marker is restored with the same id`)
|
||||
assert.equal(full.set.some(e => e.id === winMarker), false,
|
||||
`${cause}: a restart never restores a marker whose wall cause changed`)
|
||||
if (newAnchor) {
|
||||
assert.equal(full.set.some(e => e.pos[0] === newAnchor[0] && e.pos[1] === newAnchor[1]), false,
|
||||
`${cause}: the player never receives the changed wall's new anchor`)
|
||||
}
|
||||
if (reEarns) {
|
||||
const fresh = full.set.find(e => !(e.pos[0] === 400 && e.pos[1] === 350))
|
||||
assert.ok(fresh, `${cause}: the still-visible wall is re-earned only through the normal gate`)
|
||||
assert.notEqual(fresh.id, winMarker, `${cause}: a re-earned marker gets a fresh id`)
|
||||
}
|
||||
again.ws.close()
|
||||
} finally {
|
||||
await stopServer(s)
|
||||
fs.rmSync(stateDir, { recursive: true, force: true })
|
||||
}
|
||||
}
|
||||
|
||||
test('marker cause change and deletes are one commit: a crash before the derived write (#60)',
|
||||
async t => {
|
||||
await t.test('endpoint move', () => markerCrashCase({
|
||||
cause: 'endpoint move', patch: { a: [1000, 1000], b: [1000, 1200] }, newAnchor: [1000, 1100],
|
||||
reEarns: false }))
|
||||
await t.test('thickness', () => markerCrashCase({
|
||||
cause: 'thickness', patch: { thickness: 7 }, reEarns: true }))
|
||||
await t.test('player_marker off', () => markerCrashCase({
|
||||
cause: 'player_marker off', patch: { player_marker: false }, reEarns: false }))
|
||||
await t.test('no longer a window', () => markerCrashCase({
|
||||
cause: 'no longer a window', patch: { blocks_sight: true }, reEarns: false }))
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user