reflake 0.2.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. {reflake-0.2.0 → reflake-0.3.0}/.gitignore +3 -0
  2. {reflake-0.2.0 → reflake-0.3.0}/CHANGELOG.md +255 -0
  3. {reflake-0.2.0 → reflake-0.3.0}/PKG-INFO +198 -34
  4. {reflake-0.2.0 → reflake-0.3.0}/README.md +197 -33
  5. {reflake-0.2.0 → reflake-0.3.0}/pyproject.toml +6 -1
  6. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/__init__.py +71 -98
  7. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/cli.py +360 -76
  8. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/__init__.py +13 -16
  9. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/client_state.py +14 -20
  10. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/config.py +9 -0
  11. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/domain/__init__.py +10 -0
  12. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/domain/errors.py +37 -0
  13. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/domain/models.py +25 -3
  14. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/entry_codec.py +59 -70
  15. reflake-0.3.0/src/reflake/core/ignore.py +111 -0
  16. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/layout.py +11 -0
  17. reflake-0.3.0/src/reflake/core/manifest.py +70 -0
  18. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/objects/__init__.py +4 -6
  19. reflake-0.3.0/src/reflake/core/objects/backends.py +93 -0
  20. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/objects/base.py +39 -9
  21. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/objects/footer.py +77 -16
  22. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/objects/local.py +65 -6
  23. reflake-0.3.0/src/reflake/core/objects/multipart.py +187 -0
  24. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/objects/query.py +82 -43
  25. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/objects/s3.py +120 -39
  26. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/objects/source.py +55 -2
  27. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/objects/transfer.py +50 -15
  28. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/objects/tree.py +32 -7
  29. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/query/catalog.py +3 -0
  30. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/query/pruning.py +41 -11
  31. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/repository.py +204 -106
  32. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/repository_ops.py +275 -68
  33. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/repository_support.py +98 -54
  34. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/repository_sync.py +114 -51
  35. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/services/__init__.py +2 -3
  36. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/services/entries.py +18 -7
  37. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/services/refs.py +95 -21
  38. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/services/staging.py +34 -10
  39. reflake-0.3.0/src/reflake/core/services/tree.py +1571 -0
  40. reflake-0.3.0/src/reflake/core/services/tree_inspect.py +259 -0
  41. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/vfs/__init__.py +8 -2
  42. reflake-0.2.0/src/reflake/core/manifest.py +0 -174
  43. reflake-0.2.0/src/reflake/core/objects/backends.py +0 -160
  44. reflake-0.2.0/src/reflake/core/objects/derived.py +0 -71
  45. reflake-0.2.0/src/reflake/core/services/tree.py +0 -926
  46. reflake-0.2.0/src/reflake/core/services/tree_inspect.py +0 -185
  47. {reflake-0.2.0 → reflake-0.3.0}/LICENSE +0 -0
  48. {reflake-0.2.0 → reflake-0.3.0}/NOTICE +0 -0
  49. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/hashing.py +0 -0
  50. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/core/query/__init__.py +0 -0
  51. {reflake-0.2.0 → reflake-0.3.0}/src/reflake/py.typed +0 -0
@@ -162,3 +162,6 @@ cython_debug/
162
162
  # and can be added to the global gitignore or merged into this file. For a more nuclear
163
163
  # option (not recommended) you can uncomment the following to ignore the entire idea folder.
164
164
  #.idea/
165
+
166
+ # Reflake runtime state (never commit a repository into the source tree)
167
+ .reflake/
@@ -6,8 +6,263 @@ The format is based on Keep a Changelog, and Reflake currently tracks changes be
6
6
 
7
7
  ## Unreleased
8
8
 
