interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

GitHub aien-dev/aienux#237 (code only)

closed derived 0141275fa32e1112 #237

Imported from GitHub aien-dev/aienux#237 (code only)

GitHub's metadata for this pull request is unavailable: its state is DERIVED from the commits (merged: the head is reachable from this project's main; open: GitHub kept a merge ref; else closed).

Base 3e283fa9c6f180f4fc82d4fbf60835728f4cccb9 · Head a6a594e5eb4fe53e8b842c9f2bfc318033c5b6ad

Apply it

git checkout -b patch-0141275fa32e1112 3e283fa9c6f180f4fc82d4fbf60835728f4cccb9
curl -fsSL https://interplane.io/drakestapleton/aienux/patches/0141275fa32e1112.patch | git am

Raw patch (mbox) · Diff

Provenance

This proposal is imported from GitHub; it is not signed by its author. Its import statement and source record:

github-import 1
aien-dev/aienux
237
a6a594e5eb4fe53e8b842c9f2bfc318033c5b6ad
{"kind":"github-import","owner":"aien-dev","repo":"aienux","number":237,"url":"https://github.com/aien-dev/aienux/pull/237","export_sha256":"967c79e26a893657b5cdaa45efd442be5dbd2ecfe68e25f9a8c1b5da4d60d452","imported_utc":"2026-11-18T16:36:02Z","metadata":"unavailable","state_derived":true}

Changes

diff --git a/native/kernel/CONTINUITY_RECOVERY_CONTRACT.md b/native/kernel/CONTINUITY_RECOVERY_CONTRACT.md
index 51829104..fb37324b 100644
--- a/native/kernel/CONTINUITY_RECOVERY_CONTRACT.md
+++ b/native/kernel/CONTINUITY_RECOVERY_CONTRACT.md
@@ -1,10 +1,13 @@
 # C kernel contract: continuity objects and Recovery Core
 
-Status: **SPEC, NOT_RUN.** Only the codec has C code (cuts 1-2: `svc/continuity_codec.c`,
-the golden vectors and the C/Rust decode agreement run by `make -C native/kernel test`
-and `continuity-mutants`: **host PASS**, QEMU n/a, nothing wired into the kernel).
-Resolution, Recovery Core and every C gate named here stay `NOT_RUN
-(MISSING_IMPLEMENTATION)` until a forge receipt covers them.
+Status: **SPEC, NOT_RUN.** What has C code (all **host PASS**, QEMU n/a, nothing wired into the kernel):
+the codec (cuts 1-2: `svc/continuity_codec.c`, golden vectors, C/Rust decode agreement) and, new in
+cut 3, boot **resolution** (`svc/continuity_resolve.c`: P-3 lookup, INV-5 orphan/Conflict, INV-6 chain,
+INV-7 references, read-only check), the Recovery Core **challenge**, **state digest** and **operator
+HMAC** (same file), and the sealed-Store binding `svc/continuity_resolve_sealed.c`, all run by
+`make -C native/kernel test`, `sanitize` and `continuity-mutants` against the REAL sealed Store in a file.
+No provision, commit or resume (cut 4), no Recovery Core inspection or actions (cut 5), no wiring. Every C
+gate named here stays `NOT_RUN (MISSING_IMPLEMENTATION)` until a forge receipt covers it.
 QEMU qualifies nothing physical; nothing here says anything about Machine 1.
 
 Authority:
@@ -354,6 +357,10 @@ main design point of this contract.
 
 - **P-1 (PROPOSED).** Continuity objects are stored through `ss_transact` as
   `ss_object{kind = 16|17|18|20, version = 1, bytes = canonical plaintext}`.
+  **Read side IMPLEMENTED, host PASS (cut 3); write side (provision, commit) is cut 4.** Evidence:
+  `test_continuity_resolve.c` writes all four kinds with `ss_transact` at version 1 and `cr_resolve`
+  reads them back through the claims (`t_resolved`, `t_orphans`, `t_references`, at 512 and 4096 byte
+  blocks).
   The kinds do not collide with existing C application kinds (CODE:
   `CK_BOOT_KIND` 0x0B00, store_boot.h:30; `CK_ART_INDEX_KIND` 0x0A01 and
   `CK_ART_CHUNK_KIND` 0x0A02, native/kernel/svc/artifact_store.h:38-39).
@@ -365,6 +372,10 @@ main design point of this contract.
   compares bytes directly. The sealed envelope's own Store ObjectId (SHA-256
   of the envelope, keyed by the store keys; m5.h:171-181, store_sealed.c:334-345)
   is never written into a continuity object.
+  **IMPLEMENTED on the read side, host PASS (cut 3):** `cr_resolve` computes every logical id with
+  `sv1_object_id` over the decrypted plaintext (`continuity_resolve.c:113`) and follows only logical ids
+  (`read_kind`, :64-82), re-hashing each object it reads so a reference can never reach different
+  bytes (`t_references`, `t_chain`). Bytes stay bit-identical to Rust (D-1).
 - **P-3 (PROPOSED).** Lookup: after `ss_open`, the verified claims
   (`ws->claims[0..nclaims)`, store_sealed.h:92-118) give each envelope's
   application kind and version (`c.obj.object_kind`, `object_version`) without
@@ -375,6 +386,10 @@ main design point of this contract.
   becomes "claim of application kind K". A logical id that maps to two claims is
   Corrupt (PROPOSED: Rust cannot see this because Store v1 dedups identical
   objects; the sealed store gives each write its own envelope).
+  **IMPLEMENTED, host PASS (cut 3):** `continuity_resolve.c:100-130` (`build_table`; duplicate check :115-118,
+  reason `duplicate logical object id`, checked before the root count so it is Corrupt, not Conflict);
+  test `t_duplicate_id` writes the same root bytes twice into the real sealed Store. Kind 19 and every
+  non-continuity kind are never read (`t_unprovisioned`, `t_fake`), as Rust ignores them.
 
 ### 5.2 Calls the continuity and recovery code needs
 
@@ -383,7 +398,7 @@ main design point of this contract.
 | mount without writing | `ss_open` (store_sealed.h:141-143), which runs `st_open` first | CODE |
 | mount state, peer condition | `s->st.state` (`ST_VALID`, `ST_DEGRADED_RECOVERY`), `s->st.peer` (store_engine.h:22-26, :134-141) | CODE |
 | generation, active slot | `ss_generation`, `st_active_slot` (store_sealed.h:151, store_engine.h:153-155) | CODE |
-| list by kind | claims loop (P-3) | PROPOSED |
+| list by kind | claims loop (P-3), `cr_bind_sealed` in `continuity_resolve_sealed.c` | CODE (cut 3, host PASS) |
 | read one object | `ss_read(s, sid, out, cap, &len, &kind)` (store_sealed.h:149-150) | CODE |
 | commit ≤ 3 objects atomically | `ss_transact(s, objs, n, hook, arg, ids_out)` (store_sealed.h:146-147), n ≤ `SS_MAX_OBJECTS` = 8 | CODE |
 | read-only refusal | `ss_prepare` returns `ST_E_READ_ONLY_DEGRADED` when not Valid (store_sealed.c:379) | CODE; continuity still checks first (INV-11) |
@@ -421,11 +436,15 @@ main design point of this contract.
   sealed Store the anchor holds the newer generation, so `ss_open` is expected to
   refuse with `SS_E_ROLLBACK` (store_sealed.h:57). UNVERIFIED (confidence
   medium). Either way no action may be applicable (INV-15).
-- **K-5 Degraded mount through ss_open.** Whether `ss_open` returns 0 on a
-  `DegradedRecovery` mount with a malformed peer (needed for INV-11 and repair)
-  is UNVERIFIED (confidence medium-high: `st_open` sets the state without failing,
-  store_engine.c:308-314, and the anchor generation is unchanged). The first C
-  host test for repair must prove it.
+- **K-5 Degraded mount through ss_open. DECIDED by running it (cut 3, host PASS).** The question was whether
+  `ss_open` returns 0 on a `DegradedRecovery` mount with a malformed peer (needed for INV-11 and repair).
+  **Answer: yes.** `test_continuity_resolve.c` `t_degraded` (:716, printed at :751) commits two generations
+  to the real sealed Store, fills the inactive superblock slot with garbage, reopens: `ss_open` rc=0,
+  `st.state` = `ST_DEGRADED_RECOVERY`, `st.peer` = `ST_PEER_MALFORMED`, generation unchanged (3 -> 3), the
+  anchor accepts it. On that mount `cr_resolve` still returns the verified view (same agent, incarnation and
+  `memory=`), `cr_writable` returns `CR_READ_ONLY` (INV-11), and `cr_state_digest_dev` hashes the garbage
+  unit as it lies. Run at 512 and 4096 byte blocks. Not tested here: a malformed peer combined with
+  other mount or anchor damage, and repair itself (cuts 4-5).
 - **K-6 Region geometry.** The Rust qualification Store region is 256 units at
   LBA 64 with a control block at LBA 32 (crates/aienos-boot/src/store_qual.rs:13-16).
   The C layout is anchor units 0-3, Store region 4..U-2, probe unit U-1
@@ -553,9 +572,12 @@ ADR 0024 Q2 requires differential agreement, not just parallel tests.
   `CC_FIXTURE_DIR`) reproduces every byte and both ObjectIds (`cc_object_id` and `sv1_object_id`),
   decode then encode is the identity, and tampered bytes, ObjectIds and verdicts are refused.
   Added vector: `state_forksum_overflow` (hostile fork counts, refused by both).
-  **DEFERRED to the resolve cut:** the recovery challenges (both actions) and HMAC responses with the TEST key
-  (0x0f x32) are emitted as `deferred` lines but not checked, because the C codec has no challenge or
-  HMAC code yet.
+  **DONE in the resolve cut (cut 3, host PASS):** the recovery challenges (both actions) and HMAC responses
+  with the TEST key (0x0f x32) are the four `deferred` fixture lines. `test_continuity_resolve.c`
+  `test_fixture` reproduces all four byte for byte from `cr_challenge` and `cr_operator_response`
+  (system record: uuid 0x5a x16, generation 7, state digest 0x33 x32). The fixture file header and the
+  emitter text still say "C does not implement these yet": stale wording, left as is because changing it
+  means regenerating the Rust fixtures; the lines themselves are unchanged.
 - **D-2 Decode agreement.** For every single-bit flip of every vector, C and
   Rust agree on accept / refuse and on the error class.
   **DECIDED and IMPLEMENTED (cut 2, host PASS).** `continuity_verdicts.txt` holds the Rust verdict of each
@@ -580,9 +602,9 @@ M4_CONTINUITY:
 | id | mutation | must turn FAIL |
 |---|---|---|
 | MC-1 | resume provisions when Unprovisioned | 82, 87a |
-| MC-2 | drop the orphan check (INV-5): orphan objects read as Unprovisioned | 91i (and the C twin of 87a with an orphan manifest) |
+| MC-2 | drop the orphan check (INV-5): orphan objects read as Unprovisioned: `CR_MUTANT_NO_ORPHAN_CHECK`, IMPLEMENTED, killed (cut 3) | 91i (and the C twin of 87a with an orphan manifest) |
 | MC-3 | resume skips the commit (no incarnation + 1) | 84, 85, 85a, 87b |
-| MC-4 | manifest chain check ignores `previous` | 87e |
+| MC-4 | manifest chain check ignores `previous`: `CR_MUTANT_IGNORE_PREVIOUS`, IMPLEMENTED, killed (cut 3) | 87e |
 | MC-5 | accept `format_version != 0` or nonzero reserved bytes | 87h, D-2 |
 | MC-6 | `child_branch_id` index little-endian | D-1, 87i |
 | MC-7 | provision allowed when a root exists | 83a, 87c |
@@ -590,7 +612,7 @@ M4_CONTINUITY:
 | MC-9 | `writable` check removed (commit on degraded mount) | 87, 87f |
 | MC-10 | agent id from a fixed value instead of RNDR | 83b |
 | MC-11 | WAL segment truncated silently at the size bound (K-1) instead of Limit | C size-bound test (PROPOSED) |
-| MC-12 | Conflict check skipped (first root used) | 87d |
+| MC-12 | Conflict check skipped (first root used): `CR_MUTANT_SKIP_CONFLICT`, IMPLEMENTED, killed (cut 3) | 87d |
 | MC-13 | fork-count sum unchecked (wraps): `CC_MUTANT_UNCHECKED_FORK_SUM`, IMPLEMENTED, killed | 87i, `state_forksum_overflow` (D-1, D-2) |
 | MC-14 | golden mismatch only the vectors see (manifest WAL id 63 replaced by id 0): `CC_MUTANT_MANIFEST_LAST_WAL_ZERO`, IMPLEMENTED, killed | D-1 |
 | MC-15 | golden comparison skipped: `CC_MUTANT_SKIP_D1` (the test counts comparisons), IMPLEMENTED, killed | D-1 |
@@ -601,13 +623,13 @@ M4_RECOVERY:
 | id | mutation | must turn FAIL |
 |---|---|---|
 | MR-1 | inspection writes (for example repairs on inspect) | 88, 90, 91, 91d |
-| MR-2 | challenge omits `state_digest` | 89b, 91k |
-| MR-3 | challenge omits the action byte | 88c, 91k |
-| MR-4 | response compare checks only 16 bytes, or is not constant time | 91n (bit flips in bytes 16-31) |
+| MR-2 | challenge omits `state_digest`: `CR_MUTANT_CHALLENGE_NO_DIGEST`, IMPLEMENTED, killed (cut 3) | 89b, 91k |
+| MR-3 | challenge omits the action byte: `CR_MUTANT_CHALLENGE_NO_ACTION`, IMPLEMENTED, killed (cut 3) | 88c, 91k |
+| MR-4 | response compare checks only 16 bytes (`CR_MUTANT_COMPARE_16`, IMPLEMENTED, killed, cut 3), or is not constant time (not mutated: timing is not observable on the host) | 91n (bit flips in bytes 16-31) |
 | MR-5 | `applicable()` treats a degraded mount with no identity as Unprovisioned (the fe2c2bd bug) | 91g, 91 |
 | MR-6 | repair zeroes the active slot | 89, 89a |
 | MR-7 | repair offered without a resolved identity | 91h |
