Skip to content

fix: check vault directories before auto-initialising the vault - #327

Open
vinceblock99 wants to merge 15 commits into
devfrom
fix/vault-symlink-guard-order
Open

vinceblock99 wants to merge 15 commits into
devfrom
fix/vault-symlink-guard-order

Conversation

@vinceblock99

@vinceblock99 vinceblock99 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

What

In the memory create handler, run the .vault / .vault/memory directory checks before the vault is auto-initialised. The rest of the handler keeps its original order and error messages.

Why

After the dev merge, vault_repository() (which calls ensure_vault) ran first. A request that is rejected because .vault or .vault/memory is a symlink still created vault directories and files through that symlink.

Test

New vault_symlink_guard_test: fails on the current branch, passes with this change.

leefaus and others added 15 commits November 3, 2026 01:29
Add capability-gated schema-3 span changes, native recording and rendering, and transactional insertion of indexed and incoming span changes with portable semantic owners. Preserve schema-2 compatibility and add focused lifecycle and insertion tests.

Checkpoint only: spans are not enabled by default. Concurrent span conflicts and span-backed name conflicts currently fail closed; rename with simultaneous content edits and legacy span semantic-owner migration remain incomplete. The diagnostic 25-suite core harness reported 8 passed and 17 failed suites, including 5 that exited before their assertion summaries.
… testing

Preserve the exact working tree developed and tested in atomic-span-clean, including experimental span import, projected semantics, durability fencing, merge fixes, and consolidated shim coverage. AI-assisted development checkpoint; not a production-readiness claim. Span import remains opt-in and strict shim guard failures remain documented. No remote publication.
)

* perf: share one span render context per transaction

Every caller of retrieve_span_if_present built a fresh SpanRenderContext,
which verifies and decodes the whole visible closure, for every file it
rendered. On a span import of hyperfine (1,097 commits, 75 files) one
`atomic view switch` built the context 312 times, `atomic record -a` 466
times and `atomic restore -f` 157 times, at roughly 55 ms each, while the
materialization itself took milliseconds.

- Add SharedSpanRender: a lazily built context shared by every file read
  through one transaction and visibility closure. The per-file root,
  capability and visibility checks are unchanged; only the closure decode
  is shared.
- Use it in project_tree, project_change_closure_with_txn and
  plan_file_moves, which render every projected file in one transaction.
- Add Repository::get_file_contents_on_view and recorded_presence_on_view
  so callers that read many paths get one transaction, one projection and
  one context, with the absent-liveness check scoped to exactly those
  paths. Use them in the shim checkpoint observation, working-copy
  verification and the CLI and daemon restore paths, which previously
  rendered (and discarded) every file one at a time.

Batched reads are tested byte for byte against the single-path reads for
graph-origin, span-rooted, empty, directory and absent paths on two views.
On the hyperfine span import, `atomic view switch` drops from 25-34 s to
4-7 s (12 context builds) and `atomic restore -f` of all 75 files from
15 s to 4.8 s (8 builds); graph-only repositories are unaffected.

* fix: keep batched restore and checkpoint reads behaviour-identical

Checkpoint observation no longer reads graph content for paths that carry
conflict-marker bytes. Name-conflict errors carry the same path and
claimant counts as the single-path reader. The daemon and CLI restore
paths classify every path up front but still walk and report them in
status order, so untracking, failures and output lines happen exactly
where they did before. The batch-read test now asserts that the fixture
really records span-rooted files.

* fix: stream checkpoint and verify file contents

* feat: partial materialization cases and Git working-copy baseline

Add materialize_paths_noop, materialize_paths_missing and
materialize_prefix_missing to the paired graph/span materialization
benchmark, with per-sample subset write-count assertions, and a new
git_baseline.py harness that times git checkout -- full working-tree
restores on the same synthetic history shape.

First paired run (macOS/aarch64, many-files, 8 iterations): partial
materialize_paths restore of 8 of 25 files takes ~315 ms against
~565 ms full, while the partial noop floor (~187 ms) equals the full
noop — the journaled plan/lease/journal path dominates, not content
work. Span capability stays within 2% on every materialize case.
Git restores the full tree in ~22 ms.

