Skip to main content

migrate_legacy_array_to_jsonl

Function migrate_legacy_array_to_jsonl 

Source
pub fn migrate_legacy_array_to_jsonl(
    path: &Path,
    to_jsonl: impl FnOnce(&str) -> Result<String>,
) -> Result<()>
Expand description

One-time migration of a legacy JSON-array store to JSONL, shared by the append paths in meta_model.rs and feedback.rs.

No-op unless path exists and its first non-whitespace byte is [ — only that byte is needed to disambiguate, so the non-legacy hot path never reads the whole file. When a legacy array is detected, to_jsonl receives the full file text and must return the JSONL replacement (one record per line, trailing newline included).

Concurrency-safe: the migration is serialized per canonical path and the format is re-checked under the lock, so concurrent appenders don’t double-migrate. The rewrite goes through a sibling temp file + rename, so a crash mid-migration leaves either the legacy array or the migrated JSONL — never a half-written mix.