9
+ ## [0.3.0] - 2026-09-24
10
+
11
+ ### Added
12
+
13
+ - **Invariant fuzz test** (`tests/test_invariants.py`): randomized sequences of
14
+ commit / staged add / rm / mv / reset / branch / merge with tree sharding
15
+ forced on; after every step it asserts that every reachable commit and tree
16
+ parses, is duplicate-free, and references only existing objects. It found
17
+ the branch-namespace collision fixed below on its first run.
18
+ - **`scripts/profile_gc.py`**: GC benchmark harness (orphan-heavy and
19
+ reachable-heavy modes, optional tracemalloc live/peak accounting).
20
+ - **Nightly benchmark job** in CI (`schedule` + `workflow_dispatch`, excluded
21
+ from PR runs); the S3 integration job already runs on every push/PR.
22
+ - **`reflake reset <ref>`** — move a branch pointer to any existing commit or
23
+ ref (undo/redo) with a compare-and-set, without touching the worktree.
24
+ Staged changes survive (with a warning); every move lands in the reflog.
25
+ Library: `ReflakeRepository.reset()` returning `ResetResult`.
26
+ - **`reflake branch -d/--delete <name>`** — delete a branch by CAS-ing its ref
27
+ to unborn; the name can be re-created afterwards. Deleting the current
28
+ branch is refused.
29
+ - **Hierarchical branch names** (`feature/nightly-ingest`). Client-state
30
+ filenames encode the name (`feature%2Fx`), local ref listing recurses, and
31
+ the new validator rejects empty/`.`/`..`/leading-dot/consecutive-dot
32
+ segments.
33
+ - **`identity verify --drift`** — metadata-only drift detection for pointer
34
+ entries: one HEAD per entry, never a source byte read. Pointer entries
35
+ imported from S3 now record the source ETag (optional trailing field on
36
+ `m`/`mp` tree lines), and drift compares size + ETag (or last-modified for
37
+ local-file sources).
38
+ - **`--ref <branch>` for `identity verify` / `identity promote`**, so a shared
39
+ branch can be audited without changing the client's current branch.
40
+ - **Ignore rules**: worktree walks skip `.reflake/` and `.git/` by default and
41
+ honor `.reflakeignore` (comments, `!` re-include, directory patterns,
42
+ `*`/`?`/`**`, anchored patterns). Explicitly named paths are always staged.
43
+ - **GC grace window**: `gc --prune` never deletes objects younger than
44
+ `gc_grace_seconds` (config, default 24h; `--grace-seconds` overrides),
45
+ closing the mark-and-sweep race with a writer that has published objects
46
+ but not yet CAS'd its ref. Unknown ages are treated as young; the CLI and
47
+ JSON report `skipped_young`.
48
+ - **Multipart uploads and streaming downloads** for large blobs (64 MiB
49
+ threshold): files are never buffered whole, the 5 GiB single-PUT ceiling is
50
+ gone, and stream uploads verify the content hash *before* completing the
51
+ upload (a mismatch aborts).
52
+ - **`restore` streams and verifies**: blobs are hashed while streaming into a
53
+ temp file and renamed into place only when the digest matches.
54
+ - `--json` support for `branch`, `checkout`, `init`, `config`, `restore`,
55
+ `reset`, and `transfer` (all structured commands are now covered).
56
+ - New domain errors `SourceNotFoundError` (missing source input) and
57
+ `CorruptCommitError` (unparseable commit object).
58
+
59
+ ### Changed
60
+
61
+ - **The GC sweep is streaming and bounded.** `gc` accepts an `inventory`
62
+ existence source (`ObjectInventory`, defaulting to the repository store —
63
+ the seam a future S3 Inventory adapter plugs into), tests membership
64
+ against the reachable sets *as it lists*, and deletes in ≤1000-key batches
65
+ on the way through. There is no `dict(stored)`/`set(stored)` copy and no
66
+ per-subtree leaf-ref memo any more: leaf references are harvested once per
67
+ unique tree node, so memory is proportional to the reachable sets, not to
68
+ the store listing or to `files × depth`.
69
+ - Sweeps are idempotent and re-runnable: there is no cursor state to corrupt,
70
+ and an entry a crashed sweep skipped is found by the next one. Leaking
71
+ garbage is allowed; deleting live data never is.
72
+ - Local blob shards are snapshotted per directory while listing so deleting
73
+ during iteration cannot skip siblings; emptied shard directories are
74
+ removed best-effort.
75
+ - Sync planning (`push`/`pull`) walks the tree DAG once per unique node
76
+ (shared seen set) instead of re-walking it per commit.
77
+ - **A missing *source* now exits 1 (validation), not 3** — exit 3 is reserved
78
+ for missing repository refs/objects; the runbook and README say so.
79
+ - **Tree nodes are validated before they are written** (sorted, duplicate-free,
80
+ single-component names): an invalid node can no longer be published and
81
+ poisoned by a ref, the second shard-class corruption bug this guards
82
+ against.
83
+ - `mv` refuses a destination whose parent path is a file, instead of
84
+ silently replacing that leaf; staging a path and a path below it (`a` and
85
+ `a/b`) is rejected at `add`.
86
+ - Staged local sources record size + mtime; `commit` warns when a staged
87
+ source changed before the commit (staging is a recipe — the commit contains
88
+ commit-time bytes).
89
+ - Ancestor checks, merge-base, `log` ordering and sync sorting derive
90
+ generations for commits that predate the `generation` field instead of
91
+ treating "missing" as zero.
92
+ - S3 source access (`add s3://…`, pointer reads/promotes) reuses the S3-backed
93
+ repository's configured client/endpoint instead of building a default
94
+ client.
95
+ - Tree caches are shared per store (one parsed copy per tree object per
96
+ process instead of four independent caches).
97
+ - Interrupted multipart uploads are aborted (no orphaned parts).
98
+
99
+ ### Fixed
100
+
101
+ - **Staged splice corruption (P0): a staged directory (or `mv`) landing on a
102
+ committed leaf wrote a node with two entries of the same name.** The commit
103
+ succeeded and the branch head became unparseable for every reader. Both
104
+ shape-change directions now replace correctly, and the new write-time
105
+ validation turns any future occurrence into a loud error before the ref
106
+ moves.
107
+ - **S3 GC could never see blobs or commits.** Empty object ids built listing
108
+ prefixes through `blob_relpath()`/`""`, producing `blobs/.` and
109
+ `commits/.json` — prefixes that match nothing. `gc --prune` on S3 silently
110
+ reported zero blob/commit orphans, and large sync plans treated every
111
+ existing blob as missing (re-upload attempts that `IfNoneMatch` then
112
+ discarded). Empty ids now yield clean directory prefixes (`blobs/`,
113
+ `commits/`, …), with a regression test.
114
+ - **Branch namespace collisions.** Creating `feature` next to `feature/x`
115
+ crashed with `IsADirectoryError` on local repositories (reading a ref path
116
+ that is a directory) and was silently permitted on S3, diverging the two
117
+ backends. Both orders are now rejected up front with a clear `ValueError`,
118
+ and `read_branch_ref` treats a directory entry as "no such ref" rather than
119
+ crashing.
120
+ - `S3ObjectStore.write_blob_file`/`write_blob_stream` no longer load whole
121
+ objects into memory (transfer backend `upload` used `Path.read_bytes()`).
122
+ - `ReflakeRepository.log` still lists legacy histories after the generation
123
+ change (root commits legitimately have generation 0).
124
+
125
+ ### Removed
126
+
127
+ - **The package root re-exports only the documented stable surface** (stores,
128
+ protocols, codec, pruning internals, config helpers); import internals from
129
+ `reflake.core` explicitly if you need them.
130
+ - `write_branch_ref` is no longer part of the `RefCas` protocol — every ref
131
+ mutation must go through compare-and-set.
132
+
133
+ ## [0.2.1] - 2026-09-10
134
+
135
+ ### Deprecated
136
+
137
+ - **v0.2.0** is deprecated and superseded by 0.2.1 — it corrupts full commits
138
+ in directories with more than 10k entries (sharded directories). See the
139
+ notice under 0.2.0 below.
140
+
141
+ ### Fixed
142
+
143
+ - **`identity promote` keeps parquet footer stats.** Promotion rewrote
144
+ pointer entries with the plain-blob kind, so an `mp` entry (stats attached)
145
+ became `b` and every promoted file silently lost its row-group statistics —
146
+ pruning stopped working on exactly the files that had been prepared for it.
147
+ - **Nested shards can no longer be written.** Rebuilding a shard body through
148
+ the general builder re-sharded it once the range held `MAX_TREE_ENTRIES + 1`
149
+ entries, producing shard pointers inside a shard; later operations then saw
150
+ duplicate/misplaced names. Shard bodies are now written as plain nodes, and
151
+ an overflowing range splits into two balanced sibling shards.
152
+ - **A staged file can replace a directory (and vice versa) in one splice.**
153
+ The splice loop kept the existing subtree and then appended the new leaf,
154
+ writing a node with two identical names (unparseable tree stream).
155
+ - **Sharded directories no longer corrupt full commits.** A directory with
156
+ more than 10k entries is stored as name-range shard subtrees; the full
157
+ commit path merged parent *shard pointers* as if they were named children.
158
+ Depending on which file changed, this either silently dropped parent-only
159
+ entries or produced duplicate paths and an unsorted tree stream (breaking
160
+ `verify`, `promote`, and analytical indexing). Parent-directory resolution
161
+ now expands shards to real children, and `_prune_tree` tests removal
162
+ prefixes against real names. Regression suite: `tests/test_sharded_directories.py`.
163
+ - **Opening a repository no longer mutates it.** `RefManager` used to write
164
+ an empty ref for the default branch, which also "created" nonexistent S3
165
+ prefixes on open. Missing branches are now *unborn*: staging works, the ref
166
+ is created by the first commit (CAS `expected=None`).
167
+ - **`verify` is strictly read-only.** Dry-run audits no longer build or write
168
+ tree objects; only `promote` materializes and commits.
169
+ - **Path-prefix matching is component-aware everywhere.** Tree walks, VFS
170
+ listings, and staged overlays now use the same rule as `rm`/`mv`
171
+ (`a/b` matches `a/b` and `a/b/…`, never `a/bc`), so staged and committed
172
+ paths can no longer disagree.
173
+ - **CLI usage errors exit 1**, not 2 (2 is reserved for retryable conflicts).
174
+ Sync endpoint misuse raises `TransferEndpointError` instead of `TypeError`.
175
+ - **`log` shows the full parent DAG** (merged-in commits are no longer
176
+ hidden by a first-parent-only walk).
177
+ - **`restore --path <dir>` restores directory prefixes**, and unknown paths
178
+ fail with exit 3 instead of silently restoring nothing.
179
+ - **Blob reads are hash-verified** (`read_blob`/`cat`/`restore`), and s5cmd
180
+ batch downloads re-hash blobs after transfer; s5cmd failures surface as
181
+ `StorageUnavailableError` (never `CalledProcessError`).
182
+ - **Pruning parser**: `AND` inside quoted literals is no longer a clause
183
+ separator, and binary/INT96 min-max bounds are dropped instead of compared
184
+ in the wrong domain (pruning stays conservative).
185
+ - **GC walks shared subtrees once** (per-tree leaf-reference memo) instead of
186
+ re-walking the tree DAG per commit.
187
+ - **Tree cache eviction** no longer stops at the first pinned entry.
188
+ - **Merge base is the nearest common ancestor.** `merge` used to walk the
189
+ first-parent chain, so merging after a shared commit could report false
190
+ conflicts for files that only one side had touched since the divergence.
191
+ The new walk is generation-ordered over both frontiers and stops at the
192
+ first commit reachable from both sides.
193
+
194
+ ### Changed
195
+
196
+ - **Commits, splices, merges, diffs and prunes touch O(changed paths).**
197
+ - Unchanged directory nodes (and, in sharded directories, unchanged shard
198
+ bodies) are detected by content hash and never written: committing one
199
+ changed file in a 50-directory repository now PUTs 2 tree nodes instead
200
+ of 51. Full commits that change nothing PUT none.
201
+ - Staged adds/removals in a sharded directory rewrite only the shard whose
202
+ name range contains the touched paths (binary search per name), and
203
+ removal pruning tests removal prefixes against shard ranges before
204
+ loading anything.
205
+ - Merging branches that changed different ranges of the same huge
206
+ directory compares shard pointers pairwise and reads no shard bodies at
207
+ all; only ranges that both sides changed are descended into.
208
+ - `identity promote` splices materialized entries into the existing tree
209
+ instead of rebuilding it from a flattened walk.
210
+ - **New or changed worktree files are hashed in parallel** (up to 8 workers;
211
+ blake3 releases the GIL), measured at ~2.5x on a 20k-file ingest.
212
+ - **`trust_mtime` config key** (off by default): reuse a content entry whose
213
+ size *and* `mtime_ns` match the worktree file without re-hashing it. Trade
214
+ -off: a same-size, same-mtime edit is not detected.
215
+ - **`query prune` accepts a footer cache.** Footer stats are
216
+ content-addressed, so repeat scans of the same revision read no footers at
217
+ all.
218
+ - **GC deletes in batches** (`DeleteObjects`, up to 1000 keys per request)
219
+ instead of one request per object.
220
+ - **Analytical index keeps its CSV ingestion.** Benchmarked: 50k rows take
221
+ ~0.3s via the manifest CSV but ~46s via parametrized `INSERT`s (even in 10k
222
+ batches) on the pinned DuckDB, so the intermediate CSV is the fast path,
223
+ not a shortcut.
224
+
225
+ - **`merge` is tree-level and O(changed directories).** It compares
226
+ content-addressed subtree hashes and short-circuits whenever a directory is
227
+ unchanged on one side, so the tree is never flattened: merging two branches
228
+ that each changed one file in a 10k-entry / 400-directory repository costs
229
+ 2 tree reads and 1 tree write (previously every directory was re-walked and
230
+ re-materialized). Conflict rules are unchanged: one-sided changes win,
231
+ delete/modify and file↔directory shape changes conflict with the offending
232
+ paths, and identical add/add is accepted.
233
+ - **`verify`/`promote` are now nested under `reflake identity`** (breaking CLI
234
+ change): `reflake identity verify` (read-only audit; exit 1 while
235
+ unverifiable entries remain) and `reflake identity promote` (materialize
236
+ blobs + promotion commit). The library methods `repo.verify()` /
237
+ `repo.promote()` are unchanged, and the JSON payloads keep their fields.
238
+ - **Transfer planning is adaptive**: small plans probe object existence
239
+ per object; plans above 64 candidates list the destination inventory once
240
+ per object kind (one paginated listing instead of N HEAD requests). Commit
241
+ collection uses the same strategy.
242
+ - **`commit` warns about unverifiable revisions when staged pointer entries
243
+ are committed**, not only when the repository default identity is `pointer`.
244
+ - **Benchmarks are excluded from the default test run** (`pytest -m benchmark`
245
+ to run them); CI runs `-m "not integration and not benchmark"`.
246
+
247
+ ### Removed
248
+
249
+ - Top-level `reflake verify` / `reflake promote` (moved under `identity`).
250
+ - Dead v1-era surface: `ManifestReader`/`ManifestWriter`/`build_manifest_entries`,
251
+ `LocalStorageBackend`/`StorageBackend`, the derived-manifest block index
252
+ (`derived.py`, `lookup_derived_entry`), `merge_sorted_streams`,
253
+ `Entry.from_dict`, `SUPPORTED_IDENTITY_MODES`, `StageStatus.modified`, and
254
+ `TreeCache.pin`/`unpin`.
255
+ - `PLAN_PROGRESS.md` (stale duplicate of `docs/architecture.md`).
256
+ - Stale v1-era `.reflake/` state that had been committed into the source tree
257
+ (`config.json`, refs, staging leftovers). `.reflake/` is now git-ignored:
258
+ runtime state must never be committed.
259
+
9
260
  ## [0.2.0] - 2026-09-08
