commit 6e9377b12d66301d6f7c80538b27b0f2123aee0d
parent feef14a3434821c06bad6c510d0bcd037db46317
Author: anon <anon@example.com>
Date: Tue, 3 Nov 2026 05:57:07 +0000
Restore backpack pickup refused during equipment delay
Diffstat:
8 files changed, 274 insertions(+), 5 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -3744,6 +3744,13 @@ and server restarts. Turn every reproduced bug into a focused regression test.
cases, native completion/retry, page replay and exact cold ownership pass;
this leaves the broader audit open. See
[pending equipment](docs/inventory.md#another-move-while-equipment-is-pending).
+- [x] [P0] Restore a backpack withdrawal refused during pending equipment. A
+ controlled late-completion reproduction left the picked bag source hidden
+ because its packed page-107 request was silently ignored. Source cancellation
+ now restores that icon without changing the admitted server move, deadline,
+ open handle or durable inventory. Public-handler and WASM completion/retry,
+ page replay and cold recovery retain all three exact instances. See
+ [pending backpack withdrawal](docs/backpacks.md#withdrawal-during-pending-equipment).
- [ ] [P2] Review nearly invisible original item icons separately from ownership
loss. Low-Tech sleeves 70561/85744 reference icon 1010008/13228: the original
14.9.1 PNG is almost entirely chroma-key green, with only a tiny shoulder in
diff --git a/docs/backpacks.md b/docs/backpacks.md
@@ -150,6 +150,27 @@ children in reclaim. These are current server persistence policies; the original
server's filled-container death and deletion policies are not established by the
native client code.
+## Withdrawal during pending equipment
+
+A withdrawal from an already open backpack can arrive after the native equip
+bar ends while the server's weapon move still awaits completion. Silently
+ignoring that request leaves the picked bag icon hidden. The server now routes
+packed page-107 sources through the existing open-handle and carried-owner
+checks, then refuses the busy withdrawal with CharacterAction 146 using its
+unchanged packed source slot. A contents-only replay does not restore this
+native dummy icon. Action 146 also stops the native equip bar; the focused
+runtime check reproduces the case after that bar has ended. The admitted server
+move and deadline remain unchanged. This refusal policy uses the native source
+refresh contract; the original server's packet choice is not established.
+
+`TestBackpackPendingWithdrawalRestoresSourceForRetry` checks exact unchanged
+database bytes, bag handle, source slot 5 and pending move, followed by completion
+and retry. `TestBrowserBackpackDuringEquipment` reproduces the hidden source in
+the WASM client, verifies its restoration and same-window retry, and accounts
+for the weapon, bag and contained item through page and cold recovery. Its
+controlled delayed completion is not earned progression. Captures are retained
+in `local/pending-backpack/`; the broader equipment audit remains open.
+
## Verification
`server/backpacks_test.go` exercises the actual world connection for opening and
diff --git a/server/backpack_pending_test.go b/server/backpack_pending_test.go
@@ -0,0 +1,64 @@
+package main
+
+import (
+ "bytes"
+ "reflect"
+ "slices"
+ "testing"
+)
+
+func TestBackpackPendingWithdrawalRestoresSourceForRetry(t *testing.T) {
+ world, conn := newEquipmentWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ for _, template := range []uint32{99228, 42640} {
+ if granted, err := world.grantItem_locked(player, template); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ }
+ inventory := player.inventory
+ part := inventory.Items[2]
+ part.Slot = 5
+ inventory.Items = slices.Clone(inventory.Items[:2])
+ inventory.Containers = map[uint32][]ownedItem{2: {part}}
+ if err := world.saveInventory_locked(player, inventory); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleOwnedItemUse(client, backpackUseRequest(1, 65, 1)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleInventory(client, itemMovePacket(1, 64, 6)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("weapon move was not admitted", err)
+ }
+ move := *client.equipment
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ conn.packets = nil
+ request := backpackMoveRequest(107, 1<<16|5, 50000, 1, 111)[20:]
+
+ if err := world.handleInventory(client, request); err != nil {
+ t.Fatal(err)
+ }
+ after, err := readTestItemStore(world)
+
+ if err != nil || !bytes.Equal(before, after) || *client.equipment != move ||
+ !reflect.DeepEqual(client.backpacks, map[uint32]backpackHandle{1: {2, true}}) {
+ t.Fatal("refused withdrawal changed ownership, the bag or pending move", err)
+ }
+ if !reflect.DeepEqual(conn.packets, [][]byte{targetPacket(characterActionPacket(1, [5]uint32{146, 107, 1<<16 | 5}))}) {
+ t.Fatalf("refused withdrawal did not restore its native source: %x", conn.packets)
+ }
+ world.advanceEquipment(move.readyAt)
+ if err := world.handleInventory(client, request); err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t)
+ expected := []ownedItem{{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 6, Count: 1},
+ {ID: 2, Type: 51017, Template: 99228, Quality: 1, Slot: 65, Count: 1},
+ {ID: 3, Type: 51005, Template: 42640, Quality: 1, Slot: 64, Count: 1}}
+ if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) ||
+ len(player.inventory.Containers) != 0 || len(cold.characters[1].inventory.Containers) != 0 {
+ t.Fatal("withdrawal retry lost or duplicated an instance")
+ }
+}
diff --git a/server/backpacks.go b/server/backpacks.go
@@ -216,6 +216,9 @@ func (server *server) moveContainerItem_locked(client *worldClient, body []byte)
return nil
}
item := items[index]
+ if sourceBag != 0 && client.equipment != nil {
+ return client.send(characterActionPacket(client.id, [5]uint32{146, sourcePage, binary.BigEndian.Uint32(body[20:24])}))
+ }
if bank && itemStat(item.templateDefinition(), 8) > 0 {
return client.send(characterActionPacket(client.id, [5]uint32{146, sourcePage, binary.BigEndian.Uint32(body[20:24])}))
}
diff --git a/server/backpacks_test.go b/server/backpacks_test.go
@@ -159,7 +159,7 @@ func TestBackpackTransferBetweenClosedAndOpenBags(t *testing.T) {
}
func TestBackpackRejectsInvalidOwnershipAndPlacement(t *testing.T) {
- for _, scenario := range []string{"nested", "foreign bag", "unknown handle", "closed source", "unseen bag", "foreign owner", "occupied main", "equipment", "loading", "dead", "stale session"} {
+ for _, scenario := range []string{"nested", "foreign bag", "unknown handle", "closed source", "unseen bag", "foreign owner", "occupied main", "loading", "dead", "stale session"} {
t.Run(scenario, func(t *testing.T) {
world, conn := newBackpackWorld(t)
client, player := world.clients[1], world.characters[1]
@@ -181,8 +181,6 @@ func TestBackpackRejectsInvalidOwnershipAndPlacement(t *testing.T) {
binary.BigEndian.PutUint32(request[28:32], 2)
case "occupied main":
binary.BigEndian.PutUint32(request[32:36], 64)
- case "equipment":
- client.equipment = &equipmentMove{}
case "loading":
client.loading = true
case "dead":
diff --git a/server/browser_pending_backpack_test.go b/server/browser_pending_backpack_test.go
@@ -0,0 +1,88 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "slices"
+ "testing"
+ "time"
+)
+
+func TestBrowserBackpackDuringEquipment(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for backpack withdrawal during pending equipment")
+ }
+
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/pending-backpack", time.Now().Format("20060102-150405"))
+ world := newTestServer(t)
+ player := world.newCharacter()
+ player.stats = testCharacterStats()
+ player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("pending-backpack")))
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ for _, template := range []uint32{209283, 99228, 42640} {
+ if granted, err := world.grantItem_locked(player, template); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ }
+ inventory := player.inventory
+ part := inventory.Items[2]
+ part.Slot = 5
+ inventory.Items = slices.Clone(inventory.Items[:2])
+ inventory.Containers = map[uint32][]ownedItem{2: {part}}
+ if err := world.saveInventory_locked(player, inventory); err != nil {
+ t.Fatal(err)
+ }
+ mux := http.NewServeMux()
+ mux.Handle("/", world.httpHandler())
+ mux.HandleFunc("GET /test-state", func(w http.ResponseWriter, r *http.Request) {
+ world.mutex.Lock()
+ defer world.mutex.Unlock()
+ 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})
+ })
+ // Hold the admitted move to reproduce a late completion without network timing.
+ 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)
+ ctx, cancel := context.WithTimeout(context.Background(), 3*time.Minute)
+ defer cancel()
+
+ command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_pending_backpack.mjs"), host.URL, output)
+ command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr
+ err := command.Run()
+ t.Logf("Browser artifacts: %s", output)
+
+ if err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t)
+ expected := []ownedItem{{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 6, Count: 1},
+ {ID: 2, Type: 51017, Template: 99228, Quality: 1, Slot: 65, Count: 1},
+ {ID: 3, Type: 51005, Template: 42640, Quality: 1, Slot: 64, Count: 1}}
+ if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) ||
+ len(player.inventory.Containers) != 0 || len(cold.characters[1].inventory.Containers) != 0 {
+ t.Fatal("pending equipment backpack retry lost an item or retained a duplicate source")
+ }
+}
diff --git a/server/inventory.go b/server/inventory.go
@@ -252,8 +252,11 @@ func (server *server) handleInventory(client *worldClient, body []byte) error {
return server.moveContainerItem_locked(client, body)
}
if client.equipment != nil {
- // A separate corpse pickup still needs a reply while equipment is pending.
- if key == 0x47537a24 && binary.BigEndian.Uint32(body[16:20]) == 107 && binary.BigEndian.Uint32(body[20:24])>>16 == 0 {
+ // Separate container pickups still need a reply while equipment is pending.
+ if key == 0x47537a24 && binary.BigEndian.Uint32(body[16:20]) == 107 {
+ if binary.BigEndian.Uint32(body[20:24])>>16 != 0 {
+ return server.moveContainerItem_locked(client, body)
+ }
return server.takeLoot_locked(client, body)
}
if key == 0x5e477770 && binary.BigEndian.Uint32(body[16:20]) == 52 {
diff --git a/tools/client/test_pending_backpack.mjs b/tools/client/test_pending_backpack.mjs
@@ -0,0 +1,85 @@
+import assert from 'node:assert/strict';
+import fs from 'node:fs/promises';
+import {createRequire} from 'node:module';
+import {GameTest} from './game_test.mjs';
+
+const {chromium} = createRequire(import.meta.url)('playwright');
+const [url, output] = process.argv.slice(2);
+const browser = await chromium.launch({executablePath: '/usr/bin/chromium',
+ args: ['--enable-gpu', '--use-gl=angle', '--use-angle=gl', '--no-sandbox', '--disable-dev-shm-usage',
+ '--disable-background-timer-throttling', '--disable-renderer-backgrounding']});
+let game;
+const evidence = {};
+try {
+ const context = await browser.newContext({viewport: {width: 1024, height: 768}});
+ await context.addCookies([{name: 'ao_client', value: 'pending-backpack', url}]);
+ const page = await context.newPage();
+ game = await GameTest.attach(page);
+ await page.goto(url);
+ await game.ready();
+ const server = async () => (await page.request.get(url + '/test-state')).json();
+ const source = state => state.grids.flatMap(grid => grid.cells).find(cell =>
+ cell.identity[0] === 107 && cell.identity[1] === (1 << 16 | 5) && !cell.dummy);
+ const clickCell = async cell => game.click((cell.bounds[0] + cell.bounds[2]) / 2, (cell.bounds[1] + cell.bounds[3]) / 2);
+ await game.key('i');
+ await game.click(735, 45, 'right');
+ await game.wait('open backpack source', source);
+ await page.keyboard.press('Control+1');
+ const weapon = game.state.grids.flatMap(grid => grid.cells).find(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy);
+ assert(weapon);
+ const equipSequence = game.sequence;
+ await clickCell(weapon);
+ await game.click(867, 206);
+ await game.wait('actual equipment request', () => game.events.some(event => event.sequence > equipSequence &&
+ event.direction === 'framesent' && event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 104));
+ evidence.pending = await server();
+ assert(evidence.pending.pending);
+ await game.wait('local equip ends while server completion remains pending', state =>
+ !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6));
+ const withdraw = async () => {
+ const sequence = game.sequence;
+ await clickCell(source(game.state));
+ await game.wait('bag source picked', state => state.dragged[0] === 107 && state.dragged[1] === (1 << 16 | 5));
+ await game.click(789, 45);
+ await game.wait('actual backpack withdrawal', () => game.events.some(event => event.sequence > sequence &&
+ event.direction === 'framesent' && event.opcode === '47537a24' &&
+ Buffer.from(event.hex, 'hex').readUInt32BE(29) === 107));
+ return sequence;
+ };
+ const sequence = await withdraw();
+ evidence.refused = await server();
+ assert.deepEqual(evidence.refused, evidence.pending);
+ await game.save(output + '/pending');
+ await game.wait('backpack withdrawal explicitly cancelled', () => game.events.some(event => event.sequence > sequence &&
+ event.direction === 'framereceived' && event.opcode === '5e477770' &&
+ Buffer.from(event.hex, 'hex').readUInt32BE(29) === 146));
+ await game.wait('same backpack source restored', source);
+ assert.deepEqual(game.state.dragged, [0, 0]);
+ await game.save(output + '/refused');
+ assert((await page.request.post(url + '/test-complete')).ok());
+ await game.wait('original weapon completes', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 6));
+ await withdraw();
+ await game.wait('same-window withdrawal retry succeeds', state => game.local(state).inventory.some(item => item.id === 3 && item.slot === 48));
+ evidence.after = await server();
+ assert.equal(evidence.after.pending, null);
+ assert.equal(evidence.after.inventory.Containers, null);
+ assert.deepEqual(evidence.after.inventory.Items, [
+ {...evidence.pending.inventory.Items[0], Slot: 6}, evidence.pending.inventory.Items[1],
+ {...evidence.pending.inventory.Containers[2][0], Slot: 64}]);
+ assert.equal(game.events.filter(event => event.sequence > sequence && event.direction === 'framesent' &&
+ event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 107).length, 2);
+ await game.save(output + '/picked');
+ await page.reload();
+ await game.ready();
+ assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot, item.quality, item.count]).sort((a, b) => a[0] - b[0]),
+ [[1, 6, 1, 1], [2, 49, 1, 1], [3, 48, 1, 1]]);
+ assert.equal(game.errors.length, 0);
+ console.log('PASS: pending equipment backpack refusal restores its source and permits exact same-window retry/page/cold recovery');
+} finally {
+ try {
+ await fs.mkdir(output, {recursive: true});
+ await fs.writeFile(output + '/verification.json', JSON.stringify(evidence, null, 2) + '\n');
+ if (game) await game.save(output + '/final');
+ } finally { await browser.close(); }
+}