-| MR-8 | operator auth uses bare SHA-256 or omits the domain | 91o, 91p |
+| MR-8 | operator auth uses bare SHA-256 (`CR_MUTANT_BARE_SHA256`) or omits the domain (`CR_MUTANT_NO_DOMAIN`): both IMPLEMENTED, killed (cut 3) | 91o, 91p |
 | MR-9 | operator provisioning writes source Qualification | 91f |
 
 Known oracle gap (CODE, not covered by any Rust test): no power-cut campaign
@@ -650,6 +672,25 @@ gate adds one.
 | Provisioning on a store with zero roots (:50-53) | also refused when orphan continuity objects exist (continuity.rs:642-649) | port the code rule |
 | Branch-table validation sums `forks` (not specified in the ADR text; section 1.5 item 4) | Rust #232: the sum is checked, an overflowing sum is refused as Corrupt("fork indexes are not contiguous"); before #232 a release build wrapped and accepted {root forks = 2^64-1, child forks = 2} | DECIDED: C refuses on overflow (`cc_state_validate`), Rust and C agree; vector `state_forksum_overflow`, mutant MC-13 |
 
+
+### 9.1 Cut 3 (resolve): C versus the Rust `resolve`, and what C does on purpose
+
+Where code and contract differ, the safer behaviour (refuse) was chosen. Host evidence:
+`test_continuity_resolve.c`.
+
+| item | Rust | C (cut 3) | effect |
+|---|---|---|---|
+| Cortex records in the view | `Continuity.cortex` keeps every record (continuity.rs:726-736) | `cr_view` keeps `cortex_count` and the streamed `memory` digest only (`continuity_resolve.h`); no record is stored | bounded memory (a view could hold 4 MiB); the QEMU markers and a resume need only count and digest; compare D-3 on resolved values |
+| order of failures | reads objects lazily, root count first (:638-653) | `build_table` reads and hashes every object of kinds 16, 17, 18, 20 first (:100-130) | a Store read error, an oversize object or a duplicate logical id on ANY continuity object is reported before the root count; always a refusal, never a resolve |
+| duplicate logical id | impossible (Store v1 dedups) | Corrupt `duplicate logical object id` (P-3) | C-only reason |
+| oversize object | n/a | Limit `continuity object exceeds the size bound` (K-1), before decode | C-only; a Rust-legal object over 16384 bytes cannot exist in the sealed Store, so the real-Store test refuses at the write (`t_size_bound`) and the resolve Limit is tested with a fake source (`t_fake`) |
+| table bound | catalog bound 4096 over all objects (store/v1.rs:12) | Limit `too many continuity objects` above `CR_TABLE_CAP` = 4096 objects of kinds 16/17/18/20 | untested at the bound (UNVERIFIED), refusal either way |
+| empty or id-less object | n/a | Corrupt `continuity object has no valid id` | C-only; the sealed Store refused a zero-length write in the test run, so this is also unreached through the real Store |
+| re-read check | n/a | `read_kind` re-hashes the plaintext and compares with the logical id (`object changed since lookup`) | C-only defence; unreachable with the real Store |
+| manifest iteration order | catalog order | claim order | when several manifests are broken the first reported reason can differ; the class (Corrupt) is the same |
+| mount state | resolve works on a degraded mount | same (`t_degraded`), `cr_writable` gives `CR_READ_ONLY` | matches INV-11 |
+| outcome set | `Store, Unprovisioned, Conflict, AlreadyProvisioned, ReadOnly, Corrupt, Limit` | same names (`CR_*`), plus C-only `CR_E_ARG`; `CR_ALREADY_PROVISIONED` exists but resolve never returns it (cut 4) | |
+
 D-2 result (cut 2, host PASS): no C/Rust decode divergence was found over 86598
 verdicts (every single-bit flip of 22 vectors, plus the untouched vectors).
 The only known C/Rust difference in the codecs is the C-only K-1 size cap
