Skip to content

fix(container): handle depot and batch page state - #3995

Merged
dudantas merged 4 commits into
mainfrom
dudantas/fix-critical-container-bugs
Jun 9, 2026
Merged

fix(container): handle depot and batch page state#3995
dudantas merged 4 commits into
mainfrom
dudantas/fix-critical-container-bugs

Conversation

@dudantas

@dudantas dudantas commented Jun 5, 2026

Copy link
Copy Markdown
Member

This is a small functional follow-up to the container batching work.

It fixes edge cases exposed by batched container refreshes:

  • depot chest windows could remain open after the player moved away from depot access;
  • batched container refreshes could resend a stale firstIndex after removals changed the container size;
  • BatchUpdate:delete() now uses the typed shared userdata finalizer, matching the Lua userdata ownership contract.

Related context:

This PR does not add new performance behavior or change container ownership.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed container batch updates to always send valid page indices to clients.
    • Improved depot container closing behavior to properly respond to player proximity changes.

Copilot AI review requested due to automatic review settings June 5, 2026 14:31
@coderabbitai

coderabbitai Bot commented Jun 5, 2026

Copy link
Copy Markdown

Ready to act? Review this PR in Change Stack to turn feedback into patch suggestions you can inspect and refine.

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d0f68b58-2e4c-4bc7-98f8-0b1c11937680

📥 Commits

Reviewing files that changed from the base of the PR and between c2ed1c7 and e38f29d.

📒 Files selected for processing (1)
  • src/lua/functions/core/game/batch_update_functions.cpp
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/lua/functions/core/game/batch_update_functions.cpp

📝 Walkthrough

Walkthrough

Const-correctness is added to Player::isNearDepotBox in both declaration and implementation. The method is then used to refine depot-chest container closure logic. Batch container updates are hardened to recalculate page indices when out of bounds. Lua garbage-collection for BatchUpdate switches to shared-pointer semantics.

Changes

Container Management and Depot Handling

Layer / File(s) Summary
isNearDepotBox const-correctness and depot proximity logic
src/creatures/players/player.hpp, src/creatures/players/player.cpp
Player::isNearDepotBox is made const in both header and implementation. Player::shouldCloseContainer now returns !isNearDepotBox() for depot-chest-top-parent cases instead of unconditionally returning false, changing depot container closure decisions based on proximity to depot boxes.
Batch container index validation
src/creatures/players/player.cpp
Player::sendBatchUpdateContainer recalculates containerInfo.index to align with container size boundaries when the stored index falls outside the current container range, ensuring valid page indices are sent to the client.
Lua garbage collection for BatchUpdate
src/lua/functions/core/game/batch_update_functions.cpp
BatchUpdate.delete Lua method registration switches the userdata garbage-collection handler from Lua::luaGarbageCollection to Lua::luaSharedPtrGarbageCollection<BatchUpdate>.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related PRs

  • opentibiabr/canary#3970: Both PRs modify Player::sendBatchUpdateContainer in src/creatures/players/player.cpp, changing batch container update handling.

Poem

🐰 Container fixes, const and true,
Depot chests now know what's near and do,
Batch indices dance within their bounds,
Shared pointers collect in garbage rounds,
A cleaner game, one hop at a time!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix(container): handle depot and batch page state' directly and concisely captures the main changes: fixing depot container closure behavior and batch container page index handling.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dudantas/fix-critical-container-bugs

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 Infer (1.2.0)
src/lua/functions/core/game/batch_update_functions.cpp

src/lua/functions/core/game/batch_update_functions.cpp:10:10: fatal error: 'lua/functions/core/game/batch_update_functions.hpp' file not found
10 | #include "lua/functions/core/game/batch_update_functions.hpp"
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Error: the following clang command did not run successfully:
/opt/infer-linux-x86_64-v1.2.0/lib/infer/facebook-clang-plugins/clang/install/bin/clang-18
@/tmp/coderabbit-infer/e38f29d353a424582f2d2257b374a9a8c85e9249-af2f926215a39dfe/tmp/clang_command_.tmp.ba0a67.txt
++Contents of '/tmp/coderabbit-infer/e38f29d353a424582f2d2257b374a9a8c85e9249-af2f926215a39dfe/tmp/clang_command_.tmp.ba0a67.txt':
"-cc1" "-load"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../../facebook-clang-plugins/libtooling/build/FacebookClangPlugin.dylib"
"-add-plugin" "BiniouASTExporter" "-plugin-arg-BiniouASTExporter" "-"
"-plugin-arg-BiniouASTExporter" "PREPEND_CURRENT_DIR=1"
"-pl

... [truncated 1251 characters] ...

