8000 fix: batch engine persistence and contract regressions by Mnehmos · Pull Request #93 · Mnehmos/mnehmos.rpg.mcp · GitHub
[go: up one dir, main page]

Skip to content

fix: batch engine persistence and contract regressions - #93

Merged
Mnehmos merged 2 commits into
mainfrom
codex/batch-engine-issue-fixes
Aug 14, 2026
Merged

Mnehmos merged 2 commits into
mainfrom
codex/batch-engine-issue-fixes

Conversation

@Mnehmos
@Mnehmos Mnehmos commented Aug 14, 2026 •
Copy link
Copy Markdown
Owner

Summary

  • Batch-fixes confirmed engine defects across Open5e-backed character creation, equipment and healing, improvisation outcomes, spatial movement, world generation and persistence, combat completion, queued turn resolution, schema portability, and invalid-result handling.
  • Adds durable repositories and migrations for generated world snapshots, regions/structures/POIs, and queued nation actions.
  • Keeps the engine authoritative for persisted state and restores generated worlds after runtime eviction/restart.

Risk

  • The migration adds tables and indexes but preserves existing tables and data; generated-world restoration falls back to deterministic regeneration for legacy rows.
  • Turn submission semantics change from immediate mutation to durable queueing; resolution remains behind readiness and is covered by focused tests.
  • Character/background materialization is source-backed and emits provenance; unsupported source effects are reported rather than silently invented.
  • No Railway deployment is included in this PR.

Acceptance criteria

  • Confirmed engine issue paths have regression coverage and return persisted, truthful state.
  • World generation, map patches, generated entities, and queued turn actions survive the relevant eviction/restart or readiness boundary.
  • Consolidated schemas are portable to OpenAI-style tooling without $ref leakage.
  • Existing engine tests and build remain green.

Verification

  • npm run build
  • npm run test:ci -- --reporter=dot --silent — 143 files passed; 2,245 tests passed; 7 skipped.
  • Exact-head GitHub CI run 31823266129 passed on Node 18/20/22.
  • git diff --check

Related issues

This batch addresses the confirmed implementation gaps behind #61, #62, #63, #64, #65, #66, #67, #69, #70, #71, #73, #76, #90, and #91, plus the older spatial, inventory, combat, character, and schema regressions verified during the audit.

Deployment note

No Railway deployment was performed. Production remains on engine SHA 2c34688f239382a911fef9575d4fc725feac3781 until this PR is reviewed, merged, and deployed through the normal release workflow.

Summary by CodeRabbit

  • New Features
    • Added source-backed character options, creation mechanics, species bonuses, equipment, and provenance.
    • Added catalog search, item lookup, and materialization for SRD equipment.
    • Added healing item use with HP updates and equipment-slot validation.
    • Added directional movement and improved stunt damage resolution.
    • Added durable world snapshots, generated entities, and queued turn resolution.
  • Bug Fixes
    • Preserved supplied initiative values and improved encounter completion persistence.
    • Normalized legacy world environment fields and improved placement validation.
    • Corrected suggestion display and invalid JSON success reporting.
  • Documentation
    • Updated tool guidance and added SRD attribution and runtime catalog documentation.

@coderabbitai
coderabbitai Bot commented Aug 14, 2026 •
Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: cb4f9b21-d827-44ba-9563-1f1f8eb11eac

📥 Commits

Reviewing files that changed from the base of the PR and between 2c34688 and f30d72d.

