ruflo/docs/adr/ADR-031-HF-CHAT-HISTORY-PERSISTENCE.md
Proposed (2026-03-04)
2026-03-04
Chat history in HF Chat UI (chat.conveyorclaims.ai) is lost every time the Cloud Run service is redeployed. Users lose all conversations, settings, and assistant context.
The HF Chat UI Docker image (ghcr.io/huggingface/chat-ui-db:latest) bundles MongoDB as a sidecar process inside the same container. The MONGODB_URL=mongodb://localhost:27017 configuration connects to this local MongoDB instance, meaning:
gcloud run deploy or gcloud builds submit creates a new revision → new container → empty MongoDB┌─────────────────────────────────────┐
│ Cloud Run Container (ephemeral) │
│ │
│ ┌──────────┐ ┌───────────────┐ │
│ │ HF Chat │──▶│ MongoDB │ │
│ │ UI (Node)│ │ (localhost) │ │
│ │ │ │ │ │
│ └──────────┘ │ DATA LOST ON │ │
│ │ REDEPLOYMENT │ │
│ └───────────────┘ │
└─────────────────────────────────────┘
Use MongoDB Atlas free tier (M0) or shared cluster. HF Chat UI natively supports external MongoDB via MONGODB_URL.
Changes required:
MONGODB_URL=mongodb+srv://<user>:<pass>@<cluster>.mongodb.net in Cloud Run envmongodb-urlcloudbuild.yaml to use --set-secrets=MONGODB_URL=mongodb-url:latestPros: Zero code changes, native support, free tier available, managed backups Cons: External dependency, network latency (~10-30ms), 512MB limit on free tier
Cost: Free (M0) or ~$9/mo (M2 shared, 2GB)
Use Firestore in MongoDB-compatible mode (Datastore mode). HF Chat UI may require a MongoDB wire protocol proxy.
Pros: Fully managed, GCP-native, scales to zero Cons: Not wire-compatible with MongoDB driver, would need code changes or proxy
Mount a GCS bucket or NFS share as a volume for MongoDB data.
Changes required:
--add-volume and --add-volume-mount to Cloud Run deployPros: No external MongoDB needed, data persists in GCS Cons: GCS FUSE has latency, not ideal for database workloads, MongoDB may not perform well on FUSE mounts
Run MongoDB on a Compute Engine VM (similar to ruvector-postgres-vm pattern).
Pros: Full control, predictable performance, persistent Cons: Operational overhead, cost (~$25/mo for e2-small), manual backups
Option A (MongoDB Atlas) — simplest path:
cloud.mongodb.comconveyor-chat databasecloudbuild.yaml:
'--set-secrets', '...MONGODB_URL=mongodb-atlas-url:latest'
MONGODB_URL=mongodb://localhost:27017 from env vars and .env.local| Data Type | Currently Persists? | After Fix |
|---|---|---|
| Chat conversations | No (lost on redeploy) | Yes |
| User preferences | No | Yes |
| Model selections | No | Yes |
| Shared conversations | No | Yes |
| Assistant configurations | No | Yes |
| Uploaded files metadata | No | Yes |
conveyor-chatmongodb-atlas-urlinfrastructure/gcp/hf-chat-ui/cloudbuild.yaml — add secret bindinginfrastructure/gcp/hf-chat-ui/update-preprompt.js — remove localhost MongoDB URLinfrastructure/gcp/hf-chat-ui/dotenv-local.txt — remove MONGODB_URL line| ADR | Relationship |
|---|---|
| ADR-029 | HF Chat UI deployment architecture |
| ADR-030 | MCP tool gap analysis |