interplane.Get Omega
Read in your language

synapse

A component of the AienOS ecosystem.

Brought by drakestapleton

branch main Branches Tags History

synapse / docs / PHASE5_GROUP_COMMIT.md

216 lines · 15285 bytes Raw Blame History Source

Phase 5: Durable Group Commit

Status: implemented on branch feat/phase5-group-commit; measured on the Spark (GB10) host on 2026-10-14 from commit 6826610 (the code with the review fixes). Evidence: evidence/phase5-group-commit/ (manifest, report, floor, raw traces, red/green test logs, SHA256SUMS).

1. Design in Two Lines

Many submitters hand prepared changes (signature, digests and encoding done in parallel on their own threads) to one leader, which writes the whole batch with one positioned write into WAL v2 space that was written and synced in advance, then calls fdatasync once and only then acknowledges every member.

A failed write or sync rolls the batch back (zeroes it) and acknowledges nobody; if the rollback itself fails the store is poisoned until reopened, and recovery accepts a batch all-or-nothing.

2. Durability Rule

No acknowledgement before the blobs, directories and WAL bytes that make the change readable are synced. Concretely (crates/synapse-store/src/shared.rs, wal2.rs):

On-disk format: wal.v2.log, 4 KiB aligned batches with a 64-byte SWB2 header, CRC-32C per frame, and an 8-byte trailer SWB2END! (no zero byte) closing every batch. A version marker frame added to the legacy wal.log makes older fsync policies refuse the store (WalVersionUnsupported) instead of silently ignoring v2 data. The upgrade writes the old log plus the marker to wal.log.tmp, syncs it, renames it over wal.log and syncs the directory, so a crash leaves either the v1 store or the complete marker.

