Consolidate causal identity ownership
This commit is contained in:
parent
80541843ae
commit
868a5be070
12 changed files with 494 additions and 4445 deletions
|
|
@ -137,17 +137,11 @@ pub fn commit_request(
|
|||
return Ok(None);
|
||||
}
|
||||
let previous_terminal_result_id = terminal.last().map(|result| result.result_id.clone());
|
||||
let causal = rmp_serde::to_vec_named(&(
|
||||
let request_id = crate::admitted_model_direction_request_id(
|
||||
&identity.runtime_id,
|
||||
&thread.thread_id,
|
||||
model.model_revision,
|
||||
&model_hash,
|
||||
&receipts[0].receipt_id,
|
||||
&previous_terminal_result_id,
|
||||
))?;
|
||||
let request_id = format!(
|
||||
"admitted-model-direction-consideration-{:x}",
|
||||
Sha256::digest(causal)
|
||||
previous_terminal_result_id.as_deref(),
|
||||
);
|
||||
let request = AdmittedModelDirectionConsiderationRequest {
|
||||
schema_version: REQUEST_SCHEMA.into(),
|
||||
|
|
|
|||
93
epiphany-core/src/causal_work_identity.rs
Normal file
93
epiphany-core/src/causal_work_identity.rs
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
use sha2::{Digest, Sha256};
|
||||
|
||||
fn digest_id(prefix: &str, causal_parts: &[&str]) -> String {
|
||||
let mut digest = Sha256::new();
|
||||
for part in causal_parts {
|
||||
digest.update((part.len() as u64).to_be_bytes());
|
||||
digest.update(part.as_bytes());
|
||||
}
|
||||
format!("{prefix}-{:x}", digest.finalize())
|
||||
}
|
||||
|
||||
pub fn proposal_modeling_request_id(
|
||||
runtime_id: &str,
|
||||
proposal_id: &str,
|
||||
payload_sha256: &str,
|
||||
) -> String {
|
||||
digest_id(
|
||||
"repo-frontier-proposal-modeling",
|
||||
&[runtime_id, proposal_id, payload_sha256],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn frontier_research_request_id(
|
||||
runtime_id: &str,
|
||||
model_hash: &str,
|
||||
frontier_item_hash: &str,
|
||||
) -> String {
|
||||
digest_id(
|
||||
"repo-frontier-research",
|
||||
&[runtime_id, model_hash, frontier_item_hash],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn frontier_planning_request_id(
|
||||
runtime_id: &str,
|
||||
model_hash: &str,
|
||||
frontier_item_hash: &str,
|
||||
) -> String {
|
||||
digest_id(
|
||||
"repo-frontier-planning",
|
||||
&[runtime_id, model_hash, frontier_item_hash],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn frontier_plan_mind_request_id(
|
||||
runtime_id: &str,
|
||||
planning_request_id: &str,
|
||||
imagination_result_id: &str,
|
||||
candidate_sha256: &str,
|
||||
) -> String {
|
||||
digest_id(
|
||||
"repo-frontier-plan-mind",
|
||||
&[
|
||||
runtime_id,
|
||||
planning_request_id,
|
||||
imagination_result_id,
|
||||
candidate_sha256,
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
pub fn admitted_model_direction_request_id(
|
||||
runtime_id: &str,
|
||||
model_hash: &str,
|
||||
admission_receipt_id: &str,
|
||||
previous_terminal_result_id: Option<&str>,
|
||||
) -> String {
|
||||
digest_id(
|
||||
"admitted-model-direction-consideration",
|
||||
&[
|
||||
runtime_id,
|
||||
model_hash,
|
||||
admission_receipt_id,
|
||||
previous_terminal_result_id.unwrap_or(""),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn provenance_does_not_participate_in_causal_identity() {
|
||||
let first = frontier_research_request_id("runtime", "model", "frontier");
|
||||
let after_thread_transition = frontier_research_request_id("runtime", "model", "frontier");
|
||||
assert_eq!(first, after_thread_transition);
|
||||
assert_ne!(
|
||||
first,
|
||||
frontier_research_request_id("runtime", "model", "other")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -56,6 +56,11 @@ fn commit_coordinator_job_launch_in_cache(
|
|||
"coordinator commit thread id must match typed launch document"
|
||||
));
|
||||
}
|
||||
if let Some(admitted_thread) = cache.get::<crate::EpiphanyThreadStateEntry>(crate::THREAD_STATE_KEY)? {
|
||||
if admitted_thread.thread_id != thread_id || admitted_thread.state()? != *current_state {
|
||||
return Err(anyhow!("coordinator launch carrier must use the current admitted thread"));
|
||||
}
|
||||
}
|
||||
let runtime_identity = cache
|
||||
.get::<EpiphanyRuntimeIdentity>(RUNTIME_IDENTITY_KEY)?
|
||||
.ok_or_else(|| anyhow!("coordinator launch requires runtime identity"))?;
|
||||
|
|
@ -742,8 +747,8 @@ fn validate_frontier_plan_mind_launch(
|
|||
.ok_or_else(|| anyhow!("Mind launch requires thread state"))?;
|
||||
if persisted.state()? != *state
|
||||
|| request.runtime_id != identity.runtime_id
|
||||
|| request.thread_id != persisted.thread_id
|
||||
|| launch.launch_document.thread_id() != request.thread_id
|
||||
|| request.thread_id.is_empty()
|
||||
|| launch.launch_document.thread_id() != persisted.thread_id
|
||||
{
|
||||
return Err(anyhow!("Mind launch provenance mismatch"));
|
||||
}
|
||||
|
|
@ -848,9 +853,8 @@ fn validate_frontier_planning_launch(
|
|||
let persisted_state_value = persisted_state.state()?;
|
||||
if planning.request_id != request_id
|
||||
|| planning.runtime_id != identity.runtime_id
|
||||
|| planning.thread_id != persisted_state.thread_id
|
||||
|| persisted_state_value != *state
|
||||
|| launch.launch_document.thread_id() != planning.thread_id
|
||||
|| launch.launch_document.thread_id() != persisted_state.thread_id
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"frontier planning launch provenance binding mismatch"
|
||||
|
|
@ -954,9 +958,9 @@ fn validate_imagination_consideration_launch(
|
|||
.get::<crate::EpiphanyThreadStateEntry>(crate::THREAD_STATE_KEY)?
|
||||
.ok_or_else(|| anyhow!("consideration requires thread state"))?;
|
||||
if request.runtime_id != identity.runtime_id
|
||||
|| request.thread_id != persisted.thread_id
|
||||
|| request.thread_id.is_empty()
|
||||
|| persisted.state()? != *state
|
||||
|| launch.launch_document.thread_id() != request.thread_id
|
||||
|| launch.launch_document.thread_id() != persisted.thread_id
|
||||
{
|
||||
return Err(anyhow!("consideration launch provenance mismatch"));
|
||||
}
|
||||
|
|
@ -1019,9 +1023,9 @@ fn validate_admitted_model_direction_consideration_launch(
|
|||
.get::<crate::EpiphanyThreadStateEntry>(crate::THREAD_STATE_KEY)?
|
||||
.ok_or_else(|| anyhow!("model direction consideration requires thread state"))?;
|
||||
if request.runtime_id != identity.runtime_id
|
||||
|| request.thread_id != persisted.thread_id
|
||||
|| request.thread_id.is_empty()
|
||||
|| persisted.state()? != *state
|
||||
|| launch.launch_document.thread_id() != request.thread_id
|
||||
|| launch.launch_document.thread_id() != persisted.thread_id
|
||||
{
|
||||
return Err(anyhow!("model direction consideration provenance mismatch"));
|
||||
}
|
||||
|
|
@ -2111,7 +2115,7 @@ pub(crate) mod tests {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn proposal_launch_restores_its_admitted_thread_after_resident_projection_transition(
|
||||
fn proposal_launch_cannot_restore_superseded_thread_authority(
|
||||
) -> Result<()> {
|
||||
let root = tempfile::tempdir()?;
|
||||
let (store, state, request, selection) =
|
||||
|
|
@ -2129,27 +2133,17 @@ pub(crate) mod tests {
|
|||
"launcher-after-transition".into(),
|
||||
"backend-after-transition".into(),
|
||||
)?;
|
||||
let committed = commit_coordinator_job_launch(
|
||||
let before = std::fs::read(&store)?;
|
||||
let error = commit_coordinator_job_launch(
|
||||
&store,
|
||||
&selection.thread_id,
|
||||
&state,
|
||||
&request,
|
||||
&plan,
|
||||
"2026-07-13T05:00:04Z".into(),
|
||||
)?;
|
||||
|
||||
let cache = coordinator_acceptance_cache(&store)?;
|
||||
let restored = cache
|
||||
.get::<EpiphanyThreadStateEntry>(THREAD_STATE_KEY)?
|
||||
.expect("launch restores admitted cognitive thread projection");
|
||||
assert_eq!(restored.thread_id, selection.thread_id);
|
||||
assert_eq!(restored.state()?, committed.epiphany_state);
|
||||
let binding = cache
|
||||
.get::<RepoFrontierProposalModelingLaunchBinding>(
|
||||
"repo-frontier-proposal-modeling-launch-backend-after-transition",
|
||||
)?
|
||||
.expect("launch preserves admitted proposal lineage");
|
||||
assert_eq!(binding.thread_id, selection.thread_id);
|
||||
).expect_err("superseded provenance cannot rewrite the admitted carrier thread");
|
||||
assert!(error.to_string().contains("current admitted thread"));
|
||||
assert_eq!(std::fs::read(&store)?, before);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
@ -2743,7 +2737,7 @@ pub(crate) mod tests {
|
|||
#[test]
|
||||
fn frontier_planning_launch_refuses_swapped_request_bytes_without_writes() -> Result<()> {
|
||||
let root = tempfile::tempdir()?;
|
||||
for mutation in 0..8 {
|
||||
for mutation in 0..7 {
|
||||
let (store, state, launch, planning) =
|
||||
frontier_planning_launch_fixture(root.path(), &format!("causal-{mutation}"))?;
|
||||
let mut corrupt = planning.clone();
|
||||
|
|
@ -2754,8 +2748,7 @@ pub(crate) mod tests {
|
|||
3 => corrupt.frontier_item_hash = "swapped-frontier-hash".into(),
|
||||
4 => corrupt.selected_organ = "Hands".into(),
|
||||
5 => corrupt.source_scope.push("outside/scope".into()),
|
||||
6 => corrupt.runtime_id = "swapped-runtime".into(),
|
||||
_ => corrupt.thread_id = "swapped-thread".into(),
|
||||
_ => corrupt.runtime_id = "swapped-runtime".into(),
|
||||
}
|
||||
let mut cache = coordinator_acceptance_cache(&store)?;
|
||||
cache.put(&corrupt.request_id, &corrupt)?;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
mod agent_launch;
|
||||
mod agent_memory;
|
||||
mod agent_utterance_state;
|
||||
mod causal_work_identity;
|
||||
mod continuity_gateway;
|
||||
mod coordinator_acceptance;
|
||||
mod coordinator_interrupt;
|
||||
|
|
@ -33,6 +34,7 @@ mod persona_feedback_admission;
|
|||
mod persona_turn;
|
||||
mod process_observation;
|
||||
mod promotion;
|
||||
mod public_source_identity;
|
||||
mod prompt_context;
|
||||
mod proposal;
|
||||
mod repo_model_gateway;
|
||||
|
|
@ -189,6 +191,7 @@ pub use agent_utterance_state::AgentUtterancePersonalityVectors;
|
|||
pub use agent_utterance_state::AgentUtteranceState;
|
||||
pub use agent_utterance_state::AgentUtteranceValue;
|
||||
pub use agent_utterance_state::WEKSA_UTTERANCE_HANDOFF_SCHEMA_VERSION;
|
||||
pub use causal_work_identity::*;
|
||||
pub use agent_utterance_state::derive_agent_utterance_state;
|
||||
pub use continuity_gateway::*;
|
||||
pub use coordinator_acceptance::EpiphanyAcceptancePrerequisite;
|
||||
|
|
@ -967,6 +970,7 @@ pub use process_observation::observe_native_process;
|
|||
pub use process_observation::observe_process_instance;
|
||||
pub use process_observation::reap_exited_child_process;
|
||||
pub use process_observation::terminate_process_instance;
|
||||
pub use public_source_identity::ImmutableGithubSource;
|
||||
pub use promotion::EpiphanyPromotionDecision;
|
||||
pub use promotion::EpiphanyPromotionInput;
|
||||
pub use promotion::EpiphanyStateReplacementValidationInput;
|
||||
|
|
|
|||
152
epiphany-core/src/public_source_identity.rs
Normal file
152
epiphany-core/src/public_source_identity.rs
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
use anyhow::{Result, anyhow};
|
||||
use std::fmt::{Display, Formatter};
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd)]
|
||||
pub struct ImmutableGithubSource {
|
||||
owner: String,
|
||||
repository: String,
|
||||
revision: String,
|
||||
path: String,
|
||||
}
|
||||
|
||||
impl ImmutableGithubSource {
|
||||
pub fn from_components(
|
||||
owner: &str,
|
||||
repository: &str,
|
||||
revision: &str,
|
||||
path: &str,
|
||||
) -> Result<Self> {
|
||||
validate_component(owner, "owner")?;
|
||||
validate_component(repository, "repository")?;
|
||||
if revision.len() != 40 || !revision.bytes().all(|byte| byte.is_ascii_hexdigit()) {
|
||||
return Err(anyhow!(
|
||||
"GitHub revision must be an immutable 40-hex commit id"
|
||||
));
|
||||
}
|
||||
validate_path(path)?;
|
||||
Ok(Self {
|
||||
owner: owner.into(),
|
||||
repository: repository.into(),
|
||||
revision: revision.to_ascii_lowercase(),
|
||||
path: path.into(),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn parse(source_ref: &str) -> Result<Self> {
|
||||
let rest = source_ref
|
||||
.strip_prefix("github://")
|
||||
.ok_or_else(|| anyhow!("immutable GitHub source must use github://"))?;
|
||||
let (repository_identity, target) = rest
|
||||
.split_once('@')
|
||||
.ok_or_else(|| anyhow!("immutable GitHub source requires an exact revision"))?;
|
||||
if target.contains('@') {
|
||||
return Err(anyhow!(
|
||||
"immutable GitHub source contains multiple revisions"
|
||||
));
|
||||
}
|
||||
let (owner, repository) = repository_identity
|
||||
.split_once('/')
|
||||
.ok_or_else(|| anyhow!("immutable GitHub source requires owner/repository"))?;
|
||||
if repository.contains('/') {
|
||||
return Err(anyhow!("immutable GitHub repository identity is not exact"));
|
||||
}
|
||||
let (revision, path) = target
|
||||
.split_once('/')
|
||||
.ok_or_else(|| anyhow!("immutable GitHub source requires a repository path"))?;
|
||||
Self::from_components(owner, repository, revision, path)
|
||||
}
|
||||
|
||||
pub fn owner(&self) -> &str {
|
||||
&self.owner
|
||||
}
|
||||
pub fn repository_name(&self) -> &str {
|
||||
&self.repository
|
||||
}
|
||||
pub fn revision(&self) -> &str {
|
||||
&self.revision
|
||||
}
|
||||
pub fn path(&self) -> &str {
|
||||
&self.path
|
||||
}
|
||||
pub fn repository_ref(&self) -> String {
|
||||
format!("github://{}/{}", self.owner, self.repository)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ImmutableGithubSource {
|
||||
fn fmt(&self, formatter: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
formatter,
|
||||
"{}@{}/{}",
|
||||
self.repository_ref(),
|
||||
self.revision,
|
||||
self.path
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn validate_component(value: &str, name: &str) -> Result<()> {
|
||||
if value.is_empty()
|
||||
|| value.len() > 100
|
||||
|| !value
|
||||
.bytes()
|
||||
.all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_' | b'.'))
|
||||
{
|
||||
return Err(anyhow!("GitHub {name} is invalid"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_path(path: &str) -> Result<()> {
|
||||
if path.is_empty()
|
||||
|| path.len() > 512
|
||||
|| path.starts_with('/')
|
||||
|| path.split('/').any(|segment| {
|
||||
segment.is_empty()
|
||||
|| matches!(segment, "." | "..")
|
||||
|| !segment
|
||||
.bytes()
|
||||
.all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_' | b'.'))
|
||||
})
|
||||
{
|
||||
return Err(anyhow!("GitHub repository path is invalid"));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn canonicalizes_and_round_trips() -> Result<()> {
|
||||
let source = ImmutableGithubSource::from_components(
|
||||
"GameCult",
|
||||
"Epiphany",
|
||||
"ABCDEF0123456789ABCDEF0123456789ABCDEF01",
|
||||
"docs/source_file.rs",
|
||||
)?;
|
||||
assert_eq!(
|
||||
source.revision(),
|
||||
"abcdef0123456789abcdef0123456789abcdef01"
|
||||
);
|
||||
assert_eq!(ImmutableGithubSource::parse(&source.to_string())?, source);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn refuses_mutable_or_ambiguous_identity() {
|
||||
for source_ref in [
|
||||
"https://github.com/GameCult/Epiphany",
|
||||
"github://GameCult/Epiphany@main/README.md",
|
||||
"github://GameCult/Epiphany@0123456789abcdef0123456789abcdef01234567/../secret",
|
||||
"github://GameCult/Epiphany@0123456789abcdef0123456789abcdef01234567//secret",
|
||||
"github://GameCult/other/repo@0123456789abcdef0123456789abcdef01234567/file",
|
||||
] {
|
||||
assert!(
|
||||
ImmutableGithubSource::parse(source_ref).is_err(),
|
||||
"{source_ref}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3736,20 +3736,22 @@ pub(crate) fn authenticated_public_source_lookups_for_worker(
|
|||
.ok_or_else(|| anyhow!("public source receipt has no result"))?,
|
||||
)
|
||||
.context("public source receipt result is invalid")?;
|
||||
let owner = public_source_json_string(&arguments, "owner")?;
|
||||
let repository_name = public_source_json_string(&arguments, "repository")?;
|
||||
let revision = public_source_json_string(&arguments, "revision")?.to_ascii_lowercase();
|
||||
let path = public_source_json_string(&arguments, "path")?;
|
||||
let source = crate::ImmutableGithubSource::from_components(
|
||||
public_source_json_string(&arguments, "owner")?,
|
||||
public_source_json_string(&arguments, "repository")?,
|
||||
public_source_json_string(&arguments, "revision")?,
|
||||
public_source_json_string(&arguments, "path")?,
|
||||
)?;
|
||||
let content = public_source_json_string(&result, "content")?;
|
||||
let repository = format!("github://{owner}/{repository_name}");
|
||||
let source_ref = format!("{repository}@{revision}/{path}");
|
||||
let repository = source.repository_ref();
|
||||
let source_ref = source.to_string();
|
||||
let content_sha256 = format!("{:x}", Sha256::digest(content.as_bytes()));
|
||||
let byte_count = content.len() as u64;
|
||||
let lookup_receipt_id = format!("eyes-source-{}", intent.intent_id);
|
||||
if public_source_json_string(&result, "provider")? != "github"
|
||||
|| public_source_json_string(&result, "repository")? != repository
|
||||
|| public_source_json_string(&result, "revision")? != revision
|
||||
|| public_source_json_string(&result, "path")? != path
|
||||
|| public_source_json_string(&result, "revision")? != source.revision()
|
||||
|| public_source_json_string(&result, "path")? != source.path()
|
||||
|| public_source_json_string(&result, "sourceRef")? != source_ref
|
||||
|| public_source_json_string(&result, "contentSha256")? != content_sha256
|
||||
|| result.get("byteCount").and_then(serde_json::Value::as_u64)
|
||||
|
|
@ -3767,8 +3769,8 @@ pub(crate) fn authenticated_public_source_lookups_for_worker(
|
|||
tool_receipt_id: receipt.receipt_id,
|
||||
provider: "github".to_string(),
|
||||
repository,
|
||||
revision,
|
||||
path: path.to_string(),
|
||||
revision: source.revision().to_string(),
|
||||
path: source.path().to_string(),
|
||||
source_ref,
|
||||
content_sha256,
|
||||
byte_count,
|
||||
|
|
@ -4811,10 +4813,6 @@ fn validate_proposal_modeling_worker_fulfillment(
|
|||
EpiphanyWorkerLaunchDocument::Reorient(_) => None,
|
||||
};
|
||||
let identity = require_identity(cache)?;
|
||||
let thread = cache
|
||||
.get::<crate::EpiphanyThreadStateEntry>(crate::THREAD_STATE_KEY)?
|
||||
.ok_or_else(|| anyhow!("proposal Modeling fulfillment thread state is missing"))?;
|
||||
thread.state()?;
|
||||
let payload = rmp_serde::to_vec_named(&(
|
||||
&proposal.title,
|
||||
&proposal.body,
|
||||
|
|
@ -4853,12 +4851,13 @@ fn validate_proposal_modeling_worker_fulfillment(
|
|||
"request.payload",
|
||||
request.proposal_payload_sha256 != proposal.payload_sha256,
|
||||
),
|
||||
("request.identity", request.request_id != crate::proposal_modeling_request_id(&request.runtime_id, &request.proposal_id, &request.proposal_payload_sha256)),
|
||||
(
|
||||
"proposal.payload",
|
||||
proposal.payload_sha256 != proposal_payload_sha256,
|
||||
),
|
||||
("request.runtime", request.runtime_id != identity.runtime_id),
|
||||
("request.thread", request.thread_id != thread.thread_id),
|
||||
("request.thread", request.thread_id != proposal.thread_id),
|
||||
(
|
||||
"request.repository",
|
||||
request.repository != proposal.repository,
|
||||
|
|
@ -4895,7 +4894,7 @@ fn validate_proposal_modeling_worker_fulfillment(
|
|||
binding.binding_id != EPIPHANY_MODELING_ROLE_BINDING_ID,
|
||||
),
|
||||
("binding.runtime", binding.runtime_id != identity.runtime_id),
|
||||
("binding.thread", binding.thread_id != thread.thread_id),
|
||||
("binding.thread", binding.thread_id != request.thread_id),
|
||||
(
|
||||
"binding.time",
|
||||
chrono::DateTime::parse_from_rfc3339(&binding.launched_at).is_err(),
|
||||
|
|
@ -6738,10 +6737,7 @@ pub fn promote_autonomous_direction_options_for_modeling(
|
|||
};
|
||||
let selection = RepoFrontierProposalModelingRequest {
|
||||
schema_version: REPO_FRONTIER_PROPOSAL_MODELING_REQUEST_SCHEMA_VERSION.into(),
|
||||
request_id: format!(
|
||||
"repo-frontier-proposal-modeling-{:x}",
|
||||
Sha256::digest(format!("{}:{}", proposal_id, payload_sha256).as_bytes())
|
||||
),
|
||||
request_id: crate::proposal_modeling_request_id(&identity.runtime_id, &proposal_id, &payload_sha256),
|
||||
proposal_id: proposal_id.clone(),
|
||||
proposal_payload_sha256: payload_sha256,
|
||||
runtime_id: identity.runtime_id.clone(),
|
||||
|
|
@ -6959,10 +6955,7 @@ pub fn select_repo_frontier_work_proposal_for_modeling(
|
|||
if proposal.source_kind == crate::RepoFrontierProposalSourceKind::Imagination {
|
||||
validate_autonomous_proposal_binding(&cache, &proposal)?;
|
||||
}
|
||||
let thread = cache
|
||||
.get::<crate::EpiphanyThreadStateEntry>(crate::THREAD_STATE_KEY)?
|
||||
.ok_or_else(|| anyhow!("proposal selection requires authoritative thread state"))?;
|
||||
if proposal.runtime_id != identity.runtime_id || proposal.thread_id != thread.thread_id {
|
||||
if proposal.runtime_id != identity.runtime_id {
|
||||
return Err(anyhow!("proposal selection provenance mismatch"));
|
||||
}
|
||||
let existing_requests = cache.get_all::<RepoFrontierProposalModelingRequest>()?;
|
||||
|
|
@ -6978,10 +6971,7 @@ pub fn select_repo_frontier_work_proposal_for_modeling(
|
|||
return Err(anyhow!("proposal already incorporated"));
|
||||
}
|
||||
}
|
||||
let request_id = format!(
|
||||
"repo-frontier-proposal-modeling-{:x}",
|
||||
Sha256::digest(format!("{}:{}", proposal.proposal_id, proposal.payload_sha256).as_bytes())
|
||||
);
|
||||
let request_id = crate::proposal_modeling_request_id(&proposal.runtime_id, &proposal.proposal_id, &proposal.payload_sha256);
|
||||
let request = RepoFrontierProposalModelingRequest {
|
||||
schema_version: REPO_FRONTIER_PROPOSAL_MODELING_REQUEST_SCHEMA_VERSION.into(),
|
||||
request_id: request_id.clone(),
|
||||
|
|
@ -7064,16 +7054,7 @@ pub fn select_and_commit_repo_frontier_planning_request(
|
|||
let item = actionable_imagination_frontier_item(&model, &challenges)
|
||||
.ok_or_else(|| anyhow!("planning requires an actionable Imagination frontier"))?;
|
||||
let item_hash = format!("{:x}", Sha256::digest(rmp_serde::to_vec_named(item)?));
|
||||
let request_id = format!(
|
||||
"repo-frontier-planning-{:x}",
|
||||
Sha256::digest(
|
||||
format!(
|
||||
"{}:{}:{model_hash}:{}:{item_hash}",
|
||||
identity.runtime_id, thread.thread_id, item.id
|
||||
)
|
||||
.as_bytes(),
|
||||
)
|
||||
);
|
||||
let request_id = crate::frontier_planning_request_id(&identity.runtime_id, &model_hash, &item_hash);
|
||||
if cache
|
||||
.get_all::<RepoFrontierPlanDecisionReceipt>()?
|
||||
.iter()
|
||||
|
|
@ -7162,16 +7143,7 @@ pub(crate) fn validate_current_repo_frontier_planning_request(
|
|||
let item = actionable_imagination_frontier_item(&model, &challenges)
|
||||
.ok_or_else(|| anyhow!("planning request frontier is no longer actionable"))?;
|
||||
let item_hash = format!("{:x}", Sha256::digest(rmp_serde::to_vec_named(item)?));
|
||||
let expected_request_id = format!(
|
||||
"repo-frontier-planning-{:x}",
|
||||
Sha256::digest(
|
||||
format!(
|
||||
"{}:{}:{model_hash}:{}:{item_hash}",
|
||||
identity.runtime_id, thread.thread_id, item.id
|
||||
)
|
||||
.as_bytes(),
|
||||
)
|
||||
);
|
||||
let expected_request_id = crate::frontier_planning_request_id(&identity.runtime_id, &model_hash, &item_hash);
|
||||
if request.schema_version != REPO_FRONTIER_PLANNING_REQUEST_SCHEMA_VERSION
|
||||
|| request.contract != REPO_FRONTIER_PLANNING_CONTRACT
|
||||
|| request.request_id != expected_request_id
|
||||
|
|
@ -7183,10 +7155,10 @@ pub(crate) fn validate_current_repo_frontier_planning_request(
|
|||
|| request.selected_organ != "Imagination"
|
||||
|| request.source_scope != item.source_scope
|
||||
|| request.runtime_id != identity.runtime_id
|
||||
|| request.thread_id != thread.thread_id
|
||||
|| request.thread_id.is_empty()
|
||||
{
|
||||
return Err(anyhow!(
|
||||
"planning request does not exactly bind current model, frontier, runtime, and thread"
|
||||
"planning request does not exactly bind current model, frontier, and runtime"
|
||||
));
|
||||
}
|
||||
Ok(())
|
||||
|
|
@ -7227,16 +7199,7 @@ pub fn commit_repo_frontier_plan_mind_request(
|
|||
validate_current_repo_frontier_planning_request(&cache, &planning)?;
|
||||
validate_repo_frontier_plan_candidate_against_request(&cache, &candidate, &planning)?;
|
||||
let candidate_sha256 = format!("{:x}", Sha256::digest(rmp_serde::to_vec_named(&candidate)?));
|
||||
let request_id = format!(
|
||||
"repo-frontier-plan-mind-{:x}",
|
||||
Sha256::digest(
|
||||
format!(
|
||||
"{}:{}:{}:{}",
|
||||
planning.runtime_id, planning.thread_id, result.result_id, candidate_sha256
|
||||
)
|
||||
.as_bytes()
|
||||
)
|
||||
);
|
||||
let request_id = crate::frontier_plan_mind_request_id(&planning.runtime_id, &planning.request_id, &result.result_id, &candidate_sha256);
|
||||
let request = RepoFrontierPlanMindRequest {
|
||||
schema_version: REPO_FRONTIER_PLAN_MIND_REQUEST_SCHEMA_VERSION.into(),
|
||||
request_id: request_id.clone(),
|
||||
|
|
@ -8741,18 +8704,12 @@ pub fn select_and_commit_repo_frontier_research_request(
|
|||
let mut public_source_refs = item
|
||||
.evidence_refs
|
||||
.iter()
|
||||
.filter(|source_ref| immutable_github_source_ref(source_ref))
|
||||
.cloned()
|
||||
.filter_map(|source_ref| crate::ImmutableGithubSource::parse(source_ref).ok())
|
||||
.map(|source| source.to_string())
|
||||
.collect::<Vec<_>>();
|
||||
public_source_refs.sort();
|
||||
public_source_refs.dedup();
|
||||
let request_id = format!(
|
||||
"repo-frontier-research-{:x}",
|
||||
Sha256::digest(
|
||||
format!("{}:{}:{item_hash}", identity.runtime_id, model_hash)
|
||||
.as_bytes()
|
||||
)
|
||||
);
|
||||
let request_id = crate::frontier_research_request_id(&identity.runtime_id, &model_hash, &item_hash);
|
||||
let request = RepoFrontierResearchRequest {
|
||||
schema_version: REPO_FRONTIER_RESEARCH_REQUEST_SCHEMA_VERSION.to_string(),
|
||||
request_id: request_id.clone(),
|
||||
|
|
@ -8874,18 +8831,12 @@ fn repo_frontier_research_request_is_current(
|
|||
let mut expected_public_source_refs = item
|
||||
.evidence_refs
|
||||
.iter()
|
||||
.filter(|source_ref| immutable_github_source_ref(source_ref))
|
||||
.cloned()
|
||||
.filter_map(|source_ref| crate::ImmutableGithubSource::parse(source_ref).ok())
|
||||
.map(|source| source.to_string())
|
||||
.collect::<Vec<_>>();
|
||||
expected_public_source_refs.sort();
|
||||
expected_public_source_refs.dedup();
|
||||
let expected_request_id = format!(
|
||||
"repo-frontier-research-{:x}",
|
||||
Sha256::digest(
|
||||
format!("{}:{}:{item_hash}", identity.runtime_id, model_hash)
|
||||
.as_bytes()
|
||||
)
|
||||
);
|
||||
let expected_request_id = crate::frontier_research_request_id(&identity.runtime_id, &model_hash, &item_hash);
|
||||
let admission_count = cache
|
||||
.get_all::<RepoModelAdmissionReceipt>()?
|
||||
.into_iter()
|
||||
|
|
@ -10681,43 +10632,6 @@ fn safe_sorted_unique_paths(paths: &[String]) -> bool {
|
|||
})
|
||||
}
|
||||
|
||||
fn immutable_github_source_ref(source_ref: &str) -> bool {
|
||||
let Some(rest) = source_ref.strip_prefix("github://") else {
|
||||
return false;
|
||||
};
|
||||
let Some((owner, rest)) = rest.split_once('/') else {
|
||||
return false;
|
||||
};
|
||||
let Some((repository, revision_and_path)) = rest.split_once('@') else {
|
||||
return false;
|
||||
};
|
||||
let Some((revision, path)) = revision_and_path.split_once('/') else {
|
||||
return false;
|
||||
};
|
||||
let repository_component = |value: &str| {
|
||||
!value.is_empty()
|
||||
&& value.len() <= 100
|
||||
&& value.bytes().all(|byte| {
|
||||
byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_' | b'.')
|
||||
})
|
||||
};
|
||||
repository_component(owner)
|
||||
&& repository_component(repository)
|
||||
&& revision.len() == 40
|
||||
&& revision
|
||||
.bytes()
|
||||
.all(|byte| byte.is_ascii_digit() || matches!(byte, b'a'..=b'f'))
|
||||
&& !path.is_empty()
|
||||
&& path.len() <= 512
|
||||
&& path.split('/').all(|segment| {
|
||||
!segment.is_empty()
|
||||
&& !matches!(segment, "." | "..")
|
||||
&& segment.bytes().all(|byte| {
|
||||
byte.is_ascii_alphanumeric() || matches!(byte, b'-' | b'_' | b'.')
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
fn validate_hands_consequence_grant(
|
||||
store_path: &Path,
|
||||
intent_id: &str,
|
||||
|
|
@ -16430,9 +16344,9 @@ pub(crate) mod tests {
|
|||
"2026-07-13T02:02:00Z",
|
||||
)?;
|
||||
let mut second = first.clone();
|
||||
second.request_id = "repo-frontier-proposal-modeling-queued-second".into();
|
||||
second.proposal_id = "queued-second-proposal".into();
|
||||
second.proposal_payload_sha256 = "22".repeat(32);
|
||||
second.request_id = crate::proposal_modeling_request_id(&second.runtime_id, &second.proposal_id, &second.proposal_payload_sha256);
|
||||
second.selected_at = "2026-07-13T02:03:00Z".into();
|
||||
validate_repo_frontier_proposal_modeling_request(&second)?;
|
||||
overwrite_test_entry(&store, &second.request_id, &second)?;
|
||||
|
|
|
|||
Reference in a new issue