* feat: agent-sandbox sync benchmark over the daemon Materialize RPC

Add libatomic/examples/agent_sandbox_bench.rs plus a frozen runner: a
cold, empty sandbox syncs over the production tonic stack (SandboxImpl
handlers on a Unix socket, streaming Materialize with path_prefix,
write_sandbox_entry receiver), with git clone over file:// as the
wire-protocol comparison on the same synthetic history shape. Partial
sandboxes must hold exactly the requested subtree and nothing beyond it.

Recorded loopback runs: full-sync parity with git clone at both scales
(66 vs 72 ms small, 190 vs 185 ms large). The atomic prefix partial
holds a near-constant request phase because the handler walks the whole
view closure and filters at stream time — filtering during projection is
the measured next optimization.

* perf: cache verified change parses in the change store

load_verified_change re-read and re-parsed the change file on every
call. Change files are content-addressed and write-once, so a parsed,
hash-verified change is immutable for the handle's lifetime; cache it.
revalidate_verified_change callers keep the old re-read-and-compare
behavior, and explicit revalidation requests bypass the cache.

Measured on the agent-sandbox benchmark (2,048-file span fixture, 49
changes, one 11 MB baseline): a full view render went from 34.6 s to
1.08 s — every per-file span context was re-parsing the baseline, at
roughly 85 ms per render. Span partial materialize dropped from 1.13 s
to 634 ms. Graph-origin paths do not consult this cache and are
unchanged.

* perf: share one span render context per view walk

materialize_view_entries rendered each file through a fresh
SpanRenderContext, and every context decodes and verifies the whole
visible closure: a 2,048-file span view built 4,213 contexts per
materialize (traced), ~20.7 s of combined CPU hidden by rayon
parallelism.

SharedSpanContext builds once per walk, lazily on the first span-rooted
file, and is safe to share across the rayon render chunks (OnceLock;
single-threaded OnceCell cannot cross them). Graph-origin files still
fall back to the graph renderer, and callers without a shared context
keep the old per-call path.

Measured with the parse cache on the agent-sandbox benchmark (2,048-file
span fixture): partial materialize 639 -> 341 ms, full 1,091 -> 794 ms.
Span render now matches the graph backend on this fixture.

* chore: drop the local git working-copy baseline harness

The materialize_bench comparison set is atomic-internal: paired
graph/span cases and partial-vs-full ratios. Wire-protocol Git
comparison stays in the agent-sandbox benchmark, where both sides
start from nothing over their real transports.

* feat: COW sandbox provision case for the agent-sandbox benchmark

atomic_sandbox_cow times Repository::provision_sandbox on the same
synthetic fixture: the local copy-on-write clone an agent gets on a
machine that already holds the repository. Measured (2,048 files,
11 MB, reflink on APFS): 276 ms median — per-file reflink syscall
overhead dominates at ~0.13 ms/file, so provision time scales with
file count, not bytes. Beats the RPC partial (336 ms) and git clone
(779 ms); the whole-tree clonefile(2) fast path is the follow-up that
would make it near-instant.

---------

Co-authored-by: Vincent <vince@atomic.dev>
# Conflicts:
#	libatomic/src/daemon/services_agent.rs
switch_from_empty rests on a view where every tracked file is absent
(untimed setup switch) and times the switch to the full view: maximal
pure materialize work through the switch entry point — every tracked
file rendered and written, no deletions, no revert machinery.

Measured many-files: 887 ms graph / 872 ms span, comparable to
switch_many — the switch machinery itself, not the write volume,
dominates at this fixture size.
The digest array no longer implements LowerHex after the dependency
refresh on dev; encode explicitly with HEXLOWER instead.
Memory creation auto-initialised the vault before validating that
.vault and .vault/memory are real directories, so a request that is
then refused could still create directories and files through a
symlink. Run the directory and existing-file checks first, then
initialise the vault and check for a duplicate id.

Adds a regression test covering a symlinked .vault and a symlinked
.vault/memory.
Only the directory checks need to run before the vault is
auto-initialised. Restore the original order for the rest, so a
duplicate memory still reports "memory '<id>' already exists".
Base automatically changed from checkpoint/span-native-integration to dev November 11, 2026 18:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants