Files
OBLITERATUS/docs/distributed-two-host-protocol.md
T
Joseph Magly 7a96fa0d69 docs(distributed): document the two-host TP2 cross-host protocol and E3/E4 runbook
Documents the existing rank-local cross-host TP2 protocol (#365/#402): Gloo summary and chunk formats, vote order, coordinator-only durable publication and how each failure fails closed, in a new note so the policy digest of distributed-rank-local.md is unchanged. Adds a rented-hardware E3/E4 qualification runbook and fixes the stale two-host refusal text in conditional-testing.md. No runtime change; the reviewed rank_storage registry stays empty and status stays not_qualified.

Refs #287
2026-11-26 17:27:45 -05:00

8.6 KiB

Two-host TP2 cross-host protocol (#287)

Status: EXPERIMENTAL, not_qualified. This note describes the protocol so reviewers can find it in one place. The binding operator contract is the rank-local guide, and it wins wherever the two disagree. This file is not one of the rank_local.POLICY_FILES, so editing it does not change policy_digest().

Problem and chosen option

The schema v1/v2 protocol assumes both ranks can see one attempt tree. Rank 0 creates the attempt directory, the peer opens it, receipts are exchanged through files, model-load-evidence is shared, and EXPORT writers share one sibling destination. Two hosts without a shared filesystem cannot do that.

Of the two options in #287, the code implements the first: collectives instead of shared files. Each rank keeps its storage local. Only bounded, digest-bound records and fixed-size tensor frames cross the Gloo control plane. No peer-supplied pathname is ever opened. The shared-filesystem option remains design-only (plan).

Selection is explicit. The ranks use this protocol only when a schema v3 profile carries rank_storage and the profile matches an exact record in the reviewed registry ci/rank-local-profiles.json (rank_local.config_review). That registry is empty in this repository. Without such a record, v1/v2 behaviour and its refusals are unchanged.

Stage mapping

Shared-file step (v1/v2) Cross-host replacement (v3 rank_storage)
Rank 0 creates the attempt directory, peers open it Each rank runs create_attempt(root, run_id, rank), which creates <run_id>.rank-<rank> with O_EXCL, mode 0700, and an fsynced owner.json. Attempts cannot be reused.
Rank-zero nonce and terminal receipts in files exchange_summary phases PREFLIGHTED (seq 1) and PREPARED (seq 2) (preflight.py ~1521, ~2164)
Shared model-load-evidence Load evidence is written privately on each rank, and phase SOURCE_MOUNTS (seq 3) exchanges only source-mount digests (model_session.py ~865)
Writers share one destination tree Rank 0 is the only writer. Every canonical file is streamed to the peer with replicate_file (export.py ~1527).
Rank 0 validates, both ranks reload, rank 0 promotes Each rank validates and reloads its own complete tree independently. Only the coordinator publishes, through DurablePublication (export.py ~1721).
Qualification envelope Phase QUALIFICATION (seq 10) (rank_local_qualification.py ~70)

Message formats

All control records travel as canonical JSON (sorted keys, no NaN) through consensus.gloo_all_gather_records with a fixed byte capacity. A receiver checks that a record is a dict with exactly the expected keys and integer-typed integers, and that its canonical re-encoding equals the bytes received.

Summary record (capacity 8192 bytes, world size 2):

{"schema_version": 1, "run_id": "<run_id>", "identity": "<64-hex lifecycle digest>",
 "rank": 0, "phase": "PREFLIGHTED", "sequence": 1, "payload": {}}

Each gathered row must match the local run_id, identity, phase and sequence, and its rank must equal its position in the gather. Anything else raises ContractError ("stale, forged or out of phase"). The PREFLIGHTED payload is exactly {attestation_digest, mapping_digest, root_identity, attempt_identity}. Its attestation digest must equal the attested membership, and its mapping digest must equal rank_storage.mapping_digest.

Chunk record (capacity 1024 bytes), sent with each frame:

{"schema_version": 1, "identity": "<export identity>", "file_digest": "<sha256 of file>",
 "offset": 0, "size": 32768, "total": 1048576, "chunk_digest": "<sha256 of chunk>"}

The data travels as a uint8 tensor of exactly CHUNK_BYTES (32 KiB) through dist.broadcast(src=0). The receiver rejects a frame when the record differs from the expected one, when the offset is not chunk-aligned, when it overruns total, or when the padding past size is nonzero.

Vote sequence for one file

Every fallible local step ends in a unanimous_vote, in the same order on both ranks:

  1. Continue vote: cancellation first, then deadline.
  2. Prepare: rank 0 opens the source read-only and checks its size and link count. The receiver opens the target with O_CREAT|O_EXCL|O_NOFOLLOW beneath retained O_DIRECTORY|O_NOFOLLOW descriptors.
  3. For each chunk: a prepare vote, a continue vote, the record gather and frame broadcast, then a validate-and-append vote and another continue vote.
  4. Finalize: both ranks compare the complete SHA-256 with file_digest. The receiver sets the file read-only and fsyncs it. Rank 0 checks that its source inode did not change. Then a final vote and a continue vote.

A failed vote stops both ranks at the same step. No rank goes on alone.

Atomicity and promotion

Only the coordinator publishes. DurablePublication takes an exclusive fence directory .<output>.rank-local-fence and creates the state directory .<output>.rank-local-state-<export_id> and the staging directory .<output>.rank-local-stage-<export_id>. It writes append-only, fsynced phase records: PREPARED, STAGED, PROMOTION_INTENT, BACKED_UP, PROMOTED, COMMIT_DECIDED, ACKNOWLEDGED, COMPLETE, or ABORTED, UNCERTAIN or RETURN_UNCERTAIN.

The previous output moves to .<output>.rank-local-backup-<export_id> and stays there until both ranks agree on readiness. COMMIT_DECIDED is the irrevocable commit point. It is not atomic across ranks or across process death:

  • Before COMMIT_DECIDED, any loss returns LMS_EXPORT_STATE_UNCERTAIN and keeps the fence, the backup and the state records.
  • After it, the commit stands even if an acknowledgement is lost.

recovery_inventory() reports these states but does not repair anything.

Failure handling (fail closed)

Every row below is covered by multi-process Gloo tests on CPU, each rank with its own non-shared directory. _candidate_worker raises if a rank opens a path under its peer's root.

Failure Outcome Test (tests/test_distributed_rank_local_gloo.py)
Rank dies during preflight, writing, replication or reload Survivor returns an error, never success test_rank_death_is_bounded_and_never_claims_success[*_rank_death]
Coordinator killed at each publication state LMS_EXPORT_STATE_UNCERTAIN, and inventory reports uncertain ...[crash_PROMOTION_INTENT…crash_ACKNOWLEDGED]
Corrupt, truncated or replayed chunk (digest mismatch or partial transfer) Both ranks report an error, and the prior output is kept test_candidate_failure_matrix_fails_closed[corrupt_chunk, truncated_chunk, replayed_chunk]
Source truncated mid-stream, deadline, cancellation, cancellation callback fails on one rank Both refuse at the same frame boundary test_streaming_multiple_fixed_frames_and_midstream_truncation
Forged, stale or poisoned summary Both ranks refuse test_collective_summary_rejects_poison_stale_and_forged_records
Wrong storage observation or profile, resource denial, load, reload or tokenizer/index corruption, root replacement Error, and foreign or prior trees are kept test_candidate_failure_matrix_fails_closed
Peer cleanup fails, or an acknowledgement is lost before or after the decision Fence and backup kept; returns are uncertain without claiming atomic returns test_peer_cleanup_failure_…, test_post_decision_lost_ack_…
Directory swapped for a symlink during replication No write lands outside the root ...[intermediate_symlink]

Refusals that remain

LMS_TOPOLOGY_UNSUPPORTED (preflight layout admission), LMS_TP_PLAN_UNSUPPORTED (load) and LMS_EXPORT_TOPOLOGY_UNSUPPORTED (EXPORT entry votes 17_000_071 and 17_000_072) still refuse two-host v1/v2 configs, configs without a reviewed rank_storage record, and any disagreement between ranks about layout. Lifting them further would make the reviewed registry optional, which would weaken the integrity guarantee. That decision belongs to the maintainers.

Remaining work

  • Physical work: same-candidate E2, two-host E3 and over-capacity E4 evidence, following the runbook.
  • Software for E4: scripts/run_rank_local_qualification.py admits only the tiny E3 reference job. An E4 workload worker that uses the public live-session and export API with budgeted StreamingLlamaReload still has to be written and reviewed. rank_local_qualification and the checker already enforce the E4 capacity rule.
  • Issue item 3 (refreshing PROBE RAM observations) is tracked separately. The correction delivered with the shared-storage review covers part of it.