commit 31910f3883ae3a41892ae4d7b81f8e81b41c52c8
parent fd8f20869e98ef18939a60f4096fd4b107bc994c
Author: anon <anon@example.com>
Date: Tue, 3 Nov 2026 12:03:01 +0000
Restore stack join sources refused during pending equipment
Diffstat:
6 files changed, 341 insertions(+), 0 deletions(-)
diff --git a/TODO.md b/TODO.md
@@ -3776,6 +3776,14 @@ 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 carried stack source after a join refused during pending
+ equipment. A controlled late-completion checkpoint reproduced native action 53
+ leaving the removed stack hidden with an empty cursor. Restore that validated
+ source without joining counts, writing storage or changing the admitted move
+ and deadline. Public-handler wear/removal checks and short WASM completion,
+ same-source retry, page replay and cold recovery preserve six charges and the
+ exact weapon/surviving stack. Unknown and admitted sources remain untouched;
+ see [pending stack joins](docs/inventory-stacks.md#join-during-pending-equipment).
- [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
diff --git a/docs/inventory-stacks.md b/docs/inventory-stacks.md
@@ -114,6 +114,48 @@ Stacks inside the supported [backpack](backpacks.md) use page 107's packed
handle/slot positions. Their optimistic-split correction uses the native Chest
InventoryUpdate replacement instead of rebuilding ordinary inventory.
+## Join during pending equipment
+
+A controlled late-completion checkpoint reproduced a hidden ordinary-stack
+source. The local equipment bar had ended while the server's admitted weapon
+move still awaited completion. Dragging one compatible stack onto another sent
+action 53, keeping the first identity and removing the second. The server refused
+the join without replying. Counts remained three plus three in storage, but the
+removed source's cell stayed dummy with an empty cursor.
+
+The pending-equipment handler now validates the removed ordinary stack and
+restores its source through two ContainerAddItem GUI moves. Their temporary slot
+excludes both admitted equipment slots. Both stack positions and counts finish
+unchanged; the refused operation writes no database state or new identity and
+preserves the equipment move/deadline. It sends no successful join acknowledgement.
+After the admitted move completes, the same join can keep its normal identity
+and consolidate all six charges. Unknown, foreign-page and admitted sources
+remain ignored.
+
+CharacterAction 146 is not used here: original `kkr.dll` function `10062960`
+stops the equipment-delay timer before source refresh. Its existing original
+evidence is `ev_25a2e47151e712e04a9aee10cc6ae5c3b8efd8f18353f2a2896b9cea7735dbb9`,
+with ordinary-page refresh in `100624b0`, evidence
+`ev_61d1c5f099044724b2a7a112f62381870d1411303dd74b6a3e17f3636c1a8440`.
+Retained dossiers and limits are in `local/bank-failure-research/feedback/`.
+The original client's ordinary-grid refresh can also make its weapon source
+icon visible again. Preservation is checked against the unchanged admitted
+server move and its eventual native completion, not a requirement to retain
+every temporary dummy icon.
+
+`TestPendingStackJoin*` covers both merge directions during wear and removal,
+exact source feedback, unchanged database state, admitted slots/deadline,
+normal retry and cold counts/ownership. `TestBrowserStackJoinDuringPendingEquipment`
+uses real equipment and join gestures, reproduces the refused source, completes
+the weapon move and retries the same join. Page replay and a fresh database
+reader retain the exact weapon and surviving six-charge stack. The fixture holds
+server completion past the local bar; it does not establish historical
+concurrent-inventory permission or the original server's refusal packet choice.
+Related Go checks pass 67 roots/289 results; focused race checks pass 5/16 and
+vet is clean. The native check completes in 19.25 seconds with three clean,
+complete traces. Captures, baseline failures, source hashes and limits are in
+`local/pending-stack/verification-summary.json`.
+
## Verification
`server/stacks_test.go` exercises grant quantities, merge direction, source
diff --git a/server/browser_pending_stack_test.go b/server/browser_pending_stack_test.go
@@ -0,0 +1,77 @@
+package main
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/json"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "os"
+ "os/exec"
+ "path/filepath"
+ "runtime"
+ "slices"
+ "testing"
+ "time"
+)
+
+func TestBrowserStackJoinDuringPendingEquipment(t *testing.T) {
+ if os.Getenv("AO_GAME_TEST") != "1" {
+ t.Skip("set AO_GAME_TEST=1 for stack joining during pending equipment")
+ }
+
+ _, source, _, _ := runtime.Caller(0)
+ root := filepath.Dir(filepath.Dir(source))
+ output := filepath.Join(root, "local/pending-stack", time.Now().Format("20060102-150405"))
+ world := newTestServer(t)
+ player := world.newCharacter()
+ player.stats = testCharacterStats()
+ player.browserTokenHash = fmt.Sprintf("%x", sha256.Sum256([]byte("pending-stack")))
+ if err := world.saveUser_locked(player); err != nil {
+ t.Fatal(err)
+ }
+ for _, template := range []uint32{209283, 152030, 152030} {
+ if granted, err := world.grantItem_locked(player, template); err != nil || !granted {
+ t.Fatal(granted, 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})
+ })
+ 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_stack.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: 3, Type: 51005, Template: 152030, Quality: 42, Slot: 66, Count: 6}}
+ if !slices.Equal(cold.characters[1].inventory.Items, expected) {
+ t.Fatal("stack join refusal/retry changed equipment or lost charges")
+ }
+}
diff --git a/server/inventory.go b/server/inventory.go
@@ -263,6 +263,26 @@ func (server *server) handleInventory(client *worldClient, body []byte) error {
if key == 0x5e477770 && binary.BigEndian.Uint32(body[16:20]) == 52 {
return server.syncStacks_locked(client)
}
+ // Join waits for a reply with its removed stack's source hidden.
+ if key == 0x5e477770 && binary.BigEndian.Uint32(body[16:20]) == 53 &&
+ binary.BigEndian.Uint32(body[20:24]) == 104 && binary.BigEndian.Uint32(body[28:32]) == 104 {
+ source := binary.BigEndian.Uint32(body[32:36])
+ index := slices.IndexFunc(character.inventory.Items, func(item ownedItem) bool { return item.Slot == source })
+ if source >= 64 && source < 94 && index >= 0 && character.inventory.Items[index].isStackable() &&
+ character.inventory.Items[index].ID != client.equipment.itemID {
+ // Keep both pending equipment slots out of transient GUI moves.
+ other := uint32(64)
+ for other == source || other == client.equipment.source || other == client.equipment.destination {
+ other++
+ }
+ for _, packet := range [][]byte{itemMovePacket(client.id, source, other), itemMovePacket(client.id, other, source)} {
+ if err := client.send(packet); err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+ }
// Validate a separate owned-item move before restoring its native source.
if key != 0x47537a24 || binary.BigEndian.Uint32(body[24:28]) != 50000 ||
binary.BigEndian.Uint32(body[28:32]) != client.id ||
diff --git a/server/pending_stack_test.go b/server/pending_stack_test.go
@@ -0,0 +1,120 @@
+package main
+
+import (
+ "bytes"
+ "encoding/binary"
+ "reflect"
+ "slices"
+ "testing"
+)
+
+func TestPendingStackJoinRestoresSourceAndRetries(t *testing.T) {
+ for _, scenario := range []struct {
+ name string
+ unequip bool
+ removed uint32
+ kept uint32
+ remainingID uint32
+ }{{"wear/remove65", false, 65, 66, 3}, {"wear/remove66", false, 66, 65, 2},
+ {"remove/remove65", true, 65, 66, 3}, {"remove/remove66", true, 66, 65, 2}} {
+ t.Run(scenario.name, func(t *testing.T) {
+ world, conn := newEquipmentWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ for range 2 {
+ if granted, err := world.grantItem_locked(player, 152030); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ }
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ if scenario.unequip {
+ world.advanceEquipment(client.equipment.readyAt)
+ if err := world.handleInventory(client, itemMovePacket(1, 6, 64)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ }
+ pending := *client.equipment
+ before := slices.Clone(player.inventory.Items)
+ persisted, err := readTestItemStore(world)
+ if err != nil {
+ t.Fatal(err)
+ }
+ conn.packets = nil
+ auditCheckpointWrites(t, world)
+ request := stackActionPacket(1, 53, scenario.kept, scenario.removed)[20:]
+
+ err = world.handleInventory(client, request)
+ after, readErr := readTestItemStore(world)
+
+ if err != nil || readErr != nil || !bytes.Equal(persisted, after) || !slices.Equal(player.inventory.Items, before) ||
+ *client.equipment != pending || world.nextItem != 3 || len(conn.packets) != 2 {
+ t.Fatal("join refusal changed counts, identity or the admitted equipment move", err, readErr)
+ }
+ if writes := checkpointWrites(t, world); len(writes) != 0 {
+ t.Fatal("join refusal wrote durable state", writes)
+ }
+ if binary.BigEndian.Uint32(conn.packets[0][16:20]) != 0x47537a24 || binary.BigEndian.Uint32(conn.packets[1][16:20]) != 0x47537a24 ||
+ binary.BigEndian.Uint32(conn.packets[0][33:37]) != scenario.removed-16 || binary.BigEndian.Uint32(conn.packets[0][45:49]) != scenario.kept-16 ||
+ binary.BigEndian.Uint32(conn.packets[1][33:37]) != scenario.kept-16 || binary.BigEndian.Uint32(conn.packets[1][45:49]) != scenario.removed-16 {
+ t.Fatal("join refusal corrected the kept stack instead of the removed source")
+ }
+
+ // Complete the admitted move and retry the same join through public handlers.
+ world.advanceEquipment(pending.readyAt)
+ if err := world.handleInventory(client, request); err != nil {
+ t.Fatal(err)
+ }
+ cold := newTestInventoryServer(t)
+ weaponSlot := uint32(6)
+ if scenario.unequip {
+ weaponSlot = 64
+ }
+ expected := []ownedItem{{ID: 1, Type: 51018, Template: 209283, Quality: 1, Slot: weaponSlot, Count: 1},
+ {ID: scenario.remainingID, Type: 51005, Template: 152030, Quality: 42, Slot: scenario.kept, Count: 6}}
+ if client.equipment != nil || !slices.Equal(player.inventory.Items, expected) ||
+ !slices.Equal(cold.characters[1].inventory.Items, expected) || world.nextItem != 3 {
+ t.Fatal("join retry did not retain the exact weapon and six charges")
+ }
+ })
+ }
+}
+
+func TestPendingStackJoinIgnoresUnknownAndAdmittedSources(t *testing.T) {
+ for _, scenario := range []string{"foreign owner", "foreign kept page", "foreign removed page", "unknown source", "admitted source"} {
+ t.Run(scenario, func(t *testing.T) {
+ world, conn := newEquipmentWorld(t)
+ player, client := world.characters[1], world.clients[1]
+ for range 2 {
+ if granted, err := world.grantItem_locked(player, 152030); err != nil || !granted {
+ t.Fatal(granted, err)
+ }
+ }
+ if err := world.handleInventory(client, inventoryMovePacket(1, 64, 6)[20:]); err != nil {
+ t.Fatal(err)
+ }
+ pending := *client.equipment
+ before := player.inventory
+ request := stackActionPacket(1, 53, 66, 65)[20:]
+ switch scenario {
+ case "foreign owner":
+ binary.BigEndian.PutUint32(request[8:12], 2)
+ case "foreign kept page":
+ binary.BigEndian.PutUint32(request[20:24], 106)
+ case "foreign removed page":
+ binary.BigEndian.PutUint32(request[28:32], 106)
+ case "unknown source":
+ binary.BigEndian.PutUint32(request[32:36], 93)
+ case "admitted source":
+ binary.BigEndian.PutUint32(request[32:36], 64)
+ }
+ conn.packets = nil
+
+ err := world.handleInventory(client, request)
+
+ if err != nil || !reflect.DeepEqual(player.inventory, before) || *client.equipment != pending || len(conn.packets) != 0 {
+ t.Fatal("unowned, unknown or admitted source was corrected", err)
+ }
+ })
+ }
+}
diff --git a/tools/client/test_pending_stack.mjs b/tools/client/test_pending_stack.mjs
@@ -0,0 +1,74 @@
+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-stack', 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 cell = slot => game.state.grids.flatMap(grid => grid.cells).find(cell =>
+ cell.identity[0] === 104 && cell.identity[1] === slot && !cell.dummy);
+ const click = async slot => {
+ const source = cell(slot);
+ assert(source, 'the exact inventory source must be visible');
+ await game.click((source.bounds[0] + source.bounds[2]) / 2, (source.bounds[1] + source.bounds[3]) / 2);
+ };
+ await game.key('i');
+ await page.keyboard.press('Control+1');
+ await click(48);
+ await game.click(867, 206);
+ await game.wait('admitted weapon move', () => game.events.some(event =>
+ 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 equipment animation ends', state =>
+ !game.local(state).actions.includes(3) && !game.local(state).actions.includes(6));
+ const join = async () => {
+ const sequence = game.sequence;
+ await click(49);
+ await click(50);
+ await game.wait('actual native join request', () => game.events.some(event => event.sequence > sequence &&
+ event.direction === 'framesent' && event.opcode === '5e477770' && Buffer.from(event.hex, 'hex').readUInt32BE(29) === 53));
+ };
+ await join();
+ evidence.refused = await server();
+ assert.deepEqual(evidence.refused, evidence.pending);
+ await game.save(output + '/refused');
+ await game.wait('both refused stack icons remain usable', () => cell(49) && cell(50));
+ evidence.pendingWeaponVisible = Boolean(cell(48));
+ assert.deepEqual(game.state.dragged, [0, 0]);
+ assert((await page.request.post(url + '/test-complete')).ok());
+ await game.wait('weapon completes unchanged', state => game.local(state).inventory.some(item => item.id === 1 && item.slot === 6));
+ await join();
+ await game.wait('normal join retry conserves six charges', state => game.local(state).inventory.some(item =>
+ item.slot === 50 && item.count === 6) && game.local(state).inventory.length === 2);
+ evidence.after = await server();
+ assert.equal(evidence.after.pending, null);
+ assert.deepEqual(evidence.after.inventory.Items, [
+ {...evidence.pending.inventory.Items[0], Slot: 6}, {...evidence.pending.inventory.Items[2], Count: 6}]);
+ await game.save(output + '/retried');
+ await page.reload();
+ await game.ready();
+ assert.deepEqual(game.local().inventory.map(item => [item.id, item.slot, item.count]).sort((a, b) => a[0] - b[0]),
+ [[1, 6, 1], [3, 50, 6]]);
+ assert.deepEqual(game.errors, []);
+ console.log('PASS: pending equipment join refusal preserves usable stacks and permits six-charge retry');
+} 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(); }
+}