Skip to content

Fix deadlock when crafting job with reusable ingredient depends on crafting that ingredient#186

Merged
rubensworks merged 2 commits intofix/182from
copilot/add-game-test-and-fix-bug
Mar 2, 2026
Merged

Fix deadlock when crafting job with reusable ingredient depends on crafting that ingredient#186
rubensworks merged 2 commits intofix/182from
copilot/add-game-test-and-fix-bug

Conversation

Copy link
Contributor

Copilot AI commented Mar 2, 2026

When a crafting job required a reusable ingredient (e.g., shears) that itself needed to be crafted as a dependency, the system would deadlock: the reusable ingredient ended up in lastMissingIngredients during buffer fill, and the update loop condition if (lastMissingIngredients.isEmpty() || true) (the || true was a temporary workaround) gated the lazy extraction that would have unblocked the job.

Changes

CraftingHelpers

  • Added skipReusableIngredients flag (default false) to getIngredientRecipeInputs (new 9-param overload, 8-param delegates) and getRecipeInputs (new 8-param overload, 7-param delegates). When true, reusable ingredient slots are emitted as empty placeholders — not extracted from storage, not reported as missing.

CraftingJobHandler

  • fillCraftingJobBufferFromStorage: passes skipReusableIngredients=true when the job has pending dependencies, so reusable ingredients stay in storage and are extracted lazily once dependencies complete. Removes the debug System.out.println.
  • Update loop: removes the if (lastMissingIngredients.isEmpty() || true) wrapper so the reusable-ingredient handling always runs when the buffer is missing a reusable ingredient — regardless of prior fill state.

Game test

  • testItemsCraftDeadBushTagReusableNeedsCrafting: reproduces the deadlock scenario — no shears in initial storage, 2 iron ingots available to craft them, requests 10 dead bushes via a reusable-shears recipe. Asserts 10 dead bushes produced and 1 shears returned.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

…endencies

Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com>
Copilot AI changed the title [WIP] Add game test to reproduce bug and implement proposed fix Fix deadlock when crafting job with reusable ingredient depends on crafting that ingredient Mar 2, 2026
@rubensworks rubensworks marked this pull request as ready for review March 2, 2026 19:25
@rubensworks rubensworks merged commit 73e8727 into fix/182 Mar 2, 2026
2 of 3 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.

2 participants