8000 fix: close two server-kill paths and three combat integrity gaps from the engine audit by Mnehmos · Pull Request #113 · Mnehmos/mnehmos.rpg.mcp · GitHub
[go: up one dir, main page]

Skip to content

fix: close two server-kill paths and three combat integrity gaps from the engine audit - #113

Merged
Mnehmos merged 4 commits into
mainfrom
claude/practical-cannon-cel9je
Nov 9, 2026
Merged

Mnehmos merged 4 commits into
mainfrom
claude/practical-cannon-cel9je

Conversation

@Mnehmos
@Mnehmos Mnehmos commented Nov 9, 2026
Copy link
Copy Markdown
Owner

Fixes from an audit of the engine. Each was reproduced against a local HTTP server before the fix and re-checked after.

What was wrong

One tool call could take the hosted server down for every campaign

  • subscribe_to_events over HTTP left a callback pointing at the per-request transport. The next combat event in any campaign made it reject with Not connected; the unhandled rejection shut the process down. The shutdown path exited 0, and railway.json restarts only ON_FAILURE, so the service would stay down.
  • math_manage roll with 1d1! never stopped exploding and ran until the heap was exhausted (exit 134). Dice counts were also unbounded (99999999d6).

Combat applied consequences it should not have

  • A move that was then refused (blocked, no path, not enough movement) had already resolved opportunity attacks, and reported success — so the damage and the spent reaction were committed for a move that never happened.
  • Negative damage was subtracted as healing with no cap at max HP: a 7 HP goblin reached 107.

What changed

Commit Change
fix(math) Dice capped at 1000 dice of 1000 sides at every parser (math_manage, combat damage, spells, auras, improvisation). Exploding dice need at least 2 sides. Exact probability distributions are refused when too large to compute.
fix(server) Crashes exit 1; requested stops still exit 0. A subscriber whose connection is gone is dropped. Subscribers only receive their own campaign's events. On stateless HTTP, subscribe_to_events makes no subscription and points the caller at poll_events.
fix(combat) Moves are validated before opportunity attacks resolve; a refused move is an error and rolls back. Negative damage is rejected; dice damage with a penalty floors at zero.
fix(deps) @modelcontextprotocol/sdk 1.29.0 → 1.32.2 via npm audit fix (lockfile only).

Contract changes for rpg-mcp-live

  • subscribe_to_events over HTTP still returns a non-error response, but its text now says no subscription was made. It could never deliver over stateless HTTP.
  • combat_action move to an unreachable square now returns isError: true instead of a success-shaped response containing "cannot move".
  • combat_action attack with a negative damage number now returns isError: true.
  • Dice expressions over 1000 dice or 1000 sides, and exploding one-sided dice, now return isError: true.

Not in this PR

  • Attacks are still accepted out of turn, with no range check and no bounds on caller-supplied attackBonus/damage. Enforcing those is a larger contract change.
  • The zod advisory needs a breaking move to zod 4.

Testing

  • New: tests/math/dice-limits.test.ts, tests/server/events-safety.test.ts, tests/server/shutdown.test.ts, tests/server/combat-integrity.test.ts (28 tests, written failing first).
  • Two tests in tests/server/spatial-combat.test.ts updated: a blocked move now rejects rather than returning "cannot move" text.
  • Full suite: 2337 passed, 7 skipped, 3 failed. The 3 failures are tests/server/websocket.test.ts and are pre-existing in the sandbox this was run in, which has no IPv6 (listen EAFNOSUPPORT ::); they fail identically on main there.

Generated by Claude Code

…e server

An exploding one-sided die (1d1!) never stopped exploding, and dice counts
were unbounded, so one math_manage call could freeze or kill the process
for every campaign. Dice are now capped at 1000 dice of 1000 sides at every
parser, exploding dice need at least 2 sides, and exact distributions are
refused when too large to compute.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FWeViVwVRAxVuCWaf7UQS
subscribe_to_events left a callback pointing at the per-request HTTP
transport. The next combat event in any campaign made it reject with
'Not connected'; the unhandled rejection shut the process down, and the
shutdown path exited 0, so the host never restarted it.

- Crashes now exit 1; requested stops still exit 0.
- A subscriber whose connection is gone is dropped, not left to reject.
- Subscribers only receive events from their own campaign.
- On the stateless HTTP transport, where nothing can be pushed after the
  response, subscribe_to_events makes no subscription and points the
  caller at poll_events.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FWeViVwVRAxVuCWaf7UQS
- Moves are validated (destination, path, remaining movement) before
  opportunity attacks resolve. A refused move used to cost the mover hit
  points and the attacker its reaction, then report success. It is now an
  error, so the call rolls back.
- Negative damage is rejected; it was subtracted as healing with no cap
  at max HP (a 7 HP goblin reached 107). Dice damage with a penalty
  floors at zero, and applyDamage/heal ignore negative amounts.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FWeViVwVRAxVuCWaf7UQS
npm audit fix: clears the advisories in @modelcontextprotocol/sdk and its
transitive dependencies. The remaining zod advisory needs a breaking move
to zod 4 and is left for a separate change.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FWeViVwVRAxVuCWaf7UQS
@coderabbitai
coderabbitai Bot commented Nov 9, 2026
Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@Mnehmos
Mnehmos marked this pull request as ready for review November 9, 2026 22:52
@Mnehmos
Mnehmos merged commit e6db880 into main Nov 9, 2026
5 checks passed
@chatgpt-codex-connector
chatgpt-codex-connector Bot commented Nov 9, 2026 •
Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-09T22:53:30.914291Z e7269b7 Draft marked ready
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Mnehmos pushed a commit that referenced this pull request Nov 9, 2026
The earlier commits on this branch were squash-merged as #113. This merge
keeps the current tree exactly as it is; it only records that history so
the branch can be pushed without rewriting it.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FWeViVwVRAxVuCWaf7UQS
Mnehmos pushed a commit that referenced this pull request Nov 10, 2026
Tree unchanged. The earlier commits on this branch were squash-merged as
#113 and #114.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FWeViVwVRAxVuCWaf7UQS
Mnehmos pushed a commit that referenced this pull request Nov 10, 2026
Tree unchanged. The earlier commits on this branch were squash-merged as
#113, #114 and #115.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FWeViVwVRAxVuCWaf7UQS
Mnehmos pushed a commit that referenced this pull request Nov 10, 2026
Tree unchanged. The earlier commits on this branch were squash-merged as
#113 to #116.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FWeViVwVRAxVuCWaf7UQS
Mnehmos pushed a commit that referenced this pull request Nov 10, 2026
Tree unchanged. The earlier commits on this branch were squash-merged as
#113 to #117.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013FWeViVwVRAxVuCWaf7UQS
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

0