[P1] PatchGuard convention + always-on Error logging so a broken hook can't silently kill tracking #261

Closed
opened 2026-07-03 09:33:39 -07:00 by nelsong6 · 2 comments
nelsong6 commented 2026-07-03 09:33:39 -07:00 (Migrated from github.com)

Priority: P1. From the 2026-07-02 uncapped audit pass. Completes the open half of the patch-resilience work (per-class install isolation landed in PR #248; this is the exception-discipline convention).

Problem

  • RunHistoryUtilitiesCreateEntryPatch.Postfix (finding #70) is the only file under Core/Patches/ with no try/catch. Its throw propagates into RunManager.OnEnded, skipping DeleteCurrentRun at the worst moment.
  • The terminal run-end funnel and all four RunTracker lifecycle handlers (OnRunStarted / OnRunEnded / OnCombatSetUp / OnCombatEnded) have no top-level guard — a tracker throw propagates into the game's run-history creation.
  • The ~53 patches that do guard log only e.Message via LogDebug — a no-op when DebugLogging is off — so a permanently-broken patch produces zero signal in normal play. (CombatHistoryAddPatch.cs:26 (#63) relies solely on Observe's internal catch.)

Fix

Immediate: wrap the 5 hot spots — RunHistoryUtilitiesCreateEntryPatch.Postfix and the four RunTracker lifecycle handlers — in try/catch that logs the full exception at Error level (always-on).

Systemic: introduce PatchGuard.Run(site, action) with always-on rate-limited Error logging, and adopt the convention that every Harmony body and every game-event handler is exactly one PatchGuard.Run call. Enforce with a source-scan test asserting the shape. This makes "a hook silently stopped working" visible instead of invisible-until-stats-look-wrong — the failure mode behind most of this audit.

Findings: #143 (open half), #70, #63.

**Priority: P1.** From the 2026-07-02 uncapped audit pass. Completes the open half of the patch-resilience work (per-class install isolation landed in PR #248; this is the exception-discipline convention). ## Problem - `RunHistoryUtilitiesCreateEntryPatch.Postfix` (finding #70) is the only file under `Core/Patches/` with **no try/catch**. Its throw propagates into `RunManager.OnEnded`, skipping `DeleteCurrentRun` at the worst moment. - The terminal run-end funnel and all four `RunTracker` lifecycle handlers (`OnRunStarted` / `OnRunEnded` / `OnCombatSetUp` / `OnCombatEnded`) have **no** top-level guard — a tracker throw propagates into the game's run-history creation. - The ~53 patches that *do* guard log only `e.Message` via `LogDebug` — a **no-op when `DebugLogging` is off** — so a permanently-broken patch produces zero signal in normal play. (`CombatHistoryAddPatch.cs:26` (#63) relies solely on `Observe`'s internal catch.) ## Fix **Immediate:** wrap the 5 hot spots — `RunHistoryUtilitiesCreateEntryPatch.Postfix` and the four `RunTracker` lifecycle handlers — in try/catch that logs the **full** exception at **Error** level (always-on). **Systemic:** introduce `PatchGuard.Run(site, action)` with always-on **rate-limited Error** logging, and adopt the convention that every Harmony body and every game-event handler is exactly one `PatchGuard.Run` call. Enforce with a source-scan test asserting the shape. This makes "a hook silently stopped working" visible instead of invisible-until-stats-look-wrong — the failure mode behind most of this audit. Findings: #143 (open half), #70, #63.
nelsong6 commented 2026-07-03 10:03:05 -07:00 (Migrated from github.com)

Partially addressed in #265: the terminal run-end funnel (RunHistoryUtilitiesCreateEntryPatch.Postfix, previously the only patch with no try/catch) and the three event-subscribed lifecycle handlers (OnRunStarted/OnCombatSetUp/OnCombatEnded) now run under an always-on Error-logging guard. Still open: the full PatchGuard.Run convention + source-scan test across all ~57 patches, and converting the ~53 LogDebug-only catches to always-on rate-limited Error logging.

Partially addressed in #265: the terminal run-end funnel (RunHistoryUtilitiesCreateEntryPatch.Postfix, previously the only patch with no try/catch) and the three event-subscribed lifecycle handlers (OnRunStarted/OnCombatSetUp/OnCombatEnded) now run under an always-on Error-logging guard. Still open: the full PatchGuard.Run convention + source-scan test across all ~57 patches, and converting the ~53 LogDebug-only catches to always-on rate-limited Error logging.
nelsong6 commented 2026-07-05 15:44:57 -07:00 (Migrated from github.com)

Closing during repository issue cleanup. If this becomes active work again, we can reopen or recreate it as a fresh, specific task.

Closing during repository issue cleanup. If this becomes active work again, we can reopen or recreate it as a fresh, specific task.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
romaine-life/spirelens#261
No description provided.