Skip to content

[claude] fix(chat): temp-HP-first, version-guarded direct HP for untransformed characters - #193

Merged
adrev merged 4 commits into
mainfrom
claude/direct-hp-temp-authority
Aug 5, 2026
Merged

[claude] fix(chat): temp-HP-first, version-guarded direct HP for untransformed characters#193
adrev merged 4 commits into
mainfrom
claude/direct-hp-temp-authority

Conversation

@adrev

@adrev adrev commented Aug 5, 2026

Copy link
Copy Markdown
Owner

Fixes the pre-existing ordinary-character out-of-combat direct HP authority bug in applyDirectHp (server/src/services/chatCommands/hpHandlers.ts).

What changed

  • Temp HP first: negative delta from !damage / signed !hp -N consumes temp_hit_points before base HP; positive delta heals base HP up to max and leaves temp HP untouched.
  • One optimistic-lock UPDATE: all changed pools are written in a single UPDATE ... WHERE id = $ AND version = $ RETURNING version using the version selected with the row. Stale/missing/invalid version, malformed numeric pools, or a zero-row UPDATE fail closed — private whisper to the caller, no public/stat fanout, no damage side effects, no claimed success.
  • Authoritative fanout: committed hp, tempHp, and post-write version are returned and fanned out through the existing emitToTokenStatViewers owner/DM privacy scoping (unchanged).
  • A true no-op (e.g. heal at full HP) skips the UPDATE so the version trigger doesn't bump, and reports the selected version.

Absolute !hp set: left unchanged (requirement 4)

setDirectHp is not a read-modify-write on the HP pools — the written value depends only on the max-HP clamp, so the lost-update window the guard closes for delta paths barely exists there, and it already fails closed while wild-shaped. Adding a guard would also force legacy no-version rows (and the existing absolute-set test fixtures) into fail-closed territory for an administrative overwrite command — scope creep for marginal benefit.

Tests

New server/src/__tests__/direct-hp-temp-authority.test.ts: temp HP fully absorbing, partial absorb with base carryover, healing preserving temp HP, signed !hp -N routing, version conflict (zero-row) fail-closed with no fanout/side effects, missing-version fail-closed, malformed-numeric-row fail-closed, and full-no-op skip.

Updated hp-command-stat-privacy-version.test.ts (rows now carry a version; the two "omits version but still fans out" tests encoded the old bug and are now fail-closed assertions) and one mock in chat-command-token-fanout.test.ts (its UPDATE must return a version now).

Gates

  • Focused + full npm test: 1759 passed
  • npm run lint: clean (max-warnings 0)
  • npm run build: clean
  • npm audit --omit=dev: 0 vulnerabilities
  • git diff --check: clean

🤖 Generated with Claude Code

…ansformed characters

Out-of-combat !damage / !heal / signed !hp on an ordinary (untransformed)
character ignored temp_hit_points and wrote hit_points with an unguarded
UPDATE. Damage now consumes temp HP before base HP, healing tops up base
HP and leaves temp HP alone, and every changed pool lands in one
optimistic-lock UPDATE keyed on the selected characters.version. A
stale/missing/invalid version, malformed numeric row, or zero-row UPDATE
fails closed: private whisper, no fanout, no damage side effects.
Absolute !hp set semantics unchanged.

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

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 2 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: e23f8e25-f601-4f44-8096-bc4bc6ed16e6

📥 Commits

Reviewing files that changed from the base of the PR and between eef267b and 75af103.

📒 Files selected for processing (5)
  • server/src/__tests__/chat-command-token-fanout.test.ts
  • server/src/__tests__/direct-hp-temp-authority.test.ts
  • server/src/__tests__/hp-command-stat-privacy-version.test.ts
  • server/src/__tests__/wild-shape-authoritative.test.ts
  • server/src/services/chatCommands/hpHandlers.ts

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.

@adrev

adrev commented Aug 5, 2026

Copy link
Copy Markdown
Owner Author

[CodeX final review]

I completed the correction pass on Fable's implementation:

  • reject malformed persisted HP/max/temp pools before writing
  • broadcast the applied heal amount rather than the requested amount when max HP or Wild Shape caps it
  • keep direct damage event semantics aligned with CombatService
  • drive HP action cards from the authoritative applied change, including temp-HP-only and Wild Shape changes
  • add event-level regression coverage for temp absorption, capped healing, no-op healing, and Wild Shape

Local gates at head 75af103: 143 files / 1764 tests passed, lint zero, production build passed, audit 0, diff check clean. Waiting for the fresh CI run before merge.

@adrev
adrev merged commit 9abbee0 into main Aug 5, 2026
2 checks passed
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