fix: StateValidatorAgent graceful error handling instead of throwing#134
Open
pzysvip99999 wants to merge 2 commits intoNarcooo:masterfrom
Open
fix: StateValidatorAgent graceful error handling instead of throwing#134pzysvip99999 wants to merge 2 commits intoNarcooo:masterfrom
pzysvip99999 wants to merge 2 commits intoNarcooo:masterfrom
Conversation
added 2 commits
April 1, 2026 00:23
…ors from crashing the pipeline The state validator was throwing an uncaught exception when the LLM output contains invalid JSON characters (e.g. control chars, unescaped sequences), causing the entire write pipeline to crash with 'State validator returned invalid JSON'. This wraps the entire function in a try-catch so that any such errors are returned as a validation issue rather than crashing.
…errors
Instead of throwing, catch blocks in validate() and parseResult() now
return { warnings: [...], passed: true } so the pipeline continues
without crashing when the LLM outputs malformed JSON or schema
validation fails mid-flight.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix: StateValidatorAgent graceful error handling
Problem
When the LLM (Phase 3 Auditor) outputs malformed JSON during the continuity validation step,
StateValidatorAgent.parseResult()throwsError: "State validator returned invalid JSON". Similarly, if schema validation insideparseResult()fails, the error propagates up and crashes the pipeline.The existing
try/catchinvalidate()was also re-throwing, which means any LLM error during validation would abort the entire write pipeline.Fix
Two changes in
packages/core/src/agents/state-validator.ts:validate()catch block: Return{ warnings: [...], passed: true }instead of re-throwing. The pipeline continues with a logged warning.parseResult()catch block: Return{ warnings: [...], passed: true }instead of re-throwing the error. Schema validation failures become warnings, not crashes.Together with PRs #132 (outer try-catch on
validateRuntimeState) and #133 (sanitizeJSONfor LLM output), this ensures the write pipeline is resilient to LLM-generated JSON malformed output at every layer.