commit 35fe5017198af83d82bb659b834a1ccfce79b160
parent 5ccec218b92c5e687fcc66779513f73e854e9214
Author: anon <anon@example.com>
Date: Wed, 4 Nov 2026 16:44:55 +0000
Correct stale carried deposits during unrelated equipment
Diffstat:
6 files changed, 145 insertions(+), 69 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -4389,6 +4389,10 @@ and server restarts. Turn every reproduced bug into a focused regression test.
and unchanged pending equipment. A 17-second WASM check recovers the exact
loaded pistol from its earlier destination, retries on the same page and
retains all three IDs/three rounds through page replay and cold Go loading.
+ A second controlled reproduction now covers an unrelated pending equip:
+ backpack/bank deposits clear only the empty row, protect the admitted slots
+ and preserve its deadline. The 18-second WASM check completes the original axe
+ wear, recovers/retries the loaded pistol and retains all four exact instances.
This controlled checkpoint leaves the broader disappearance audit open; see
[stale carried deposits](docs/backpacks.md#stale-carried-deposit-sources).
- [x] [P0] Preserve selected-quality stack contracts after a refused split.
diff --git a/docs/backpacks.md b/docs/backpacks.md
@@ -341,9 +341,10 @@ An earlier committed transfer can leave an old carried icon visible while its
ordinary source row is empty on the server. Backpack and bank deposits shared
a silent return for that case. Real native pickup/place then hid the icon and
left its cell marked dummy, even though the physical item remained owned in
-another container. A current living session without pending equipment now
+another container. A current living session now
receives CharacterAction146 followed by CharacterAction112 for only that empty
-page104 row. This reuses the native GUI correction described under
+page104 row, including during unrelated pending equipment. The admitted move's
+own source and destination stay protected. This reuses the correction under
[stale carried moves](inventory.md#stale-carried-move-sources). The refusal sends
no successful transfer, changes no container session and performs no ownership
writes or item allocation.
@@ -351,16 +352,20 @@ writes or item allocation.
`TestStaleCarriedContainerDepositClearsOnlyEmptySource` uses public opening and
transfer handlers before repeating the stale deposit into a backpack or bank.
It checks both carried boundaries, ordered repeated replies, exact cold
-ownership, unchanged sessions and zero checkpoint writes. Its companion keeps
-invalid source rows ignored and preserves a real pending equipment move and
-deadline.
+ownership, unchanged sessions and zero checkpoint writes. Idle, pending wear
+and pending removal cases retain the original move/deadline and finish with
+every instance cold-owned. Its companion keeps invalid source rows and a real
+pending removal's empty destination untouched.
`TestBrowserStaleCarriedContainerDeposit` commits an earlier transfer of a loaded
-QL2 pistol into a second bag without publishing the carried removal. Real native
-pickup/place reproduces the missing reply. Correction clears the empty row;
-the same page opens the second bag, withdraws that exact pistol and deposits it
+QL2 pistol into a second bag without publishing the carried removal, then holds
+an unrelated real axe wear request past the native animation. Real native
+pickup/place reproduces the missing reply during that pending move. Correction
+clears the empty row without changing the axe's identity, destination or deadline.
+The original wear completes before the same page opens the second bag,
+withdraws that exact pistol and deposits it
into the first bag. Page replay retains usable contents, and a fresh Go database
-reader retains both bags, the pistol's selected endpoints and its three rounds.
+reader retains both bags, the worn axe, the pistol's endpoints and three rounds.
This is controlled missed-publication evidence, separate from earned progression
and the original server's unrecovered refusal policy. Captures and checks are
retained under `local/stale-container-deposit/`; the broader disappearance audit
@@ -369,6 +374,8 @@ The native baseline fails in 22.51 seconds; the fixed check passes in 16.69.
Related Go checks pass 12 roots and 44 results both normally and under the race
detector. Vet and driver syntax checks pass. The independent packet, snapshot
and ledger report is `local/stale-container-deposit/verification.json`.
+The pending-deposit baseline fails in 21.21 seconds; the corrected scenario passes
+in 18.30. Its evidence and independent report are in `local/pending-stale-deposit/`.
## Verification
diff --git a/server/backpacks.go b/server/backpacks.go
@@ -229,7 +229,7 @@ func (server *server) moveContainerItem_locked(client *worldClient, body []byte)
index := slices.IndexFunc(items, func(item ownedItem) bool { return item.Slot == sourceSlot })
if index < 0 {
// Cancel a stale carried deposit before clearing only its empty source row.
- if sourcePage == 104 && client.equipment == nil {
+ if sourcePage == 104 && (client.equipment == nil || sourceSlot != client.equipment.source && sourceSlot != client.equipment.destination) {
for _, action := range []uint32{146, 112} {
if err := client.send(characterActionPacket(client.id, [5]uint32{action, 104, sourceSlot})); err != nil {
return err
diff --git a/server/browser_stale_container_deposit_test.go b/server/browser_stale_container_deposit_test.go
@@ -27,15 +27,17 @@ func TestBrowserStaleCarriedContainerDeposit(t *testing.T) {
output := filepath.Join(root, "local/stale-container-deposit", time.Now().Format("20060102-150405"))
world := newTestServer(t)
player := world.newCharacter()
+ player.level = 2
player.playfield, player.position = 1183, [3]float32{193.79826, 5.01, 136.83983}
player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("stale-container-deposit")))
if err := world.saveUser_locked(player); err != nil {
t.Fatal(err)
}
- inventory := playerInventory{LastID: 3, Items: []ownedItem{
+ inventory := playerInventory{LastID: 4, Items: []ownedItem{
{ID: 1, Type: 51017, Template: 99228, Quality: 1, Slot: 64, Count: 1},
{ID: 2, Type: 51017, Template: 99228, Quality: 1, Slot: 65, Count: 1},
- {ID: 3, Type: 51018, Template: 123742, Quality: 2, Slot: 66, Count: 1, Ammo: 3}}}
+ {ID: 3, Type: 51018, Template: 123742, Quality: 2, Slot: 66, Count: 1, Ammo: 3},
+ {ID: 4, Type: 51018, Template: 209283, Quality: 1, Slot: 67, Count: 1}}}
if err := world.saveInventory_locked(player, inventory); err != nil {
t.Fatal(err)
}
@@ -44,7 +46,12 @@ func TestBrowserStaleCarriedContainerDeposit(t *testing.T) {
mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) {
world.mutex.Lock()
defer world.mutex.Unlock()
- json.NewEncoder(w).Encode(player.inventory)
+ var pending any
+ if client := world.clients[1]; client != nil && client.equipment != nil {
+ pending = map[string]any{"itemID": client.equipment.itemID, "source": client.equipment.source,
+ "destination": client.equipment.destination, "readyAt": client.equipment.readyAt}
+ }
+ json.NewEncoder(w).Encode(map[string]any{"inventory": player.inventory, "pending": pending})
})
// Commit an earlier transfer without publishing the carried source removal.
mux.HandleFunc("POST /test-stale-view", func(w http.ResponseWriter, r *http.Request) {
@@ -55,13 +62,19 @@ func TestBrowserStaleCarriedContainerDeposit(t *testing.T) {
inventory := player.inventory
item := inventory.Items[2]
item.Slot = 0
- inventory.Items = slices.Clone(inventory.Items[:2])
+ inventory.Items = append(slices.Clone(inventory.Items[:2]), inventory.Items[3])
inventory.Containers = map[uint32][]ownedItem{2: {item}}
if err := world.saveInventory_locked(player, inventory); err != nil {
t.Error(err)
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
+ mux.HandleFunc("POST /test-complete", func(w http.ResponseWriter, r *http.Request) {
+ world.mutex.Lock()
+ finish := world.clients[1].equipment.readyAt
+ world.mutex.Unlock()
+ world.advanceEquipment(finish)
+ })
host := httptest.NewServer(mux)
t.Cleanup(host.Close)
closeTestBrowserStreams(t, world)
@@ -77,7 +90,8 @@ func TestBrowserStaleCarriedContainerDeposit(t *testing.T) {
t.Fatal(err)
}
cold := newTestInventoryServer(t).characters[1].inventory
- if !reflect.DeepEqual(player.inventory, cold) || world.nextItem != 3 || len(cold.Items) != 2 || len(cold.Containers) != 1 ||
+ if !reflect.DeepEqual(player.inventory, cold) || world.nextItem != 4 || len(cold.Items) != 3 || len(cold.Containers) != 1 ||
+ cold.Items[2] != (ownedItem{ID: 4, Type: 51018, Template: 209283, Quality: 1, Slot: 6, Count: 1}) ||
!slices.Equal(cold.Containers[1], []ownedItem{{ID: 3, Type: 51018, Template: 123742, Quality: 2, Slot: 0, Count: 1, Ammo: 3}}) {
t.Fatal("stale carried deposit/retry lost a physical instance or loaded rounds")
}
diff --git a/server/stale_container_deposit_test.go b/server/stale_container_deposit_test.go
@@ -12,65 +12,99 @@ import (
func TestStaleCarriedContainerDepositClearsOnlyEmptySource(t *testing.T) {
for _, destination := range []uint32{51017, 57005} {
for _, source := range []uint32{64, 93} {
- t.Run(fmt.Sprintf("%d/%d", destination, source), func(t *testing.T) {
- world, output := newBankWorld(t)
- player, client := world.characters[1], world.clients[1]
- inventory := player.inventory
- inventory.Items = slices.Clone(inventory.Items)
- inventory.Items[0].Slot, inventory.Items[4].Slot = 68, source
- if err := world.saveInventory_locked(player, inventory); err != nil {
- t.Fatal(err)
- }
- for index, slot := range []uint32{66, 67} {
- if err := world.handleOwnedItemUse(client, backpackUseRequest(1, slot, uint32(index+2))[20:]); err != nil {
+ for _, phase := range []string{"idle", "wear", "removal"} {
+ t.Run(fmt.Sprintf("%d/%d/%s", destination, source, phase), func(t *testing.T) {
+ world, output := newBankWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ if granted, err := world.grantItem_locked(player, 209283); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ inventory := player.inventory
+ inventory.Items = slices.Clone(inventory.Items)
+ inventory.Items[0].Slot, inventory.Items[4].Slot = 68, source
+ if err := world.saveInventory_locked(player, inventory); err != nil {
t.Fatal(err)
}
- }
- if err := world.handleInventory(client, backpackMoveRequest(104, source, 51017, 4, 111)[20:]); err != nil {
- t.Fatal(err)
- }
- target := uint32(3)
- if destination == 57005 {
- target = 1
- }
- before, err := readTestItemStore(world)
- if err != nil {
- t.Fatal(err)
- }
- handles, bank, inventory := maps.Clone(client.backpacks), *client.bank, player.inventory
- auditCheckpointWrites(t, world)
- output.packets = nil
-
- for range 2 {
- if err := world.handleInventory(client, backpackMoveRequest(104, source, destination, target, 111)[20:]); err != nil {
+ for index, slot := range []uint32{66, 67} {
+ if err := world.handleOwnedItemUse(client, backpackUseRequest(1, slot, uint32(index+2))[20:]); err != nil {
+ t.Fatal(err)
+ }
+ }
+ if err := world.handleInventory(client, backpackMoveRequest(104, source, 51017, 4, 111)[20:]); err != nil {
t.Fatal(err)
}
- }
- after, err := readTestItemStore(world)
- cold := newTestInventoryServer(t)
+ target := uint32(3)
+ if destination == 57005 {
+ target = 1
+ }
+ var pending equipmentMove
+ if phase != "idle" {
+ if err := world.handleInventory(client, inventoryMovePacket(1, 69, 6)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("fixture axe wear did not begin", err)
+ }
+ if phase == "removal" {
+ world.advanceEquipment(client.equipment.readyAt)
+ if err := world.handleInventory(client, itemMovePacket(1, 6, 69)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("fixture axe removal did not begin", err)
+ }
+ }
+ pending = *client.equipment
+ }
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ handles, bank, inventory := maps.Clone(client.backpacks), *client.bank, player.inventory
+ auditCheckpointWrites(t, world)
+ output.packets = nil
- if err != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 ||
- !reflect.DeepEqual(player.inventory, inventory) || !reflect.DeepEqual(cold.characters[1].inventory, inventory) ||
- !reflect.DeepEqual(client.backpacks, handles) || *client.bank != bank || client.equipment != nil || world.nextItem != 5 || cold.nextItem != 5 {
- t.Fatal("stale carried deposit changed ownership, allocation or container sessions", err)
- }
- var expected [][]byte
- for range 2 {
- for _, action := range []uint32{146, 112} {
- expected = append(expected, targetPacket(characterActionPacket(1, [5]uint32{action, 104, source})))
+ for range 2 {
+ if err := world.handleInventory(client, backpackMoveRequest(104, source, destination, target, 111)[20:]); err != nil {
+ t.Fatal(err)
+ }
}
- }
- if !reflect.DeepEqual(output.packets, expected) {
- t.Fatalf("stale carried deposit needs cancellation then only its empty row cleared: got %d replies", len(output.packets))
- }
- })
+ after, err := readTestItemStore(world)
+ cold := newTestInventoryServer(t)
+
+ if err != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 ||
+ !reflect.DeepEqual(player.inventory, inventory) || !reflect.DeepEqual(cold.characters[1].inventory, inventory) ||
+ !reflect.DeepEqual(client.backpacks, handles) || *client.bank != bank ||
+ (phase != "idle") != (client.equipment != nil) || client.equipment != nil && *client.equipment != pending ||
+ world.nextItem != 6 || cold.nextItem != 6 {
+ t.Fatal("stale carried deposit changed ownership, allocation or container sessions", err)
+ }
+ var expected [][]byte
+ for range 2 {
+ for _, action := range []uint32{146, 112} {
+ expected = append(expected, targetPacket(characterActionPacket(1, [5]uint32{action, 104, source})))
+ }
+ }
+ if !reflect.DeepEqual(output.packets, expected) {
+ t.Fatalf("stale carried deposit needs cancellation then only its empty row cleared: got %d replies", len(output.packets))
+ }
+ if phase != "idle" {
+ world.advanceEquipment(pending.readyAt)
+ expected := inventory
+ expected.Items = slices.Clone(inventory.Items)
+ expected.Items[4].Slot = 6
+ if phase == "removal" {
+ expected.Items[4].Slot = 69
+ }
+ cold = newTestInventoryServer(t)
+ if client.equipment != nil || !reflect.DeepEqual(player.inventory, expected) ||
+ !reflect.DeepEqual(cold.characters[1].inventory, expected) {
+ t.Fatal("original equipment completion lost a retained item")
+ }
+ }
+ })
+ }
}
}
}
func TestStaleCarriedContainerDepositIgnoresInvalidOrPendingSources(t *testing.T) {
for _, destination := range []uint32{51017, 57005} {
- for _, scenario := range []string{"below carried range", "above carried range", "pending equipment"} {
+ for _, scenario := range []string{"below carried range", "above carried range", "pending destination"} {
t.Run(fmt.Sprintf("%d/%s", destination, scenario), func(t *testing.T) {
world, output := newBankWorld(t)
client := world.clients[1]
@@ -89,10 +123,14 @@ func TestStaleCarriedContainerDepositIgnoresInvalidOrPendingSources(t *testing.T
source = 63
case "above carried range":
source = 94
- case "pending equipment":
+ case "pending destination":
if err := world.handleInventory(client, inventoryMovePacket(1, 68, 6)[20:]); err != nil || client.equipment == nil {
t.Fatal("fixture did not begin weapon equipment", err)
}
+ world.advanceEquipment(client.equipment.readyAt)
+ if err := world.handleInventory(client, itemMovePacket(1, 6, 64)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("fixture did not begin removal to the protected empty destination", err)
+ }
}
var pending equipmentMove
if client.equipment != nil {
@@ -108,7 +146,7 @@ func TestStaleCarriedContainerDepositIgnoresInvalidOrPendingSources(t *testing.T
after, readErr := readTestItemStore(world)
if err != nil || readErr != nil || !bytes.Equal(before, after) || len(output.packets) != 0 ||
- (scenario == "pending equipment") != (client.equipment != nil) || client.equipment != nil && *client.equipment != pending {
+ (scenario == "pending destination") != (client.equipment != nil) || client.equipment != nil && *client.equipment != pending {
t.Fatal("invalid/pending stale deposit changed storage, replies or the admitted equipment move", err, readErr)
}
})
diff --git a/tools/client/test_stale_container_deposit.mjs b/tools/client/test_stale_container_deposit.mjs
@@ -45,17 +45,30 @@ try {
await toggle(48, true);
assert((await page.request.post(url + '/test-stale-view')).ok());
evidence.transferred = await server();
- assert.deepEqual(evidence.transferred.Containers[2], [{ID: 3, Type: 51018, Template: 123742, Quality: 2, Slot: 0, Count: 1, Ammo: 3}]);
+ assert.deepEqual(evidence.transferred.inventory.Containers[2], [{ID: 3, Type: 51018, Template: 123742, Quality: 2, Slot: 0, Count: 1, Ammo: 3}]);
+ const equip = game.sequence;
+ await click(cell(game.state, 104, 51), 'right');
+ await game.wait('actual unrelated axe wear request', () => game.events.some(event => event.sequence > equip &&
+ event.direction === 'framesent' && event.opcode === '47537a24'));
+ evidence.pending = await server();
+ assert.equal(evidence.pending.pending.itemID, 4);
+ await game.wait('native axe animation ends', state => !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6));
await game.save(output + '/stale');
const sequence = await deposit();
await game.save(output + '/requested');
await game.wait('stale carried deposit cancelled and empty row cleared', state => !cell(state, 104, 50) &&
game.events.some(event => event.sequence > sequence && event.direction === 'framereceived' && event.opcode === '5e477770' &&
Buffer.from(event.hex, 'hex').readUInt32BE(29) === 112));
+ const replies = game.events.filter(event => event.sequence > sequence && event.direction === 'framereceived' &&
+ event.opcode === '5e477770').map(event => Array.from({length: 5}, (_, index) => Buffer.from(event.hex, 'hex').readUInt32BE(29 + index * 4)));
+ assert.deepEqual(replies, [[146, 104, 50, 0, 0], [112, 104, 50, 0, 0]]);
assert.deepEqual(game.state.dragged, [0, 0]);
evidence.refused = await server();
- assert.deepEqual(evidence.refused, evidence.transferred);
+ assert.deepEqual(evidence.refused, evidence.pending);
await game.save(output + '/refused');
+ assert((await page.request.post(url + '/test-complete')).ok());
+ await game.wait('original axe wear completes', state => game.local(state).inventory.some(item => item.id === 4 && item.slot === 6));
+ assert.equal((await server()).pending, null);
// Recover the exact earlier-transferred instance and retry on the same page.
await toggle(48, false);
@@ -70,8 +83,8 @@ try {
await deposit();
await game.wait('same-page deposit succeeds', state => cell(state, 107, 1 << 16) && !cell(state, 104, 50));
evidence.after = await server();
- assert.deepEqual(evidence.after.Items.map(item => [item.ID, item.Slot]), [[1, 64], [2, 65]]);
- assert.deepEqual(evidence.after.Containers, {1: [{ID: 3, Type: 51018, Template: 123742, Quality: 2, Slot: 0, Count: 1, Ammo: 3}]});
+ assert.deepEqual(evidence.after.inventory.Items.map(item => [item.ID, item.Slot]), [[1, 64], [2, 65], [4, 6]]);
+ assert.deepEqual(evidence.after.inventory.Containers, {1: [{ID: 3, Type: 51018, Template: 123742, Quality: 2, Slot: 0, Count: 1, Ammo: 3}]});
await game.save(output + '/retried');
await page.reload();
await game.ready();
@@ -83,7 +96,7 @@ try {
assert.deepEqual(await server(), evidence.after);
assert.deepEqual(game.errors, []);
assert.equal(game.dropped, 0);
- console.log('PASS: stale carried deposit clears only its empty row; same-page recovery/retry and page/cold retain the loaded pistol');
+ console.log('PASS: stale deposit clears during unrelated equipment; completion/retry and page/cold retain four items and loaded rounds');
} finally {
try {
await fs.mkdir(output, {recursive: true});