commit b8b6860d7627e9c93972f6b048564b7bae9b74c1
parent e40a3e1450189481effbdecd987aadcec72241dc
Author: anon <anon@example.com>
Date: Tue, 3 Nov 2026 05:01:24 +0000
Restore reclaim sources after pickup during pending equipment
Diffstat:
6 files changed, 255 insertions(+), 6 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -1227,6 +1227,12 @@ Historical outdoor give-up timing and wider route-selection fidelity remain open
See [courtyard access](docs/insurance.md#original-omni-courtyard-stair-access),
[street insurance](docs/insurance.md#street-level-omni-pair) and
[Clan/ICC coverage](docs/insurance.md#clan-and-icc-scanners).
+ A controlled late-completion check now also fixes reclaim pickup ignored
+ during pending equipment. Explicit cancellation restores its source without
+ changing the first move/deadline or reclaim mapping; native completion/retry,
+ page/cold ownership and a partially collected nonzero-slot handler case pass.
+ This verifies refusal behavior rather than connected earned faction travel;
+ see [reclaim](docs/reclaim.md).
Unsaved training return must not imply that training contains a reclaim booth.
- [x] [P0] Restore the reclaim icon after an authoritative full-inventory refusal.
A controlled stale native space check now receives page106 cancellation,
diff --git a/docs/reclaim.md b/docs/reclaim.md
@@ -134,12 +134,15 @@ Reclaim messages are private to the requesting owner. State changes use the
normal update/state lock order; packet sends occur after releasing the state
mutex.
-An otherwise eligible pickup refused for full inventory sends CharacterAction
-146 with page106 and the snapshot source slot. This cancels the pending native
-move and restores its source icon without reopening or replacing the window.
+An otherwise eligible pickup refused for full inventory or pending equipment
+sends CharacterAction 146 with page106 and the snapshot source slot. This
+cancels the pending native move and restores its source icon without reopening
+or replacing the window.
The source is the fixed window index, including after an earlier slot has been
collected; it is not the item's old inventory slot. No item or mapping changes
-on refusal, and a later pickup can retry the same source once space is available.
+on refusal, and a later pickup can retry the same source once space is available
+or the original equipment move has completed. Refusal preserves that equipment
+move's identity, destination and deadline.
If an otherwise valid open-source pickup arrives after leaving booth range or
changing playfield, the server clears its snapshot mapping, cancels the pending
@@ -148,6 +151,19 @@ unchanged. Returning to a booth can open a fresh mapping of the same items.
## Verification
+`TestBrowserReclaimDuringEquipment` opens reclaim beside the original street
+booth, starts real axe placement and holds its server completion at a controlled
+checkpoint. After the local animation ends, native pickup previously received
+no reply and hid the reclaim icon. Cancellation restores the same open source
+without changing its mapping, either owned item or the original equipment move.
+Completing that move permits same-window pickup; both exact instances survive
+native page replay and cold loading. This is controlled ownership evidence.
+`TestReclaimPendingEquipmentRestoresSourceForRetry` also collects one entry
+before starting removal and verifies cancellation of the remaining nonzero
+window slot, byte-identical durable state, unchanged completion timer, retry
+and exact cold locations for all five instances.
+Accepted native captures: `local/pending-reclaim/20261102-205841/`.
+
`TestBrowserReclaimPickupRefusal` uses a controlled stale free-space view beside
the original street-level reclaim booth. Unpublished filler grants reach the
server's 30 ordinary slots before a real page106 pickup. Refusal restores the
diff --git a/server/browser_pending_reclaim_test.go b/server/browser_pending_reclaim_test.go
@@ -0,0 +1,89 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "slices"
+ "testing"
+ "time"
+)
+
+func TestBrowserReclaimDuringEquipment(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for reclaim pickup during pending equipment")
+ }
+
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/pending-reclaim", time.Now().Format("20060102-150405"))
+ world := newTestServer(t)
+ player := world.newCharacter()
+ world.characters = map[uint32]*character{player.id: player}
+ player.level, player.appearance = 10, 0x515
+ player.playfield, player.position = 705, [3]float32{598, 16.9, 329}
+ player.rotation = [4]float32{0, 0.70710677, 0, 0.70710677}
+ player.stats = testCharacterStats()
+ player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("pending-reclaim")))
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ for _, template := range []uint32{209283, 42640} {
+ if granted, err := world.grantItem_locked(player, template); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ }
+ inventory := player.inventory
+ inventory.Reclaim = []reclaimItem{{inventory.Items[1], time.Now().Add(-time.Hour).UTC()}}
+ inventory.Items = slices.Clone(inventory.Items[:1])
+ 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,
+ "reclaimSlots": world.clients[1].reclaimItems})
+ })
+ // Hold the admitted equipment move until the refused pickup has been observed.
+ 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_reclaim.mjs"), host.URL, output)
+ command.Dir, command.Stdout, command.Stderr = root, os.Stdout, os.Stderr
+ if err := command.Run(); 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: 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(cold.characters[1].inventory.Reclaim) != 0 {
+ t.Fatal("pending equipment reclaim retry lost an item or retained a duplicate source")
+ }
+ t.Logf("Browser artifacts: %s", output)
+}
diff --git a/server/reclaim.go b/server/reclaim.go
@@ -98,7 +98,7 @@ func (server *server) takeReclaim(client *worldClient, body []byte) error {
server.mutex.Lock()
player := server.characters[client.id]
source := binary.BigEndian.Uint32(body[20:24])
- if !client.target || server.clients[client.id] != client || !client.ready || client.loading || player.health == 0 || client.equipment != nil || client.trade != nil ||
+ if !client.target || server.clients[client.id] != client || !client.ready || client.loading || player.health == 0 || client.trade != nil ||
binary.BigEndian.Uint32(body[4:8]) != 50000 || binary.BigEndian.Uint32(body[8:12]) != client.id ||
binary.BigEndian.Uint32(body[24:28]) != 50000 || binary.BigEndian.Uint32(body[28:32]) != client.id ||
binary.BigEndian.Uint32(body[32:36]) != 111 || source >= uint32(len(client.reclaimItems)) ||
@@ -125,7 +125,7 @@ func (server *server) takeReclaim(client *worldClient, body []byte) error {
break
}
}
- if slot == 94 {
+ if slot == 94 || client.equipment != nil {
server.mutex.Unlock()
return client.send(characterActionPacket(client.id, [5]uint32{146, 106, source}))
}
diff --git a/server/reclaim_test.go b/server/reclaim_test.go
@@ -300,6 +300,64 @@ func TestReclaimFullInventoryAndFailedPickupSaveRetainSource(t *testing.T) {
}
}
+func TestReclaimPendingEquipmentRestoresSourceForRetry(t *testing.T) {
+ world, conn := newReclaimWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ inventory := player.inventory
+ inventory.LastID, world.nextItem = 5, 5
+ inventory.Reclaim = []reclaimItem{
+ {ownedItem{ID: 4, Type: 51005, Template: 42640, Quality: 1, Slot: 65, Count: 1}, time.Now().Add(-time.Second)},
+ {ownedItem{ID: 5, Type: 51005, Template: 42640, Quality: 1, Slot: 65, Count: 1}, time.Now().Add(-time.Second)},
+ }
+ if err := world.saveInventory_locked(player, inventory); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleReclaim(client, reclaimRequest(109)); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleInventory(client, reclaimTakeRequest(0)); err != nil {
+ t.Fatal(err)
+ }
+ if err := world.handleInventory(client, itemMovePacket(1, 6, 111)[20:]); err != nil || client.equipment == nil {
+ t.Fatal("equipment removal did not begin", err)
+ }
+ move := *client.equipment
+ before, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ conn.packets = nil
+
+ if err := world.handleInventory(client, reclaimTakeRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ after, err := readTestItemStore(world)
+
+ if err != nil || !bytes.Equal(before, after) || *client.equipment != move ||
+ !slices.Equal(client.reclaimItems, []uint32{0, 5}) {
+ t.Fatal("busy reclaim pickup changed durable ownership, its source mapping or the original move", err)
+ }
+ if len(conn.packets) != 1 || binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x5e477770 ||
+ binary.BigEndian.Uint32(conn.packets[0][29:33]) != 146 || binary.BigEndian.Uint32(conn.packets[0][33:37]) != 106 ||
+ binary.BigEndian.Uint32(conn.packets[0][37:41]) != 1 {
+ t.Fatal("busy reclaim pickup did not restore the exact native source")
+ }
+ world.advanceEquipment(move.readyAt)
+ if err := world.handleInventory(client, reclaimTakeRequest(1)); err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t)
+ if !reflect.DeepEqual(player.inventory, cold.characters[1].inventory) || len(player.inventory.Reclaim) != 0 ||
+ !slices.Equal(client.reclaimItems, []uint32{0, 0}) || len(player.inventory.Items) != 5 {
+ t.Fatal("reclaim retry lost or duplicated durable items")
+ }
+ for i, slot := range []uint32{67, 64, 65, 66, 68} {
+ if player.inventory.Items[i].ID != uint32(i+1) || player.inventory.Items[i].Slot != slot {
+ t.Fatal("reclaim retry changed an exact item's location", player.inventory.Items)
+ }
+ }
+}
+
func TestReclaimConcurrentPickupKeepsOtherWindowSlotsStable(t *testing.T) {
world, _ := newReclaimWorld(t)
player, client := world.characters[1], world.clients[1]
diff --git a/tools/client/test_pending_reclaim.mjs b/tools/client/test_pending_reclaim.mjs
@@ -0,0 +1,80 @@
+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-reclaim', 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 [x, y] = await game.pick(51059, 0xc00a02c1);
+ await game.click(x, y, 'right');
+ await game.wait('reclaim source icon', state => state.grids.some(grid => grid.cells.some(cell => cell.identity[0] === 106 && !cell.dummy)));
+ await game.key('i');
+ await page.keyboard.press('Control+1');
+ const weapon = game.state.grids.flatMap(grid => grid.cells).find(cell => cell.identity[0] === 104 && !cell.dummy);
+ assert(weapon);
+ const equipSequence = game.sequence;
+ await game.click((weapon.bounds[0] + weapon.bounds[2]) / 2, (weapon.bounds[1] + weapon.bounds[3]) / 2);
+ 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);
+ assert.deepEqual(evidence.pending.reclaimSlots, [2]);
+ 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 sequence = game.sequence;
+ await game.click(30, 45);
+ await game.wait('actual reclaim pickup during pending equipment', () => game.events.some(event => event.sequence > sequence &&
+ event.direction === 'framesent' && event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 106));
+ evidence.refused = await server();
+ assert.deepEqual(evidence.refused, evidence.pending);
+ await game.save(output + '/pending');
+ await game.wait('pending reclaim pickup 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('reclaim source icon restored', state => state.grids.some(grid => grid.cells.some(cell =>
+ cell.identity[0] === 106 && cell.identity[1] === 0 && !cell.dummy)));
+ 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 equipment completes', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 6));
+ await game.click(30, 45);
+ await game.wait('same-window reclaim retry succeeds', state => game.local(state).inventory.some(item => item.id === 2 && item.slot === 48));
+ evidence.after = await server();
+ assert.equal(evidence.after.pending, null);
+ assert.deepEqual(evidence.after.reclaimSlots, [0]);
+ assert.deepEqual(evidence.after.inventory, {...evidence.pending.inventory, Reclaim: null, Items: [
+ {...evidence.pending.inventory.Items[0], Slot: 6}, {...evidence.pending.inventory.Reclaim[0].Item, Slot: 64}]});
+ assert.equal(game.events.filter(event => event.sequence > sequence && event.direction === 'framesent' &&
+ event.opcode === '47537a24' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 106).length, 2);
+ await game.save(output + '/picked');
+ await page.reload();
+ await game.ready();
+ await page.waitForFunction(() => touchRegion(500, 400)?.world === true);
+ await game.snapshot();
+ if (!game.state.grids.some(grid => grid.cells.some(cell => cell.identity[0] === 104 && !cell.dummy))) await game.key('i');
+ await game.wait('recovered part visible after replay', state => state.grids.some(grid => grid.cells.some(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === 48 && !cell.dummy)));
+ 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, 48, 1, 1]]);
+ assert.equal(game.errors.length, 0);
+ console.log('PASS: pending equipment reclaim refusal restores its source, retains the move and permits exact 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(); }
+}