fix(back): wire DATABASE_URL through to the RAG retrieval path (WO-06) - #124
Merged
Conversation
Every generation ran without RAG passages: the system prompt went out with "(no example passages provided)" and the passport carried rag_sources: [], while the request still returned 200 (issue #87 / WO-06). Two independent breaks were masking each other: * The backend never read `.env`, despite README/CONTRIBUTING/DEPLOYMENT all instructing developers to create one. app.config now loads the repo-root `.env` on import, which is enough for the whole process because every entry point reaches configuration through that module. * `routes/generate.py` never forwarded `database_url` to `orchestrate()`, so `autoria_ai.db` fell back to `os.environ["DATABASE_URL"]` and the resulting KeyError was swallowed by generator.py's `except Exception` — turning a configuration error into a per-request warning. `.env` is loaded with `override=False`: Railway and Vercel inject the real secrets into the process environment, and a stale `.env` shipped in an image must never outrank them. DATABASE_URL is normalised to the `postgresql+asyncpg://` form in app.config.to_asyncpg_dsn. `.env.example` documents the plain `postgresql://` scheme (what Supabase hands out, what the psycopg2 seeding scripts consume) but SQLAlchemy's create_async_engine rejects a driver-less URL, so the backend translates at the boundary — the same rule, in the same direction, as scripts/seed_corpus.py:to_asyncpg_url. `ai_pipeline/autoria_ai/db.py` is untouched; its contract was already correct. A missing DATABASE_URL is now reported once, explicitly, at import, instead of surfacing as a generic "RAG retrieval failed" warning on every generation. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #87. Rama rescatada: existía sin PR y con ~10 PRs de Sprint 3 por delante. Rebasada sobre
main, no mergeada (un merge habría revertido medio Sprint 3).El defecto
La ruta llamaba a
orchestrate(...)sindatabase_url. La cadena completa:generator.pyllamaba aretrieve_top_k(..., database_url=None).autoria_ai/db.pycaía aos.environ["DATABASE_URL"]..enven ningún punto.KeyErrorresultante lo tragaba elexcept Exceptiondel generador.Resultado: cada generación corría con cero pasajes RAG y emitía un Passport con
rag_sources: [], en silencio, con solo un warning en el log. La "R" de RAG no existía en el producto.El arreglo
app/config.pycarga el.envde la raíz conoverride=False— la variable inyectada por la plataforma siempre gana, así que en Railway/Vercel es un no-op. La ausencia depython-dotenvse degrada con warning en vez de tumbar/health.to_asyncpg_dsn()traduce en la frontera:.envdocumentapostgresql://(lo que da Supabase y lo que esperan los scripts de siembra con psycopg2), perocreate_async_enginelo rechaza sin driver. Se traduce en el backend en vez de romper cualquiera de los dos contratos.database_url=settings.database_urlexplícitamente.Verificación
El único fallo es
test_generate_live_watsonx, que apunta alibm/granite-3-8b-instructretirado upstream — ajeno a esta rama, en curso en el PR #120.Hallazgo destapado al verificar esto de punta a punta
Con el RAG por fin activo,
orchestratecontra Supabase + Watsonx reales falló de forma intermitente: la rama condicionada agota el timeout duro de 8 s unas veces sí y otras no. La causa está medida y corregida en el PR #123 (el tope de salida se ignoraba y luego 512 tokens no cabían en el presupuesto de latencia). Los dos PRs se necesitan mutuamente para que/api/generatesea fiable: este pone los pasajes, aquel evita el 503.🤖 Generated with Claude Code