smriti/backend/app
Himanshu Dongre 0c63ead534
Some checks failed
Deploy website to GitHub Pages / deploy (push) Has been cancelled
Stop swallowing chat-title generation failures silently
The /api/v4/chat/sessions/{id}/title endpoint wrapped its entire body
in a bare `except Exception: pass`. When the background LLM provider
was missing or the call failed, the endpoint silently returned the
unchanged session — clients could not tell "title not requested yet"
apart from "tried and failed because no provider." Same anti-pattern
as the extract bug (713ed9a), lower severity (titles are cosmetic).

This is the smallest correct fix:

  - Title generation is still best-effort. The endpoint always returns
    200 with the session. The chat surface is never blocked.
  - Failures are no longer silent. The bare except is replaced with
    three typed branches:
      * ProviderNotConfiguredError → WARNING log + status
        "skipped:provider_not_configured"
      * generic provider call error → WARNING log + status
        "skipped:provider_error"
      * DB write error after successful generation → ERROR log + status
        "skipped:db_error" (also rolls back the session)
  - SessionResponse gains an optional `title_generation_status: str` field
    (default None). The title endpoint sets it to one of the four enum
    values above ("ok" on success). Every other endpoint that returns
    SessionResponse continues to return null for this field — additive,
    no client-breaking change.
  - Logs carry session_id, provider, model, exception type, and message
    — enough to diagnose, no secrets (provider SDK errors do not place
    API keys in str(e); the test asserts no "sk-" / "bearer " patterns).

Chat-send is not touched. Title generation is only invoked by the
dedicated /title endpoint (verified by grep), so chat-send was already
independent of this code path and remains independent.

Tests (new file backend/tests/integration/test_chat_title.py):
  - test_title_generation_succeeds_with_provider: pins the happy path
    (status "ok", no WARNING/ERROR noise).
  - test_title_generation_fails_loud_without_provider: regression test
    for the bare-except bug — asserts 200, session title unchanged,
    status "skipped:provider_not_configured", exactly one WARNING log
    with diagnostic context, no exception bubbles.
  - test_title_generation_handles_provider_call_error: pins the generic
    provider-error branch.
  - test_title_endpoint_400_when_no_turns: pins the existing precondition
    so the typed-except rewrite doesn't accidentally swallow it.
  - test_other_session_endpoints_omit_title_generation_status: confirms
    the additive field is null on other SessionResponse endpoints.

Full backend integration suite: 170 passed locally (was 165 + 5 new).
2026-05-23 18:09:27 +05:30
..
api Stop swallowing chat-title generation failures silently 2026-05-23 18:09:27 +05:30
db Add optional local-first SQLite mode (Phase A core) 2026-05-16 22:26:05 +05:30
domain Initial public release 2026-03-22 13:48:50 +05:30
providers Add generic OpenAI-compatible provider for cheap/local model support 2026-04-13 16:56:34 +05:30
repositories Initial public release 2026-03-22 13:48:50 +05:30
schemas Refuse to silently extract mock content into a real Space 2026-05-23 17:48:14 +05:30
services Add V3 dirty paths and skill pack v2.1 2026-05-04 13:11:20 +05:30
__init__.py Initial public release 2026-03-22 13:48:50 +05:30
config.py Add optional local-first SQLite mode (Phase A core) 2026-05-16 22:26:05 +05:30
config_loader.py Add generic OpenAI-compatible provider for cheap/local model support 2026-04-13 16:56:34 +05:30
main.py Expand doctor activation diagnostics 2026-05-17 00:26:03 +05:30