diff --git a/native/kernel/GATES.md b/native/kernel/GATES.md
index 04bf1f86..2515ff1f 100644
--- a/native/kernel/GATES.md
+++ b/native/kernel/GATES.md
@@ -336,7 +336,7 @@ The default `make full` image must carry no crash hook string (Makefile
 Contract: `native/kernel/CONTINUITY_RECOVERY_CONTRACT.md` (SPEC, NOT_RUN). One row per Rust check: rows 81-87 are the
 QEMU PASS lines of `scripts/qemu_continuity_test.sh` (receipt `evidence/continuity_qemu_2026-09-25.md`), rows
 87a-87i are the host tests `cargo test -p aienos-kernel --lib continuity`
-(`crates/aienos-kernel/src/continuity_tests.rs`). The C continuity codec (`svc/continuity_codec.c`, cuts 1-2) has a host test only, with no kernel wiring and no QEMU run: rows 87h, 87i and the codec rows 87j-87k below say HOST PASS for that host test; no gate row is QEMU PASS and `M4_CONTINUITY` stays NOT_RUN. Every other row is NOT_RUN.
+(`crates/aienos-kernel/src/continuity_tests.rs`). The C continuity codec (`svc/continuity_codec.c`, cuts 1-2) and the C resolve + challenge/HMAC code (`svc/continuity_resolve.c`, cut 3, run over the real sealed Store in a file) have host tests only, with no kernel wiring and no QEMU run: rows 87a, 87d-87f, 87h-87k, 91i, 91k and 91m-91p below say HOST PASS (for the half that has code, where stated) for those host tests; no gate row is QEMU PASS and `M4_CONTINUITY` stays NOT_RUN. Every other row is NOT_RUN.
 
 | # | Rust check | CK gate | Status |
 | --- | --- | --- | --- |
@@ -356,16 +356,16 @@ QEMU PASS lines of `scripts/qemu_continuity_test.sh` (receipt `evidence/continui
 | 86e | SIGKILL at `after_superblock_write`: same agent, old or new memory | M4_CONTINUITY | NOT_RUN (MISSING_IMPLEMENTATION; C name `after_inactive_superblock`; the sealed Store adds two anchor checkpoints, contract section 6.1) |
 | 86f | SIGKILL at `after_final_flush`: same agent, new memory | M4_CONTINUITY | NOT_RUN (MISSING_IMPLEMENTATION) |
 | 87 | malformed peer superblock: `CONTINUITY: RESUMED_READONLY`, same agent and memory, image unchanged (:196-205) | M4_CONTINUITY | NOT_RUN (MISSING_IMPLEMENTATION) |
-| 87a | host `unprovisioned_store_never_mints_an_identity` (continuity_tests.rs:84) | M4_CONTINUITY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
+| 87a | host `unprovisioned_store_never_mints_an_identity` (continuity_tests.rs:84) | M4_CONTINUITY (host) | HOST PASS for the resolve half (cut 3, `test_continuity_resolve` (`make -C native/kernel test`, real sealed Store in a file): empty formatted store is Unprovisioned, kind 19 and unrelated kinds ignored, resolve writes no block; the no-mint-on-resume half is cut 4); gate NOT_RUN |
 | 87b | host `provision_then_cold_restart_returns_the_same_identity_and_memory` (:97) | M4_CONTINUITY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
 | 87c | host `provisioning_twice_is_refused` (:142) | M4_CONTINUITY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
-| 87d | host `two_roots_stop_with_conflict` (:152) | M4_CONTINUITY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
-| 87e | host `forked_or_gapped_manifest_chains_are_corrupt` (:178) | M4_CONTINUITY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
-| 87f | host `degraded_mount_resumes_read_only` (:221) | M4_CONTINUITY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
+| 87d | host `two_roots_stop_with_conflict` (:152) | M4_CONTINUITY (host) | HOST PASS (cut 3, `test_continuity_resolve` (`make -C native/kernel test`, real sealed Store in a file): two roots give Conflict, mutant MC-12 `CR_MUTANT_SKIP_CONFLICT` killed); gate NOT_RUN (no QEMU, no kernel wiring) |
+| 87e | host `forked_or_gapped_manifest_chains_are_corrupt` (:178) | M4_CONTINUITY (host) | HOST PASS (cut 3, `test_continuity_resolve` (`make -C native/kernel test`, real sealed Store in a file): wrong previous, absent previous, sequence gap, fork, foreign root, root without manifest are Corrupt with the Rust reason text; mutant MC-4 `CR_MUTANT_IGNORE_PREVIOUS` killed); gate NOT_RUN |
+| 87f | host `degraded_mount_resumes_read_only` (:221) | M4_CONTINUITY (host) | HOST PASS for the resolve half (cut 3, `test_continuity_resolve` (`make -C native/kernel test`, real sealed Store in a file): K-5 answered, ss_open returns 0 on a malformed-peer mount, resolve returns the same agent and memory, `cr_writable` is read-only; the committed=false resume half is cut 4); gate NOT_RUN |
 | 87g | host `a_crash_at_every_write_of_a_commit_leaves_old_or_new_never_a_third_state` (:242) | M4_CONTINUITY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
 | 87h | host `encodings_round_trip_and_reject_tampering` (:286) | M4_CONTINUITY (host) | HOST PASS for the C codec twin (`make -C native/kernel test`, `test_continuity_codec`: round trips, one refusal per rule, every single-bit flip of every golden vector decodes as in Rust, D-2); gate NOT_RUN (no QEMU, no kernel wiring) |
 | 87i | host `branch_table_validation_rejects_broken_lineage` (:328) | M4_CONTINUITY (host) | HOST PASS for the C codec twin (`cc_state_validate`, incl. the checked fork-count sum and hostile fork counts); gate NOT_RUN (no QEMU, no kernel wiring) |
-| 87j | D-1 golden vectors (contract 6.3): Rust-emitted canonical bytes and ObjectIds for 22 vectors, reproduced by C from `native/kernel/tests/fixtures/continuity_vectors.txt`; tampered bytes, ObjectId and verdicts are refused (`cargo test -p aienos-kernel --lib continuity_vectors` fails on fixture drift) | M4_CONTINUITY (host) | HOST PASS (`make -C native/kernel test`, `continuity-mutants`: golden and skip-D1 mutants killed); challenges and HMAC responses are emitted but DEFERRED to the resolve cut (no C implementation); gate NOT_RUN |
+| 87j | D-1 golden vectors (contract 6.3): Rust-emitted canonical bytes and ObjectIds for 22 vectors, reproduced by C from `native/kernel/tests/fixtures/continuity_vectors.txt`; tampered bytes, ObjectId and verdicts are refused (`cargo test -p aienos-kernel --lib continuity_vectors` fails on fixture drift) | M4_CONTINUITY (host) | HOST PASS (`make -C native/kernel test`, `continuity-mutants`: golden and skip-D1 mutants killed); challenges and HMAC responses (4 fixture lines) are now reproduced byte for byte by C (cut 3, `test_continuity_resolve`); gate NOT_RUN |
 | 87k | D-2 decode agreement (contract 6.3): every single-bit flip of every vector, C and Rust agree on accept/refuse and error class and text (86598 verdicts, 0 divergences) | M4_CONTINUITY (host) | HOST PASS (`make -C native/kernel test`; skip-D2 mutant killed); gate NOT_RUN |
 
 ## M4 recovery: scripts/qemu_recovery_test.sh -> CK `M4_RECOVERY`
@@ -397,14 +397,14 @@ row is NOT_RUN. Operator key is TEST-ONLY in the oracle.
 | 91f | host `provisioning_is_operator_only_and_only_on_an_unprovisioned_store` (:154) | M4_RECOVERY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
 | 91g | host `identity_lost_in_the_newest_root_never_looks_unprovisioned` (:178) | M4_RECOVERY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
 | 91h | host `malformed_peer_without_a_resolvable_identity_is_not_repaired` (:222) | M4_RECOVERY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
-| 91i | host `orphaned_continuity_objects_are_corrupt_not_unprovisioned` (:236) | M4_RECOVERY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
+| 91i | host `orphaned_continuity_objects_are_corrupt_not_unprovisioned` (:236) | M4_RECOVERY (host) | HOST PASS for the resolve half (cut 3, `test_continuity_resolve` (`make -C native/kernel test`, real sealed Store in a file): orphan manifest, orphan agent state and orphan WAL are Corrupt `continuity objects without an agent root`; mutant MC-2 `CR_MUTANT_NO_ORPHAN_CHECK` killed); the Recovery Core entry reason is cut 5; gate NOT_RUN |
 | 91j | host `identity_loss_through_corruption_offers_no_action_that_mints` (:267) | M4_RECOVERY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
-| 91k | host `challenges_bind_state_and_action` (:300) | M4_RECOVERY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
+| 91k | host `challenges_bind_state_and_action` (:300) | M4_RECOVERY (host) | HOST PASS for the primitive (cut 3, `test_continuity_resolve` (`make -C native/kernel test`, real sealed Store in a file): `cr_challenge` binds action, state digest, generation and uuid, a response for one action is refused on the other; mutants MR-2 and MR-3 killed); the system record that carries them is cut 5; gate NOT_RUN |
 | 91l | host `hmac_primitive_rfc4231_case_2` (recovery.rs:238) | M4_RECOVERY (host) | NOT_RUN (MISSING_IMPLEMENTATION: no C operator-auth wrapper; the C HMAC primitive itself is `aienos_hmac_sha256` in native/crypto) |
-| 91m | host `operator_auth_known_answer_accepted` (recovery.rs:251) | M4_RECOVERY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
-| 91n | host `operator_auth_rejects_any_single_bit_flip` (recovery.rs:269) | M4_RECOVERY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
-| 91o | host `operator_auth_rejects_legacy_bare_sha256_response` (recovery.rs:299) | M4_RECOVERY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
-| 91p | host `operator_auth_rejects_undomained_hmac_and_zero_response` (recovery.rs:311) | M4_RECOVERY (host) | NOT_RUN (MISSING_IMPLEMENTATION) |
+| 91m | host `operator_auth_known_answer_accepted` (recovery.rs:251) | M4_RECOVERY (host) | HOST PASS (cut 3, `test_continuity_resolve` (`make -C native/kernel test`, real sealed Store in a file): `cr_operator_response` reproduces the Rust known answer and the four Rust-emitted fixture lines byte for byte); gate NOT_RUN |
+| 91n | host `operator_auth_rejects_any_single_bit_flip` (recovery.rs:269) | M4_RECOVERY (host) | HOST PASS (cut 3, `test_continuity_resolve` (`make -C native/kernel test`, real sealed Store in a file): every single-bit flip of response, challenge and key is refused; mutant MR-4 `CR_MUTANT_COMPARE_16` killed); gate NOT_RUN |
+| 91o | host `operator_auth_rejects_legacy_bare_sha256_response` (recovery.rs:299) | M4_RECOVERY (host) | HOST PASS (cut 3, `test_continuity_resolve` (`make -C native/kernel test`, real sealed Store in a file): bare SHA-256 response refused; mutant MR-8 `CR_MUTANT_BARE_SHA256` killed); gate NOT_RUN |
+| 91p | host `operator_auth_rejects_undomained_hmac_and_zero_response` (recovery.rs:311) | M4_RECOVERY (host) | HOST PASS (cut 3, `test_continuity_resolve` (`make -C native/kernel test`, real sealed Store in a file): undomained HMAC and zero response refused; mutant MR-8 `CR_MUTANT_NO_DOMAIN` killed); gate NOT_RUN |
 
 ## TRUST-1 Gate 4: scripts/qemu_security_suite.sh, scripts/qemu_secureboot_signing_test.sh
 
diff --git a/native/kernel/Makefile b/native/kernel/Makefile
index dae60fd5..edf67e33 100644
--- a/native/kernel/Makefile
+++ b/native/kernel/Makefile
@@ -57,6 +57,9 @@
 #   make continuity-mutants
 #                        TEST-only -D mutants of svc/continuity_codec.c must
 #                        each fail test_continuity_codec -> CK_CONTINUITY_CODEC_MUTANTS: PASS
+#   make continuity-resolve-mutants
+#                        TEST-only -D mutants of svc/continuity_resolve.c must each fail
+#                        test_continuity_resolve -> CK_CONTINUITY_RESOLVE_MUTANTS: PASS
 #   make stage-test | stage-sanitize | stage-free   stage host tests (stage.mk)
 #   make print-kcflags   flags stage code must be built with
 #   make udp-echo        host UDP echo helper for scripts/qemu_ck_net_test.sh:
@@ -491,7 +494,7 @@ HOST_SRCS := $(KDIR)/core/fmt.c $(KDIR)/core/acpi.c $(KDIR)/core/smmu.c $(KDIR)/
 	$(KDIR)/mm/pt.c $(KDIR)/mm/heap.c $(KDIR)/core/sched.c $(KDIR)/core/ipc.c $(KDIR)/core/entropy.c \
 	$(KDIR)/core/handoff_check.c
 TESTS := test_fmt test_frames test_pt test_acpi test_heap test_smmu test_sched test_ipc test_artifact test_entropy test_handoff \
-	test_continuity_codec
+	test_continuity_codec test_continuity_resolve
 HCFLAGS := -std=gnu11 -O1 -g -Wall -Wextra -Werror -I$(KDIR)/core -I$(KDIR)/mm -I$(KDIR)/tests -I$(BOOT)
 SANFLAGS := -fsanitize=address,undefined -fno-sanitize-recover=all -fno-omit-frame-pointer
 
@@ -571,7 +574,7 @@ $(OUT)/host-san/test_continuity_codec: $(KDIR)/tests/test_continuity_codec.c $(C
 	@mkdir -p $(dir $@)
 	$(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(CC_HOST_INC) $(CC_FIXTURE_DEF) -o $@ $< $(CC_HOST_SRCS)
 
-continuity-mutants: $(OUT)/host/test_continuity_codec
+continuity-mutants: $(OUT)/host/test_continuity_codec continuity-resolve-mutants
 	@mkdir -p $(OUT)/host-mut; fail=0; \
 	$(OUT)/host/test_continuity_codec > $(OUT)/host-mut/base.log 2>&1 || { echo "unmutated test_continuity_codec fails"; fail=1; }; \
 	for m in $(CC_MUTANTS); do \
@@ -589,6 +592,54 @@ continuity-mutants: $(OUT)/host/test_continuity_codec
 	else echo "mutant flag refused under CK_HARDWARE_STAGING"; fi; \
 	if [ $$fail = 0 ]; then echo "CK_CONTINUITY_CODEC_MUTANTS: PASS"; else echo "CK_CONTINUITY_CODEC_MUTANTS: FAIL"; exit 1; fi
 
+# Continuity resolve + challenge/HMAC (C port cut 3): host test over the REAL
+# sealed Store in a file (native/store + m5 + crypto + disk), TEST-only -D
+# mutants, each of which must make the test print its FAIL verdict. Mutant flags
+# are refused under CK_HARDWARE_STAGING (svc/continuity_resolve.h).
+CR_STORE_SRCS := $(NATIVE)/store/store_v1.c $(NATIVE)/store/store_engine.c $(NATIVE)/store/store_disk.c \
+	$(NATIVE)/store/store_sealed.c $(NATIVE)/store/torn_slot.c $(NATIVE)/disk/disk.c $(NATIVE)/disk/disk_file.c \
+	$(NATIVE)/m5/m5_keys.c $(NATIVE)/m5/m5_envelope.c $(NATIVE)/m5/m5_state.c $(NATIVE)/crypto/aes.c \
+	$(NATIVE)/crypto/polyval.c $(NATIVE)/crypto/gcm_siv.c $(NATIVE)/crypto/hmac.c $(NATIVE)/crypto/ct.c
+CR_HOST_SRCS := $(KDIR)/svc/continuity_resolve.c $(KDIR)/svc/continuity_resolve_sealed.c \
+	$(KDIR)/svc/continuity_codec.c $(NATIVE)/argus/sha256.c $(CR_STORE_SRCS)
+CR_HOST_INC := -I$(KDIR)/svc -I$(NATIVE)/argus -I$(NATIVE)/store -I$(NATIVE)/disk -I$(NATIVE)/m5 -I$(NATIVE)/crypto
+CR_HOST_DEPS := $(wildcard $(KDIR)/tests/fixtures/continuity_*.txt) $(CR_HOST_SRCS) $(wildcard $(KDIR)/svc/continuity_*.h) \
+	$(wildcard $(NATIVE)/store/*.h $(NATIVE)/m5/*.h $(NATIVE)/disk/*.h $(NATIVE)/crypto/*.h) $(KDIR)/tests/ck_test.h
+CR_FIXTURE_DEF := -DCR_FIXTURE_DIR='"$(CC_FIXTURES)"'
+# MC-2 orphan check, MC-4 previous, MC-12 conflict, MR-2 digest, MR-3 action,
+# MR-4 16-byte compare, MR-8 bare SHA-256 and no domain.
+CR_MUTANTS := CR_MUTANT_NO_ORPHAN_CHECK CR_MUTANT_IGNORE_PREVIOUS CR_MUTANT_SKIP_CONFLICT \
+	CR_MUTANT_CHALLENGE_NO_DIGEST CR_MUTANT_CHALLENGE_NO_ACTION CR_MUTANT_COMPARE_16 \
+	CR_MUTANT_BARE_SHA256 CR_MUTANT_NO_DOMAIN
+
+$(OUT)/host/test_continuity_resolve: $(KDIR)/tests/test_continuity_resolve.c $(CR_HOST_DEPS)
+	@mkdir -p $(dir $@)
+	$(HOSTCC) $(HCFLAGS) $(CR_HOST_INC) $(CR_FIXTURE_DEF) -o $@ $< $(CR_HOST_SRCS)
+
+$(OUT)/host-san/test_continuity_resolve: $(KDIR)/tests/test_continuity_resolve.c $(CR_HOST_DEPS)
+	@mkdir -p $(dir $@)
+	$(HOSTCC) $(HCFLAGS) $(SANFLAGS) $(CR_HOST_INC) $(CR_FIXTURE_DEF) -o $@ $< $(CR_HOST_SRCS)
+
+continuity-resolve-mutants: $(OUT)/host/test_continuity_resolve
+	@mkdir -p $(OUT)/host-mut; fail=0; \
+	$(OUT)/host/test_continuity_resolve > $(OUT)/host-mut/resolve_base.log 2>&1 || { echo "unmutated test_continuity_resolve fails"; fail=1; }; \
+	for m in $(CR_MUTANTS); do \
+	  b=$(OUT)/host-mut/test_continuity_resolve_$$m; \
+	  if ! $(HOSTCC) $(HCFLAGS) $(CR_HOST_INC) $(CR_FIXTURE_DEF) -D$$m -o $$b $(KDIR)/tests/test_continuity_resolve.c $(CR_HOST_SRCS); then \
+	    echo "mutant $$m: does not build (FAIL)"; fail=1; continue; fi; \
+	  if $$b > $$b.log 2>&1; then echo "mutant $$m: SURVIVED (FAIL)"; fail=1; \
+	  elif grep -q "^test_continuity_resolve: FAIL" $$b.log; then \
+	    echo "mutant $$m: killed ($$(grep -c '^  FAIL ' $$b.log) checks failed)"; \
+	  else echo "mutant $$m: no FAIL verdict (crashed?) (FAIL)"; fail=1; fi; \
+	done; \
+	for m in $(CR_MUTANTS); do \
+	  if $(HOSTCC) $(HCFLAGS) $(CR_HOST_INC) -DCK_HARDWARE_STAGING=1 -D$$m \
+	      -fsyntax-only $(KDIR)/svc/continuity_resolve.c 2>/dev/null; then \
+	    echo "mutant flag $$m accepted under CK_HARDWARE_STAGING (FAIL)"; fail=1; \
+	  else echo "mutant flag $$m refused under CK_HARDWARE_STAGING"; fi; \
+	done; \
+	if [ $$fail = 0 ]; then echo "CK_CONTINUITY_RESOLVE_MUTANTS: PASS"; else echo "CK_CONTINUITY_RESOLVE_MUTANTS: FAIL"; exit 1; fi
+
 ART_TOOL := $(OUT)/host/ck_artifact_tool
 $(ART_TOOL): $(KDIR)/tools/ck_artifact_tool.c $(ART_HOST_DEPS)
 	@mkdir -p $(dir $@)
@@ -632,4 +683,4 @@ clean:
 	rm -rf $(OUT)
 
 FORCE:
-.PHONY: all full test sanitize handoff-mutant clean print-kcflags udp-echo tool store-image gpt-image owner-gen continuity-mutants FORCE
+.PHONY: all full test sanitize handoff-mutant clean print-kcflags udp-echo tool store-image gpt-image owner-gen continuity-mutants continuity-resolve-mutants FORCE
diff --git a/native/kernel/svc/continuity_resolve.c b/native/kernel/svc/continuity_resolve.c
new file mode 100644
index 00000000..0e4f0e6c
--- /dev/null
+++ b/native/kernel/svc/continuity_resolve.c
@@ -0,0 +1,364 @@
+/* continuity_resolve.c -- see continuity_resolve.h. Resolve only; no write. */
+#include <string.h>
+
+#include "continuity_resolve.h"
+#include "../../argus/sha256.h"
+#include "../../crypto/aienos_crypto.h"
+#include "../../store/store_v1.h"
+
+const char *cr_outcome_name(int o)
+{
+    switch (o) {
+    case CR_RESOLVED: return "Resolved";
+    case CR_UNPROVISIONED: return "Unprovisioned";
+    case CR_CONFLICT: return "Conflict";
+    case CR_CORRUPT: return "Corrupt";
+    case CR_LIMIT: return "Limit";
+    case CR_STORE: return "Store";
+    case CR_ALREADY_PROVISIONED: return "AlreadyProvisioned";
+    case CR_READ_ONLY: return "ReadOnly";
+    case CR_E_ARG: return "Arg";
+    }
+    return "?";
+}
+
+struct ctx {
+    const struct cr_source *src;
+    struct cr_work *w;
+    const char *why;
+    int store_rc;
+};
+
+static int fail(struct ctx *c, int outcome, const char *why)
+{
+    c->why = why;
+    return outcome;
+}
+
+static int is_tracked(uint16_t k)
+{
+    return k == CC_KIND_AGENT_ROOT || k == CC_KIND_MANIFEST || k == CC_KIND_AGENT_STATE ||
+           k == CC_KIND_CORTEX_WAL;
+}
+
+static int is_zero32(const uint8_t *p)
+{
+    uint8_t a = 0;
+    for (int i = 0; i < 32; i++) a |= p[i];
+    return a == 0;
+}
+
+/* Read source object i into w->buf. 0, or a CR_* outcome with c->why / c->store_rc set. */
+static int read_obj(struct ctx *c, uint32_t i, size_t *len)
+{
+    int rc = c->src->read(c->src->ctx, i, c->w->buf, sizeof c->w->buf, len);
+    if (rc != 0) {
+        c->store_rc = rc;
+        return CR_STORE;
+    }
+    /* K-1 (contract 5.3): never truncate, never decode past the bound. */
+    if (*len > CC_MAX_OBJECT_BYTES) return fail(c, CR_LIMIT, "continuity object exceeds the size bound");
+    return 0;
+}
+
+/* rs read_kind (continuity.rs:619-633): the entry for id must exist with the
+ * kind and Store version 1; its plaintext lands in w->buf. */
+static int read_kind(struct ctx *c, const uint8_t id[32], uint16_t kind, size_t *len)
+{
+    const struct cr_entry *e = NULL;
+    for (uint32_t i = 0; i < c->w->n; i++)
+        if (memcmp(c->w->t[i].id, id, 32) == 0) {
+            e = &c->w->t[i];
+            break;
+        }
+    if (!e) return fail(c, CR_CORRUPT, "referenced object is absent");
+    if (e->kind != kind || e->version != CC_STORE_OBJECT_VERSION)
+        return fail(c, CR_CORRUPT, "referenced object has the wrong kind");
+    int r = read_obj(c, e->src, len);
+    if (r) return r;
+    uint8_t chk[32];
+    if (sv1_object_id(e->kind, e->version, c->w->buf, *len, chk) != 0 || memcmp(chk, id, 32) != 0)
+        return fail(c, CR_CORRUPT, "object changed since lookup"); /* C only */
+    return 0;
+}
+
+static int map_cc(struct ctx *c, int rc, const char *why)
+{
+    if (rc == CC_OK) return 0;
+    c->why = why ? why : "continuity object";
+    if (rc == CC_E_CORRUPT) return CR_CORRUPT;
+    if (rc == CC_E_LIMIT) return CR_LIMIT;
+    return CR_E_ARG;
+}
+
+static int build_table(struct ctx *c)
+{
+    struct cr_work *w = c->w;
+    uint32_t cnt = c->src->count(c->src->ctx);
+    w->n = 0;
+    for (uint32_t i = 0; i < cnt; i++) {
+        uint16_t k = 0, ver = 0;
+        int rc = c->src->entry(c->src->ctx, i, &k, &ver);
+        if (rc != 0) {
+            c->store_rc = rc;
+            return CR_STORE;
+        }
+        if (!is_tracked(k)) continue;
+        if (w->n >= CR_TABLE_CAP) return fail(c, CR_LIMIT, "too many continuity objects");
+        size_t len = 0;
+        int r = read_obj(c, i, &len);
+        if (r) return r;
+        struct cr_entry *e = &w->t[w->n];
+        memset(e, 0, sizeof *e);
+        if (sv1_object_id(k, ver, w->buf, len, e->id) != 0)
+            return fail(c, CR_CORRUPT, "continuity object has no valid id"); /* C only: empty */
+        /* P-3: a logical id seen twice is Corrupt. */
+        for (uint32_t j = 0; j < w->n; j++)
+            if (memcmp(w->t[j].id, e->id, 32) == 0)
+                return fail(c, CR_CORRUPT, "duplicate logical object id"); /* C only */
+        e->kind = k;
+        e->version = ver;
+        e->src = i;
+        w->n++;
+    }
+    return 0;
+}
+
+static uint32_t count_kind(const struct cr_work *w, uint16_t kind)
+{
+    uint32_t n = 0;
+    for (uint32_t i = 0; i < w->n; i++) n += w->t[i].kind == kind;
+    return n;
+}
+
+static void put32(uint8_t *p, uint32_t v)
+{
+    for (int i = 0; i < 4; i++) p[i] = (uint8_t)(v >> (8 * i));
+}
+
+int cr_resolve(const struct cr_source *src, struct cr_work *w, struct cr_view *v, const char **why,
+               int *store_rc)
+{
+    struct ctx c = {src, w, NULL, 0};
+    int out;
+    if (why) *why = NULL;
+    if (store_rc) *store_rc = 0;
+    if (!src || !src->count || !src->entry || !src->read || !w || !v) return CR_E_ARG;
+    memset(v, 0, sizeof *v);
+
+    out = build_table(&c);
+    if (out) goto done;
+
+    /* INV-5, in this order (rs :638-653). */
+    uint32_t roots = count_kind(w, CC_KIND_AGENT_ROOT);
+    if (roots == 0) {
+#ifndef CR_MUTANT_NO_ORPHAN_CHECK
+        if (count_kind(w, CC_KIND_MANIFEST) || count_kind(w, CC_KIND_AGENT_STATE) ||
+            count_kind(w, CC_KIND_CORTEX_WAL)) {
+            out = fail(&c, CR_CORRUPT, "continuity objects without an agent root");
+            goto done;
+        }
+#endif
+        out = CR_UNPROVISIONED;
+        goto done;
+    }
+#ifndef CR_MUTANT_SKIP_CONFLICT
+    if (roots > 1) {
+        out = CR_CONFLICT;
+        goto done;
+    }
+#endif
+    const struct cr_entry *re = NULL;
+    for (uint32_t i = 0; i < w->n && !re; i++)
+        if (w->t[i].kind == CC_KIND_AGENT_ROOT) re = &w->t[i];
+    memcpy(v->root_id, re->id, 32);
+    size_t len = 0;
+    if ((out = read_kind(&c, v->root_id, CC_KIND_AGENT_ROOT, &len))) goto done;
+    {
+        const char *y = NULL;
+        int rc = cc_root_decode(w->buf, len, &v->root, &y);
+        if ((out = map_cc(&c, rc, y))) goto done;
+    }
+
+    /* INV-6: every manifest names this root; sorted by sequence they are 1..n. */
+    uint32_t nm = 0;
+    for (uint32_t i = 0; i < w->n; i++) {
+        struct cr_entry *e = &w->t[i];
+        if (e->kind != CC_KIND_MANIFEST) continue;
+        if ((out = read_kind(&c, e->id, CC_KIND_MANIFEST, &len))) goto done;
+        const char *y = NULL;
+        int rc = cc_manifest_decode(w->buf, len, &v->manifest, &y);
+        if ((out = map_cc(&c, rc, y))) goto done;
+        if (memcmp(v->manifest.root, v->root_id, 32) != 0) {
+            out = fail(&c, CR_CORRUPT, "manifest names a foreign root");
+            goto done;
+        }
+        e->seq = v->manifest.sequence;
+        memcpy(e->root, v->manifest.root, 32);
+        memcpy(e->previous, v->manifest.previous, 32);
+        w->mi[nm++] = i;
+    }
+    if (nm == 0) {
+        out = fail(&c, CR_CORRUPT, "agent root has no manifest");
+        goto done;
+    }
+    for (uint32_t i = 1; i < nm; i++) { /* stable insertion sort by sequence */
+        uint32_t x = w->mi[i];
+        uint32_t j = i;
+        while (j > 0 && w->t[w->mi[j - 1]].seq > w->t[x].seq) {
+            w->mi[j] = w->mi[j - 1];
+            j--;
+        }
+        w->mi[j] = x;
+    }
+    static const uint8_t ZERO[32];
+    for (uint32_t i = 0; i < nm; i++) {
+        const struct cr_entry *m = &w->t[w->mi[i]];
+        if (m->seq != (uint64_t)i + 1) {
+            out = fail(&c, CR_CORRUPT, "manifest sequence gap or fork");
+            goto done;
+        }
+        const uint8_t *expect = i ? w->t[w->mi[i - 1]].id : ZERO;
+#ifndef CR_MUTANT_IGNORE_PREVIOUS
+        if (memcmp(m->previous, expect, 32) != 0) {
+            out = fail(&c, CR_CORRUPT, "manifest chain is broken");
+            goto done;
+        }
+#else
+        (void)expect;
+#endif
+    }
+    const struct cr_entry *cur = &w->t[w->mi[nm - 1]];
+    memcpy(v->manifest_id, cur->id, 32);
+    if ((out = read_kind(&c, v->manifest_id, CC_KIND_MANIFEST, &len))) goto done;
+    {
+        const char *y = NULL;
+        int rc = cc_manifest_decode(w->buf, len, &v->manifest, &y);
+        if ((out = map_cc(&c, rc, y))) goto done;
+    }
+
+    /* INV-7: agent state of the current manifest. */
+    if (is_zero32(v->manifest.agent_state)) {
+        out = fail(&c, CR_CORRUPT, "manifest has no agent state");
+        goto done;
+    }
+    if ((out = read_kind(&c, v->manifest.agent_state, CC_KIND_AGENT_STATE, &len))) goto done;
+    {
+        const char *y = NULL;
+        int rc = cc_state_decode(w->buf, len, &v->state, &y);
+        if ((out = map_cc(&c, rc, y))) goto done;
+    }
+    if (memcmp(v->state.agent_id, v->root.agent_id, 32) != 0) {
+        out = fail(&c, CR_CORRUPT, "agent state belongs to another agent");
+        goto done;
+    }
+
+    /* WAL segments in manifest order, strictly increasing, <= manifest.sequence. */
+    sha256_ctx mem;
+    sha256_init(&mem);
+    uint64_t last = 0;
+    for (uint32_t s = 0; s < v->manifest.n_wal; s++) {
+        if ((out = read_kind(&c, v->manifest.wal[s], CC_KIND_CORTEX_WAL, &len))) goto done;
+        const char *y = NULL;
+        int rc = cc_wal_decode(w->buf, len, &w->wal, &y);
+        if ((out = map_cc(&c, rc, y))) goto done;
+        if (w->wal.sequence <= last || w->wal.sequence > v->manifest.sequence) {
+            out = fail(&c, CR_CORRUPT, "WAL segments out of order");
+            goto done;
+        }
+        last = w->wal.sequence;
+        for (uint32_t r = 0; r < w->wal.n; r++) {
+            uint8_t l4[4];
+            put32(l4, w->wal.rec[r].len);
+            sha256_update(&mem, l4, 4);
+            sha256_update(&mem, w->wal.rec[r].statement, w->wal.rec[r].len);
+            v->cortex_count++;
+        }
+    }
+    sha256_final(&mem, v->memory);
+    out = CR_RESOLVED;
+
+done:
+    if (out != CR_RESOLVED) memset(v, 0, sizeof *v);
+    if (why) *why = c.why;
+    if (store_rc) *store_rc = c.store_rc;
+    return out;
+}
+
+int cr_writable(const struct cr_source *src)
+{
+    if (!src || !src->mount_state) return CR_READ_ONLY; /* fail closed */
+    return src->mount_state(src->ctx) == CR_MOUNT_VALID ? CR_RESOLVED : CR_READ_ONLY;
+}
+
+/* ---- challenge and operator response ---- */
+
+void cr_state_digest(const uint8_t unit0[4096], const uint8_t unit1[4096], uint8_t out[32])
+{
+    sha256_ctx h;
+    sha256_init(&h);
+    sha256_update(&h, unit0, 4096);
+    sha256_update(&h, unit1, 4096);
+    sha256_final(&h, out);
+}
+
+void cr_challenge(const uint8_t uuid[16], uint64_t generation, uint8_t action,
+                  const uint8_t state_digest[32], uint8_t out[32])
+{
+    static const char D[] = "AIENOS-RECOVERY-CHALLENGE-v1"; /* + NUL: 29 bytes */
+    uint8_t g[8];
+    for (int i = 0; i < 8; i++) g[i] = (uint8_t)(generation >> (8 * i));
+    sha256_ctx h;
+    sha256_init(&h);
+    sha256_update(&h, (const uint8_t *)D, sizeof D); /* includes the NUL */
+    sha256_update(&h, uuid, 16);
+    sha256_update(&h, g, 8);
+#ifndef CR_MUTANT_CHALLENGE_NO_ACTION
+    sha256_update(&h, &action, 1);
+#else
+    (void)action;
+#endif
+#ifndef CR_MUTANT_CHALLENGE_NO_DIGEST
+    sha256_update(&h, state_digest, 32);
+#else
+    (void)state_digest;
+#endif
+    sha256_final(&h, out);
+}
+
+void cr_operator_response(const uint8_t key[32], const uint8_t challenge[32], uint8_t out[32])
+{
+    static const char D[] = "AIENOS-RECOVERY-OPERATOR-AUTH-v1"; /* + NUL: 33 bytes */
+    uint8_t msg[sizeof D + 32];
+#if defined(CR_MUTANT_BARE_SHA256)
+    sha256_ctx h;
+    sha256_init(&h);
+    sha256_update(&h, key, 32);
+    sha256_update(&h, challenge, 32);
+    sha256_final(&h, out);
+    (void)msg;
+    return;
+#elif defined(CR_MUTANT_NO_DOMAIN)
+    (void)msg;
+    aienos_hmac_sha256(key, challenge, 32, out);
+    return;
+#else
+    memcpy(msg, D, sizeof D); /* includes the NUL */
+    memcpy(msg + sizeof D, challenge, 32);
+    aienos_hmac_sha256(key, msg, sizeof msg, out);
+    aienos_wipe(msg, sizeof msg);
+#endif
+}
+
+int cr_operator_verify(const uint8_t key[32], const uint8_t challenge[32], const uint8_t response[32])
+{
+    uint8_t expected[32];
+    cr_operator_response(key, challenge, expected);
+#ifdef CR_MUTANT_COMPARE_16
+    int ok = aienos_ct_equal(expected, response, 16);
+#else
+    int ok = aienos_ct_equal(expected, response, 32);
+#endif
+    aienos_wipe(expected, sizeof expected);
+    return ok;
+}
diff --git a/native/kernel/svc/continuity_resolve.h b/native/kernel/svc/continuity_resolve.h
new file mode 100644
index 00000000..066f79ea
--- /dev/null
+++ b/native/kernel/svc/continuity_resolve.h
@@ -0,0 +1,140 @@
+/* continuity_resolve.h -- C port, cut 3: boot resolution of the continuity
+ * objects (INV-4..INV-7, contract section 3), the Recovery Core challenge and
+ * the operator response (INV-15/16 inputs, contract 1.7 and 5.2).
+ *
+ * Contract: native/kernel/CONTINUITY_RECOVERY_CONTRACT.md. Oracle: the Rust
+ * kernel at aienos 4a116e5: continuity.rs `resolve` (:637-710, "rs:" below),
+ * recovery_core.rs `challenge` (:94-104) and `inspect` digest (:109-133),
+ * recovery.rs `OperatorAuth` (:103, :124-140).
+ *
+ * Resolve only. No provision, no commit, no resume (cut 4). Nothing here
+ * writes: the storage interface (cr_source) has no write call.
+ *
+ * Storage access goes through cr_source. continuity_resolve_sealed.c binds it
+ * to the real sealed Store (ss_store); the host test drives the real sealed
+ * Store in a file and also a fake source for cases the real Store cannot make.
+ *
+ * Lookup (contract P-3): the table of (kind, version, logical id) is built once
+ * per resolve by reading every continuity object of kinds 16, 17, 18, 20 and
+ * hashing the plaintext (Store v1 ObjectId rule). The Rust code never sees a
+ * logical id twice (Store v1 dedups); the sealed Store gives every write its
+ * own envelope, so a logical id that appears twice is Corrupt here.
+ *
+ * Memory: the Rust Continuity view keeps every Cortex record. The C view keeps
+ * the record count and the streamed SHA-256 `memory` digest (contract 1.7),
+ * which is all the QEMU markers and a resume need; no record is stored.
+ *
+ * Nothing here is wired into the kernel. */
+#ifndef CK_CONTINUITY_RESOLVE_H
+#define CK_CONTINUITY_RESOLVE_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#include "continuity_codec.h"
+
+/* TEST-only mutants for the host mutation run (Makefile continuity-mutants). */
+#if defined(CK_HARDWARE_STAGING) &&                                                        \
+    (defined(CR_MUTANT_NO_ORPHAN_CHECK) || defined(CR_MUTANT_IGNORE_PREVIOUS) ||           \
+     defined(CR_MUTANT_SKIP_CONFLICT) || defined(CR_MUTANT_CHALLENGE_NO_DIGEST) ||         \
+     defined(CR_MUTANT_CHALLENGE_NO_ACTION) || defined(CR_MUTANT_COMPARE_16) ||            \
+     defined(CR_MUTANT_BARE_SHA256) || defined(CR_MUTANT_NO_DOMAIN))
+#error "continuity resolve mutants are TEST-only and refused under CK_HARDWARE_STAGING"
+#endif
+
+/* ---- outcomes (ContinuityError, continuity.rs:40-55) ---- */
+enum {
+    CR_RESOLVED = 0,         /* Ok(Continuity) */
+    CR_UNPROVISIONED = 1,    /* ContinuityError::Unprovisioned */
+    CR_CONFLICT = 2,         /* ContinuityError::Conflict */
+    CR_CORRUPT = 3,          /* ContinuityError::Corrupt(why) */
+    CR_LIMIT = 4,            /* ContinuityError::Limit(why) */
+    CR_STORE = 5,            /* ContinuityError::Store(e): *store_rc has the error */
+    CR_ALREADY_PROVISIONED = 6, /* provision only (cut 4); never returned by resolve */
+    CR_READ_ONLY = 7,        /* cr_writable on a mount that is not Valid */
+    CR_E_ARG = 8,            /* C only: caller bug (NULL); nothing read */
+};
+const char *cr_outcome_name(int outcome); /* Rust spelling: "Unprovisioned", ... */
+
+/* Entry reason for a degraded mount: the Recovery Core uses these (cut 5). */
+#define CR_MOUNT_VALID 0
+#define CR_MOUNT_DEGRADED 1
+
+/* ---- storage interface (read only) ---- */
+struct cr_source {
+    void *ctx;
+    /* Number of verified application objects (sealed claims). */
+    uint32_t (*count)(void *ctx);
+    /* Application kind and version of object i (no decryption), and nothing
+     * else. Returns 0 or a store error. */
+    int (*entry)(void *ctx, uint32_t i, uint16_t *kind, uint16_t *version);
+    /* Plaintext of object i into out[0..cap). *len is the true length; if it
+     * exceeds cap the object is oversize and out is not meaningful. Returns 0
+     * or a store error (nonzero, passed through as CR_STORE). */
+    int (*read)(void *ctx, uint32_t i, uint8_t *out, size_t cap, size_t *len);
+    /* CR_MOUNT_VALID or CR_MOUNT_DEGRADED. */
+    int (*mount_state)(void *ctx);
+};
+
+/* Objects this layer tracks: kinds 16, 17, 18, 20 (kind 19 is ignored, as in Rust). */
+#define CR_TABLE_CAP 4096u /* SV1_MAX_CATALOG_ENTRIES (store/v1.rs:12) */
+
+struct cr_entry {
+    uint8_t id[32]; /* logical ObjectId (store v1 rule, kind, claim version) */
+    uint64_t seq;   /* manifests: sequence */
+    uint8_t root[32];     /* manifests: root */
+    uint8_t previous[32]; /* manifests: previous */
+    uint32_t src;   /* index in the source */
+    uint16_t kind, version;
+};
+
+/* Caller-owned scratch, ~0.5 MiB: static storage. */
+struct cr_work {
+    struct cr_entry t[CR_TABLE_CAP];
+    uint32_t n;
+    uint32_t mi[CR_TABLE_CAP]; /* manifest table indices, sorted by sequence */
+    uint8_t buf[CC_MAX_OBJECT_BYTES];
+    struct cc_wal wal;
+};
+
+/* The verified continuity view (rs `Continuity`, continuity.rs:726-736). */
+struct cr_view {
+    uint8_t root_id[32];
+    struct cc_root root;
+    uint8_t manifest_id[32];
+    struct cc_manifest manifest;
+    struct cc_state state;
+    uint64_t cortex_count;   /* records over all segments */
+    uint8_t memory[32];      /* SHA-256 over (len u32 LE || statement) per record; marker prints [0..8) */
+};
+
+/* Locate and verify the continuity view without writing. Never creates an
+ * identity. Returns a CR_* outcome. For CR_CORRUPT / CR_LIMIT *why (optional)
+ * is the Rust reason text (or a C-only reason, see contract section 9); for
+ * CR_STORE *store_rc (optional) is the store error. */
+int cr_resolve(const struct cr_source *src, struct cr_work *w, struct cr_view *v, const char **why,
+               int *store_rc);
+
+/* rs `writable` (continuity.rs:776-781): CR_RESOLVED when the mount is Valid,
+ * else CR_READ_ONLY (INV-11). */
+int cr_writable(const struct cr_source *src);
+
+/* ---- Recovery Core challenge and operator response ---- */
+#define CR_ACTION_REPAIR_DEGRADED_PEER 1u /* recovery_core.rs:38-44 */
+#define CR_ACTION_PROVISION_IDENTITY 2u
+
+/* state_digest = SHA-256(unit 0 || unit 1), 4096 bytes each; a unit that could
+ * not be read is passed as 4096 zero bytes (recovery_core.rs:109-133). */
+void cr_state_digest(const uint8_t unit0[4096], const uint8_t unit1[4096], uint8_t out[32]);
+/* SHA-256("AIENOS-RECOVERY-CHALLENGE-v1\0" || uuid || generation u64 LE ||
+ * action u8 || state_digest), recovery_core.rs:94-104. */
+void cr_challenge(const uint8_t uuid[16], uint64_t generation, uint8_t action,
+                  const uint8_t state_digest[32], uint8_t out[32]);
+/* HMAC-SHA256(key, "AIENOS-RECOVERY-OPERATOR-AUTH-v1\0" || challenge),
+ * recovery.rs:103, :124-140. */
+void cr_operator_response(const uint8_t key[32], const uint8_t challenge[32], uint8_t out[32]);
+/* 1 if response is the operator response, compared in constant time (all 32 bytes). */
+int cr_operator_verify(const uint8_t key[32], const uint8_t challenge[32],
+                       const uint8_t response[32]);
+
+#endif /* CK_CONTINUITY_RESOLVE_H */
diff --git a/native/kernel/svc/continuity_resolve_sealed.c b/native/kernel/svc/continuity_resolve_sealed.c
new file mode 100644
index 00000000..8822cda2
--- /dev/null
+++ b/native/kernel/svc/continuity_resolve_sealed.c
@@ -0,0 +1,63 @@
+/* continuity_resolve_sealed.c -- see continuity_resolve_sealed.h. */
+#include <string.h>
+
+#include "continuity_resolve_sealed.h"
+
+static uint32_t sealed_count(void *ctx)
+{
+    const ss_store *s = ctx;
+    return s->nclaims;
+}
+
+static int sealed_entry(void *ctx, uint32_t i, uint16_t *kind, uint16_t *version)
+{
+    const ss_store *s = ctx;
+    if (i >= s->nclaims) return ST_E_INVALID_OBJECT;
+    *kind = s->ws->claims[i].c.obj.object_kind;
+    *version = s->ws->claims[i].c.obj.object_version;
+    return 0;
+}
+
+static int sealed_read(void *ctx, uint32_t i, uint8_t *out, size_t cap, size_t *len)
+{
+    ss_store *s = ctx;
+    if (i >= s->nclaims) return ST_E_INVALID_OBJECT;
+    uint8_t sid[32];
+    memcpy(sid, s->ws->claims[i].sid, 32);
+    uint16_t kind = 0;
+    int rc = ss_read(s, sid, out, cap, len, &kind);
+    if (rc != 0) return rc;
+    /* The claim and the envelope binding must agree on the application kind. */
+    if (kind != s->ws->claims[i].c.obj.object_kind) return SS_E_ENVELOPE;
+    return 0;
+}
+
+static int sealed_mount_state(void *ctx)
+{
+    const ss_store *s = ctx;
+    return s->st.state == ST_VALID ? CR_MOUNT_VALID : CR_MOUNT_DEGRADED;
+}
+
+void cr_bind_sealed(struct cr_source *out, ss_store *s)
+{
+    out->ctx = s;
+    out->count = sealed_count;
+    out->entry = sealed_entry;
+    out->read = sealed_read;
+    out->mount_state = sealed_mount_state;
+}
+
+void cr_state_digest_dev(const st_dev *dev, uint8_t out[32])
+{
+    uint8_t raw[2][SV1_UNIT];
+    sha256_ctx h;
+    for (unsigned u = 0; u < 2; u++) {
+        memset(raw[u], 0, SV1_UNIT);
+        if (!dev || !dev->read_unit || dev->read_unit(dev->ctx, u, raw[u]) != 0)
+            memset(raw[u], 0, SV1_UNIT); /* recovery_core.rs:109-133: error leaves zero */
+    }
+    sha256_init(&h);
+    sha256_update(&h, raw[0], SV1_UNIT);
+    sha256_update(&h, raw[1], SV1_UNIT);
+    sha256_final(&h, out);
+}
diff --git a/native/kernel/svc/continuity_resolve_sealed.h b/native/kernel/svc/continuity_resolve_sealed.h
new file mode 100644
index 00000000..d3c9c94f
--- /dev/null
+++ b/native/kernel/svc/continuity_resolve_sealed.h
@@ -0,0 +1,17 @@
+/* continuity_resolve_sealed.h -- binds cr_source (continuity_resolve.h) to the
+ * real sealed Store (native/store/store_sealed.h). Reads only. */
+#ifndef CK_CONTINUITY_RESOLVE_SEALED_H
+#define CK_CONTINUITY_RESOLVE_SEALED_H
+
+#include "continuity_resolve.h"
+#include "store_sealed.h"
+
+/* Source over the verified claims of an opened ss_store (P-3: kind and version
+ * come from the claim, no decryption to list). The store must stay open. */
+void cr_bind_sealed(struct cr_source *out, ss_store *s);
+
+/* Raw-unit state digest of the Store region (units 0 and 1 of dev), as
+ * recovery_core.rs:109-133: an unreadable unit leaves its buffer zero. */
+void cr_state_digest_dev(const st_dev *dev, uint8_t out[32]);
+
+#endif
diff --git a/native/kernel/tests/test_continuity_resolve.c b/native/kernel/tests/test_continuity_resolve.c
new file mode 100644
index 00000000..a62e49ef
--- /dev/null
+++ b/native/kernel/tests/test_continuity_resolve.c
@@ -0,0 +1,881 @@
+/* test_continuity_resolve.c -- host tests of svc/continuity_resolve.c (C
+ * continuity port, cut 3; contract native/kernel/CONTINUITY_RECOVERY_CONTRACT.md,
+ * aienos#222). Oracle: crates/aienos-kernel/src/continuity.rs `resolve`
+ * (:637-710), recovery_core.rs (:94-133), recovery.rs (:103, :124-140).
+ *
+ * Storage: the REAL sealed Store (native/store, M5 envelopes, anchor) in a
+ * file, at 512 and 4096 byte blocks; a fake cr_source only for the cases the
+ * real Store cannot produce (an oversize object, a read error).
+ *
+ * 1. Challenge, operator response, deferred D-1 fixture lines (byte for byte).
+ * 2. One resolve outcome per case, including the hostile ones.
+ * 3. K-5: a degraded mount through ss_open, answered by running it.
+ * Mutants (make continuity-mutants) must each turn this test FAIL. */
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "ck_test.h"
+#include "continuity_resolve_sealed.h"
+#include "disk_file.h"
+#include "aienos_crypto.h"
+#include "../argus/sha256.h"
+
+#define CK_(c, ...)                                                            \
+    do {                                                                       \
+        ck_t_run++;                                                            \
+        if (!(c)) {                                                            \
+            ck_t_fail++;                                                       \
+            printf("  FAIL %s:%d: %s: ", __FILE__, __LINE__, #c);              \
+            printf(__VA_ARGS__);                                               \
+            printf("\n");                                                      \
+        }                                                                      \
+    } while (0)
+
+static int hexv(char c) { return c <= '9' ? c - '0' : c - 'a' + 10; }
+static void unhex(const char *h, uint8_t *o)
+{
+    for (size_t i = 0; h[2 * i]; i++) o[i] = (uint8_t)(hexv(h[2 * i]) << 4 | hexv(h[2 * i + 1]));
+}
+
+/* ------------------------------------------------------------------ */
+/* 1. challenge, response, fixtures                                    */
+/* ------------------------------------------------------------------ */
+
+static uint8_t UUID[16], DIGEST[32], KEY0F[32];
+
+static void test_challenge_kat(void)
+{
+    /* Rust-emitted values (fixture lines of cut 2); also recomputed with sha256sum
+     * over printf-built input (domain, uuid 5a x16, generation 7 LE, action, digest 33 x32). */
+    uint8_t c[32], e[32];
+    cr_challenge(UUID, 7, CR_ACTION_REPAIR_DEGRADED_PEER, DIGEST, c);
+    unhex("7dfd4366095705ca21c81268752c14bf8961d000ed1a276d9dcf0753c0f2f4b5", e);
+    CK_(memcmp(c, e, 32) == 0, "repair challenge KAT");
+    cr_challenge(UUID, 7, CR_ACTION_PROVISION_IDENTITY, DIGEST, c);
+    unhex("91fe9cff4a2afe23d343ae77c5530bed2c3115bea3df648562b6c19004b184fc", e);
+    CK_(memcmp(c, e, 32) == 0, "provision challenge KAT");
+}
+
+/* recovery.rs:206-235: KEY 00..1f, CHALLENGE a0..bf, openssl-computed answer. */
+static void test_operator_kat(void)
+{
+    uint8_t key[32], ch[32], r[32], want[32];
+    for (int i = 0; i < 32; i++) {
+        key[i] = (uint8_t)i;
+        ch[i] = (uint8_t)(0xa0 + i);
+    }
+    unhex("f6162da5f879e9bd4defc7108c463b5d164f4db68ae991781bf798fc14907aaa", want);
+    cr_operator_response(key, ch, r);
+    CK_(memcmp(r, want, 32) == 0, "operator response KAT (rs recovery.rs:231)");
+    CK_(cr_operator_verify(key, ch, want) == 1, "verify accepts the KAT");
+
+    /* rs :269: any single-bit flip of response, challenge or key is refused. */
+    int bad = 0;
+    for (int byte = 0; byte < 32; byte++)
+        for (int bit = 0; bit < 8; bit++) {
+            uint8_t m = (uint8_t)(1u << bit), x[32], k2[32], c2[32];
+            memcpy(x, want, 32);
+            x[byte] ^= m;
+            bad += cr_operator_verify(key, ch, x);
+            memcpy(c2, ch, 32);
+            c2[byte] ^= m;
+            bad += cr_operator_verify(key, c2, want);
+            memcpy(k2, key, 32);
+            k2[byte] ^= m;
+            bad += cr_operator_verify(k2, ch, want);
+        }
+    CK_(bad == 0, "%d bit flips accepted (MR-4: bytes 16-31 of the response)", bad);
+
+    /* rs :299, :311: bare SHA-256, un-domained HMAC and zero are refused. */
+    uint8_t legacy[32], undom[32], z[32] = {0};
+    sha256_ctx h;
+    sha256_init(&h);
+    sha256_update(&h, key, 32);
+    sha256_update(&h, ch, 32);
+    sha256_final(&h, legacy);
+    CK_(cr_operator_verify(key, ch, legacy) == 0, "legacy bare SHA-256 refused (MR-8)");
+    aienos_hmac_sha256(key, ch, 32, undom);
+    CK_(cr_operator_verify(key, ch, undom) == 0, "undomained HMAC refused (MR-8)");
+    CK_(cr_operator_verify(key, ch, z) == 0, "zero response refused");
+    uint8_t zk[32] = {0};
+    CK_(cr_operator_verify(zk, zk, z) == 0, "all-zero key and challenge still need the MAC");
+    /* flipping only byte 16..31 of the response must fail on its own (MR-4). */
+    uint8_t hi[32];
+    memcpy(hi, want, 32);
+    hi[31] ^= 1;
+    CK_(cr_operator_verify(key, ch, hi) == 0, "flip in the last byte refused");
+}
+
+static void test_challenge_binding(void) /* rs recovery_core_tests.rs:300-315 (91k) */
+{
+    uint8_t base[32], c[32], d2[32];
+    cr_challenge(UUID, 7, 1, DIGEST, base);
+    cr_challenge(UUID, 7, 2, DIGEST, c);
+    CK_(memcmp(base, c, 32) != 0, "challenge binds the action (MR-3)");
+    memcpy(d2, DIGEST, 32);
+    d2[0] ^= 1;
+    cr_challenge(UUID, 7, 1, d2, c);
+    CK_(memcmp(base, c, 32) != 0, "challenge binds the state digest (MR-2)");
+    cr_challenge(UUID, 8, 1, DIGEST, c);
+    CK_(memcmp(base, c, 32) != 0, "challenge binds the generation");
+    uint8_t u2[16];
+    memcpy(u2, UUID, 16);
+    u2[15] ^= 1;
+    cr_challenge(u2, 7, 1, DIGEST, c);
+    CK_(memcmp(base, c, 32) != 0, "challenge binds the store uuid");
+    /* An authorisation for one action does not verify for the other. */
+    uint8_t ch1[32], ch2[32], resp1[32];
+    cr_challenge(UUID, 7, 1, DIGEST, ch1);
+    cr_challenge(UUID, 7, 2, DIGEST, ch2);
+    cr_operator_response(KEY0F, ch1, resp1);
+    CK_(cr_operator_verify(KEY0F, ch1, resp1) == 1, "own challenge verifies");
+    CK_(cr_operator_verify(KEY0F, ch2, resp1) == 0, "response replayed on the other action refused");
+    CK_(cr_operator_verify(KEY0F, ch1, resp1) == 1, "and still verifies on its own");
+}
+
+static void test_state_digest(void)
+{
+    static uint8_t u0[4096], u1[4096];
+    uint8_t a[32], b[32];
+    memset(u0, 0xa5, sizeof u0);
+    memset(u1, 0x5a, sizeof u1);
+    cr_state_digest(u0, u1, a);
+    uint8_t both[8192];
+    memcpy(both, u0, 4096);
+    memcpy(both + 4096, u1, 4096);
+    sha256_hash(both, sizeof both, b);
+    CK_(memcmp(a, b, 32) == 0, "state digest = SHA-256(unit0 || unit1)");
+    cr_state_digest(u1, u0, b);
+    CK_(memcmp(a, b, 32) != 0, "unit order matters");
+}
+
+/* The deferred lines of cut 2: Rust-emitted challenges and responses for the
+ * system record {uuid 5a x16, generation 7, digest 33 x32, key 0f x32}. */
+static int fx_checked;
+static int test_fixture(const char *dir)
+{
+    char path[512], line[1024];
+    snprintf(path, sizeof path, "%s/continuity_vectors.txt", dir);
+    FILE *f = fopen(path, "r");
+    if (!f) return 0;
+    uint8_t ch[2][32], rs[2][32];
+    int seen = 0;
+    while (fgets(line, sizeof line, f)) {
+        char kw[32], name[64], hex[128];
+        if (sscanf(line, "%31s %63s %127s", kw, name, hex) != 3 || strcmp(kw, "deferred")) continue;
+        uint8_t want[32], got[32];
+        unhex(hex, want);
+        int act = strstr(name, "repair_degraded_peer") ? 1 : strstr(name, "provision_identity") ? 2 : 0;
+        if (!act) continue;
+        cr_challenge(UUID, 7, (uint8_t)act, DIGEST, ch[act - 1]);
+        cr_operator_response(KEY0F, ch[act - 1], rs[act - 1]);
+        memcpy(got, !strncmp(name, "challenge_", 10) ? ch[act - 1] : rs[act - 1], 32);
+        CK_(memcmp(got, want, 32) == 0, "fixture %s differs from the Rust oracle", name);
+        seen++;
+        fx_checked++;
+    }
+    fclose(f);
+    CK_(seen == 4, "fixture has %d deferred lines, want 4", seen);
+    return 1;
+}
+
+/* ------------------------------------------------------------------ */
+/* 2. a real sealed Store in a file                                    */
+/* ------------------------------------------------------------------ */
+
+#define A_UNITS 4u
+#define S_UNITS 512u
+#define T_UNITS (A_UNITS + S_UNITS)
+
+static ss_workspace g_ws;
+static ss_store g_s;
+static disk_file g_f;
+static disk_dev g_d;
+static st_disk g_sd;
+static st_dev g_sdev;
+static ts_device g_tdev;
+static ss_keys g_k;
+static uint32_t g_bs;
+static char g_path[256];
+static struct cr_work g_w;
+static struct cr_view g_v;
+
+static const uint8_t RUUID[16] = {0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a,
+                                  0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a, 0x5a};
+
+static int g_open;
+static void dev_close(void)
+{
+    if (g_open) disk_file_close(&g_f);
+    g_open = 0;
+}
+static int dev_open(int create)
+{
+    dev_close();
+    uint32_t bpu = 4096u / g_bs;
+    if (create) unlink(g_path);
+    memset(&g_f, 0, sizeof g_f);
+    if (disk_file_open(&g_f, &g_d, g_path, g_bs, (uint64_t)T_UNITS * bpu, create) != 0) return -1;
+    g_open = 1;
+    if (st_disk_bind(&g_sd, &g_d, (uint64_t)A_UNITS * bpu, S_UNITS, &g_sdev) != 0) return -2;
+    ss_ts_device(&g_d, &g_tdev);
+    return 0;
+}
+
+static void make_keys(void)
+{
+    uint8_t kvol[32];
+    memset(kvol, 0x77, 32);
+    m5_subkeys sk;
+    m5_derive_subkeys(kvol, M5_ID_TEST, 0, &sk);
+    memset(&g_k, 0, sizeof g_k);
+    g_k.identity_class = M5_ID_TEST;
+    g_k.key_generation = 1;
+    memcpy(g_k.k_root_auth, sk.k_root_auth, 32);
+    memcpy(g_k.k_domain, sk.k_artifact, 32);
+    m5_subkeys_wipe(&sk);
+}
+
+/* New formatted, opened Store. */
+static void fresh(void)
+{
+    CK_(dev_open(1) == 0, "rig create");
+    CK_(ss_format(&g_sdev, &g_tdev, 0, RUUID, &g_k, &g_ws) == 0, "format");
+    CK_(ss_open(&g_s, &g_sdev, &g_tdev, 0, &g_k, &g_ws) == 0, "open genesis");
+}
+static int reopen(void)
+{
+    if (dev_open(0) != 0) return -9999;
+    memset(&g_s, 0, sizeof g_s);
+    return ss_open(&g_s, &g_sdev, &g_tdev, 0, &g_k, &g_ws);
+}
+
+struct obj {
+    uint16_t kind, ver;
+    uint8_t b[CC_MAX_OBJECT_BYTES];
+    size_t n;
+    uint8_t id[32];
+};
+static struct obj O[8];
+
+static uint8_t AG[32], AG2[32];
+
+static void fin(struct obj *o, uint16_t kind)
+{
+    o->kind = kind;
+    o->ver = 1;
+    CK_(cc_object_id(kind, o->b, o->n, o->id) == CC_OK, "object id");
+}
+static void mk_root(struct obj *o, const uint8_t agent[32], uint8_t source)
+{
+    struct cc_root r;
+    memset(&r, 0, sizeof r);
+    memcpy(r.agent_id, agent, 32);
+    memcpy(r.store_uuid, RUUID, 16);
+    cc_root_branch_id(agent, r.root_branch);
+    r.provisioned_generation = 2;
+    r.source = source;
+    CK_(cc_root_encode(&r, o->b, sizeof o->b, &o->n, NULL) == CC_OK, "root encode");
+    fin(o, CC_KIND_AGENT_ROOT);
+}
+static void mk_state(struct obj *o, const uint8_t agent[32], uint64_t written_at)
+{
+    static struct cc_state s;
+    cc_state_genesis(&s, agent, written_at);
+    CK_(cc_state_encode(&s, o->b, sizeof o->b, &o->n, NULL) == CC_OK, "state encode");
+    fin(o, CC_KIND_AGENT_STATE);
+}
+static void mk_man(struct obj *o, const uint8_t root[32], const uint8_t *prev, uint64_t seq,
+                   uint64_t inc, const uint8_t *state, const uint8_t (*wal)[32], uint32_t nwal)
+{
+    static struct cc_manifest m;
+    memset(&m, 0, sizeof m);
+    memcpy(m.root, root, 32);
+    if (prev) memcpy(m.previous, prev, 32);
+    m.sequence = seq;
+    m.incarnation = inc;
+    if (state) memcpy(m.agent_state, state, 32);
+    m.n_wal = nwal;
+    for (uint32_t i = 0; i < nwal; i++) memcpy(m.wal[i], wal[i], 32);
+    int rc = cc_manifest_encode(&m, o->b, sizeof o->b, &o->n, NULL);
+    CK_(rc == CC_OK, "manifest encode rc=%d", rc);
+    fin(o, CC_KIND_MANIFEST);
+}
+static void mk_wal(struct obj *o, uint64_t seq, const char *const *stmts, uint32_t n)
+{
+    static struct cc_wal w;
+    memset(&w, 0, sizeof w);
+    w.sequence = seq;
+    w.n = n;
+    for (uint32_t i = 0; i < n; i++) {
+        w.rec[i].status = CC_EPI_DIRECT_OBSERVATION;
+        memset(w.rec[i].evidence_hash, (int)(0x40 + i), 32);
+        w.rec[i].len = (uint16_t)strlen(stmts[i]);
+        w.rec[i].statement = (const uint8_t *)stmts[i];
+    }
+    CK_(cc_wal_encode(&w, o->b, sizeof o->b, &o->n, NULL) == CC_OK, "wal encode");
+    fin(o, CC_KIND_CORTEX_WAL);
+}
+
+static int commit(struct obj **os, size_t n)
+{
+    ss_object so[SS_MAX_OBJECTS];
+    for (size_t i = 0; i < n; i++) {
+        so[i].kind = os[i]->kind;
+        so[i].version = os[i]->ver;
+        so[i].bytes = os[i]->b;
+        so[i].len = os[i]->n;
+    }
+    return ss_transact(&g_s, so, n, NULL, NULL, NULL);
+}
+static int commit1(struct obj *o)
+{
+    struct obj *a[1] = {o};
+    return commit(a, 1);
+}
+
+static int do_resolve(const char **why, int *rc)
+{
+    struct cr_source src;
+    cr_bind_sealed(&src, &g_s);
+    return cr_resolve(&src, &g_w, &g_v, why, rc);
+}
+
+#define EXPECT(outcome, reason)                                                          \
+    do {                                                                                 \
+        const char *w_ = NULL, *r_ = (reason);                                           \
+        int rc_ = 0, o_ = do_resolve(&w_, &rc_);                                         \
+        CK_(o_ == (outcome) && (!r_ || (w_ && !strcmp(w_, r_))),                       \
+            "bs=%u %s: got %s (%s), want %s (%s)", g_bs, __func__, cr_outcome_name(o_),  \
+            w_ ? w_ : "-", cr_outcome_name(outcome), r_ ? r_ : "-");                     \
+    } while (0)
+
+/* Genesis, as provision would write it (INV-8): root, state(written_at 1),
+ * manifest 1 in one transaction. ids in O[0..3]. */
+static void genesis(void)
+{
+    mk_root(&O[0], AG, CC_SOURCE_OPERATOR);
+    mk_state(&O[1], AG, 1);
+    mk_man(&O[2], O[0].id, NULL, 1, 1, O[1].id, NULL, 0);
+    struct obj *a[3] = {&O[0], &O[1], &O[2]};
+    CK_(commit(a, 3) == 0, "commit genesis");
+}
+
+static void t_unprovisioned(void)
+{
+    fresh();
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_UNPROVISIONED, NULL);
+    /* kind 19 (CortexCheckpoint) is ignored by Rust (no code reads it): still Unprovisioned. */
+    memset(&O[7], 0, sizeof O[7]);
+    memcpy(O[7].b, "stray", 5);
+    O[7].n = 5;
+    O[7].kind = 19;
+    O[7].ver = 1;
+    CK_(commit1(&O[7]) == 0, "kind 19 write");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_UNPROVISIONED, NULL);
+    /* an unrelated application kind is ignored as well */
+    O[7].kind = 0x0B00;
+    CK_(commit1(&O[7]) == 0, "boot kind write");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_UNPROVISIONED, NULL);
+}
+
+/* The memory digest of {alpha, bravo!}, computed with sha256sum outside C. */
+#define MEM_AB "d6ac0e5f36b30cbac775b60eb8beccb8260390e26373cbec5613ef8f157e922c"
+#define MEM_EMPTY "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"
+
+static void t_resolved(void)
+{
+    fresh();
+    genesis();
+    CK_(reopen() == 0, "reopen");
+    const char *w = NULL;
+    int rc = 0, o = do_resolve(&w, &rc);
+    CK_(o == CR_RESOLVED, "genesis resolves: %s %s", cr_outcome_name(o), w ? w : "-");
+    uint8_t want[32];
+    CK_(memcmp(g_v.root.agent_id, AG, 32) == 0, "agent id");
+    CK_(g_v.manifest.sequence == 1 && g_v.manifest.incarnation == 1, "sequence/incarnation");
+    CK_(g_v.state.n == 1 && g_v.cortex_count == 0, "branches/cortex");
+    unhex(MEM_EMPTY, want);
+    CK_(memcmp(g_v.memory, want, 32) == 0, "empty memory digest");
+    CK_(memcmp(g_v.root_id, O[0].id, 32) == 0 && memcmp(g_v.manifest_id, O[2].id, 32) == 0, "ids");
+
+    /* manifest 2 (+WAL seq 2, 2 records), manifest 3 (+WAL seq 3, 1 record, state rewritten) */
+    const char *s1[] = {"alpha", "bravo!"};
+    mk_wal(&O[3], 2, s1, 2);
+    uint8_t wl[2][32];
+    memcpy(wl[0], O[3].id, 32);
+    mk_man(&O[4], O[0].id, O[2].id, 2, 2, O[1].id, wl, 1);
+    struct obj *a1[2] = {&O[3], &O[4]};
+    CK_(commit(a1, 2) == 0, "commit 2");
+    CK_(reopen() == 0, "reopen");
+    o = do_resolve(&w, &rc);
+    CK_(o == CR_RESOLVED, "chain of 2 resolves: %s %s", cr_outcome_name(o), w ? w : "-");
+    CK_(g_v.manifest.sequence == 2 && g_v.manifest.incarnation == 2 && g_v.cortex_count == 2, "view 2");
+    unhex(MEM_AB, want);
+    CK_(memcmp(g_v.memory, want, 32) == 0, "memory digest of {alpha, bravo!}");
+
+    const char *s2[] = {"charlie"};
+    mk_wal(&O[5], 3, s2, 1);
+    memcpy(wl[1], O[5].id, 32);
+    mk_man(&O[6], O[0].id, O[4].id, 3, 3, O[1].id, wl, 2);
+    struct obj *a2[2] = {&O[5], &O[6]};
+    CK_(commit(a2, 2) == 0, "commit 3");
+    CK_(reopen() == 0, "reopen");
+    o = do_resolve(&w, &rc);
+    CK_(o == CR_RESOLVED, "chain of 3 resolves: %s %s", cr_outcome_name(o), w ? w : "-");
+    CK_(g_v.manifest.sequence == 3 && g_v.cortex_count == 3 && g_v.manifest.n_wal == 2, "view 3");
+    CK_(memcmp(g_v.manifest_id, O[6].id, 32) == 0, "current manifest is the highest sequence");
+    /* memory digest over all three records, streamed in commit order */
+    uint8_t m3[32];
+    {
+        static const char *all[] = {"alpha", "bravo!", "charlie"};
+        sha256_ctx h;
+        sha256_init(&h);
+        for (int i = 0; i < 3; i++) {
+            uint8_t l4[4] = {(uint8_t)strlen(all[i]), 0, 0, 0};
+            sha256_update(&h, l4, 4);
+            sha256_update(&h, (const uint8_t *)all[i], strlen(all[i]));
+        }
+        sha256_final(&h, m3);
+    }
+    CK_(memcmp(g_v.memory, m3, 32) == 0, "memory digest over three records");
+}
+
+static void t_resolve_never_writes(void)
+{
+    fresh();
+    genesis();
+    CK_(reopen() == 0, "reopen");
+    static uint8_t a[T_UNITS * 4096u], b[T_UNITS * 4096u];
+    FILE *f = fopen(g_path, "rb");
+    CK_(f && fread(a, 1, sizeof a, f) == sizeof a, "read image");
+    if (f) fclose(f);
+    uint64_t w0 = g_f.blocks_written, f0 = g_f.flushes;
+    EXPECT(CR_RESOLVED, NULL);
+    CK_(g_f.blocks_written == w0 && g_f.flushes == f0, "no block written, no flush");
+    f = fopen(g_path, "rb");
+    CK_(f && fread(b, 1, sizeof b, f) == sizeof b, "reread image");
+    if (f) fclose(f);
+    CK_(memcmp(a, b, sizeof a) == 0, "image unchanged after resolve");
+}
+
+/* INV-5 / MC-2: continuity objects with no root are Corrupt, never Unprovisioned. */
+static void t_orphans(void)
+{
+    static const char *WHY = "continuity objects without an agent root";
+    uint8_t rootid[32];
+    memset(rootid, 0xee, 32);
+    /* orphan manifest */
+    fresh();
+    mk_state(&O[1], AG, 1);
+    mk_man(&O[2], rootid, NULL, 1, 1, O[1].id, NULL, 0);
+    CK_(commit1(&O[2]) == 0, "write orphan manifest");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, WHY);
+    /* orphan agent state */
+    fresh();
+    CK_(commit1(&O[1]) == 0, "write orphan state");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, WHY);
+    /* orphan WAL */
+    fresh();
+    const char *s[] = {"x"};
+    mk_wal(&O[3], 1, s, 1);
+    CK_(commit1(&O[3]) == 0, "write orphan wal");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, WHY);
+}
+
+static void t_conflict(void) /* INV-5, MC-12: two roots */
+{
+    fresh();
+    genesis();
+    mk_root(&O[5], AG2, CC_SOURCE_QUALIFICATION);
+    CK_(commit1(&O[5]) == 0, "second root");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CONFLICT, NULL);
+}
+
+static void t_duplicate_id(void) /* P-3 */
+{
+    fresh();
+    genesis();
+    CK_(commit1(&O[0]) == 0, "same root bytes written twice (sealed store allows it)");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "duplicate logical object id");
+    /* the duplicate is detected before the root count: it is not a Conflict */
+}
+
+static void t_chain(void) /* INV-6, MC-4 */
+{
+    /* previous names a wrong id (an object that exists, but is not manifest 1) */
+    fresh();
+    genesis();
+    mk_man(&O[3], O[0].id, O[1].id, 2, 2, O[1].id, NULL, 0);
+    CK_(commit1(&O[3]) == 0, "manifest 2 with wrong previous");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "manifest chain is broken");
+    /* previous = an id that exists nowhere */
+    fresh();
+    genesis();
+    uint8_t nowhere[32];
+    memset(nowhere, 0xcd, 32);
+    mk_man(&O[3], O[0].id, nowhere, 2, 2, O[1].id, NULL, 0);
+    CK_(commit1(&O[3]) == 0, "manifest 2 with absent previous");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "manifest chain is broken");
+    /* gap: sequence 3 after 1 */
+    fresh();
+    genesis();
+    mk_man(&O[3], O[0].id, O[2].id, 3, 2, O[1].id, NULL, 0);
+    CK_(commit1(&O[3]) == 0, "manifest with sequence 3");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "manifest sequence gap or fork");
+    /* fork: two manifests with sequence 2 */
+    fresh();
+    genesis();
+    mk_man(&O[3], O[0].id, O[2].id, 2, 2, O[1].id, NULL, 0);
+    mk_man(&O[4], O[0].id, O[2].id, 2, 3, O[1].id, NULL, 0);
+    struct obj *a[2] = {&O[3], &O[4]};
+    CK_(commit(a, 2) == 0, "two manifests with sequence 2");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "manifest sequence gap or fork");
+    /* foreign root */
+    fresh();
+    genesis();
+    uint8_t other[32];
+    memset(other, 0x99, 32);
+    mk_man(&O[3], other, O[2].id, 2, 2, O[1].id, NULL, 0);
+    CK_(commit1(&O[3]) == 0, "manifest naming a foreign root");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "manifest names a foreign root");
+    /* root and state but no manifest */
+    fresh();
+    mk_root(&O[0], AG, CC_SOURCE_OPERATOR);
+    mk_state(&O[1], AG, 1);
+    struct obj *b[2] = {&O[0], &O[1]};
+    CK_(commit(b, 2) == 0, "root + state only");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "agent root has no manifest");
+}
+
+static void t_references(void) /* INV-7: kinds, absence, order */
+{
+    /* manifest names a WAL object as its agent state (wrong kind) */
+    const char *s[] = {"w"};
+    fresh();
+    mk_root(&O[0], AG, CC_SOURCE_OPERATOR);
+    mk_wal(&O[3], 1, s, 1);
+    mk_man(&O[2], O[0].id, NULL, 1, 1, O[3].id, NULL, 0);
+    struct obj *a[3] = {&O[0], &O[3], &O[2]};
+    CK_(commit(a, 3) == 0, "wrong-kind state reference");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "referenced object has the wrong kind");
+    /* WAL list names a state object (wrong kind) */
+    fresh();
+    mk_root(&O[0], AG, CC_SOURCE_OPERATOR);
+    mk_state(&O[1], AG, 1);
+    uint8_t wl[2][32];
+    memcpy(wl[0], O[1].id, 32);
+    mk_man(&O[2], O[0].id, NULL, 1, 1, O[1].id, wl, 1);
+    struct obj *b[3] = {&O[0], &O[1], &O[2]};
+    CK_(commit(b, 3) == 0, "state named as WAL");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "referenced object has the wrong kind");
+    /* absent state */
+    fresh();
+    mk_root(&O[0], AG, CC_SOURCE_OPERATOR);
+    uint8_t gone[32];
+    memset(gone, 0xab, 32);
+    mk_man(&O[2], O[0].id, NULL, 1, 1, gone, NULL, 0);
+    struct obj *c[2] = {&O[0], &O[2]};
+    CK_(commit(c, 2) == 0, "absent state reference");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "referenced object is absent");
+    /* zero state id */
+    fresh();
+    mk_root(&O[0], AG, CC_SOURCE_OPERATOR);
+    mk_man(&O[2], O[0].id, NULL, 1, 1, NULL, NULL, 0);
+    struct obj *d[2] = {&O[0], &O[2]};
+    CK_(commit(d, 2) == 0, "no agent state");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "manifest has no agent state");
+    /* state of another agent */
+    fresh();
+    mk_root(&O[0], AG, CC_SOURCE_OPERATOR);
+    mk_state(&O[1], AG2, 1);
+    mk_man(&O[2], O[0].id, NULL, 1, 1, O[1].id, NULL, 0);
+    struct obj *e[3] = {&O[0], &O[1], &O[2]};
+    CK_(commit(e, 3) == 0, "state of another agent");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "agent state belongs to another agent");
+    /* WAL segments out of order (sequence 2 then 1) and beyond the manifest */
+    fresh();
+    mk_root(&O[0], AG, CC_SOURCE_OPERATOR);
+    mk_state(&O[1], AG, 1);
+    mk_man(&O[2], O[0].id, NULL, 1, 1, O[1].id, NULL, 0);
+    mk_wal(&O[3], 2, s, 1);
+    mk_wal(&O[4], 1, s, 1);
+    memcpy(wl[0], O[3].id, 32);
+    memcpy(wl[1], O[4].id, 32);
+    mk_man(&O[5], O[0].id, O[2].id, 2, 2, O[1].id, wl, 2);
+    struct obj *f[5] = {&O[0], &O[1], &O[2], &O[3], &O[4]};
+    CK_(commit(f, 5) == 0, "genesis + two wal");
+    CK_(commit1(&O[5]) == 0, "manifest 2 with WAL order 2,1");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "WAL segments out of order");
+    /* WAL sequence beyond the manifest sequence */
+    fresh();
+    mk_root(&O[0], AG, CC_SOURCE_OPERATOR);
+    mk_state(&O[1], AG, 1);
+    mk_wal(&O[3], 5, s, 1);
+    memcpy(wl[0], O[3].id, 32);
+    mk_man(&O[2], O[0].id, NULL, 1, 1, O[1].id, wl, 1);
+    struct obj *g[4] = {&O[0], &O[1], &O[3], &O[2]};
+    CK_(commit(g, 4) == 0, "WAL from the future");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "WAL segments out of order");
+}
+
+static void t_versions_and_decode(void)
+{
+    /* a root stored with Store version 2 counts as a root but cannot be read as one */
+    fresh();
+    mk_root(&O[0], AG, CC_SOURCE_OPERATOR);
+    O[0].ver = 2;
+    CK_(commit1(&O[0]) == 0, "root v2");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "referenced object has the wrong kind");
+    /* bad magic root */
+    fresh();
+    mk_root(&O[0], AG, CC_SOURCE_OPERATOR);
+    O[0].b[0] ^= 1;
+    CK_(commit1(&O[0]) == 0, "root with bad magic");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_CORRUPT, "bad magic");
+    /* empty object: a continuity kind with zero bytes cannot have a logical id */
+    fresh();
+    memset(&O[6], 0, sizeof O[6]);
+    O[6].kind = CC_KIND_MANIFEST;
+    O[6].ver = 1;
+    O[6].n = 0;
+    ss_object so = {CC_KIND_MANIFEST, 1, O[6].b, 0};
+    int rc = ss_transact(&g_s, &so, 1, NULL, NULL, NULL);
+    if (rc == 0) {
+        CK_(reopen() == 0, "reopen");
+        EXPECT(CR_CORRUPT, "continuity object has no valid id");
+    } else {
+        printf("note: sealed store refuses a zero-length object (rc=%d)\n", rc);
+    }
+}
+
+/* K-1 (contract 5.3): 16384 bytes is the sealed Store bound. The largest legal
+ * branch table (204 branches) goes through the whole pipeline; one object past
+ * the bound cannot be written to the sealed Store at all. */
+static void t_size_bound(void)
+{
+    static struct cc_state s;
+    fresh();
+    mk_root(&O[0], AG, CC_SOURCE_OPERATOR);
+    cc_state_genesis(&s, AG, 1);
+    uint8_t child[32];
+    for (int i = 1; i < (int)CC_MAX_BRANCHES_IN_CAP; i++)
+        CK_(cc_state_fork(&s, s.br[0].id, child, NULL) == CC_OK, "fork %d", i);
+    CK_(cc_state_encode(&s, O[1].b, sizeof O[1].b, &O[1].n, NULL) == CC_OK, "encode 204 branches");
+    CK_(O[1].n == CC_MAX_OBJECT_BYTES, "204 branches are exactly %u bytes (got %zu)", CC_MAX_OBJECT_BYTES, O[1].n);
+    fin(&O[1], CC_KIND_AGENT_STATE);
+    mk_man(&O[2], O[0].id, NULL, 1, 1, O[1].id, NULL, 0);
+    struct obj *a[3] = {&O[0], &O[1], &O[2]};
+    CK_(commit(a, 3) == 0, "commit 16384-byte state");
+    CK_(reopen() == 0, "reopen");
+    EXPECT(CR_RESOLVED, NULL);
+    CK_(g_v.state.n == CC_MAX_BRANCHES_IN_CAP, "204 branches read back");
+
+    /* one byte past the bound: the sealed Store refuses to write it */
+    fresh();
+    uint64_t gen0 = ss_generation(&g_s);
+    static uint8_t big[SS_MAX_PLAINTEXT + 1];
+    memset(big, 0x41, sizeof big);
+    ss_object so = {CC_KIND_AGENT_STATE, 1, big, sizeof big};
+    int rc = ss_transact(&g_s, &so, 1, NULL, NULL, NULL);
+    CK_(rc != 0, "sealed Store accepted %zu bytes", sizeof big);
+    CK_(ss_generation(&g_s) == gen0, "nothing committed");
+    CK_(reopen() == 0, "reopen");
+    CK_(ss_generation(&g_s) == gen0, "generation unchanged after reopen");
+    EXPECT(CR_UNPROVISIONED, NULL);
+}
+
+/* K-5: does ss_open return 0 on a DegradedRecovery mount with a malformed
+ * peer? Answered here by running it; the result is printed and checked. */
+static void t_degraded(void)
+{
+    fresh();
+    genesis();
+    const char *s[] = {"alpha", "bravo!"};
+    mk_wal(&O[3], 2, s, 2);
+    uint8_t wl[1][32];
+    memcpy(wl[0], O[3].id, 32);
+    mk_man(&O[4], O[0].id, O[2].id, 2, 2, O[1].id, wl, 1);
+    struct obj *a[2] = {&O[3], &O[4]};
+    CK_(commit(a, 2) == 0, "commit 2");
+    CK_(reopen() == 0, "reopen valid");
+    EXPECT(CR_RESOLVED, NULL);
+    uint8_t agent[32], mem[32];
+    memcpy(agent, g_v.root.agent_id, 32);
+    memcpy(mem, g_v.memory, 32);
+    struct cr_source src;
+    cr_bind_sealed(&src, &g_s);
+    CK_(g_s.st.state == ST_VALID, "valid mount");
+    CK_(cr_writable(&src) == CR_RESOLVED, "valid mount is writable");
+    uint32_t active = st_active_slot(&g_s.st);
+    uint64_t gen = ss_generation(&g_s);
+
+    /* Fill the inactive superblock slot (Store-region unit 1 - active) with garbage. */
+    dev_close();
+    FILE *f = fopen(g_path, "r+b");
+    CK_(f != NULL, "open image");
+    static uint8_t junk[4096];
+    for (size_t i = 0; i < sizeof junk; i++) junk[i] = (uint8_t)(i * 37u + 11u);
+    if (f) {
+        fseek(f, (long)((A_UNITS + (1u - active)) * 4096u), SEEK_SET);
+        CK_(fwrite(junk, 1, sizeof junk, f) == sizeof junk, "write junk");
+        fclose(f);
+    }
+    int orc = reopen();
+    printf("K-5 answer: ss_open rc=%d, state=%d (1 = DegradedRecovery), peer=%d (2 = Malformed), "
+           "generation %llu -> %llu\n",
+           orc, g_s.st.state, g_s.st.peer, (unsigned long long)gen,
+           (unsigned long long)ss_generation(&g_s));
+    CK_(orc == 0, "K-5: ss_open returns 0 on a degraded mount with a malformed peer");
+    CK_(g_s.st.state == ST_DEGRADED_RECOVERY && g_s.st.peer == ST_PEER_MALFORMED, "degraded, malformed peer");
+    CK_(ss_generation(&g_s) == gen, "same generation");
+    cr_bind_sealed(&src, &g_s);
+    CK_(cr_writable(&src) == CR_READ_ONLY, "degraded mount is not writable (INV-11)");
+    const char *w = NULL;
+    int rc = 0, o = do_resolve(&w, &rc);
+    CK_(o == CR_RESOLVED, "degraded mount still resolves the verified view: %s %s", cr_outcome_name(o), w ? w : "-");
+    CK_(memcmp(g_v.root.agent_id, agent, 32) == 0 && memcmp(g_v.memory, mem, 32) == 0, "same agent and memory");
+    CK_(g_v.manifest.incarnation == 2 && g_v.cortex_count == 2, "same view");
+    /* The raw state digest reads the junk unit as it is (not repaired, not decoded). */
+    uint8_t dg[32], expect[32];
+    cr_state_digest_dev(&g_sdev, dg);
+    static uint8_t raw[2 * 4096];
+    f = fopen(g_path, "rb");
+    CK_(f && fseek(f, (long)(A_UNITS * 4096u), SEEK_SET) == 0 && fread(raw, 1, sizeof raw, f) == sizeof raw,
+        "read raw units");
+    if (f) fclose(f);
+    sha256_hash(raw, sizeof raw, expect);
+    CK_(memcmp(dg, expect, 32) == 0, "cr_state_digest_dev = SHA-256 of the two raw Store units");
+}
+
+/* ---- fake source: the cases the real Store cannot produce ---- */
+struct fake {
+    uint16_t kind[4];
+    size_t len[4];
+    int rc[4];
+    uint32_t n;
+    int mount;
+};
+static uint32_t fk_count(void *c) { return ((struct fake *)c)->n; }
+static int fk_entry(void *c, uint32_t i, uint16_t *k, uint16_t *v)
+{
+    struct fake *f = c;
+    *k = f->kind[i];
+    *v = 1;
+    return 0;
+}
+static int fk_read(void *c, uint32_t i, uint8_t *out, size_t cap, size_t *len)
+{
+    struct fake *f = c;
+    if (f->rc[i]) return f->rc[i];
+    *len = f->len[i];
+    memset(out, 0x55, *len < cap ? *len : cap);
+    return 0;
+}
+static int fk_mount(void *c) { return ((struct fake *)c)->mount; }
+
+static void t_fake(void)
+{
+    struct fake f;
+    memset(&f, 0, sizeof f);
+    struct cr_source src = {&f, fk_count, fk_entry, fk_read, fk_mount};
+    const char *w = NULL;
+    int rc = 0;
+    /* oversize (K-1): Limit, never decoded, never truncated */
+    f.n = 1;
+    f.kind[0] = CC_KIND_AGENT_STATE;
+    f.len[0] = CC_MAX_OBJECT_BYTES + 1;
+    int o = cr_resolve(&src, &g_w, &g_v, &w, &rc);
+    CK_(o == CR_LIMIT && w && !strcmp(w, "continuity object exceeds the size bound"), "oversize: %s", cr_outcome_name(o));
+    f.len[0] = CC_MAX_OBJECT_BYTES; /* at the bound: read, then refused by the decoder as Corrupt */
+    o = cr_resolve(&src, &g_w, &g_v, &w, &rc);
+    CK_(o == CR_CORRUPT, "bound-sized garbage is Corrupt, not Limit: %s", cr_outcome_name(o));
+    /* read error passes through as Store */
+    f.rc[0] = -4242;
+    o = cr_resolve(&src, &g_w, &g_v, &w, &rc);
+    CK_(o == CR_STORE && rc == -4242, "store error passes through: %s %d", cr_outcome_name(o), rc);
+    /* untracked kinds are never read */
+    f.kind[0] = 0x0B00;
+    f.rc[0] = -1;
+    o = cr_resolve(&src, &g_w, &g_v, &w, &rc);
+    CK_(o == CR_UNPROVISIONED, "unrelated kind never read: %s", cr_outcome_name(o));
+    /* mount state */
+    f.mount = CR_MOUNT_DEGRADED;
+    CK_(cr_writable(&src) == CR_READ_ONLY, "degraded fake is read only");
+    f.mount = CR_MOUNT_VALID;
+    CK_(cr_writable(&src) == CR_RESOLVED, "valid fake is writable");
+    struct cr_source bad = src;
+    bad.mount_state = NULL;
+    CK_(cr_writable(&bad) == CR_READ_ONLY, "no mount_state fails closed");
+    CK_(cr_resolve(NULL, &g_w, &g_v, &w, &rc) == CR_E_ARG, "NULL source");
+    CK_(cr_resolve(&src, NULL, &g_v, &w, &rc) == CR_E_ARG, "NULL work");
+}
+
+static const char *fixture_dir;
+
+int main(int argc, char **argv)
+{
+    memset(UUID, 0x5a, 16);
+    memset(DIGEST, 0x33, 32);
+    memset(KEY0F, 0x0f, 32);
+    memset(AG, 0x11, 32);
+    memset(AG2, 0x22, 32);
+#ifdef CR_FIXTURE_DIR
+    fixture_dir = argc > 1 ? argv[1] : CR_FIXTURE_DIR;
+#else
+    fixture_dir = argc > 1 ? argv[1] : NULL;
+#endif
+    test_challenge_kat();
+    test_operator_kat();
+    test_challenge_binding();
+    test_state_digest();
+    CK_(fixture_dir && test_fixture(fixture_dir) && fx_checked == 4, "deferred fixture lines compared: %d", fx_checked);
+
+    make_keys();
+    snprintf(g_path, sizeof g_path, "/tmp/ck_cr_test_%d.img", (int)getpid());
+    t_fake();
+    static const uint32_t geos[2] = {4096u, 512u};
+    for (int g = 0; g < 2; g++) {
+        g_bs = geos[g];
+        t_unprovisioned();
+        t_resolved();
+        t_resolve_never_writes();
+        t_orphans();
+        t_conflict();
+        t_duplicate_id();
+        t_chain();
+        t_references();
+        t_versions_and_decode();
+        t_size_bound();
+        t_degraded();
+    }
+    dev_close();
+    unlink(g_path);
+    return ck_t_verdict("test_continuity_resolve");
+}