Summary
- Fixed legacy local sync imports that stalled on orphan prompt/observation session dependencies.
- Allows old malformed
.engram/chunksexports to recover data instead of failing forever with a foreign key error.
Details
- Local
engram sync --importnow scans manifest chunks for real session upserts before deciding a dependency is truly missing. - When a missing session is absent from both the local DB and every chunk, import synthesizes a deterministic recovered session stub with directory
(recovered-missing-session). - Existing cross-chunk dependency-safe behavior is preserved: real session chunks still win over recovered stubs.
Validation
go test ./internal/sync -run 'TestLocalImport(RecoversLegacyChunkWithMissingSessionStub|DependencySafeAcrossChunksRegardlessManifestOrder|OrdersExplicitMutationsAndDirectArraysSafely)' -count=1 -vgo test ./internal/sync ./internal/store -count=1go test ./cmd/engram ./internal/cloud/cloudserver ./internal/cloud/cloudstore ./internal/cloud/remote ./internal/sync ./internal/store -count=1go test ./... -count=1git diff --check