📒 Files selected for processing (62)
  • README.md
  • config/OPEN5E-SRD-ATTRIBUTION.md
  • config/open5e-srd-2014-runtime.json
  • docs/hosted-handoff/RULESET-TRANSCRIPTION.md
  • package.json
  • scripts/generate-open5e-runtime-catalog.mjs
  • src/content/open5e-catalog.ts
  • src/engine/combat/engine.ts
  • src/engine/worldgen/validation.ts
  • src/schema/world.ts
  • src/server/consolidated/aura-manage.ts
  • src/server/consolidated/batch-manage.ts
  • src/server/consolidated/character-manage.ts
  • src/server/consolidated/combat-action.ts
  • src/server/consolidated/combat-manage.ts
  • src/server/consolidated/combat-map.ts
  • src/server/consolidated/corpse-manage.ts
  • src/server/consolidated/improvisation-manage.ts
  • src/server/consolidated/inventory-manage.ts
  • src/server/consolidated/item-manage.ts
  • src/server/consolidated/math-manage.ts
  • src/server/consolidated/narrative-manage.ts
  • src/server/consolidated/npc-manage.ts
  • src/server/consolidated/party-manage.ts
  • src/server/consolidated/quest-manage.ts
  • src/server/consolidated/spatial-manage.ts
  • src/server/consolidated/spawn-manage.ts
  • src/server/consolidated/strategy-manage.ts
  • src/server/consolidated/theft-manage.ts
  • src/server/consolidated/travel-manage.ts
  • src/server/consolidated/turn-manage.ts
  • src/server/consolidated/world-manage.ts
  • src/server/consolidated/world-map.ts
  • src/server/handlers/combat-handlers.ts
  • src/server/handlers/spatial-handlers.ts
  • src/server/index.ts
  • src/server/schema-shape.ts
  • src/server/tools.ts
  • src/services/generated-world-persistence.service.ts
  • src/services/open5e-item.service.ts
  • src/services/starting-equipment.service.ts
  • src/storage/migrations.ts
  • src/storage/repos/encounter.repo.ts
  • src/storage/repos/nation.repo.ts
  • src/storage/repos/poi.repo.ts
  • src/storage/repos/structure.repo.ts
  • src/storage/repos/turn-action.repo.ts
  • src/storage/repos/world-snapshot.repo.ts
  • src/storage/repos/world.repo.ts
  • tests/server/consolidated/combat-manage.test.ts
  • tests/server/consolidated/improvisation-manage.test.ts
  • tests/server/consolidated/inventory-manage.test.ts
  • tests/server/consolidated/open5e-authority.test.ts
  • tests/server/consolidated/spatial-manage.test.ts
  • tests/server/consolidated/spawn-manage.test.ts
  • tests/server/consolidated/turn-manage.test.ts
  • tests/server/consolidated/world-manage.test.ts
  • tests/server/consolidated/world-map.test.ts
  • tests/server/meta-tools.test.ts
  • tests/server/schema-shape.test.ts
  • tests/storage/world.repo.test.ts
  • tests/worldgen/validation.test.ts

📝 Walkthrough

Walkthrough

Changes

Open5e runtime catalog and rules