10
261
 
262
+ > **Deprecated — superseded by 0.2.1.** This release corrupts full commits in
263
+ > directories with more than 10k entries (sharded directories) and can drop
264
+ > parquet footer statistics on `identity promote`. Use 0.2.1 or later.
265
+
11
266
  ### Breaking pre-1.0 cleanup
12
267
 
13
268
  No backcompat is kept for anything below — this is the last window for it.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: reflake
3
- Version: 0.2.0
3
+ Version: 0.3.0
4
4
  Summary: A client-first, object-storage-first data versioning engine
5
5
  Project-URL: Repository, https://github.com/londogard/reflake
6
6
  Project-URL: Documentation, https://github.com/londogard/reflake#readme
@@ -746,14 +746,21 @@ Reflake separates data into three layers:
746
746
 
747
747
  | Area | Commands |
748
748
  |---|---|
749
- | Ingest | `init`, `add`, `commit [--staged]`, `verify` (audit), `promote` |
749
+ | Ingest | `init`, `add`, `commit [--staged]` |
750
+ | Identity | `identity verify [--drift] [--ref]` (read-only audit), `identity promote [--ref]` (materialize) |
750
751
  | Inspect | `status`, `log`, `diff`, `list` (`ls`), `cat`, `branches`, `reflog` |
