pub const SEED_LABELS: &[&str] = &[
"pack.mmr_tiebreak",
"pack.selection_id",
"pack.skipped_order",
"search.score_jitter",
"search.canonical_ties",
"search.rerank",
"ulid.memory",
"ulid.audit",
"ulid.workspace",
"ulid.pack",
"clustering.kmeans_init",
"counterfactual.replay",
"lab.replay",
];
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct SeedLabelDefinition {
pub label: &'static str,
pub producer_call_site: &'static str,
pub consumer: &'static str,
}
impl SeedLabelDefinition {
#[must_use]
pub const fn new(
label: &'static str,
producer_call_site: &'static str,
consumer: &'static str,
) -> Self {
Self {
label,
producer_call_site,
consumer,
}
}
}
pub const SEED_LABEL_REGISTRY: &[SeedLabelDefinition] = &[
SeedLabelDefinition::new(
"pack.mmr_tiebreak",
"src/pack/mod.rs:assemble_mmr_draft",
"MMR diversity tie-breaks during pack assembly",
),
SeedLabelDefinition::new(
"pack.selection_id",
"src/core/context.rs:persist_pack_record",
"Context pack selection and persisted pack IDs",
),
SeedLabelDefinition::new(
"pack.skipped_order",
"src/pack/mod.rs:PackDraft::skipped_for_output",
"Stable ordering for omitted or skipped candidates",
),
SeedLabelDefinition::new(
"search.score_jitter",
"src/core/search.rs:run_search",
"Deterministic score perturbation for stability tests",
),
SeedLabelDefinition::new(
"search.canonical_ties",
"src/core/search.rs:canonicalize_equivalent_component_scores",
"Stable ordering for equal-score search results",
),
SeedLabelDefinition::new(
"search.rerank",
"src/core/search.rs:search_sync",
"Rerank-stage deterministic tie-breaks",
),
SeedLabelDefinition::new(
"ulid.memory",
"src/models/id.rs:Id::now_seeded",
"Memory UUIDv7 generation",
),
SeedLabelDefinition::new(
"ulid.audit",
"src/db/mod.rs:generate_audit_id_seeded",
"Audit UUIDv7 generation",
),
SeedLabelDefinition::new(
"ulid.workspace",
"src/core/workspace.rs:stable_workspace_id_seeded",
"Workspace UUIDv7 generation",
),
SeedLabelDefinition::new(
"ulid.pack",
"src/core/context.rs:persist_pack_record_seeded",
"Context pack UUIDv7 generation",
),
SeedLabelDefinition::new(
"clustering.kmeans_init",
"src/curate/cluster_coherence.rs:centroid_hash",
"Cluster centroid hash derivation",
),
SeedLabelDefinition::new(
"counterfactual.replay",
"src/core/lab.rs:run_counterfactual",
"Counterfactual replay child seed",
),
SeedLabelDefinition::new(
"lab.replay",
"src/core/lab.rs:replay_episode",
"Lab replay child seed",
),
];
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum DeterministicTokenShape {
Shared,
Mutable,
}
impl DeterministicTokenShape {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Shared => "&Deterministic<Seed>",
Self::Mutable => "&mut Deterministic<Seed>",
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ThreadingSurfaceDefinition {
pub surface: &'static str,
pub token_shape: DeterministicTokenShape,
}
impl ThreadingSurfaceDefinition {
#[must_use]
pub const fn new(surface: &'static str, token_shape: DeterministicTokenShape) -> Self {
Self {
surface,
token_shape,
}
}
}
pub const THREADING_SURFACES: &[&str] = &[
"crate::core::search::run_search",
"crate::core::search::canonicalize_equivalent_component_scores",
"crate::core::search::search_sync",
"crate::pack::assemble_draft_with_profile_and_options",
"crate::pack::assemble_mmr_draft",
"crate::models::Id::now",
"crate::db::generate_audit_id",
"crate::core::workspace::stable_workspace_id",
"crate::core::context::persist_pack_record",
"crate::runtime::determinism::DeterministicClock::next_uuid_v7",
];
pub const THREADING_SURFACE_REGISTRY: &[ThreadingSurfaceDefinition] = &[
ThreadingSurfaceDefinition::new(
"crate::core::search::run_search",
DeterministicTokenShape::Shared,
),
ThreadingSurfaceDefinition::new(
"crate::core::search::canonicalize_equivalent_component_scores",
DeterministicTokenShape::Shared,
),
ThreadingSurfaceDefinition::new(
"crate::core::search::search_sync",
DeterministicTokenShape::Shared,
),
ThreadingSurfaceDefinition::new(
"crate::pack::assemble_draft_with_profile_and_options",
DeterministicTokenShape::Shared,
),
ThreadingSurfaceDefinition::new(
"crate::pack::assemble_mmr_draft",
DeterministicTokenShape::Shared,
),
ThreadingSurfaceDefinition::new("crate::models::Id::now", DeterministicTokenShape::Mutable),
ThreadingSurfaceDefinition::new(
"crate::db::generate_audit_id",
DeterministicTokenShape::Mutable,
),
ThreadingSurfaceDefinition::new(
"crate::core::workspace::stable_workspace_id",
DeterministicTokenShape::Mutable,
),
ThreadingSurfaceDefinition::new(
"crate::core::context::persist_pack_record",
DeterministicTokenShape::Shared,
),
ThreadingSurfaceDefinition::new(
"crate::runtime::determinism::DeterministicClock::next_uuid_v7",
DeterministicTokenShape::Mutable,
),
];
#[must_use]
pub fn is_label_registered(label: &str) -> bool {
SEED_LABELS.contains(&label)
}
#[must_use]
pub fn seed_label_definition(label: &str) -> Option<&'static SeedLabelDefinition> {
SEED_LABEL_REGISTRY
.iter()
.find(|definition| definition.label == label)
}
pub fn assert_label_registered(label: &str) {
assert!(
is_label_registered(label),
"unregistered deterministic seed-derivation label `{label}`"
);
}