Layer / File(s) Summary
Catalog generation and validation
scripts/generate-open5e-runtime-catalog.mjs, src/content/open5e-catalog.ts, config/*, docs/hosted-handoff/*, package.json
The project generates and validates a pinned offline Open5e SRD catalog with provenance and license metadata.
Character creation integration
src/server/consolidated/character-manage.ts, src/server/consolidated/batch-manage.ts, src/services/starting-equipment.service.ts
Character creation applies source-backed class, species, background, proficiency, HP, AC, spell, equipment, and provenance data.
Item catalog integration
src/server/consolidated/item-manage.ts, src/services/open5e-item.service.ts, tests/server/consolidated/open5e-authority.test.ts
Item management supports catalog search, lookup, materialization, idempotent refresh, equipment slots, and AC updates.

World and spatial persistence

Layer / File(s) Summary
Environment normalization
src/schema/world.ts, src/storage/repos/world.repo.ts, src/server/consolidated/world-manage.ts
World environments use a strict canonical schema and normalize legacy keys.
Generated-world persistence
src/server/tools.ts, src/server/consolidated/world-manage.ts, src/services/generated-world-persistence.service.ts, src/storage/repos/world-snapshot.repo.ts, src/storage/repos/structure.repo.ts, src/storage/migrations.ts
Generated entities and snapshots persist in SQLite. Restoration loads snapshots before deterministic regeneration.
POI, spawn, travel, and movement
src/storage/repos/poi.repo.ts, src/server/consolidated/spawn-manage.ts, src/server/consolidated/travel-manage.ts, src/server/handlers/spatial-handlers.ts, src/server/consolidated/spatial-manage.ts
POIs and spatial nodes use repositories. Travel persists discovery and position. Movement can resolve a destination from an open exit direction.

Turn, combat, and gameplay resolution

Layer / File(s) Summary
Queued turn resolution
src/storage/repos/turn-action.repo.ts, src/server/consolidated/turn-manage.ts, src/storage/migrations.ts
Nation actions are queued per turn and resolved transactionally when nations are ready.
Combat lifecycle
src/server/handlers/combat-handlers.ts, src/server/consolidated/combat-manage.ts, src/storage/repos/encounter.repo.ts
Combat supports default creation values, supplied initiatives, and persisted terminal encounter state.
Stunt and inventory resolution
src/server/consolidated/improvisation-manage.ts, src/server/consolidated/inventory-manage.ts
Stunts validate all damage targets before transactional HP updates. Consumable use applies capped healing and returns detailed HP results.
Validation and schema adapters
src/server/schema-shape.ts, src/server/index.ts, src/server/consolidated/narrative-manage.ts, src/server/consolidated/party-manage.ts, tests/server/schema-shape.test.ts
Tool schema extraction handles wrapped and intersected Zod schemas. Shared schema factories preserve validation values.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant CharacterManage
  participant Open5eCatalog
  participant ItemService
  participant Repository
  Client->>CharacterManage: create source-backed character
  CharacterManage->>Open5eCatalog: resolve character options
  Open5eCatalog-->>CharacterManage: rules and provenance
  CharacterManage->>ItemService: materialize starting equipment
  ItemService->>Repository: create or refresh item records
  Repository-->>CharacterManage: persisted equipment
  CharacterManage-->>Client: character and applied mechanics
Loading
sequenceDiagram
  participant Nation
  participant TurnManage
  participant TurnActionRepository
  participant DiplomacyEngine
  Nation->>TurnManage: submit actions
  TurnManage->>TurnActionRepository: persist queued actions
  TurnManage->>TurnActionRepository: load pending actions at resolution
  TurnManage->>DiplomacyEngine: apply diplomacy actions
  DiplomacyEngine-->>TurnManage: resolution messages
  TurnManage->>TurnActionRepository: mark actions resolved
  TurnManage-->>Nation: resolved action results
Loading
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/batch-engine-issue-fixes

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 was referenced Aug 14, 2026
@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f30d72da6c

ℹ️ 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".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +155 to +156
const catalogUrl = new URL('../../config/open5e-srd-2014-runtime.json', import.meta.url);
const parsed = JSON.parse(readFileSync(catalogUrl, 'utf8'));
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Package the Open5e catalog with standalone binaries

When using the advertised pkg-produced standalone binaries, this runtime file is unavailable: the binary build in esbuild.config.mjs packages only server.cjs with assets: [] and never copies config/open5e-srd-2014-runtime.json. Consequently, the first character or source-item operation that calls getOpen5eCatalog() cannot read the catalog, effectively breaking those tools for binary users; embed/import the catalog or include it as a packaged asset with a binary-safe path.

Useful? React with 👍 / 👎.

@@ -304,10 +312,14 @@ async function handleMarkReady(args: z.infer<typeof MarkReadySchema>): Promise<o
// Start resolution
turnStateRepo.updatePhase(args.worldId, 'resolution');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Include the resolution phase change in the transaction

If any queued action throws during resolution—for example, break_alliance with a nonexistent toNationId causes a foreign-key failure—the transaction rolls back its mutations, but this earlier phase update remains committed. The world is then permanently left in resolution, and both submit_actions and mark_ready reject further calls with no recovery action available; move this update into the transaction or restore planning when resolution fails.

Useful? React with 👍 / 👎.

Comment on lines +254 to +257
const character = await handleCharacterCreate({
action: 'create',
...charData
} as any) as any;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Parse batch characters through the character creation schema

When create_characters omits applySpeciesAbilityBonuses, this direct handler call bypasses CreateSchema and therefore never applies its default(true). Source-backed batch characters consequently differ from individually created characters—for example, a batch-created Hill Dwarf keeps its unadjusted CON/WIS and derives lower HP—despite this path being intended to share authoritative creation behavior.

Useful? React with 👍 / 👎.

Comment on lines +341 to +343
if (healingValue === undefined && typeof effect === 'string' && /heal|restore|regain/i.test(effect)) {
healingValue = effect;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Require affirmative healing metadata before restoring HP

For consumables without an explicit healing property, this substring test treats negative mentions of healing as restorative effects and then rolls the first dice expression in the text. The included SRD Pale Tincture says its poison damage “can't be healed,” so using the materialized poison rolls its 1d6 damage as healing and increases the target's HP; only explicit healing metadata or an unambiguous structured effect should trigger healing.

Useful? React with 👍 / 👎.

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

0