751
- | Branch | `branch`, `checkout`, `merge` (fast-forward + 3-way metadata merge) |
752
- | Mutate | `rm`, `mv`, `gc [--prune]`, `restore` |
752
+ | Branch | `branch [-d]`, `checkout`, `merge` (fast-forward + 3-way metadata merge), `reset` (undo/redo) |
753
+ | Mutate | `rm`, `mv`, `gc [--prune] [--grace-seconds N]`, `restore` |
753
754
  | Sync | `push`, `pull`, `fetch`, `transfer` |
754
755
  | Analyze | `query build` (DuckDB/Parquet), `query prune` (row-group pruning) |
755
756
 
756
- Exit codes: `0` ok · `1` usage/validation (including `verify` with remaining pointer entries) · `2` conflict, retryable (CAS race, non-fast-forward, merge conflict) · `3` missing ref/object.
757
+ Worktree walks honor `.reflakeignore` (plus built-in `.reflake/` and `.git/`)
758
+ unless a path is named explicitly.
759
+
760
+ Exit codes: `0` ok · `1` usage/validation (unknown/missing **source** inputs,
761
+ `identity verify` with remaining pointer entries or detected drift) · `2`
762
+ conflict, retryable (CAS race, non-fast-forward, merge conflict) · `3` missing
763
+ repository ref/object. Every command with structured output honors `--json`.
757
764
 
