Skip to content

test(coop): start soldiers empty in the base-screen tests that move items - #238

Merged
NonPolynomialTim merged 3 commits into
mainfrom
claude/fix-flaky-base-writes-belt
Nov 7, 2026
Merged

NonPolynomialTim merged 3 commits into
mainfrom
claude/fix-flaky-base-writes-belt

Conversation

@NonPolynomialTim

@NonPolynomialTim NonPolynomialTim commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Symptom

test_shared_base_writes failed once in CI: PR #233, run 42113610511 attempt 1, coop-shard (3). Row base_write_9 failed its setup check, and attempt 2 passed.

Cause (reproduced)

base_write_9 moves a grenade onto the host soldier H's belt. In the CI run, H's belt was already full: two autocannon clips at (0, 0) and (2, 0), two cells wide each, a grenade at (0, 1) and a smoke grenade at (3, 1). The grenade had no free cell.

That gear comes from the base inventory screen. When it opens, the game hands items to every soldier that has no saved layout (BattlescapeGenerator::autoEquip). The items come out of a container ordered by memory address, so the gear changes from boot to boot. It also differs between the host and the client for the same soldier in the same boot. In one probe boot, the host's screen showed a soldier with a rifle and the client's screen showed the same soldier with a rocket launcher. test_base_partner_held (#224) failed for the same reason.

Fix

  1. base_write_9 moves every item off H's belt before it stages the grenade.
  2. harness.NO_AUTO_EQUIP turns on the stock disableAutoEquip option, so every soldier starts with empty slots on both machines. The 8 tests that move items on base or craft inventory screens boot with it. Two boots keep the old setting:
    • The option-ON boot in test_shared_craft_loads, whose setup needs every craft crew member to leave the soldier screen with a saved layout.
    • test_separate_equipment_templates, which starts a battle (deployment would hand out nothing either).
  3. Rows that relied on starting gear now stage their own items. base_write_4 and base_write_8 put a pistol in the client soldier's left hand before saving its layout.
  4. test_shared_equip_transfer now drags its soldier's gear on the host's screen instead of writing the layout with give_layout. When the host closes the screen it sends only the soldier records the screen changed, and that record is what carries the soldier's new name to the client. With empty starting gear, a layout written before the screen opened was sent only when the item order happened to change. In failing runs the host's shared-command count stayed at 3 and the client never got the new name or gear.
  5. The shared close_soldier_screen helper presses OK only once SoldiersState is the top screen, and keeps the stack before and after the press. soldiers_ok presses OK on a SoldiersState anywhere in the stack, and OK closes whatever screen is on top. So a screen sitting above the soldier screen got closed instead and the soldier screen stayed open. separate_template_armor failed once locally with that exact signature. It did not reproduce in about 260 runs, so what sat on top that time is unknown. The kept stacks will name it if it happens again. The helper is used by 5 test files. The other 22 soldiers_ok call sites in 12 files are unchanged.

Proof

  • Full belt forced (pistol clips added to H's belt just before staging): the old test failed 3 of 3 times, with the same check as CI. The new test passed 3 of 3.
  • Plain runs: the unchanged test also failed base_write_9 once by itself in 5 runs.
  • disableAutoEquip probe: in 2 boots, 0 of 8 soldiers carried anything on either machine.
  • test_shared_equip_transfer: with the option and the old give_layout, 5 of 10 runs failed the world-equality check after equip and unseat. With the change, 9 of 9 passed.
  • Close helper, forced: a notice was pushed over the soldier screen the moment the inventory closed, and dismissed 1.5 s later. The old helper left SoldiersState open with soldiers_ok replying ok, 3 of 3 runs, the same signature as the local failure. The new helper waited for the notice and then closed the screen, 3 of 3. All 5 tests that use the helper passed afterwards. test_base_visit_pointer took 7.0 s, old and new.

Old and new were run interleaved on the same harness slot. CPU load was 5 to 18 % for most runs.

Test Old wall (median) New wall (median) New runs passed
test_shared_base_writes 32.3 s 32.5 s 5 of 5
test_shared_base_equip 4.6 s 4.4 s 5 of 5
test_base_partner_held 8.9 s 8.9 s 5 of 5
test_base_partner_view 52.7 s 52.6 s 5 of 5
test_shared_craft_loads 60.4 s 60.6 s 5 of 5
test_coop_equip_layout_sync 11.8 s 12.0 s 5 of 5
test_coop_peer_equip_screens 5.5 s 5.4 s 5 of 5
test_shared_equip_transfer 5.9 s 6.5 s 9 of 9

…tes stages its grenade

base_write_9 stages the host's soldier H by moving one grenade from the
ground onto H's belt. The fixture does not pin H's starting gear. In the
failing CI run H's belt already held two autocannon clips, a grenade and
a smoke grenade, which fill all six belt cells, so the grenade had no
cell, the move failed and the setup check failed.

The host now moves every item off H's belt to the ground on the same
screen before the grenade move, repeating until the belt is empty. The
setup check also requires the belt to be empty, and the moves are kept
in the row's evidence.
When a base or craft inventory screen opens, the game hands starting gear
to every soldier that has no saved layout. The items come out of a
container ordered by memory address, so the gear changes from boot to
boot and differs between the host and the client. A test that moves an
item into a slot that gear already fills fails on some boots:
test_shared_base_writes failed once in CI when the host soldier's belt
held two autocannon clips, a grenade and a smoke grenade.

harness.NO_AUTO_EQUIP turns on the stock disableAutoEquip option, so
every soldier starts with empty slots on both machines. The eight tests
that move items on these screens boot with it. test_shared_craft_loads
keeps the old setting for its option-ON boot, whose setup needs every
craft crew member to leave the soldier screen with a layout.

Rows that relied on the starting gear now stage their own items:
- test_shared_base_writes base_write_4 and base_write_8 put a pistol in
  the client soldier's left hand before saving its layout.
- test_shared_equip_transfer drags its soldier's gear on the host's
  screen in place of writing the layout with give_layout. The host's OK
  sends only the records the screen changed, and that record is what
  carries the soldier's new name to the client. With empty starting gear
  a layout written before the screen opened was sent only when the item
  order happened to change (3 of 6 runs failed).
soldiers_ok presses OK on a SoldiersState found anywhere in the state
stack, and OK closes whatever screen is on top. When another screen sits
above SoldiersState at that moment, soldiers_ok closes that screen and
leaves the soldier screen open. test_shared_base_writes
separate_template_armor failed once locally with that signature:
soldiers_ok replied ok and SoldiersState stayed open for the whole 30 s
wait. The row's later close then failed as a knock-on.

close_soldier_screen now waits until SoldiersState is the top screen
before it presses OK, and keeps the stack before and after the press in
the cell, so a repeat names the screen that was on top. Forced with a
notice pushed over the soldier screen and closed 1.5 s later: the old
helper left SoldiersState open (3 of 3 runs), the new one closed it once
the notice was gone (3 of 3).
@NonPolynomialTim
NonPolynomialTim merged commit 4aee8b3 into main Nov 7, 2026
11 checks passed
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.

1 participant