connector-many-callers: one connector serves every Mind as its own caller; session handles are an HMAC under a connector secret over caller, session, instance, instructions, model and transcript prefix; config add-caller/add-lease-caller; one owner for distinct admissions (squash of eureka-body/connector-many-callers d1f25b5..a96b276; Soul s1-s2)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-30 00:11:53 +01:00
commit fdcfa063c7
14 changed files with 1228 additions and 150 deletions

View file

@ -19,7 +19,7 @@ use crate::envelope::{
use crate::readout::PlanQuotaSnapshot;
use crate::service::{
CallerAdmission, PriceTable, ProviderCall, SpendCeiling, SpendWindowMs, TransportAdmission,
TransportService,
TransportService, distinct_admissions,
};
/// The only provider seam of the connector kit. A connector binary implements
@ -87,6 +87,7 @@ impl ServeLimits {
if admissions.is_empty() {
return Err(ServeError::InvalidConfig("callers"));
}
distinct_admissions(admissions)?;
let slots = admissions
.iter()
.try_fold(0_usize, |total, caller| {
@ -950,6 +951,26 @@ mod tests {
));
}
#[test]
fn the_limits_refuse_callers_that_share_a_key_or_an_id() {
let limits = limits();
let shared_key = [
caller("one", "shared-key", 1),
caller("two", "shared-key", 1),
];
assert!(matches!(
limits.validate(&shared_key),
Err(ServeError::Service(ServiceError::SharedCallerKey))
));
let shared_id = [caller("one", "key-a", 1), caller("one", "key-b", 1)];
assert!(matches!(
limits.validate(&shared_id),
Err(ServeError::Service(ServiceError::DuplicateCaller))
));
let distinct = [caller("one", "key-a", 1), caller("two", "key-b", 1)];
assert!(limits.validate(&distinct).is_ok());
}
#[test]
fn only_loopback_peers_are_admitted() {
assert!(peer_admitted(IpAddr::from([127, 0, 0, 1])));

View file

@ -47,6 +47,24 @@ pub struct SpendCeiling(pub u64);
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct SpendWindowMs(pub u64);
/// The rule that admitted callers are distinct: no two share a connection key
/// (a key names its caller), and no two share a caller id. `TransportService`
/// opens only under it, and a readiness check that must agree with opening
/// asks the same function.
pub fn distinct_admissions(admissions: &[CallerAdmission]) -> Result<(), ServiceError> {
let mut keys = HashSet::new();
let mut ids = HashSet::new();
for admission in admissions {
if !keys.insert(admission.security.0) {
return Err(ServiceError::SharedCallerKey);
}
if !ids.insert(admission.caller_runtime_id.as_str()) {
return Err(ServiceError::DuplicateCaller);
}
}
Ok(())
}
pub struct CallerAdmission {
caller_runtime_id: String,
connection_key_epoch: u32,
@ -388,6 +406,12 @@ impl ProviderCall {
&self.request
}
/// The caller this call was admitted for: the caller whose key sealed the
/// invocation, never a name the request carries.
pub fn caller_runtime_id(&self) -> &str {
&self.receipt.caller_runtime_id
}
/// How many foreign reasoning items the service removed from the request.
pub fn foreign_reasoning_dropped(&self) -> u32 {
self.receipt.foreign_reasoning_dropped
@ -533,17 +557,12 @@ impl TransportService {
{
return Err(ServiceError::InvalidAdmission);
}
let mut callers = HashMap::new();
let mut keys = HashSet::new();
for admission in admissions {
if !keys.insert(admission.security.0) {
return Err(ServiceError::SharedCallerKey);
}
let caller_runtime_id = admission.caller_runtime_id.clone();
if callers.insert(caller_runtime_id, admission).is_some() {
return Err(ServiceError::DuplicateCaller);
}
}
let admissions: Vec<CallerAdmission> = admissions.into_iter().collect();
distinct_admissions(&admissions)?;
let callers: HashMap<String, CallerAdmission> = admissions
.into_iter()
.map(|admission| (admission.caller_runtime_id.clone(), admission))
.collect();
if callers.is_empty() {
return Err(ServiceError::InvalidAdmission);
}
@ -3800,6 +3819,28 @@ mod tests {
assert_eq!((idle.spent_micro_usd, idle.reserved_micro_usd), (0, 0));
}
#[test]
fn any_admitted_caller_reads_every_callers_row() {
let store = TestStore::new();
let mut service = open_service(&store, 4);
let claim = claim_at(&mut service, "request-1", 1_000);
let result = text_result(claim.call(), "done");
service.complete(*claim, result, FRAME).unwrap();
// Ghostlight asks, with its own key, and sees epiphany's spend.
let readout = readout_as(
&service,
"ghostlight-yggdrasil",
"ghostlight-distinct-test-key",
1_500,
FRAME,
)
.unwrap();
assert_eq!(row(&readout, CALLER).spent_micro_usd, FIXTURE_USAGE_COST);
assert_eq!(row(&readout, "ghostlight-yggdrasil").spent_micro_usd, 0);
// A key that belongs to no admitted caller reads nothing.
assert!(readout_as(&service, "ghostlight-yggdrasil", KEY, 1_500, FRAME).is_err());
}
#[test]
fn a_claim_a_crash_left_reads_as_spent_not_reserved() {
let store = TestStore::new();