758
765
  ## Guardrails (Strict)
759
766
 
@@ -799,8 +806,8 @@ uv run reflake --repo /tmp/reflake-demo commit -m "initial"
799
806
  # Stage an S3 prefix as pointer entries, then commit the staged additions
800
807
  uv run reflake --repo /tmp/reflake-demo add --identity pointer --as imports/bootstrap s3://my-bucket/bootstrap
801
808
  uv run reflake --repo /tmp/reflake-demo commit --staged -m "metadata import"
802
- uv run reflake --repo /tmp/reflake-demo verify
803
- uv run reflake --repo /tmp/reflake-demo promote
809
+ uv run reflake --repo /tmp/reflake-demo identity verify
810
+ uv run reflake --repo /tmp/reflake-demo identity promote
804
811
 
805
812
  # branch-scoped staged flow
806
813
  uv run reflake --repo /tmp/reflake-demo branch feature
@@ -862,21 +869,23 @@ This is useful for large bootstrap imports where strong content verification can
862
869
 
863
870
  Pointer (`pointer`) revisions are **unverifiable**: the entry's
864
871
  identity is derived from path and size, not from content bytes. Until you run
865
- `reflake promote`, Reflake cannot prove that the content at `source_uri` matches
866
- what was originally imported.
872
+ `reflake identity promote`, Reflake cannot prove that the content at
873
+ `source_uri` matches what was originally imported.
867
874
 
868
875
  **Warnings.** The CLI emits a warning to stderr whenever you stage with
869
876
  `--identity pointer` or commit a repository whose identity is configured to `pointer`,
870
- and `verify` reports how many unverifiable entries remain (exiting non-zero).
877
+ and `identity verify` reports how many unverifiable entries remain (exiting
878
+ non-zero).
871
879
 
872
880
  **Source-retention policy.** Because pointer entries have no canonical
873
881
  blob, you **must** retain the source objects at their original `source_uri`
874
- until the entry has been promoted via `reflake promote`. If a source object is
882
+ until the entry has been promoted via `reflake identity promote`. If a source
883
+ object is
875
884
  deleted, overwritten, or moved before promotion, the corresponding
876
885
  entry becomes irrecoverable — no content can be read and no hash can be
877
886
  validated.
878
887
 
879
- **Promotion to verifiable.** Run `reflake promote` to read every pointer
888
+ **Promotion to verifiable.** Run `reflake identity promote` to read every pointer
880
889
  entry's source blob, compute a content hash, store the canonical blob,
881
890
  and rewrite the entry in `content` mode. After promotion the source
882
891
  retention requirement is lifted for those entries.
@@ -888,23 +897,49 @@ retention requirement is lifted for those entries.
888
897
  | Pointer | `pointer` | `null` | ✅ (from `source_uri`) | ❌ | ✅ |
889
898
  | Verified | `content` | hash | ✅ (from `blobs/`) | ✅ | ❌ |
890
899
 
891
- ## Verify And Promote Commands
900
+ ### Drift detection (metadata-only)
892
901
 
893
- `reflake verify` is a read-only audit: it reports how many pointer entries of the current branch would be promoted, and exits non-zero while any remain:
902
+ Pointer entries imported from S3 record the source object's size,
903
+ last-modified time, and ETag (the optional trailing field on `m`/`mp` tree
904
+ lines). `reflake identity verify --drift` then compares those recorded values
905
+ against the source with **one metadata request per entry — never a byte
906
+ read**, and exits non-zero when a source was overwritten, resized, or
907
+ deleted:
894
908
 
895
909
  ```bash
896
- uv run reflake --repo /tmp/reflake-demo verify
897
- uv run reflake --repo /tmp/reflake-demo verify --path images --path logs/2026
910
+ uv run reflake --repo s3://my-bucket/datasets/demo identity verify --drift
898
911
  ```
899
912
 
900
- `reflake promote` materializes canonical blobs and writes a promotion commit (only when at least one entry is promoted):
913
+ Drift detection is a best-effort metadata comparison (local-file sources have
914
+ no ETag, so size + mtime are used there); it proves *change*, not content
915
+ equality. `identity promote` remains the only way to make a pointer entry
916
+ verifiable.
917
+
918
+ ## Identity: Audit And Promotion
919
+
920
+ Entry identity has two modes (`content` / `pointer`), so both commands that
921
+ reason about it live under `reflake identity`.
922
+
923
+ `reflake identity verify` is a read-only audit: it reports how many pointer
924
+ entries of the current branch would be promoted, and exits non-zero while any
925
+ remain:
901
926
 
