Skip to content

stations: reduce ChemistryStation recipe/entry duplicate warning noise#43

Draft
Khundiann wants to merge 1 commit intoifBars:stablefrom
Khundiann:stations/reduce-ChemistryStation-recipe/entry-duplicate-warning-noise
Draft

stations: reduce ChemistryStation recipe/entry duplicate warning noise#43
Khundiann wants to merge 1 commit intoifBars:stablefrom
Khundiann:stations/reduce-ChemistryStation-recipe/entry-duplicate-warning-noise

Conversation

@Khundiann
Copy link

@Khundiann Khundiann commented Jan 30, 2026

Summary

This PR reduces log noise in ChemistryStationPatches by treating repeated/in-idempotent injections as normal behavior (no log spam), while still warning on real conflicts.

What’s changed

  • ChemistryStationPatches duplicate handling is now conflict-aware:
    • If the same RecipeID is already present and it’s the same recipe instance S1API would inject, S1API stays silent.
    • If the same RecipeID is present but it’s a different recipe instance, S1API warns once and skips injection for that ID.
    • Same logic applies to recipeEntries (existing entry for the same RecipeID):
      • Silent if it points at the same recipe instance.
      • Warn once if it points at a different recipe.
  • Per-canvas “warned once” tracking is kept minimal via ConditionalWeakTable<ChemistryStationCanvas, …>.

Notes / rationale

  • The Chemistry Station UI can call Awake/Open multiple times across normal play. Logging “already has X” in those cases creates unnecessary noise even though the behavior is correct and idempotent.
  • Warnings are kept only for actionable cases: same ID, different underlying recipe, which indicates a true mod/mod (or mod/base) conflict.

Release Notes

  • Reduce warning noise for Chemistry Station recipe/entry injections: Chemistry Station UI can call Awake/Open multiple times during normal play; idempotent repeated injections are now silent, while true conflicts (different recipe instances) still produce warnings
  • Per-canvas conflict tracking: Implements ConditionalWeakTable-based per-canvas state (CanvasInjectionState) to track warned-once conflicts, keeping tracking minimal and localized
  • Conflict-aware duplicate handling:
    • If a RecipeID already exists and matches the same recipe instance, no log is produced
    • If a RecipeID exists but points to a different recipe instance, S1API warns once and skips injection
    • Same rules apply to recipeEntries (silent for identical instances, warn once for different recipes)
  • Refactored helper methods:
    • ContainsRecipeId()FindRecipeById() (now returns StationRecipe? instead of bool)
    • ContainsEntryForRecipeId()FindEntryByRecipeId() (now returns StationRecipeEntry? instead of bool)

Lines Added/Removed by Author

Author Additions Deletions Net Change
Khundiann 37 16 +21

@coderabbitai
Copy link

coderabbitai bot commented Jan 30, 2026

📝 Walkthrough

Walkthrough

Refactors conflict logging in chemistry station recipe injection from global HashSet-based tracking to per-canvas state management. Updates helper methods from boolean returns to nullable object returns, enabling direct access to conflicting recipe or entry instances while maintaining per-canvas conflict history.

Changes

Cohort / File(s) Summary
Chemistry Station Patch State Refactoring
S1API/Internal/Patches/ChemistryStationPatches.cs
Introduces CanvasInjectionState class for per-canvas conflict tracking via ConditionalWeakTable. Refactors ContainsRecipeId()FindRecipeById() and ContainsEntryForRecipeId()FindEntryByRecipeId() to return nullable objects instead of booleans. Adds GetCanvasState() helper. Updates recipe and entry injection logic to detect conflicts using new finder methods and log conflicts to per-canvas state instead of global collections.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 The chemistry station's recipes now have their own home,
Per-canvas states instead of globals that roam,
Conflicts are tracked where they belong with care,
Nullable finders replace boolean snares! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 70.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'stations: reduce ChemistryStation recipe/entry duplicate warning noise' clearly summarizes the main change: reducing log noise from duplicate warnings in ChemistryStation recipe/entry handling.

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

🧪 Unit Test Generation v2 is now available!

We have significantly improved our unit test generation capabilities.

To enable: Add this to your .coderabbit.yaml configuration:

reviews:
  finishing_touches:
    unit_tests:
      enabled: true

Try it out by using the @coderabbitai generate unit tests command on your code files or under ✨ Finishing Touches on the walkthrough!

Have feedback? Share your thoughts on our Discord thread!


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

@Khundiann Khundiann marked this pull request as draft January 30, 2026 12:16
@ifBars ifBars self-assigned this Feb 3, 2026
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