Skip to content

docs(inventory): cite the declared sgw_inventory PK in bandolier TOCTOU comments - #603

Open
BangRocket wants to merge 1 commit into
mainfrom
fix/533-inventory-pk-wording
Open

BangRocket wants to merge 1 commit into
mainfrom
fix/533-inventory-pk-wording

Conversation

@BangRocket

Copy link
Copy Markdown
Contributor

Summary

Corrects two doc comments that understated the uniqueness guarantee behind the bandolier-ammo TOCTOU guard. Both claimed sgw_inventory.item_id is unique only incidentally (sequence allocation + the sgw_inventory_unique_slot index) with "no declared PK/UNIQUE constraint." That's wrong — db/sgw/_primary_keys.sql declares:

  • L31 sgw_inventory_base_pkey PRIMARY KEY (item_id)
  • L39 sgw_inventory_pkey PRIMARY KEY (item_id)

The child table carries its own PK because a parent PK doesn't span INHERITS children, and update_bandolier_ammo targets sgw_inventory directly — so the child PK applies and the WHERE … item_id = $5 guard added in #520 matches at most one row by declared constraint, not just by construction.

Changes

  • crates/entity/src/cell_entity/mod.rs — BandolierItem.instance_id doc now cites sgw_inventory_pkey, notes the INHERITS PK subtlety, and mentions the local_id_check CHECK (item_id >= 10000) that keeps the optimistic-grant instance_id: 0 sentinel collision-free.
  • crates/services/src/base/world_entry/methods/inventory/ammo.rs — update_bandolier_ammo doc keys the at-most-one-row claim on the declared PK instead of the slot-uniqueness index.

Also settles #520's "defense-in-depth UNIQUE INDEX on item_id" follow-up note as moot — the PK already provides it; no migration needed.

No runtime change — comment accuracy only. cargo fmt + cargo clippy --all-targets green on both touched crates.

Closes #533

🤖 Generated with Claude Code

…OU comments (#533)

sgw_inventory.item_id has a declared primary key (sgw_inventory_pkey,
db/sgw/_primary_keys.sql L39) — the instance_id doc comment and the
update_bandolier_ammo doc wrongly attributed its uniqueness to the
sgw_inventory_unique_slot index alone. The PK makes the #520 TOCTOU
guard stronger than the comments claimed; also notes the local_id_check
CHECK that keeps the instance_id:0 grant sentinel collision-free.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@BangRocket, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 55 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0e46af41-ed2b-4c0f-a433-181712c7ec83

📥 Commits

Reviewing files that changed from the base of the PR and between 2536371 and b717e3d.

📒 Files selected for processing (2)
  • crates/entity/src/cell_entity/mod.rs
  • crates/services/src/base/world_entry/methods/inventory/ammo.rs
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/533-inventory-pk-wording

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.

This branch has not been deployed

No deployments
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.

docs: sgw_inventory.item_id HAS a declared PRIMARY KEY — correct the bandolier ammo "no PK" wording

1 participant