902
927
  ```bash
903
- uv run reflake --repo /tmp/reflake-demo promote
904
- uv run reflake --repo /tmp/reflake-demo promote --path images --path logs/2026
928
+ uv run reflake --repo /tmp/reflake-demo identity verify
929
+ uv run reflake --repo /tmp/reflake-demo identity verify --path images --path logs/2026
930
+ uv run reflake --repo /tmp/reflake-demo identity verify --ref feature --drift
905
931
  ```
906
932
 
907
- - Both audit all entries by default (or selected path prefixes with `--path`).
933
+ `reflake identity promote` materializes canonical blobs and writes a promotion
934
+ commit (only when at least one entry is promoted):
935
+
936
+ ```bash
937
+ uv run reflake --repo /tmp/reflake-demo identity promote
938
+ uv run reflake --repo /tmp/reflake-demo identity promote --path images --path logs/2026
939
+ ```
940
+
941
+ - Both commands accept `--ref <branch>` (default: current branch) and audit all
942
+ entries by default (or selected path prefixes with `--path`).
908
943
  - Promotion reads bytes from each entry's `source_uri`, computes the content hash, and stores canonical blob content.
909
944
 
910
945
  ## Incremental Ingress
@@ -916,12 +951,12 @@ uv run reflake --repo /tmp/reflake-demo add --as imports/new-batch /tmp/random/n
916
951
  uv run reflake --repo /tmp/reflake-demo add --identity pointer --as imports/bootstrap.csv s3://my-bucket/bootstrap.csv
917
952
  uv run reflake --repo /tmp/reflake-demo add --identity pointer --as imports/bootstrap s3://my-bucket/bootstrap
918
953
  uv run reflake --repo /tmp/reflake-demo commit --staged -m "add one file"
