Legacy store import fails on every boot with MongoDB storage: conditioned handles cannot declare collections
Summary
With the MongoDB storage backend, the legacy cron and sessions imports fail on every boot, before any data is written:
ERROR openhuman::storage_import: [storage::import] import failed; the legacy files are untouched and it is retried on the next boot domain="cron" error=[storage::import] storage: unsupported capability conditional_writes: conditioned MongoDB handles cannot mutate collection declarations
ERROR openhuman::storage_import: [storage::import] import failed; the legacy files are untouched and it is retried on the next boot domain="sessions" error=[storage::import] storage: unsupported capability conditional_writes: conditioned MongoDB handles cannot mutate collection declarations
WARN openhuman_core::core::runtime::bootstrap: [runtime] legacy cron store import failed: …
WARN openhuman_core::core::runtime::bootstrap: [runtime] legacy sessions store import failed: …
Problem
Where this was observed: an embedding host (Chottu, openhuman-embed with storage-mongodb + legacy-import, pinned at 0caf743388) logs both errors once per pod boot, so every deploy raises an operator alert. The pods are not restarting (0 restarts).
Cause: every importer runs its writes inside an import claim (import_state::with_claim), through storage bound to the claim's WriteCondition. That storage comes from either:
import_state::backend_with_condition→ClaimBoundBackend, used bytinyflows::import_cron(viamarked) andsessions::import, ordocuments::Repo::conditioned, used byimport_onefor the per-domain sources.
The writes through that storage start by declaring their collections (DocumentStore::ensure_collection). The drivers disagree on whether a conditioned handle may do that:
| driver | ensure_collection on a conditioned handle |
|---|---|
| memory, file, SQLite | allowed (idempotent spec merge) |
MongoDB (tinystoragedrivers-document/src/mongodb/documents.rs:438) |
Unsupported(ConditionalWrites): "conditioned MongoDB handles cannot mutate collection declarations" |
So on MongoDB every claimed import that declares a collection fails. The import tests run on SQLite and never see it. Upstream main has the same code (crates/openhuman-core/src/storage/import/mod.rs:454-487, storage/import/tinyflows.rs marked/import_cron, storage/import/sessions.rs).
Impact:
- The legacy records are never imported on MongoDB. The files are left untouched, so nothing is lost.
- Every boot logs two ERROR lines.
- The
flowsimport uses the same claim. If it hit a declaration, workflow access would stay paused (ensure_flow_scope_ready).
Steps to reproduce:
- Use the MongoDB storage backend with
legacy-import. - Have a workspace containing
cron/jobs.dborsession_db/sessions.db(orsession_raw/, ormemory/conversations/turn_states/). - Boot. Both imports fail with the error above.
Solution
A collection declaration is idempotent schema metadata. The claim exists to fence data writes, so a writer that lost its claim must not write records, but declaring a collection does no harm. The fix is to have claim-bound storage declare collections (ensure_collection and the read-only validate_collection_spec) through the scope's unconditioned handle, while every data write keeps the claim's condition. Do this in one place shared by ClaimBoundBackend and Repo::conditioned, so every importer gets it. The MongoDB driver's refusal stays as it is.
Open question: the observed host runs OpenHuman with a stateless workspace (Workspace::stateless()), yet the importer finds a legacy cron/jobs.db and session store at boot. Something earlier in the boot may create them. This fix doesn't depend on the answer, but it may deserve its own issue.
Acceptance criteria
- [ ] Repro gone: claimed imports succeed on a backend whose conditioned handles refuse declarations, as MongoDB's do.
- [ ] Regression safety: a test with a declaration-refusing conditioned backend, checking that collections get declared and that a stale claim's data writes are still refused.
- [ ] Diff coverage ≥ 80%.
Related
- Driver guard:
vendor/tinystoragedrivers/crates/tinystoragedrivers-document/src/mongodb/documents.rs:438 - Claim plumbing:
crates/openhuman-core/src/storage/import_state.rs(backend_with_condition),crates/openhuman-core/src/storage/documents.rs(Repo::conditioned)
With the MongoDB storage backend, claimed legacy imports fail on every boot because MongoDB's conditioned handles refuse ensure_collection, so the cron/sessions imports never run and two ERROR lines are logged per boot (files are left untouched, so no data loss). Fix should let claim-bound storage declare collections through the unconditioned scope handle while keeping claim conditions on data writes. No matching duplicate or fix among the candidates.
Labelled priority: p2.