Skip to content

fix(inventory): prevent phantoms, wipes and dupes of inventory items#747

Open
olisikh wants to merge 8 commits intoMUnique:masterfrom
olisikh:fix/prevent-inventory-wipes
Open

fix(inventory): prevent phantoms, wipes and dupes of inventory items#747
olisikh wants to merge 8 commits intoMUnique:masterfrom
olisikh:fix/prevent-inventory-wipes

Conversation

@olisikh
Copy link
Copy Markdown
Contributor

@olisikh olisikh commented Apr 5, 2026

This PR hardens item movement and rollback behavior to prevent inventory wipes, dupes, and desyncs during failed operations and edge-case states.

What changed

  • Added move-state validation so item moves are only processed in valid gameplay states (EnteredWorld, NpcDialogOpened, TradeOpened, TradeButtonPressed).
  • Strengthened rollback for failed moves:
    • first restore to original slot,
    • then fallback to any free slot,
    • log critical context if both fail,
    • trigger inventory refresh to resync client/server state.
  • Fixed complete-stack handling so the source item is actually removed from its storage after stacking.
  • Fixed slot-blocking logic that used the wrong index while scanning occupied slots.
  • Corrected IItemMovingPlugIn call to report the actual target storage.
  • Hardened trade/disconnect backup restore paths with per-item exception handling, fallback placement, and detailed logging so one bad item doesn’t abort full restore.

Effect

  • Lower risk of full inventory wipe on restore/cancel flows.
  • Lower risk of duplication from stack/move edge cases.
  • Better consistency between in-memory inventory, persisted state, and client view.
  • Better diagnostics when recovery paths are hit.

I have been running these changes on my local server and didn't see an issue, but this PR should be taken with a grain of salt.

@olisikh olisikh closed this Apr 5, 2026
@olisikh olisikh reopened this Apr 5, 2026
@olisikh olisikh changed the title bug(inventory): prevent phantoms, wipes and dupes of inventory items fix(inventory): prevent phantoms, wipes and dupes of inventory items Apr 5, 2026
@olisikh olisikh force-pushed the fix/prevent-inventory-wipes branch from 65afed6 to a6a8c81 Compare April 5, 2026 15:27
@olisikh olisikh marked this pull request as ready for review April 9, 2026 11:53
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the stability and reliability of the inventory system by addressing potential issues leading to item wipes, duplications, and desynchronizations. It introduces stricter validation for item movements, implements a more resilient rollback mechanism for failed operations, and improves the robustness of backup inventory restoration processes. These changes aim to provide a more consistent and predictable inventory experience for players while offering better diagnostic capabilities for developers.

Highlights

  • Enhanced Item Movement Validation: Item movements are now strictly validated against the player's current gameplay state (e.g., EnteredWorld, NpcDialogOpened, TradeOpened, TradeButtonPressed) to prevent unintended operations.
  • Robust Rollback for Failed Item Moves: The system now attempts to restore items to their original slot upon a failed move. If that fails, it tries any free slot. Critical errors are logged, and the client's inventory state is refreshed to ensure synchronization.
  • Corrected Full Stack Item Handling: When items are fully stacked, the source item is now correctly removed from its original storage, preventing item duplication.
  • Fixed Slot Blocking Logic: The logic for determining occupied slots during item placement has been corrected to use the proper index, resolving issues with item placement and potential phantom items.
  • Hardened Backup Inventory Restoration: During trade cancellations and disconnects, the backup inventory restoration process now includes per-item exception handling and fallback placement, ensuring that one problematic item does not prevent the restoration of others.
  • Improved Client Inventory Synchronization: The client-side inventory update mechanism now handles cases with missing item definitions and prevents issues caused by duplicate item slots, leading to better consistency between server and client.
  • Comprehensive Item Movement Tests: New unit tests have been added to cover various item movement scenarios, including stacking, failed moves, and persistence, significantly improving code reliability.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request significantly enhances item management and trade functionalities. It introduces more robust error handling and logging for item restoration during player login and trade cancellations, ensuring that items are restored reliably even if some fail. The item movement logic has been refined with a new IsMoveAllowed check for player states, corrected plugin parameter passing, and improved rollback mechanisms for failed moves, including critical logging for inconsistent inventory states. The inventory update process now prevents duplicate item entries and dynamically adjusts item counts. New comprehensive unit tests have been added for item movement and trade cancellation scenarios, including a test for graceful handling of invalid backup items during trade cancellation. Feedback suggests refactoring the FullStackAsync method to use a more semantically appropriate plugin for item consumption instead of ItemMoveFailedAsync, and removing the redundant AreTargetSlotsBlocked method.

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