919
- uv run reflake --repo /tmp/reflake-demo promote --path images --path root.txt
954
+ uv run reflake --repo /tmp/reflake-demo identity promote --path images --path root.txt
920
955
  ```
921
956
 
922
957
  - `add` + `commit --staged` preserves the current branch manifest and reads bytes only for staged additions.
923
958
  - `add` accepts repo-relative files, arbitrary local files, local directories, single S3 objects, and S3 prefixes; `--as` maps a single file/object to one logical path or remaps a directory/prefix under a destination prefix.
924
- - `promote` reads bytes only for selected pointer entries that still need canonical blobs.
959
+ - `identity promote` reads bytes only for selected pointer entries that still need canonical blobs.
925
960
  - Existing entries are preserved without re-uploading unchanged blob content.
926
961
 
927
962
  ## Merge Command
@@ -952,6 +987,83 @@ uv run reflake --repo /tmp/reflake-demo commit --staged -m "remove old logs and
952
987
  - `mv` accepts a file path or prefix and rewrites matching logical paths.
953
988
  - `reflake status` shows staged removals and renames before `reflake commit --staged`.
954
989
 
990
+ ## Commits, Deletions, And Branch Switching
991
+
992
+ A full `commit` treats the working tree as an **overlay** on the committed tree:
993
+ files present on disk join the commit, and committed entries stay in the
994
+ commit even if the file is missing locally. Deletion is never inferred from
995
+ the filesystem — it is an explicit metadata operation:
996
+
997
+ ```bash
998
+ uv run reflake --repo /tmp/reflake-demo rm old-prefix # stage the removal
999
+ uv run reflake --repo /tmp/reflake-demo commit --staged -m "drop old-prefix"
1000
+ ```
1001
+
1002
+ This is deliberate (an S3-first engine cannot know whether a missing local
1003
+ file means "deleted" or "never materialized"), which is why `reflake status`
1004
+ compares the working tree against the committed tree: you see exactly what a
1005
+ commit would add or change, and stage removals for everything else.
1006
+
1007
+ Symlinks are neither followed nor stored: the worktree walk skips them (it
1008
+ never escapes the repository root). Store the target's bytes, or stage the
1009
+ external file explicitly with `add --as`.
1010
+
1011
+ `reflake checkout <branch>` only **points the client at another branch** (a
1012
+ client-local symbolic ref); it never rewrites the working tree. Materializing
1013
+ data is an explicit, separate step: `restore <ref>` (optionally `--path <dir>`),
1014
+ `pull`, `cat`, or the read-only VFS. Files are only ever downloaded because you
1015
+ asked for them.
1016
+
1017
+ ### Staging semantics: a recipe, not a snapshot
1018
+
1019
+ `add` records a *recipe* (logical path + source), not frozen bytes: content is
1020
+ read when you commit. If a staged source changes in between, the commit
1021
+ contains the bytes **at commit time** — the CLI warns loudly (`Staged
1022
+ source(s) changed since \`add\``) rather than committing silently.
1023
+
1024
+ ### Branch names, and deleting branches
1025
+
1026
+ Branch names may be hierarchical (`feature/nightly-ingest`). `reflake branch
1027
+ draft -d` deletes a branch by CAS-ing its ref to *unborn* — a concurrent
1028
+ advance surfaces as a conflict instead of losing an update, and the name can
1029
+ be re-created with `reflake branch draft`.
1030
+
1031
+ ## Ignore Rules
1032
+
1033
+ Worktree walks (`commit`, `status`, `add <dir>`) skip:
1034
+
1035
+ - `.reflake/` and `.git/` (built-in, so a dataset repository never swallows
1036
+ git's metadata);
1037
+ - anything matched by `.reflakeignore` in the tree root (the file itself is
1038
+ tracked);
1039
+ - a path named explicitly on the command line is always staged — explicit
1040
+ wins.
1041
+
1042
+ `.reflakeignore` syntax: one glob per line, `#` comments, `!` to re-include,
1043
+ trailing `/` for directories, `*`/`?` don't cross `/`, `**` does, and a
1044
+ pattern containing `/` is anchored to the tree root.
1045
+
1046
+ ```gitignore
1047
+ scratch/
1048
+ *.tmp
1049
+ **/*.parquet.bak
1050
+ !important.tmp
1051
+ ```
1052
+
1053
+ ## Undo: `reset`
1054
+
1055
+ `reset` moves a branch pointer to any existing commit or ref (backwards or
1056
+ forwards) with a CAS, without touching the worktree:
1057
+
1058
+ ```bash
1059
+ uv run reflake --repo /tmp/reflake-demo log # find the commit you want
1060
+ uv run reflake --repo /tmp/reflake-demo reset <commit>
1061
+ uv run reflake --repo /tmp/reflake-demo reset main # also accepts refs
1062
+ ```
1063
+
1064
+ Staged changes are kept (a warning reminds you that `commit --staged` will now
1065
+ apply them onto the new parent). Every move is recorded in `reflake reflog`.
1066
+
955
1067
  ## Sync (push/pull/fetch)
956
1068
 
957
1069
  ```bash
@@ -961,9 +1073,11 @@ uv run reflake --repo . fetch s3://my-bucket/datasets/demo
961
1073
  ```
962
1074
 
963
1075
  - Objects transfer plan-first: the exact missing set (commits, trees, footers, blobs) is computed, then executed via `boto3` per-object or batched through [`s5cmd`](https://github.com/peak/s5cmd) when configured (`config set transfer_backend s5cmd`).
1076
+ - Planning is adaptive: small plans probe object existence one by one; plans over ~64 objects list the destination's object ids once per kind instead of issuing N HEAD requests.
964
1077
  - Divergent history is rejected before any bytes move (`NonFastForwardError`); the final ref update is a CAS, so concurrent pushes surface conflicts instead of overwriting.
965
1078
  - Push after a local merge transfers the entire merged lineage, including both parents' commits.
966
- - S3-compatible endpoints (MinIO, Ministack, …) configured via `reflake init --backend s3 --s3-endpoint …` (or `config set s3.endpoint_url …`) are honored for repository operations; direct `s3://` remotes use the ambient AWS configuration chain.
1079
+ - Large blobs stream: uploads above 64 MiB use multipart (never a single 5 GiB-capped PUT, never a whole file in memory), downloads stream to disk, and `restore` verifies hashes while streaming into a temp file before renaming it into place.
1080
+ - S3-compatible endpoints (MinIO, Ministack, …) configured via `reflake init --backend s3 --s3-endpoint …` (or `config set s3.endpoint_url …`) are honored for repository operations **and** for `add s3://…` source access on S3-backed repositories.
967
1081
 
968
1082
  ## Analytical Index (Derived, Disposable)
969
1083
 
@@ -987,6 +1101,33 @@ With `config set parquet_footer true`, parquet ingests also capture compact foot
987
1101
  uv run reflake --repo /tmp/reflake-demo query prune <ref> images/ --where "id >= 100 AND active = true"
988
1102
  ```
989
1103
 
1104
+ `query prune` reuses a footer cache inside the index directory: footers are
1105
+ content-addressed, so scanning the same revision twice reads nothing further.
1106
+ Stats survive `identity promote` — promoting an `mp` entry yields `bp`, never a
1107
+ statless plain blob.
1108
+
1109
+ ## Commit Cost Model
1110
+
1111
+ Commits, splices, merges, diffs and prunes are proportional to what changed,
1112
+ not to the size of the tree:
1113
+
1114
+ - Tree nodes are content-addressed and written with `IfNoneMatch`: unchanged
1115
+ directories (and, inside sharded directories, unchanged shard bodies) are
1116
+ detected by hash and never re-written. Committing one changed file in a
1117
+ 50-directory repository puts 2 tree objects; a full commit that changes
1118
+ nothing puts none.
1119
+ - Directories above 10k entries are stored as name-range shards. A staged
1120
+ add or removal rewrites only the shard whose range contains the touched
1121
+ paths (binary search per name), and merges compare shard pointers pairwise,
1122
+ reading shard bodies only where both sides changed the same range.
1123
+ - New or changed worktree files are hashed in parallel (up to 8 workers;
1124
+ blake3 releases the GIL).
1125
+ - With `config set trust_mtime true`, a worktree file whose size *and*
1126
+ `mtime_ns` match the committed entry is reused without hashing. Trade-off:
1127
+ a same-size, same-mtime edit is not detected — off by default.
1128
+ - GC issues batched `DeleteObjects` calls (up to 1000 keys each) instead of
1129
+ one request per object.
1130
+
990
1131
  ## `fsspec` URI Example
991
1132
 
992
1133
  ```python
@@ -1013,8 +1154,8 @@ repo = open_repository("/tmp/reflake-demo") # fails unless initialized
1013
1154
  repo = open_repository("s3://my-bucket/datasets/demo") # remote (lazy)
1014
1155
 
1015
1156
  commit_id = repo.commit("snapshot")
1016
- repo.verify() # read-only audit of pointer entries
1017
- repo.promote() # materialize blobs + commit
1157
+ repo.verify() # read-only audit of pointer entries (CLI: identity verify)
1158
+ repo.promote() # materialize blobs + commit (CLI: identity promote)
1018
1159
  repo.merge("feature", "main")
1019
1160
  ```
1020
1161
 
@@ -1025,7 +1166,8 @@ Public, stable surface (everything else is internal and may change):
1025
1166
  - reads: `ReflakeFileSystem`, `ReflakeURI`
1026
1167
  - sync: `push`, `pull`, `fetch`
1027
1168
  - errors: `ReflakeError` and subclasses (`RefConflictError`,
1028
- `NonFastForwardError`, `UnknownRefError`, …)
1169
+ `NonFastForwardError`, `UnknownRefError`, `BlobIntegrityError`,
1170
+ `TransferEndpointError`, …)
1029
1171
 
1030
1172
  `core.services`, `core.objects`, `core.query` internals and the store
1031
1173
  protocols are not covered by stability guarantees. Read paths (`diff`,
@@ -1040,36 +1182,58 @@ Reflake creates `.reflake/` under each dataset root:
1040
1182
  - `trees/` - Merkle tree nodes (sorted JSONL, content-addressed)
1041
1183
  - `footers/` - parquet footer-stats objects (when enabled)
1042
1184
  - `commits/` - commit metadata objects
1043
- - `refs/heads/` - branch pointers only (CAS-updated)
1044
- - `refs/HEAD` - symbolic active branch reference (default `main`)
1185
+ - `refs/heads/` - branch pointers only (CAS-updated, `feature/x` allowed)
1186
+ - `refs/HEAD` - **client-local** symbolic active branch reference (never shared)
1045
1187
  - `state/` - client-local branch snapshots (never shared, never a ref)
1046
1188
  - `staging/`, `cache/`, `index/`, `reflog/` - client-local state
1047
1189
 
1048
1190
  Every object kind has exactly one physical location, defined by
1049
1191
  `layout.object_relative_key()` — the local filesystem and the S3 key space are
1050
1192
  guaranteed to stay in sync because both derive from that single mapping.
1193
+ Client-state filenames encode branch names (`feature/x` → `feature%2Fx`), so
1194
+ hierarchical branches can never collide with each other on disk.
1195
+
1196
+ ## Garbage Collection Safety
1197
+
1198
+ `reflake gc` is audit-only by default. `--prune` never deletes objects younger
1199
+ than a grace window (`gc_grace_seconds`, default 24h; override with
1200
+ `--grace-seconds N`), because a concurrent writer publishes immutable objects
1201
+ *before* it CASes its ref: without the window, mark-and-sweep would race that
1202
+ window and delete live data. Unknown object ages are treated as young.
1203
+
1204
+ The sweep streams the store listing, tests reachability as it goes, and
1205
+ deletes in 1000-key batches, so memory stays proportional to the *reachable*
1206
+ object set rather than to the store size. The listing comes from a pluggable
1207
+ existence source (the seam a future S3 Inventory adapter plugs into). Sweeps
1208
+ are idempotent — re-run one instead of resuming it; an entry a crashed sweep
1209
+ missed is simply found next time. Run `gc` (audit) before pruning in a shared
1210
+ repository, as always.
1051
1211
 
1052
1212
  ## Concurrency Model
1053
1213
 
1054
1214
  There are no locks. Every shared mutation goes through compare-and-swap:
1055
1215
 
1056
- - Local repos use version tokens (mtime+size) checked before writing.
1216
+ - Local repos serialise CAS through an OS file lock (`flock`/`msvcrt`) and write atomically (temp file + rename).
1057
1217
  - S3 repos use conditional `PutObject` (`IfMatch`/`IfNoneMatch`) so the check-and-write is atomic server-side.
1058
1218
  - `commit --staged` re-applies its overlay onto the new parent and retries on conflict; other mutations surface `RefConflictError` with both commit ids.
1219
+ - Opening a repository never mutates it: a branch with no ref yet is *unborn* (staging works, the first `commit` creates the ref).
1059
1220
 
1060
1221
  ## Mandatory Validation Coverage
1061
1222
 
1062
1223
  Current tests cover required invariants:
1063
1224
 
1064
- - Metadata-only diff reads no blob payloads.
1065
- - Manifest generation for 100k entries stays under RAM cap.
1225
+ - Metadata-only diff, remove, and move read no blob payloads; `identity verify` (dry run) writes no objects at all.
1226
+ - Sharded directories (>10k entries) survive full commits without duplicate or lost entries.
1227
+ - Build a 100k-entry tree under a RAM cap (benchmark, see below).
1066
1228
  - `reflake://my_data@main/test.csv` resolves and returns expected bytes.
1067
- - Staged commits stay correct regardless of path sort order; merged lineages survive push/pull.
1229
+ - Staged commits stay correct regardless of path sort order; merged lineages survive push/pull; blob reads are hash-verified.
1068
1230
 
1069
- Run test suite:
1231
+ Run the test suite:
1070
1232
 
1071
1233
  ```bash
1072
- uv run pytest tests
1234
+ uv run pytest tests # fast suite (benchmarks excluded)
1235
+ uv run pytest tests -m benchmark # wall-clock/memory benchmarks
1236
+ uv run pytest tests -m integration # needs a real S3 endpoint (see below)
1073
1237
  ```
1074
1238
 
1075
1239
  ## S3 Integration Tests