Skip to content

fix(chat): run a model step again once when the provider ends it in an error with nothing in it - #2064

Merged
gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/chat-provider-error-finish
Nov 3, 2026
Merged

gkhngyk merged 2 commits into
ansvisor:mainfrom
cihan-gyk:fix/chat-provider-error-finish

Conversation

@cihan-gyk

Copy link
Copy Markdown
Collaborator

Summary

A Chat answer could come out empty when the provider ended a model step in an error with nothing in it.

Chat's model test set (W4-35) found this with Gemini 3.5 Flash Lite through OpenRouter. A step finished other (raw error) with no text, no tool call and no output token. The engine read it as the model's reply, so the run went on from there and could end done with no answer.

Fix (modelLoop and modelStep in web/src/lib/chat/engine.ts):

  • A step the provider ended that way runs again once, after a one-second wait.
  • The retry is the same step, so nothing from the failed try is in its prompt.
  • The failed step is never taken as an answer, and doesn't use up the one "write your answer" request from fix(chat): ask once for the answer when a reply has only next moves or nothing, as GPT and Gemini do #2040.
  • At most once a run (progress.stepRetried). A second such step goes on as before.
  • The failed try used no tokens, so it costs nothing. The retry costs one normal step.

In the test set, this was the last cause of an empty answer after #2040.

Related issue

None. Found by the Chat Wave 4 model test set (W4-35).

Type of change

  • feat — New feature
  • fix — Bug fix
  • chore — Maintenance / dependencies
  • docs — Documentation only
  • refactor — Code change that neither fixes a bug nor adds a feature
  • test — Adding or updating tests

How to test

  1. cd web && yarn vitest run src/lib/chat/engine.test.ts -t "provider ends in an error". Two tests:
    • a step ended in an error with nothing in it runs again once, with the same prompt, and the answer comes from the second try;
    • a second such step isn't retried again.

No migration. No new environment variables. No Help change.

Checklist

  • Branch follows the naming convention
  • Commits follow Conventional Commits
  • yarn lint passes
  • yarn typecheck passes
  • yarn format:check passes
  • Changes are focused — one concern per PR
  • Help article updated under help/ (or no user-visible change)

CI passed on this branch (e39a0bd), run on the fork (https://github.com/cihan-gyk/ansvisor/actions/runs/41599168256): schema is up to date; web format:check, lint, typecheck, all tests and yarn build pass; server lint, format:check and all tests pass.

🤖 Generated with Claude Code

…n error with nothing in it

Co-Authored-By: Claude Opus 5.5 <[email protected]>
gkhngyk
gkhngyk previously approved these changes Nov 3, 2026
# Conflicts:
#	web/src/lib/chat/engine.test.ts
#	web/src/lib/chat/engine.ts
@cihan-gyk

Copy link
Copy Markdown
Collaborator Author

Note on the 3 model calls with #2040 (read from head ad9fca2; no push from us during the merge wave).

Why it happens: two independent once-per-run flags.

Both can fire in one run:

  • provider error → retry → model empty → "write the answer" = 3 calls;
  • model empty → "write the answer" step hits a provider error → retry = 3 calls.

With #2062's language rewrite, the worst case is 4. Also, a failedEmpty in Claude's read phase spends the retry for nothing: an empty read step already moves on to writing.

Suggested merge: one recovery per run for an empty answer.

  1. One flag (e.g. progress.recovered). Whichever fires first uses it.
  2. The cause picks the kind of recovery: a provider error retries the same prompt (no note); the model's own empty or next-moves-only reply asks with ANSWER_NOTE and no next-moves tool.
  3. Retry only in the write phase.
  4. If the recovery step is empty too, the run ends as today.

That caps the final answer at 2 calls, or 3 with the language rewrite.

Tests to keep: error → empty = 2 calls; empty → error = 2 calls; a read-phase failedEmpty doesn't retry; the existing "once a run" tests move to the new flag.

If you'd rather we write this, say so after the wave and we'll open it as a new PR on top of main, not as a push here.

🤖 Generated with Claude Code

@gkhngyk gkhngyk 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.

LGTM

@gkhngyk
gkhngyk merged commit 12c9405 into ansvisor:main Nov 3, 2026
5 checks passed
gkhngyk pushed a commit that referenced this pull request Nov 4, 2026
…y its cause (#2113)

* fix(chat): recover an empty answer once a run, the kind picked by its cause

A provider error retry (#2064) and the ask for the answer (#2040) each had
their own once-a-run flag, so one empty answer could take 3 model calls (4
with the language rewrite). One flag, progress.recovered, now holds the run's
single recovery: a writing step the provider ended in an error runs again as
it was; the model's own empty or next-moves-only reply is asked for the answer
with ANSWER_NOTE and no next moves tool. A reading step with nothing in it no
longer spends the retry: it moves on to writing anyway. A recovery step that
is empty too ends the run as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(chat): hold the run's one recovery across a card and a change-only job's reading

Main now has two paths the single recovery meets: a run that waits on a card
and goes on as the same run (an agent's run_agent too, #2052), and a change-only
job that stops on "No change" once its reading ends (#2015). The recovery a run
spent before its card stays spent after it, and a reading step the provider
ended with nothing in it is taken as read enough: the job still stops on "No
change" with no retry and no writing step.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01SvzkMf5TZg7yqwaSeMFba9

---------

Co-authored-by: Cihan <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
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.

2 participants