Memory snapshots #
extension.gleam exposes export_snapshot(workspace) and
import_snapshot(target, origin, transfer_id, snapshot) for daemon transfer. A
Snapshot holds the source workspace label and relative UTF-8 file contents.
The transfer adapter stages files as memory/<relative path> and imports them
into the destination workspace at activation. Retries use the origin daemon,
transfer ID, and source workspace to identify files already imported.
Contents and workspace identity #
Export includes this workspace's memory.md and journal/YYYY-MM-DD.md,
without following workspace links. Empty memory is omitted. Empty journal files
are retained. The working directory need not exist locally: memory lives on the
daemon's disk under $ALBEDO_HOME/memories.
files.gleam derives the directory and lock key by replacing
each non-ASCII-alphanumeric character in the workspace string with -. This is
a lossy slug. Distinct workspace strings can share memory storage and a lock. Do
not assume collision-free workspace isolation.
Validation and transfer identity #
Each source file and merged target file is limited to 1 MiB. Journal appends that would exceed 1 MiB leave the existing file intact. Snapshot contents are limited to 16 MiB. Export fails on unreadable or oversized files rather than skipping them. Import validates paths, duplicates, UTF-8 bodies, and snapshot limits before writing. Journal paths must match the date-shaped filename pattern, which does not check calendar validity.
The target .transfers/<digest> manifest binds the origin and transfer ID to
the source label and sorted file contents. Reusing that identity with a changed
snapshot fails before merging, including when files were added or removed. File
order does not change snapshot identity. Target merge sizes are checked later,
per file, so input validation does not guarantee every merge will succeed.
Direct import binds even an empty snapshot. The transfer adapter instead returns
success for an empty staged list without checking or creating a manifest. See
install in extension.gleam.
Locks and merge behavior #
The owner serializes cooperating callers with albedo_file.with_lock on the
workspace directory, a lock within the daemon's VM. This is not a filesystem
lock. External writers do not participate, and the lock is not a basis for
independent daemons to share a home.
Export holds the source lock and recovers pending imports for the files it exports, so export can write recovery state. Import holds only the target lock. No operation holds both workspace locks. Ordinary save, append, and journal operations recover the pending import for the file they will modify before writing. Reads do not trigger recovery.
An empty target receives source bytes unchanged. A nonempty target keeps its
bytes and receives the source under
## imported from <workspace> on <utc-date>. Missing journal days are copied
and overlapping days are appended. Empty source memory is skipped. The date
comes from that import invocation. On a later retry, files not yet started can
receive a later date, while pending files retain their recorded after bytes.
Receipts, retries, and recovery #
Each target file has a <file>.imports receipt containing hashed origin,
transfer, and source-workspace identities paired with content digests. A retry
skips committed files, including after memory.save replaces their content.
Committed receipts do not compare the current payload with the imported bytes.
Use a new transfer ID to import later source edits.
Receipts and manifests are retained without pruning. Saving empty memory or
removing memory.md does not remove their duplicate protection. Removing the
workspace memory directory and its metadata does. Do not delete metadata to
force a retry.
A file import writes a pending receipt with the before and after bytes, replaces the payload, then commits the receipt. Each replacement syncs and closes a temporary file before renaming it in the same directory. Recovery applies the after bytes if the target still matches the before bytes, or commits the receipt if it already matches the after bytes.
An unreadable or invalid receipt fails recovery. While a receipt is pending, target bytes matching neither recorded state cause a conflict and retain the receipt. Receipt validation checks the encoded structure, not arbitrary tampering. A retry with the same identity and unchanged snapshot resumes files independently. Earlier files can be committed while later files remain untouched. There is no transaction across files. The protocol handles daemon interruption between operations, without a power-loss guarantee for directory metadata.
The owner is files.gleam. Its native
albedo_ext_memory_ffi.erl keeps the reads,
appends, directory creation and journal glob that
albedo_file does not
provide; paths, file information, listings, atomic replacement and the lock go
through albedo_file. files.gleam encodes import receipts and transfer
digests in the external term format through
albedo_bytes/term_codec.
Supporting scenarios live in the
snapshot tests,
receipt compatibility tests,
and
transfer-owner tests.
See workspaces for transfer ownership
and linked-workspace behavior.