Torn tail rule: an invalid batch is a torn tail only when no valid batch follows it, the sector holding the end of its declared extent reads back all zero, and every byte after it is zero (or its header's whole sector is zero). The space was zero before the write and the trailer has no zero byte, so a complete batch never ends in zeros, however few bytes of it sit in the last sector. Strict open refuses a torn tail; TruncateTornTail drops that whole batch. A batch that still ends in its trailer but fails validation is corruption, and both policies refuse it, even when its blobs contain whole zero sectors.

Checkpoint crash window: checkpoint_and_compact syncs the WAL, renames checkpoint.v1 into place, then empties the logs. A crash between the rename and the emptying leaves frames the checkpoint already covers. Recovery verifies them (CRC, frame digest, one unbroken hash chain that must end at the checkpoint's sequence and anchor digest) and skips them, for wal.log (v1 frames and the v2 marker) and wal.v2.log alike. Skipping is allowed only before the first frame is applied.

Unknown outcome: a refusal is not proof of non-commit. When a batch's rollback fails (the store is then poisoned) or the leader dies after its write, callers get IoFailure although the batch may be durable. Clients must reopen and retry with the same idempotency key; the retry returns IdempotentDuplicate if the first attempt landed and commits exactly once otherwise (SharedStore::submit documents this, and the error message says so).

API edit: SynapseService::submit was split into admit_submit (authorization and checks) and index_submitted (index update) with unchanged behaviour, so the bench can run admission, then SharedStore::submit outside the service lock. No root Cargo.toml changes.

3. Tests and Red-Before-Green Evidence

crates/synapse-store/src/group_tests.rs (15 tests; the store crate runs 21, all pass):

TestWhat it proves
test_crc32c_hardware_matches_portableArm crc32c instructions equal the portable table
test_group_commit_roundtrip_reopen_and_legacy_policy_refusalData survives reopen; legacy policy refuses a v2 store
test_v1_store_upgrades_to_v2_with_continuous_chainv1 history stays readable, sequence continues
test_concurrent_submitters_acks_unique_contiguous_and_durable_before_ack16 threads x 8 changes behind a Barrier; acks unique, contiguous 1..=128, never ahead of the durable watermark
test_duplicate_idempotency_keys_inside_one_batchSame key twice in one batch commits once
test_injected_sync_failure_acks_nothing_and_retry_commits_onceFailed fdatasync: no ack, nothing visible after reopen, retry commits once
test_injected_write_failure_acks_nothing_and_retry_commits_oncePartial write (1500 bytes): same as above
test_rollback_failure_poisons_store_until_reopenSync and rollback both fail: store refuses work until reopen; after reopen the refused record is there and the retry is IdempotentDuplicate
test_shutdown_drains_queued_submissions_and_refuses_new_onesQueued work finishes, new work refused
test_subprocess_crash_mid_batch_no_lost_ack_no_phantomChild process exits mid-batch write; every ack survives, no unacked change appears
test_v2_checkpoint_crash_window_reopens_and_skips_covered_framesCrash after the checkpoint rename, before wal.log is replaced and before wal.v2.log is reset: reopens with the same state, new commits follow; a damaged covered frame or a covered chain short of the anchor is refused
test_v1_checkpoint_crash_window_reopens_and_skips_covered_framesSame window for a v1 store (before wal.log is truncated)
test_torn_last_sector_with_short_tail_is_truncatableLast batch ends 9 to 63 bytes into its last sector and that sector is lost: strict refuses (WalTornFrame), TruncateTornTail drops only that batch
test_corrupt_last_batch_with_zero_sector_in_blob_is_not_droppedOne flipped bit in an acknowledged last batch whose blob holds whole zero sectors: both policies refuse, nothing truncated
test_v2_upgrade_marker_is_atomic_and_survives_a_stray_temp_fileA crash mid-upgrade leaves the v1 store intact; the upgrade then completes

Red runs (code deliberately broken, logs in evidence/phase5-group-commit/red-green/; each mutation was reverted from a saved copy):

  1. Crash: recovery made to keep the valid frames of a torn batch. Crash test fails: "strict recovery accepted the torn batch: committed_seq wal:5 with 4 acknowledged".
  2. Failed flush: rollback zeroing removed. Sync test fails "failed batch visible after reopen"; write test fails on reopen with a CRC mismatch (WalTornFrame).
  3. Ack ordering: waiters released before the batch write. Four tests fail, including "acknowledged wal:8 while the durable watermark was wal:1" and "no waiter of a failed batch is acknowledged".

Green: all three restored; full store suite 16/16, three consecutive runs.

Review fixes (independent review of PR #18), red on the unfixed code, then green (red-green/review-red.txt, review-green.txt):

  1. Checkpoint crash window: both crash-window tests fail before the fix with WalSequenceGap ("expected wal:6, found wal:1" for v2, "expected wal:4, found wal:1" for v1): the store could never be opened again.
  2. Torn tail rule: before the fix the short-tail test fails because the lost sector is not recognised as torn (strict open returns WalCrcMismatch instead of WalTornFrame, so TruncateTornTail refuses to open too), and the bit-rot test fails because the corrupt acknowledged batch is classified as torn (WalTornFrame), which TruncateTornTail would drop.
  3. Atomic upgrade: before the fix the upgrade appended in place (the stray-temp-file test fails on its wal.log.tmp check).

Green: store crate 21/21, three consecutive runs.

4. Measurement Method

Command (release binary built from commit 6826610e7cd2, clean tree; manifest.json records the revision and the git archive source digest):

synapse-bench run --fixture-repo ~/workspace/aien-sovereign-core \
  --fixture-rev 1b6e340d48417dfbcfe2df56d48a0696a3a9b250 --write-only --arms S1,S3 \
  --tiers 1,4,8,32 --reps 3 --ops-floor 4000 --idle-window-s 30
synapse-bench floor   # hardware floor, floor.json

Energy sensor: the aien_spbm hwmon device, which reads the GB10 SPBM firmware energy counters. It covers the SoC package only (CPU clusters plus the rest of the package); the NVMe drive is UNMEASURED. 1 mJ step, the counter updates about every 0.1 s, sampled at 10 Hz. There is no published accuracy and it has never been compared with an external meter: treat all joules as uncalibrated. A 30 s idle window (22.731 W) is the counterfactual baseline for "above idle" values.

5. Hardware Floor

From floor.json (300 iterations each, same filesystem):

Floor itemMeasured p50
Overwrite already-synced space + fdatasync, 4 KiB / 64 KiB / 1 MiB1.106 / 0.903 / 0.805 ms
Append + fsync or fdatasync (4 KiB to 1 MiB)3.5 to 3.8 ms
fallocated space + fdatasync3.715 ms
New blob file + fsync + rename + directory fsync6.401 ms
Sequential write, O_DIRECT / buffered0.138 / 0.263 s per GiB
Ed25519 verify / sign0.023 / 0.010 ms
Blob digest (12 KiB) / CRC-32C (request sized)0.021 / 0.001 ms

Floor per change at N agents (assumptions: ext4 file, not raw block device; the cheapest sync measured; all N changes share one sync; the essential CPU work runs on 20 cores in parallel):

One idle baseline throughout: the sweep's 30 s idle window, 22.731 W. floor.json stores per-operation above-idle energy against its own 5 s idle window (23.19 W), which gives 0.2504 mJ for the same four operations; re-based to 22.731 W (per operation: package joules minus 22.731 W times the operation's share of its window) they sum to 0.2766 mJ: verify 0.0919, sign 0.0165, blob digest 0.1655, CRC 0.0027 mJ. floor.json itself is unchanged; it was measured with the floor subcommand from the earlier build de17a0a (the floor is hardware and file system behaviour, and that subcommand did not change).

"Fraction of floor" = floor / measured. 1.0 would mean running at the floor.

6. Results (medians of 3)

ArmAgentss per changefloorfractionJ per change (pkg)floorfractionabove idlemean W
S1114.217 ms0.806 ms0.057305.2 mJ18.61 mJ0.061-18.0 mJ21.5
S312.048 ms0.806 ms0.39451.7 mJ18.61 mJ0.3604.9 mJ24.9
S1414.030 ms0.203 ms0.014316.3 mJ4.88 mJ0.015-3.0 mJ22.5
S340.726 ms0.203 ms0.27917.2 mJ4.88 mJ0.2830.7 mJ23.8
S1813.623 ms0.102 ms0.007376.9 mJ2.60 mJ0.00767.3 mJ27.7
S380.411 ms0.102 ms0.24812.9 mJ2.60 mJ0.2024.0 mJ33.1
S13214.038 ms0.027 ms0.002305.2 mJ0.88 mJ0.003-13.9 mJ21.7
S3320.349 ms0.027 ms0.0768.5 mJ0.88 mJ0.1040.6 mJ24.6

7. What Still Sits Between the Agent and the Floor

8. Limits

9. Reproduction

cargo build --release -p synapse-bench, then the two commands in section 4 with --out and --work-dir set. Verify the evidence with cd evidence/phase5-group-commit && sha256sum -c SHA256SUMS.