"-internal-isystem" "/usr/local/include" "-internal-isystem"
"/usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include"
"-internal-externc-isystem" "/usr/include/x86_64-linux-gnu"
"-internal-externc-isystem" "/include" "-internal-externc-isystem"
"/usr/include" "-Wno-ignored-optimization-argument" "-Wno-everything"
"-fdeprecated-macro" "-ferror-limit" "19" "-fgnuc-version=4.2.1"
"-fskip-odr-check-in-gmf" "-fcxx-exceptions" "-fexceptions"
"-D__GCC_HAVE_DWARF2_CFI_ASM=1" "-o"
"/tmp/coderabbit-infer/af2f926215a39dfe/file.o" "-x" "c++"
"src/lua/functions/core/game/batch_update_functions.cpp" "-O0"
"-fno-builtin" "-include"
"/opt/infer-linux-x86_64-v1.2.0/lib/infer/infer/bin/../lib/clang_wrappers/global_defines.h"
"-Wno-everything"


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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

Copy link
Copy Markdown

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 marks Player::isNearDepotBox() as a const method, updates the depot chest closing logic to check if the player is near a depot box, and adjusts the container batch update logic to dynamically correct out-of-bounds indices. Additionally, it fixes the Lua garbage collection registration for BatchUpdate to use luaSharedPtrGarbageCollection. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Follow-up fix to the recent container batching work, addressing edge cases in container window lifecycle and Lua userdata ownership. It ensures depot-related container windows don’t remain open after losing depot access, and hardens batched container refresh behavior when the container size changes.

Changes:

  • Switch BatchUpdate.delete() to the typed shared-userdata shared_ptr finalizer (luaSharedPtrGarbageCollection), aligning with the shared userdata ownership contract.
  • Make Player::isNearDepotBox() const and use it to close depot chest windows when the player is no longer near a depot tile.
  • Clamp/adjust the container “first index” during batched container sends to avoid resending an out-of-range index after removals shrink the container.

Tests: Not run (review only).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/lua/functions/core/game/batch_update_functions.cpp Aligns BatchUpdate.delete() with typed shared-userdata shared_ptr GC behavior.
src/creatures/players/player.hpp Makes isNearDepotBox() const to support calls from const contexts.
src/creatures/players/player.cpp Fixes batched container resend index when size shrinks; closes depot chest containers when player moves away from depot access.

@dudantas dudantas changed the title fix(container): close stale depot and batch windows fix(container): handle depot and batch page state Jun 5, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/lua-api/lua_api.d.lua`:
- Around line 104-105: The LuaDoc for BatchUpdate.delete currently declares
"---@return any" but the binding uses
Lua::luaSharedPtrGarbageCollection<BatchUpdate> which returns no Lua values
(effectively nil); update the documentation for the function BatchUpdate.delete
to "---@return nil" to match other delete methods (e.g., Condition.delete,
NetworkMessage.delete) and the actual binding behavior.

In `@docs/lua-api/lua_api.json`:
- Around line 172-175: The docs entry for BatchUpdate.delete incorrectly
declares "return": "any"; update the JSON so the return matches the actual
implementation (luaSharedPtrGarbageCollection<BatchUpdate> via
lua_functions_loader.hpp) which returns no Lua values—change the "return" field
to your project’s no-return convention (e.g., "nil" or explicit "void"/"none"
used elsewhere) for the "delete" function in the JSON to accurately reflect
runtime behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e6f66267-a6f8-4d03-92ca-61f1a49a929b

📥 Commits

Reviewing files that changed from the base of the PR and between 31fa9d2 and c2ed1c7.

📒 Files selected for processing (3)
  • docs/lua-api/lua_api.d.lua
  • docs/lua-api/lua_api.json
  • docs/lua-api/lua_api.md
✅ Files skipped from review due to trivial changes (1)
  • docs/lua-api/lua_api.md

Comment thread docs/lua-api/lua_api.d.lua Outdated
Comment thread docs/lua-api/lua_api.json
@sonarqubecloud

sonarqubecloud Bot commented Jun 5, 2026

Copy link
Copy Markdown

@dudantas
dudantas merged commit 6725cfa into main Jun 9, 2026
20 checks passed
@dudantas
dudantas deleted the dudantas/fix-critical-container-bugs branch June 9, 2026 17:42
nicollassantos added a commit to nicollassantos/canary that referenced this pull request Jun 10, 2026
Merges 4 upstream commits from main:
- fix(container) opentibiabr#3995: page-index bounds clamp in sendBatchUpdateContainer,
  isNearDepotBox() → const, shouldCloseContainer depot proximity fix
- fix(teleport) opentibiabr#3818: anti-recursive teleport guard in InternalGame namespace
- feat: release workflow + MyAAC client 1501→1511
- chore: release metadata 3.5.0→3.6.0

SOLID boundary preserved:
- Page-index fix ported to PlayerStashComponent::sendBatchUpdateContainer
  (not re-inlined in player.cpp)
- isNearDepotBox() const propagated through PlayerStashComponent
- Teleport guard added to Game::internalTeleport facade; actual teleport
  logic stays in MovementService::internalTeleport
- 3 regression tests added (isNearDepotBox const, sendBatchUpdate null guard)

Tests: 579/579 passing

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

3 participants