commit 5ccec218b92c5e687fcc66779513f73e854e9214
parent 073d32874d0250c985c7b5597ce49e38f1754ebf
Author: anon <anon@example.com>
Date: Wed, 4 Nov 2026 16:34:40 +0000
Clear stale weapon hands during pending armor moves
Diffstat:
6 files changed, 317 insertions(+), 5 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -4285,8 +4285,12 @@ and server restarts. Turn every reproduced bug into a focused regression test.
previously received no reply. Cancellation, the existing unequip notification
and row clearing now preserve the detached banked weapon. Native same-page
withdrawal/re-equip and page/cold recovery retain both exact fixture items.
- First/last ordinary destinations, first-free111, repeats, foreign/pending guards
- and zero writes pass. See [stale hand](docs/inventory.md#stale-right-hand-move-sources).
+ First/last ordinary destinations, first-free111, repeats, foreign requests,
+ protected pending slots and zero writes pass. An unrelated pending armor move
+ now permits the same correction: native removal clears the hand, preserves
+ the vest's identity/deadline, completes its wear and re-equips the retained
+ axe after page replay. Cold loading retains both instances. See
+ [stale hand](docs/inventory.md#stale-right-hand-move-sources).
- [x] [P0] Clear an empty carried source after a stale ground drop. A controlled
completed backpack deposit leaves the old carried icon visible; native dropping
sends a real request that previously received no response. Cancellation then
diff --git a/docs/inventory.md b/docs/inventory.md
@@ -233,8 +233,8 @@ first-free111, correction now sends action146, the existing weapon-unequip97
notification and action112 for101:6. This clears the hand/model and row without
destroying the detached weapon, publishing a successful move or writing ownership.
Other worn slots are not admitted by this specific correction: their effect
-contracts remain separate. Pending equipment, foreign requests and invalid
-destinations retain their guards.
+contracts remain separate. The pending move's own source and destination,
+foreign requests and invalid destinations retain their guards.
The public-handler regression first failed with zero replies at destinations64,
93 and111. Repeated correction now preserves the exact banked item, allocation
@@ -249,6 +249,30 @@ recovery retain axe1 worn at6 and part2 at65, zero cash and allocator2. The
ordinary companion also passes; all eight traces have no client errors or
dropped events. This is controlled ownership/view evidence, not earned progression.
+The same correction also applies during an unrelated pending armor move. A
+controlled missed refresh leaves the axe in native hand6 after its committed
+move to carried65. While vest64->21 is held, actual hand removal previously
+received no reply. The hand's guard now allows correction outside the pending
+source/destination, using the existing146/97/112 sequence and resource refresh.
+No inventory transfer, deletion or pending-clock change occurs.
+
+`TestStaleHandDuringUnrelatedArmor` covers armor wear/removal, destinations64,
+93 and111, repeat requests, zero writes, protected ownership and original
+completion/cold recovery. Existing pending-weapon tests protect hand6 when it
+belongs to the admitted move. `TestBrowserStaleHandDuringEquipment` checks real
+native removal, unchanged vest deadline, successful vest completion and exact
+axe re-wear after page replay. Both physical IDs survive cold loading; native
+vest AC remains `5,5,1,1,5,5,1,5`. The controlled level2 fixture uses
+Sense8/Agility8 and does not claim earned progression or a new scheduling rule.
+
+Baseline `local/pending-stale-hand/20261104-082656` fails in21.97s; fixed
+`20261104-083000` passes in18.97s. Corrected/retained screenshots were reviewed,
+and all four accepted traces have no client errors or dropped events.
+Focused Go checks pass16 roots/159 results in23.089s; race checks pass17 roots/160
+results in113.355s. Maintained-package vet, driver syntax and whitespace checks
+pass. Independent packet/state
+checks and source hashes are retained in that folder's `verification.json`.
+
### Stale worn-armor sources
A controlled completed bank transfer leaves a QL1 Metaplast helmet visible in
diff --git a/server/browser_pending_stale_hand_test.go b/server/browser_pending_stale_hand_test.go
@@ -0,0 +1,104 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "slices"
+ "testing"
+ "time"
+)
+
+func TestBrowserStaleHandDuringEquipment(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for a stale hand during pending equipment")
+ }
+
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/pending-stale-hand", time.Now().Format("20060102-150405"))
+ world := newTestServer(t)
+ player := world.newCharacter()
+ player.level = 2
+ player.stats.Abilities.Sense, player.stats.Abilities.Agility = 8, 8
+ player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("pending-stale-hand")))
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ for _, template := range []uint32{209283, 85481} {
+ if granted, err := world.grantItem_locked(player, template); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ }
+ inventory := player.inventory
+ inventory.Items = slices.Clone(inventory.Items)
+ inventory.Items[0].Slot = 6
+ inventory.Items[1].Slot = 64
+ 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}
+ }
+ var armor [8]int32
+ for index := range armor {
+ armor[index] = player.equipmentBonus(90 + uint32(index))
+ }
+ json.NewEncoder(w).Encode(map[string]any{"inventory": player.inventory, "pending": pending, "armor": armor})
+ })
+ // A committed removal with no refresh leaves the old native weapon hand stale.
+ mux.HandleFunc("POST /test-stale-view", func(w http.ResponseWriter, r *http.Request) {
+ world.updateMutex.Lock()
+ defer world.updateMutex.Unlock()
+ world.mutex.Lock()
+ defer world.mutex.Unlock()
+ inventory := player.inventory
+ inventory.Items = slices.Clone(inventory.Items)
+ inventory.Items[0].Slot = 65
+ 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)
+ ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
+ defer cancel()
+
+ command := exec.CommandContext(ctx, "node", filepath.Join(root, "tools/client/test_pending_stale_hand.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: 51022, Template: 85481, Quality: 1, Slot: 21, Count: 1}}
+ if !slices.Equal(player.inventory.Items, expected) || !slices.Equal(cold.characters[1].inventory.Items, expected) ||
+ world.nextItem != 2 || cold.nextItem != 2 {
+ t.Fatal("stale-source correction lost an equipment instance")
+ }
+}
diff --git a/server/inventory.go b/server/inventory.go
@@ -372,7 +372,8 @@ func (server *server) handleInventory(client *worldClient, body []byte) error {
}
return client.send(characterActionPacket(client.id, [5]uint32{112, 104, sourceSlot}))
}
- if index < 0 && client.equipment == nil && key == 0x47537a24 && sourceType == 101 && sourceSlot == 6 &&
+ if index < 0 && (client.equipment == nil || sourceSlot != client.equipment.source && sourceSlot != client.equipment.destination) &&
+ key == 0x47537a24 && sourceType == 101 && sourceSlot == 6 &&
binary.BigEndian.Uint32(body[24:28]) == 50000 && binary.BigEndian.Uint32(body[28:32]) == client.id &&
(destination == 111 || destination >= 64 && destination < 94) {
// Clear an empty hand without destroying its detached physical weapon.
diff --git a/server/pending_stale_hand_test.go b/server/pending_stale_hand_test.go
@@ -0,0 +1,89 @@
+package main
+
+import (
+ "bytes"
+ "fmt"
+ "reflect"
+ "slices"
+ "testing"
+)
+
+func TestStaleHandDuringUnrelatedArmor(t *testing.T) {
+ for _, removing := range []bool{false, true} {
+ for _, destination := range []uint32{64, 93, 111} {
+ t.Run(fmt.Sprintf("removing%v/destination%d", removing, destination), func(t *testing.T) {
+ world, output := newEquipmentWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("fixture axe wear did not begin", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ if granted, err := world.grantItem_locked(player, 85481); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ if removing {
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 21)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("fixture vest wear did not begin", err)
+ }
+ world.advanceEquipment(client.equipment.readyAt)
+ }
+ inventory := player.inventory
+ inventory.Items = slices.Clone(inventory.Items)
+ inventory.Items[0].Slot = 65
+ if err := world.saveInventory_locked(player, inventory); err != nil {
+ t.Fatal(err)
+ }
+ request := inventoryMovePacket(1, 64, 21)[20:]
+ if removing {
+ request = itemMovePacket(1, 21, 64)[20:]
+ }
+ if err := world.handleInventory(client, request); err != nil || client.equipment == nil {
+ t.Fatal("fixture pending vest move did not begin", err)
+ }
+ pending := *client.equipment
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ output.packets = nil
+ auditCheckpointWrites(t, world)
+
+ for range 2 {
+ if err := world.handleInventory(client, itemMovePacket(1, 6, destination)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ }
+ after, err := readTestItemStore(world)
+
+ if err != nil || !bytes.Equal(before, after) || len(checkpointWrites(t, world)) != 0 ||
+ !reflect.DeepEqual(player.inventory, inventory) || client.equipment == nil || *client.equipment != pending ||
+ world.nextItem != 2 || len(output.packets) != 16 {
+ t.Fatal("stale hand correction omitted replies or changed storage, pending armor or allocation", err, len(output.packets))
+ }
+ for repeat := range 2 {
+ for index, packet := range [][]byte{
+ targetPacket(characterActionPacket(1, [5]uint32{146, 101, 6})),
+ targetPacket(weaponUnequipPacket(1)),
+ targetPacket(characterActionPacket(1, [5]uint32{112, 101, 6})),
+ } {
+ if !bytes.Equal(output.packets[repeat*8+index], packet) {
+ t.Fatal("stale hand correction did not cancel, unequip and clear only its own row")
+ }
+ }
+ }
+ world.advanceEquipment(pending.readyAt)
+ vestSlot := uint32(21)
+ if removing {
+ vestSlot = 64
+ }
+ expected := []ownedItem{{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: 65, Count: 1},
+ {ID: 2, Type: 51022, Template: 85481, Quality: 1, Slot: vestSlot, Count: 1}}
+ cold := newTestInventoryServer(t)
+ if client.equipment != nil || !slices.Equal(player.inventory.Items, expected) ||
+ !slices.Equal(cold.characters[1].inventory.Items, expected) || cold.nextItem != 2 {
+ t.Fatal("original vest completion lost either retained instance")
+ }
+ })
+ }
+ }
+}
diff --git a/tools/client/test_pending_stale_hand.mjs b/tools/client/test_pending_stale_hand.mjs
@@ -0,0 +1,90 @@
+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-stale-hand', url}]);
+ const page = await context.newPage();
+ game = await GameTest.attach(page);
+ const server = async () => (await page.request.get(url + '/test-state')).json();
+ const armor = [5, 5, 1, 1, 5, 5, 1, 5];
+ await page.goto(url);
+ await game.ready();
+ assert(game.local().inventory.some(item => item.id === 1 && item.slot === 6));
+ await game.key('i');
+ await page.keyboard.press('Control+1');
+ await game.click(953, 53);
+ assert((await page.request.post(url + '/test-stale-view')).ok());
+
+ // Hold vest wear while the native weapon still occupies its old hand.
+ const carried = game.state.grids.flatMap(grid => grid.cells).find(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy);
+ assert(carried);
+ const first = game.sequence;
+ await game.click((carried.bounds[0] + carried.bounds[2]) / 2, (carried.bounds[1] + carried.bounds[3]) / 2);
+ await game.click(927, 148);
+ await game.wait('actual vest equip request', () => game.events.some(event => event.sequence > first &&
+ event.direction === 'framesent' && event.opcode === '47537a24'));
+ evidence.pending = await server();
+ assert.equal(evidence.pending.pending.itemID, 2);
+ await game.wait('native vest animation ends', state => !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6));
+
+ // A real removal request addresses the now-empty authoritative weapon hand.
+ await game.click(867, 53);
+ const sequence = game.sequence;
+ await game.click(867, 206, 'right');
+ await game.wait('actual stale hand removal request', () => game.events.some(event => event.sequence > sequence &&
+ event.direction === 'framesent' && event.opcode === '47537a24' &&
+ Buffer.from(event.hex, 'hex').readUInt32BE(29) === 101 && Buffer.from(event.hex, 'hex').readUInt32BE(33) === 6));
+ evidence.refused = await server();
+ assert.deepEqual(evidence.refused, evidence.pending);
+ await game.save(output + '/requested');
+ await game.wait('stale weapon hand cleared during pending vest wear', state => !game.local(state).inventory.some(item => item.slot === 6));
+ 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, 101, 6, 0, 0], [97, 0, 0, 0, 6], [112, 101, 6, 0, 0]]);
+ await game.save(output + '/corrected');
+ assert((await page.request.post(url + '/test-complete')).ok());
+ await game.wait('original vest equip completes', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 21));
+ assert.deepEqual(game.local().effectiveArmor, armor);
+ evidence.completed = await server();
+ assert.equal(evidence.completed.pending, null);
+
+ // Replay exposes the exact axe at its committed carried slot for ordinary wear.
+ await page.reload();
+ await game.ready();
+ if (!game.state.grids.some(grid => grid.cells.some(cell => cell.identity[0] === 104 && cell.identity[1] === 49))) await game.key('i');
+ await page.keyboard.press('Control+1');
+ await game.wait('retained axe carried row available', state => state.grids.some(grid => grid.cells.some(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === 49 && !cell.dummy)));
+ const axe = game.state.grids.flatMap(grid => grid.cells).find(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === 49 && !cell.dummy);
+ const recovered = game.sequence;
+ await game.click((axe.bounds[0] + axe.bounds[2]) / 2, (axe.bounds[1] + axe.bounds[3]) / 2, 'right');
+ await game.wait('actual recovered axe wear request', () => game.events.some(event => event.sequence > recovered &&
+ event.direction === 'framesent' && event.opcode === '47537a24'));
+ assert((await page.request.post(url + '/test-complete')).ok());
+ await game.wait('retained axe wears again', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 6));
+ evidence.after = await server();
+ assert.deepEqual(evidence.after.inventory.Items.map(item => [item.ID, item.Slot, item.Count]), [[1, 6, 1], [2, 21, 1]]);
+ assert.deepEqual(evidence.after.armor, armor);
+ assert.deepEqual(game.errors, []);
+ assert.equal(game.dropped, 0);
+ await game.save(output + '/retained');
+ console.log('PASS: stale hand clears without changing pending armor wear; both exact items remain usable');
+} 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(); }
+}