Skip to content

fix: clear a chest's lid open count when its block is replaced; make useChests await its fill commands - #4059

Open
u9g wants to merge 1 commit into
masterfrom
fix/chest-lid-stale-open-count
Open

fix: clear a chest's lid open count when its block is replaced; make useChests await its fill commands#4059
u9g wants to merge 1 commit into
masterfrom
fix/chest-lid-stale-open-count

Conversation

@u9g

@u9g u9g commented Sep 6, 2026

Copy link
Copy Markdown
Member

Fixes the useChests failure on 1.21.11 in https://github.com/PrismarineJS/mineflayer/actions/runs/34038030872/job/101499603931 (release PR #4058, which only touches the changelog).

What happened

Two stacked problems, visible in the uploaded packet trace:

  1. First attempt: a race in the test. fillChest fires three /item replace commands and opens the chest immediately. On 1.21.9+ block interaction packets run from the server's PacketProcessor queue at the start of the next tick, while chat commands wait on the main task queue and only run while the tick has time left. Under CI load the window snapshot arrived with only the first replace applied, and the mycelium assertion failed.
  2. Every retry: stale open count in block_actions.js. The aborted attempt left the double chest open, so openCountByPos held 1 for that position. The harness reset's /fill replaced the chest with air, and the server drops a container's closing block event once the block is no longer a chest, so the count was never cleared. On each retry the server's open block action carried the same count, chestLidMove was never emitted, and once(chest, 'close') timed out three times.

The second problem is a user-facing bug too: any chest broken while open never emits chestLidMove at that position again.

Changes

  • lib/plugins/block_actions.js: drop the open count on a blockUpdate that changes the block's name.
  • test/externalTests/plugins/testCommon.js: extract the superflat reset's marker echo into bot.test.awaitCommandsProcessed(marker).
  • test/externalTests/useChests.js: fillChest awaits that echo before the chest is opened.
  • test/internalTest.js: regression test that opens a chest, replaces it via block_change, and expects chestLidMove on the next open. It times out on master and passes with the fix.

Verification

  • New internal test: passes on 1.8.8, 1.12.2, 1.16.5, 1.21.11 and 26.1 with the fix; fails on unpatched master.
  • External useChests: passes locally on 1.21.11 and 1.8.8.
  • standard clean.

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Tests more than 1.5x slower than master (durations are noisy, so this is informational):

   4148ms ->   10006ms  mineflayer_external 1.10.2v fishing
   4197ms ->    9625ms  mineflayer_external 1.11.2v nether
   3314ms ->    8560ms  mineflayer_external 1.21.6v fishing

@rom1504

rom1504 commented Sep 6, 2026

Copy link
Copy Markdown
Member

Approved, resolved conflict and merge

…est(useChests): await the fill commands before opening the chest

The block_actions plugin only forgets a position's open count on a closing
block_action. A chest broken or replaced while open never gets one: the
server drops the close block event once the block is no longer a chest.
Every later open at that position then matches the stale count and
chestLidMove is never emitted again.

useChests hit exactly that on retry. The first attempt raced: fillChest
sends three /item replace commands and opens the chest right away, but on
1.21.9+ block interaction packets run from a separate PacketProcessor queue
at the start of the tick while commands wait on the main task queue, so the
window snapshot arrived with only the first replace applied. The aborted
attempt left the chest open, the reset's /fill removed it, and all three
retries then timed out waiting for the close that chestLidMove triggers.

Wait for a chat marker echo after the fill commands (extracted from the
superflat reset into bot.test.awaitCommandsProcessed), and drop the open
count on any blockUpdate that changes the block's name.
@u9g
u9g force-pushed the fix/chest-lid-stale-open-count branch 2 times, most recently from e85ad0b to 60c76e9 Compare September 6, 2026 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants