Admit v10 mutation choices through the cellular host and sessions

The region host checks a choice against the committed offer, reserves the
successor for the next tick, and publishes it with that tick's batch; the
owner's v10 session gets the receipt and final outcome. Schema v35 now
refuses a checkpoint that skips a reserved choice, and the host reloads
pending reservations after uncertainty, refusal or recovery (ADR-0121).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
dingo
2026-10-13 19:45:23 -04:00
co-authored by Claude Opus 5.5
parent 1bbac48543
commit f59c8498b1
14 changed files with 583 additions and 12 deletions
@@ -203,6 +203,24 @@ BEGIN
RETURN n;
END $$;
-- Choices of this region reserved for a tick in (begin, end] and not bound to another
-- commit. A checkpoint must carry every one of them: a reserved choice that a later
-- checkpoint skipped could never publish and would block its account's next choice.
CREATE INDEX cellular_mutation_reservations_by_tick
ON evolution.cellular_mutation_reservations(world_id, region_id, target_tick);
CREATE FUNCTION evolution.cellular_mutations_due(p_manifest bytea)
RETURNS integer LANGUAGE plpgsql STABLE SECURITY INVOKER
SET search_path = pg_catalog, pg_temp AS $$
DECLARE c evolution.checkpoint_manifest := evolution.parse_checkpoint_manifest(p_manifest);
BEGIN
RETURN (SELECT count(*) FROM evolution.cellular_mutation_reservations r
WHERE r.world_id = c.world_id AND r.region_id = c.region_id
AND r.target_tick > c.begin_tick AND r.target_tick <= c.end_tick
AND NOT EXISTS (SELECT 1 FROM evolution.cellular_mutation_action_publications p
WHERE p.world_id = r.world_id AND p.account_id = r.account_id
AND p.action_id = r.action_id AND p.commit_id <> c.commit_id));
END $$;
-- True when this commit already bound exactly these actions with these results.
CREATE FUNCTION evolution.cellular_mutation_publications_match(p_world evolution.u64,
p_commit uuid, p_mutations bytea, p_results bytea)
@@ -242,6 +260,11 @@ BEGIN
IF EXISTS (SELECT 1 FROM evolution.cellular_mutation_selections(p_trace, p_manifest)) THEN
RAISE EXCEPTION 'cellular mutation selections need their action block' USING ERRCODE = '22023';
END IF;
IF NOT EXISTS (SELECT 1 FROM evolution.region_commits x
WHERE x.commit_id = (evolution.parse_checkpoint_manifest(p_manifest)).commit_id)
AND evolution.cellular_mutations_due(p_manifest) <> 0 THEN
RAISE EXCEPTION 'cellular checkpoint omits a reserved mutation' USING ERRCODE = '22023';
END IF;
RETURN QUERY SELECT * FROM evolution.publish_cellular_birth_checkpoint(
p_manifest, p_decisions, p_actions, p_trace);
END $$;
@@ -270,6 +293,9 @@ BEGIN
p_manifest, p_decisions, p_actions, p_trace);
RETURN;
END IF;
IF evolution.cellular_mutations_due(p_manifest) <> n THEN
RAISE EXCEPTION 'cellular checkpoint omits a reserved mutation' USING ERRCODE = '22023';
END IF;
-- A choice binds to one commit only; another commit's binding is a reused identity.
FOR i IN 0 .. n - 1 LOOP
IF EXISTS (SELECT 1 FROM evolution.cellular_mutation_action_publications p
@@ -342,6 +368,7 @@ BEGIN
END $$;
REVOKE ALL ON FUNCTION evolution.cellular_mutation_selections(bytea, bytea),
evolution.cellular_mutations_due(bytea),
evolution.check_cellular_mutation_block(bytea, bytea, bytea, bytea),
evolution.cellular_mutation_publications_match(evolution.u64, uuid, bytea, bytea),
evolution.publish_cellular_checkpoint(bytea, bytea, bytea, bytea),