mirror of
https://github.com/Pasta-Devs/Marinara-Engine.git
synced 2026-12-03 19:00:50 +07:00
[PR #1641] [MERGED] Surface invalid combat action responses instead of advancing combat #5171
Labels
No labels
android
bug
bugfix
ci
client
code freeze pause
container
dependencies
docs
documentation
duplicate
enhancement
feature
feature
feature
feature-creep
fixed-in-refactor
fixed-in-staging
good first issue
help wanted
in-pr
in-pr
needs-codeowner-decision
normal-scope
old-codebase
old-codebase
pull-request
qol
question
refactor
regression
revisit later
roadmap
scope-risk
scope-risk
server
server
shared
soup
upstream
windows
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Pasta-Devs/Marinara-Engine#5171
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Pasta-Devs/Marinara-Engine/pull/1641
Author: @Romuromylus
Created: 5/30/2026
Status: ✅ Merged
Merged: 5/30/2026
Merged by: @Romuromylus
Base:
refactor← Head:fix/encounter-invalid-response📝 Commits (2)
ef99b48Surface invalid combat action responses instead of advancing combat703a000Format encounter fix to repository Prettier style📊 Changes
4 files changed (+158 additions, -0 deletions)
View changed files
📝
src/engine/contracts/types/combat-encounter.ts(+6 -0)➕
src/engine/modes/roleplay/encounter/encounter-service.test.ts(+135 -0)📝
src/engine/modes/roleplay/encounter/encounter-service.ts(+9 -0)📝
src/features/modes/roleplay/encounter/hooks/use-encounter.ts(+8 -0)📄 Description
Why this change
A malformed / non-JSON combat action response was silently treated as a successful turn.
completeJsonObjectreturnsnullon unparseable output or an LLM error, butresolveRoleplayEncounterActionthen ranrecordValue(parsed?.result) ?? parsed(which isnull) throughsanitizeCombatActionResult, which rebuilds a fully valid-lookingCombatActionResultfrom the deterministic fallback. The caller had no way to tell "sanitized a garbage response" from "a real turn", so it advanced party/enemy HP and the log, and could even reach victory + a summary writeback to the chat from a malformed reply.What changed
combat-encounter.ts: add an optionalinvalid?: booleantoEncounterActionResponse(documented: the caller must surface a retryable error and leave combat unchanged).encounter-service.ts: whencompleteJsonObjectreturnsnull, return{ result: fallback, invalid: true }before the sanitize path runs. The fallback is returned only to satisfy the requiredresultfield; the caller must not apply it.use-encounter.ts: checkres.invalidfirst and reuse the existing recoverable error path (setError("AI returned an invalid response. Try again.")+ clear processing + early return), which runs before anyupdateCombat/endCombat/generateSummary, so combat state and the chat are untouched and the retry controls stay mounted. No new UI.A present-but-partial response (a real record missing
result/combatStats) is still a real turn and continues through the sanitizer unchanged, and the genuine empty-inputinterruptedbranch stays reachable, because only anullparse flags invalid.Verification
pnpm exec tsc -bclean;pnpm check:architectureclean (no new cross-layer import).encounter-service.test.ts) cover: malformed non-JSON output flags invalid, an LLM error flags invalid, a valid JSON turn resolves normally (not invalid), and a present-but-partial response is not flagged invalid.Risk / note
This also routes a transient LLM-call failure (timeout, 5xx) into the same retryable error instead of the previous silent fallback turn. That is the intended, more-correct behavior, but it does broaden the trigger beyond pure malformed JSON, so it is called out here. The hook + inline error rendering are covered by code reading; the engine root cause is covered by the unit tests.
Linked issue
Closes #1520.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.