# Recover roots before collecting

An original, synthetic counterexample to treating reachability before recovery
as a safe reclamation decision. This is not a Makalu implementation, benchmark,
power-loss test or conservative garbage collector.

## Read the result

Objects `a`, `b` and `c` exist. Object `a` points to `b`; no other edges exist.
At the crash boundary, the root set is empty. Application recovery will restore
the root to `a`. The example assumes those recovered roots are authoritative.

| Order | Reclaimed objects | Needed objects already lost |
| --- | --- | --- |
| Collect using crash roots, then restore roots | a, b, c | a, b |
| Restore roots, then collect | c | none |

The first order destroys storage needed by the recovered application.
The second retains the entire recovered chain. A separate case leaves `c`
unpublished: it can be reclaimed without losing either rooted object.
An unrooted two-object cycle is also collectible under exact tracing.

A fourth case has one reachable account object whose value is 0 when the
application requires 7. Reachability accepts its storage, but the payload
invariant fails. A graph traversal cannot infer or repair the intended value.

## Reproduce

Use Node.js with no external dependencies, in this directory:

```sh
node model.mjs
node model.mjs --check results.json
node --test model.test.mjs
```

[Model](model.mjs), [tests](model.test.mjs), [generated results](results.json).

The exhaustive test enumerates all 512 directed graphs on three labeled objects,
including self-edges, and all 8 crash-root sets times 8 recovered-root sets:
32,768 cases. An independent bitset fixed-point oracle checks both reachable sets
and the exact set reclaimed too early. This is exhaustive only for that finite
model. It does not estimate a real failure rate.

## Source boundary

The [Makalu record](https://hesela.dev/terms/makalu/) provides the research
context and primary references. The pinned
[implementation README](https://github.com/HewlettPackard/Atlas/blob/d4fd983322a4e247724aa636f380aa023b927e0b/makalu_alloc/README.md)
assigns application-data recovery to the client, separately from allocator
recovery. The [public header](https://github.com/HewlettPackard/Atlas/blob/d4fd983322a4e247724aa636f380aa023b927e0b/makalu_alloc/include/makalu.h)
declares `MAK_collect_off`, `MAK_set_defer_free_fn` and `MAK_free_imm`.
Do not substitute the paper's differently named interfaces when compiling
against that header.

[Source identities](sources.json) record the paper hash, DOI, code revision,
header hash and access date. External source files are linked, not redistributed.
The code header carries LGPL-3.0-or-later notices; this example does not copy it.

## Check the header separately

The optional [header probe](header-probe.mjs) checks the SHA-256 of the pinned
upstream header before invoking a local C compiler named `cc`. Obtain
`makalu.h` from the linked revision, then run:

```sh
node header-probe.mjs ./makalu.h
```

[Recorded results](header-results.json) contain the compiler identity, all six
inputs and diagnostics. Three declared names compile; three paper names are
intentionally rejected as undeclared. These are declaration-availability checks,
not function calls, link tests or execution of allocator recovery. No upstream
header is bundled with the example.

## Limits

The model has exact object identities and pointers. It excludes conservative
false retention, address reuse, transactional log replay, pointer-field recovery,
torn writes, CPU caches, fences, allocator metadata, concurrency and failures
during recovery. It assumes correct allocation metadata and a known recovered
root set. Its order comparison is explanatory, not a bug report about Makalu.
The correct-order case is not a proof of a complete recovery protocol.

The historical paper's measurements are not rerun here. No throughput,
recovery-time or production-readiness claim follows from these examples.
