Skip to content

fix: report empty Copilot replies as empty instead of invalid JSON (#91) - #253

Merged
Sanjay Singh (san360) merged 1 commit into
mainfrom
san360-issue-91-error-llm-returned-invalid-json-after-3-666c20
Nov 23, 2026
Merged

Sanjay Singh (san360) merged 1 commit into
mainfrom
san360-issue-91-error-llm-returned-invalid-json-after-3-666c20

Conversation

@san360

@san360 Sanjay Singh (san360) commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Description

AI features such as Generate Quiz, Slop or Not and Skill Finder could fail with "LLM returned invalid JSON after 3 attempts. Please try again." when GitHub Copilot returned an empty response (#91).

Root cause: callLlmJson in src/webview/panel-llm.ts passed an empty reply straight to the JSON parser. JSON.parse failed, then the lenient parser threw "No JSON structure found in LLM response", which matched the parse-failure check, so each empty retry was counted as invalid JSON and the user saw a misleading message.

Fix:

  • A whitespace-only reply is now detected before either parse path (structured output and the lenient parser) and reported with the message callLlm already uses (the existing EMPTY_RESPONSE_MESSAGE): "GitHub Copilot returned an empty response. Try again."
  • Genuine parse failures still report "LLM returned invalid JSON after 3 attempts". If any attempt returned non-JSON text, that message wins.
  • Retries behave as on main: structured output is dropped on every retry (Fix: drop structured-output options unconditionally on retry #277) and the JSON hint is added for the next attempt, including after an empty reply. That logic moved into a small prepareJsonRetry helper to keep callLlmJson within the lint complexity limit.
  • The call-failed debug log now classifies a whitespace-only reply as shape=empty.
  • Tests in src/webview/panel-llm-call.test.ts:
    • three empty replies produce the empty-response message (fails on main with "LLM returned invalid JSON after 3 attempts", passes with this change);
    • a non-JSON reply still produces "LLM returned invalid JSON after 3 attempts";
    • an empty reply followed by valid JSON recovers, with the retry sent in plain mode and with the JSON hint.
  • CHANGELOG.md entry under Unreleased.

Rebase: rebased on current main. Model selection stays on Copilot Auto via selectModel (#301) and the unconditional structured-output fallback from #277 is kept; this PR only adds the empty-reply handling. #272 also changes empty-response handling in callLlmJson, so whichever lands later will need a rebase.

Related Issues

Fixes #91

Checklist

  • npm run check passes (typecheck + lint + spellcheck + knip + tests): each step run locally on the final head:
    • npm run typecheck: passed
    • npm run lint: passed (0 errors, no new warnings; no warnings in the changed files)
    • npm run spellcheck (cspell "src/**/*.ts" "docs/**/*.md" "*.md"): passed (416 files, 0 issues)
    • npm run knip: passed
    • npm run lockfile-lint: passed
    • npm test: passed (168 files, 3776 passed, 5 skipped)
    • npm run build: passed
    • npm run check-size: passed (dist/extension.js 1.76 MB, within the 2 MB budget)
  • Changes are covered by tests (if applicable)
  • Documentation updated (if applicable): CHANGELOG.md

@github-actions

github-actions Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@san360
Sanjay Singh (san360) force-pushed the san360-issue-91-error-llm-returned-invalid-json-after-3-666c20 branch from c7e9130 to c27d574 Compare November 20, 2026 18:27
@san360 Sanjay Singh (san360) changed the title fix: use Copilot Auto model router and handle empty LLM responses (#91) fix: report empty Copilot replies as empty instead of invalid JSON (#91) Nov 20, 2026
@san360
Sanjay Singh (san360) requested a balanced review from Copilot November 20, 2026 21:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are recorded for the change to empty-response error reporting.

No open issues 🎉

What changed in this PR

Corrects misleading errors in JSON-based AI features such as Generate Quiz, Slop or Not, and Skill Finder. Empty Copilot replies now produce an empty-response message rather than an invalid-JSON error, addressing #91.

Changes:

  • Detects whitespace-only replies before JSON parsing while preserving retry behavior.
  • Extracts retry preparation into a helper.
  • Adds a regression test and changelog entry.
File Description
src/​webview/​panel-llm.ts Distinguishes empty replies from JSON parse failures and extracts retry preparation.
src/​webview/​panel-llm-call.test.ts Verifies three empty replies produce the empty-response error.
CHANGELOG.md Documents the corrected error reporting.

Review effort: Balanced

callLlmJson passed an empty reply to the JSON parser, which threw a JSON
error, so every retry counted as a parse failure and AI features such as
Generate Quiz, Slop or Not and Skill Finder showed "LLM returned invalid
JSON after 3 attempts". A whitespace-only reply is now detected before
either parse path (structured output or the lenient parser) and, when no
attempt returns non-JSON text, reported with the same "GitHub Copilot
returned an empty response" message callLlm already uses. Genuine parse
failures still report invalid JSON. Retries behave as before: structured
output is dropped on every retry and the JSON hint is added.

Fixes #91

Co-authored-by: Copilot App <[email protected]>
@san360
Sanjay Singh (san360) force-pushed the san360-issue-91-error-llm-returned-invalid-json-after-3-666c20 branch from c27d574 to 2f9a916 Compare November 23, 2026 08:48
@san360
Sanjay Singh (san360) requested a balanced review from Copilot November 23, 2026 08:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues block the change to distinguish empty Copilot replies from malformed JSON.

No open issues 🎉

Review effort: Balanced

@san360
Sanjay Singh (san360) merged commit 009c6c1 into main Nov 23, 2026
8 checks passed
@san360
Sanjay Singh (san360) deleted the san360-issue-91-error-llm-returned-invalid-json-after-3-666c20 branch November 23, 2026 10:35
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.

Error: LLM returned invalid JSON after 3 attempts. Please try again.

3 participants