8000 fix(llm): ask a server that dropped the connection once more, and let a thinking model finish by adeelahmad · Pull Request #705 · adeelahmad/lense · GitHub
[go: up one dir, main page]

Skip to content

fix(llm): ask a server that dropped the connection once more, and let a thinking model finish - #705

Merged
adeelahmad merged 1 commit into
mainfrom
claude/project-thread-6jbtnr
Oct 20, 2026
Merged

adeelahmad merged 1 commit into
mainfrom
claude/project-thread-6jbtnr

Conversation

@adeelahmad
Copy link
Copy Markdown
Owner

Requested by Adeel · project thread

Description

Before: on a single Ollama box that serves the chat model, a vision model and embeddings, Ollama resets connections while it swaps models, and each Connection reset by peer failed the whole job. A reasoning model (Qwen 3) asked for a short answer with max_tokens, such as a conversation's title, spent the whole budget thinking. It returned content: "", so the title came back as "the model didn't write a title".

After: when the server drops the connection (reset, aborted, or a remote disconnect), Lens waits two seconds and asks once more. Timeouts, refusals and HTTP errors still fail at once, with the same message. When llm.chat gets an empty answer cut at the length limit, it asks again without max_tokens.

Motivation and Context

This comes from Adeel's install, which was moved from Gemini to a LAN Ollama on 10-16. Its activity ledger had zero failures on Gemini. Since the move, the job errors include 42 can't reach the LLM server … [Errno 104] Connection reset by peer, 16 raw ConnectionResetError and about 70 timeouts at 300 s. Probes from inside the install showed the server, key and models are fine: /models returns 200, gemma3 takes 19.6 s on a reload, and Qwen with max_tokens: 5 returns content "" and finish_reason "length" with the answer in reasoning.

Steps to reproduce (if appropriate):

See tests/domain/test_llm_resilience.py.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change; ! in the title)

Checklist:

  • The title is a Conventional Commit.
  • My code follows the code style of this project (make hooks checks it on commit).
  • I added or updated tests.
  • My change requires documentation updates, and I have updated docs/ accordingly (configuration.md, "A busy local model server").
  • Users need more than the title to understand it, so I wrote a fragment in changelog.d/llm-retry-dropped.md.

Done questions (AGENTS.md)

  • Goal: model calls survive a busy local server. Merges on green CI.
  • Agents: every model call goes through llm._post, so the assistant, MCP and API paths all benefit.
  • Zero setup: no new prerequisite.
  • Fewest clicks: n/a, there is no UI.
  • Configurable: n/a, no new setting. The retry is one fixed redial.
  • Light: yes.
  • Private and secure: n/a. The retry goes to the same address with the same request, and no new surface is added.
  • Cost: a retried dropped call is still one ledger entry. The uncapped title retry is a second ledger entry and happens only when the first one said nothing.
  • User decides: defaults are unchanged.
  • Upgrades: n/a, no stored data changes.
  • Honest: yes.
  • Tests and docs updated.
  • Open: no new dependencies.
  • Reported in the project thread with evidence. Refine later: Ollama keep_alive per request through its native API, so models stay loaded without the user having to set OLLAMA_KEEP_ALIVE.
  • Reuse: reuses unthink and the existing _post fallback.

Generated by Claude Code

… a thinking model finish

A busy Ollama box serving chat, vision and embeddings resets connections while it
swaps models, and each reset failed the whole job (42 "Connection reset by peer"
job failures on one install). A dropped connection is now retried once after two
seconds; timeouts, refusals and HTTP errors still fail at once.

A reasoning model given a small max_tokens (conversation titles) spent it all
thinking and returned no content; llm.chat now asks again without the limit.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QmAhBKz3DtXEjcQLTR3jtx
@adeelahmad adeelahmad self-assigned this Oct 20, 2026
@adeelahmad
adeelahmad merged commit a60bf2b into main Oct 20, 2026
12 checks passed
@adeelahmad
adeelahmad deleted the claude/project-thread-6jbtnr branch October 20, 2026 16:21
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

0