open-notebook/frontend
dyzur 9f75748c4d
fix: prevent Ask streaming loading from getting stuck on dangling connections (#777) (#1146)
* fix: prevent Ask streaming loading from getting stuck on dangling connections

Adds a safety-net timeout (5 min) to useAsk that forces the loading
state to end even when the SSE stream's 'done' signal doesn't reach
the browser — which happens in Docker/standalone deployments where
the Next.js proxy connection is left open without proper termination.

Changes:
- use-ask.ts: AbortController per request, mountedRef for cleanup,
  STREAM_TIMEOUT_MS that resets isStreaming, stopStreaming() helper
  that centralizes cleanup + clears the timeout
- search.ts: pass AbortSignal through to fetch() so the timeout can
  actually cancel the HTTP request

The complete event now also carries final_answer content as a
backup path in case the final_answer event is missed.

Co-Authored-By: Claude <noreply@anthropic.com>

* chore: reduce stream timeout from 5 min to 75s

* fix(ask): make stream watchdog idle-based and abort dangling connections

The Ask stream safety timeout was a fixed 75s wall-clock cap measured from
stream start and never reset by incoming SSE events. A legitimately slow but
healthy Ask (slow local models — Ollama, LM Studio) would have its loading
state killed mid-stream, showing a partial/empty answer while the backend was
still producing — the exact slow-hardware scenario in #777.

- Re-arm the timeout on every received chunk so it fires only when the
  connection goes genuinely silent (idle timeout, not wall-clock).
- Align the idle window to the API client budget (NEXT_PUBLIC_API_TIMEOUT_MS,
  default 10 min; 0 disables) so slow local models aren't cut off. Export
  API_TIMEOUT_MS from the client for this.
- On fire, abort the in-flight request so a truly dangling connection frees the
  socket/reader instead of leaking it (the catch already swallows AbortError).

---------

Co-authored-by: dyzur <dyzur@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Luis Novo <lfnovo@gmail.com>
2026-07-21 11:11:02 -03:00
..
public Version 1 (#160) 2025-10-18 12:46:22 -03:00
src fix: prevent Ask streaming loading from getting stuck on dangling connections (#777) (#1146) 2026-07-21 11:11:02 -03:00
test-results feat(i18n): add Turkish (tr-TR) translation (#871) 2026-06-13 08:46:15 -03:00
.gitignore chore: export docs for custom gpt 2025-10-18 20:26:11 -03:00
AGENTS.md chore(frontend): typed locales, drop unused deps, fix AGENTS.md drift (#1061) 2026-07-11 18:45:57 -03:00
CLAUDE.md docs: restructure documentation around AGENTS.md, VISION.md and decision records (#1032) 2026-07-10 15:33:19 -03:00
components.json Version 1 (#160) 2025-10-18 12:46:22 -03:00
eslint.config.mjs Version 1 (#160) 2025-10-18 12:46:22 -03:00
next.config.ts fix(frontend): support allowedDevOrigins via env var (#1190) 2026-07-21 09:23:52 -03:00
package-lock.json chore(deps): resolve open Dependabot security alerts (#1191) 2026-07-20 17:40:16 -03:00
package.json chore(deps): resolve open Dependabot security alerts (#1191) 2026-07-20 17:40:16 -03:00
postcss.config.mjs Version 1 (#160) 2025-10-18 12:46:22 -03:00
start-server.js fix: use Node.js wrapper for cross-platform PORT fallback 2026-01-14 22:51:39 -03:00
tsconfig.json Feat/localization tests docker (#371) 2026-01-15 13:51:05 -03:00
vitest.config.ts fix: make validate_url() async so DNS resolution doesn't block the event loop (#1011) 2026-07-10 10:43:36 -03:00