fix(gemini): recover JSON review when model emits prose before the envelope - #22
Open
AlgizPure wants to merge 1 commit into
Open
fix(gemini): recover JSON review when model emits prose before the envelope#22AlgizPure wants to merge 1 commit into
AlgizPure wants to merge 1 commit into
Conversation
…velope
parseReviewOutput strips a markdown code-fence only when it sits at offset 0:
.replace(/^```(?:json)?\s*/i, "").replace(/\s*```$/i, "")
When Gemini streams narration first (e.g. "I've checked .gitignore. Now let's
check reindex_cases.py") and only then the ```json block, the fence is no longer
at offset 0, so JSON.parse runs on the prose and throws REVIEW_PARSE_ERROR — the
entire review (a valid envelope sitting later in the output) is discarded. This
happens often on research-heavy reviews where the model narrates before
converging to JSON.
Fix: add an additive extractJsonCandidate fallback in the catch — on parse
failure, recover the JSON (last fenced ```json block, else the first-{..last-}
run) and parse that; only throw if that also fails. The happy path is unchanged
(clean output parses on the first try and never reaches the fallback); genuinely
non-JSON output still throws REVIEW_PARSE_ERROR.
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.
Problem
parseReviewOutput(plugins/gemini/scripts/lib/gemini.mjs) strips a markdown code-fence only when it sits at offset 0:When Gemini streams narration before the JSON envelope — e.g.
clean output : OK
fenced-only output : OK
prose + fenced (the bug): OK ← now recovered
prose + bare braces : OK
non-JSON garbage : throws REVIEW_PARSE_ERROR (unchanged)