Repository navigation
Fix: drop structured-output options unconditionally on retry - #277
Sanjay Singh (san360) merged 3 commits into
Conversation
callLlmJson only cleared options.modelOptions on retry when the error message matched a narrow regex (response_format|modelOptions|not supported|JSON|parse). Providers that reject structured output with a generic error bypassed this guard, so every retry attempt failed identically and exhausted the retry budget with no recovery. Drop modelOptions unconditionally on the first failure instead, since plain-text mode has its own JSON-extraction fallback. Also log a raw response snippet on failure for easier diagnosis.
|
Hi maintainers, a gentle ping on this PR whenever you have a moment to review. I'm happy to make any changes or add tests if something needs adjusting. Thank you for your time! |
|
Mayuri Phad (@mayuriphad), Could you provide the steps to reproduce? I do understand the issue though not sure about the scenarios where it will fail |
|
Sure. The failure needs a model or provider that rejects the structured-output request ( Steps:
|
|
Thanks Sanjay Singh (@san360). The failing scenario is any model or provider that rejects the structured-output request ( Steps:
I can't point to a specific provider that does this. |
|
Sanjay Singh (@san360) It fails whenever the first, structured request ( Messages like that come from the provider, not from this extension. Examples are a bare HTTP status ( Steps to reproduce:
Plain mode already has its own JSON extraction ( |
|
Thanks Sanjay Singh (@san360). Steps to reproduce:
I don't have a confirmed list of exact provider messages. The regex depends on how each provider words its error, so the fix stops depending on the wording. After any failure in structured mode, the next attempt uses plain mode. If you'd rather keep structured mode for some errors (for example cancellations, which are already rethrown, or rate limits), I can limit the fallback to those cases. |
Sanjay Singh (san360)
left a comment
There was a problem hiding this comment.
Thanks again Mayuri Phad (@mayuriphad) for this fix, and for the patient, detailed answers to our questions. The mocked regression test makes the failure easy to see, and the change itself is small and focused.
What we verified on the latest main with your commit merged in:
src/webview/panel-llm.test.tspasses with your change and fails without it (Cannot read properties of undefined (reading 'text')), so it covers the bug well.- Typecheck passes, and all webview tests pass (42 files, 840 tests).
Two small things before we merge:
-
Rebase on
main. The branch is from September, and its CI runs expired before they were approved. A rebase (or mergingmainin) gives us a fresh run, and a maintainer will approve it. There are no conflicts. -
Please don't log the model's reply (inline suggestion below).
raw=writes up to 300 characters of the reply toruntime.logand to the extension's Output channel. That reply can repeat content from the user's chat transcripts or repository files. We redact prompts before sending them, but this text isn't redacted, and people often paste their Output channel into bug reports. Also, in the case this PR fixes (the request itself is rejected), nothing has streamed yet, so the log would only sayraw=(empty). A content-free hint about the reply's shape keeps the diagnostic value without the private text.
Optional, if you have time: two more cases in the new test file would be nice:
- a reply that can't be parsed still adds the "respond ONLY with JSON" message exactly once;
- a
vscode.CancellationErroris rethrown without another attempt.
Happy to merge once 1 and 2 are in and CI is green. Thanks again for the contribution!
| const rawSnippet = text ? text.slice(0, 300) : '(empty)'; | ||
| runtimeDebug('panel-llm', 'call-failed', | ||
| `schema=${schemaName} attempt=${attempt + 1} structured=${options.modelOptions !== undefined} ` + | ||
| `model=${model.id} textLen=${text.length} error=${err instanceof Error ? err.message : String(err)}`); | ||
| `model=${model.id} textLen=${text.length} error=${err instanceof Error ? err.message : String(err)} raw=${rawSnippet}`); |
There was a problem hiding this comment.
Could we log the shape of the reply instead of its content? The reply can repeat transcript or repository content, and this line ends up in runtime.log and the Output channel. For the rejection case this PR fixes, text is empty anyway.
| const rawSnippet = text ? text.slice(0, 300) : '(empty)'; | |
| runtimeDebug('panel-llm', 'call-failed', | |
| `schema=${schemaName} attempt=${attempt + 1} structured=${options.modelOptions !== undefined} ` + | |
| `model=${model.id} textLen=${text.length} error=${err instanceof Error ? err.message : String(err)}`); | |
| `model=${model.id} textLen=${text.length} error=${err instanceof Error ? err.message : String(err)} raw=${rawSnippet}`); | |
| const shape = !text ? 'empty' : /^\s*```/.test(text) ? 'fenced' : /^\s*[[{]/.test(text) ? 'json-like' : 'text'; | |
| runtimeDebug('panel-llm', 'call-failed', | |
| `schema=${schemaName} attempt=${attempt + 1} structured=${options.modelOptions !== undefined} ` + | |
| `model=${model.id} textLen=${text.length} shape=${shape} error=${err instanceof Error ? err.message : String(err)}`); |
Add tests for the JSON-only nudge being added once and for CancellationError being rethrown without a retry. Signed-off-by: mayuriphad <[email protected]>
…d-output-detection
|
Thanks Sanjay Singh (@san360). Pushed two commits, no force-push:
It also adds the two optional cases to
Locally on the merged head: |
Summary
Fixes #276.
callLlmJsoninsrc/webview/panel-llm.tsonly clearedoptions.modelOptions(the structured-output request) on retry when the error message matched a narrow regex:/response_format|modelOptions|not supported|JSON|parse/i. Models/providers that rejectresponse_formatwith a generic error bypass this guard entirely, so every retry attempt fails identically in structured mode and the retry budget is exhausted with no recovery.Fix
modelOptionsunconditionally on the first failure whenever it is set, since plain-text mode already has its own JSON-extraction fallback (parseLlmJson). No need to pattern-match the error message to decide whether to fall back.(empty)when the response is blank).Test plan
src/webview/panel-llm.test.ts, mocking thevscodemodule to simulate a model that rejects the first (structured) request with a generic, non-pattern-matching error and succeeds on the second (plain) request. AssertsmodelOptionsis cleared between attempts and the call ultimately recovers.Cannot read properties of undefined (reading 'text')— retries exhausted) and passes with the fix.npx vitest run— 1342 passed; the 7 pre-existing failures insrc/core/github-app-analytics.test.tsare unrelated to this change and fail identically onmain.