commit 907583635308c50bbc8b3ec6bc061a18c5021b1c
parent b3be4c7cea6b10477890877b9edda6442b5bbff1
Author: anon <anon@example.com>
Date: Tue, 3 Nov 2026 09:06:22 +0000
Correct late withdrawals from unavailable bank sessions
Diffstat:
6 files changed, 73 insertions(+), 12 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -3790,6 +3790,13 @@ and server restarts. Turn every reproduced bug into a focused regression test.
admitted-source duplicate remains pending. Public-handler and WASM retry,
page replay and cold recovery retain the same axe, bag and contained part. See
[pending backpack deposit](docs/backpacks.md#deposit-during-pending-equipment).
+- [x] [P0] Correct a late bank withdrawal after its session becomes unavailable
+ during pending equipment. Public-handler cases reproduce no reply after
+ closure or moving beyond the bank anchor. Check explicit native source
+ correction, unchanged ownership and admitted move/deadline, normal reopening
+ and retry, page replay and cold identity retention now pass. Go checks cover
+ 32 roots/91 results, focused race checks pass 2/6, and all ten native traces
+ are clean. Evidence: `local/pending-bank-unavailable/`.
- [x] [P0] Restore a bank icon after withdrawal refused during pending equipment.
A short controlled WASM reproduction sends a real page-105 withdrawal after
the local equip bar ends; replaying BankIIR leaves the source marked dummy.
diff --git a/docs/bank-storage.md b/docs/bank-storage.md
@@ -155,6 +155,15 @@ Page replay and cold database loading account for all four physical instances.
The original hidden-icon reproduction is retained in
`local/pending-bank-withdrawal/`.
+Late withdrawals after a bank close or loss of locality use that same source
+correction, including while equipment is pending. The Go fixture covers both
+unavailable states without changing the admitted move or durable inventory.
+The WASM fixture processes the real bank-close handler at a controlled
+checkpoint before delivering another native withdrawal. Its source must remain
+usable, and ordinary terminal reopening after equip completion permits retry.
+This close checkpoint isolates a late request; it does not establish earned
+travel. Evidence: `local/pending-bank-unavailable/`.
+
Contained deposits also validate their open carried bag, handle and member
before refusing a busy transfer. CharacterAction 146 retains the full packed
page-107 source slot and restores its icon. This stops the native equipment
diff --git a/server/backpacks.go b/server/backpacks.go
@@ -189,14 +189,8 @@ func (server *server) moveContainerItem_locked(client *worldClient, body []byte)
sourceBag := uint32(0)
items := inventory.Items
bank := sourcePage == 105 || binary.BigEndian.Uint32(body[24:28]) == 57005
- if sourcePage == 105 && client.equipment != nil {
- // Cancel the picked bank source while retaining the admitted server move.
- if server.bankAvailable_locked(client) {
- return client.send(characterActionPacket(client.id, [5]uint32{146, sourcePage, sourceSlot}))
- }
- return nil
- }
- if bank && !server.bankAvailable_locked(client) {
+ // Refuse unavailable transfers and busy withdrawals without losing their source.
+ if bank && (!server.bankAvailable_locked(client) || sourcePage == 105 && client.equipment != nil) {
return client.send(characterActionPacket(client.id, [5]uint32{146, sourcePage, sourceSlot}))
}
if sourcePage == 105 {
diff --git a/server/bank_test.go b/server/bank_test.go
@@ -602,8 +602,12 @@ func TestBankUniqueRejectionRestoresSourceWithoutContractFeedback(t *testing.T)
}
func TestBankTransferRejectionPreservesPendingEquipmentTimer(t *testing.T) {
- for _, page := range []uint32{104, 105} {
- t.Run(map[uint32]string{104: "deposit", 105: "withdraw"}[page], func(t *testing.T) {
+ for _, scenario := range []string{"deposit", "withdraw", "closed withdrawal", "distant withdrawal"} {
+ t.Run(scenario, func(t *testing.T) {
+ page := uint32(105)
+ if scenario == "deposit" {
+ page = 104
+ }
world, conn := newBankWorld(t)
player, client := world.characters[1], world.clients[1]
if err := world.handleInventory(client, backpackMoveRequest(104, 64, 57005, 1, 111)[20:]); err != nil {
@@ -620,6 +624,17 @@ func TestBankTransferRejectionPreservesPendingEquipmentTimer(t *testing.T) {
t.Fatal("pistol equip was not admitted")
}
move, bank := *client.equipment, *client.bank
+ var expectedBank *bankSession
+ switch scenario {
+ case "closed withdrawal":
+ if err := world.handleBankClose(client, characterActionPacket(1, [5]uint32{106})[20:]); err != nil {
+ t.Fatal(err)
+ }
+ case "distant withdrawal":
+ player.position[0] += 6
+ default:
+ expectedBank = &bank
+ }
before, _ := readTestItemStore(world)
conn.packets = nil
request := backpackMoveRequest(105, 0, 50000, 1, 111)
@@ -630,7 +645,7 @@ func TestBankTransferRejectionPreservesPendingEquipmentTimer(t *testing.T) {
err := world.handleInventory(client, request[20:])
after, _ := readTestItemStore(world)
- if err != nil || !bytes.Equal(before, after) || *client.equipment != move || *client.bank != bank || len(player.inventory.Bank) != 1 {
+ if err != nil || !bytes.Equal(before, after) || *client.equipment != move || !reflect.DeepEqual(client.bank, expectedBank) || len(player.inventory.Bank) != 1 {
t.Fatal("busy rejection changed equipment or ownership", err)
}
if page == 104 && !reflect.DeepEqual(conn.packets, [][]byte{
@@ -640,7 +655,13 @@ func TestBankTransferRejectionPreservesPendingEquipmentTimer(t *testing.T) {
}) {
t.Fatalf("busy rejection did not restore its source without stopping equipment: %x", conn.packets)
}
+ player.position = bank.position
world.advanceEquipment(move.readyAt)
+ if client.bank == nil {
+ if err := world.handleTerminalUse(client, bankUseRequest(2)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ }
if err := world.handleInventory(client, request[20:]); err != nil {
t.Fatal(err)
}
diff --git a/server/browser_pending_bank_test.go b/server/browser_pending_bank_test.go
@@ -70,6 +70,14 @@ func TestBrowserBankDepositDuringEquipment(t *testing.T) {
world.mutex.Unlock()
world.advanceEquipment(finish)
})
+ mux.HandleFunc("POST /test-close-bank", func(w http.ResponseWriter, r *http.Request) {
+ world.mutex.Lock()
+ client := world.clients[1]
+ world.mutex.Unlock()
+ if err := world.handleBankClose(client, characterActionPacket(1, [5]uint32{106})[20:]); err != nil {
+ t.Error(err)
+ }
+ })
host := httptest.NewServer(mux)
t.Cleanup(host.Close)
closeTestBrowserStreams(t, world)
diff --git a/tools/client/test_pending_bank.mjs b/tools/client/test_pending_bank.mjs
@@ -166,10 +166,32 @@ try {
assert.deepEqual(evidence.withdrawRefused, evidence.withdrawPending);
assert.deepEqual(game.state.dragged, [0, 0]);
await game.save(output + '/withdraw-refused');
+
+ // Deliver a late request after the server has processed the bank close.
+ assert((await page.request.post(url + '/test-close-bank')).ok());
+ evidence.closedPending = await server();
+ assert.equal(evidence.closedPending.bank, null);
+ assert.deepEqual(evidence.closedPending.pending, evidence.withdrawPending.pending);
+ const closed = game.sequence;
+ await withdraw();
+ await game.wait('late withdrawal reaches server', () => game.events.some(event => event.sequence > closed &&
+ event.direction === 'framesent' && event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 105));
+ await game.wait('late closed-bank withdrawal cancelled', () => game.events.some(event => event.sequence > closed &&
+ event.direction === 'framereceived' && event.opcode === '5e477770' &&
+ Buffer.from(event.hex, 'hex').readUInt32BE(29) === 146 && Buffer.from(event.hex, 'hex').readUInt32BE(33) === 105 &&
+ Buffer.from(event.hex, 'hex').readUInt32BE(37) === 0));
+ await game.wait('late closed-bank source restored', state => state.grids.some(grid => grid.cells.some(cell =>
+ cell.identity[0] === 105 && cell.identity[1] === 0 && !cell.dummy)));
+ evidence.closedRefused = await server();
+ assert.deepEqual(evidence.closedRefused, evidence.closedPending);
+ await game.save(output + '/closed-refused');
assert((await page.request.post(url + '/test-complete')).ok());
await game.wait('original axe equip completes', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 6));
+ await game.click(...await game.pick(51005, 3221357727), 'right');
+ await game.wait('bank reopens after the admitted move completes', () => game.events.some(event => event.sequence > closed &&
+ event.direction === 'framereceived' && event.opcode === '343c287f'));
await withdraw();
- await game.wait('same-window withdrawal retry succeeds', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 48));
+ await game.wait('withdrawal retry succeeds after reopening', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 48));
evidence.withdrawAfter = await server();
assert.equal(evidence.withdrawAfter.pending, null);
assert.deepEqual(evidence.withdrawAfter.bank, evidence.withdrawPending.bank);