Reclaim the lend on every exit path, and cut three leftovers
`take_oracle` now runs above the caller-identity and expiry gates, so a refused `infer` reclaims the lend instead of leaving a dead lane's tool-result owner in the map under a request id nothing will call again. The port's doc already claimed this; the test that recorded the divergence now asserts the reclaim. `fixture_prepared` was `prepare_invocation`'s body a third time, with the same caller id and the same expiry as `fixture_prepared_inference` beside it. Its call sites use that one instead. `ElaboratorSession`, `ElaborationCheckpoint`, `SeedSession`, and `SeedCheckpoint` go back to `pub(super)`: nothing outside `world` names them, and `pub(crate)` was reach they never needed. `private_interfaces` then reports them the way it already reports the grouped, narrative, and operational checkpoints, which are private under the same `pub(crate)` `ControllerWork`. Runtime binds the SDK model prefix from `DEFAULT_SDK_MODEL_PREFIX` rather than spelling `claude` twice more. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
a791d559d5
commit
d72c246b1f
5 changed files with 34 additions and 51 deletions
|
|
@ -13,11 +13,11 @@ use crate::{
|
|||
AffordanceId, CONSUMER_BODY_LIMIT, CellRun, CommandBody, CommandId, ConnectorBinding,
|
||||
ConsumerPort, ConsumerRegistry, ControllerError, ControllerModels, ControllerPendingReason,
|
||||
ControllerRunner, ControllerWorkCustody, Cover, CoverBudget, CreateJurisdictionIntent,
|
||||
CreateWorldIntent, DecisionInvocation, DecisionOpportunity, KernelError, MailboxError,
|
||||
NarrativeRun, OperationalRun, PrincipalCommandIntent, PrincipalId, SdkBinding, SeedOutcome,
|
||||
SeedPort, Statement, SubjectKind, SubmissionDisposition, SubmitReceipt, TickMinutes,
|
||||
VaultEvidenceSource, WorldMailbox, WorldPhase, WorldSnapshot, derive_cover,
|
||||
open_controller_work, open_inference,
|
||||
CreateWorldIntent, DEFAULT_SDK_MODEL_PREFIX, DecisionInvocation, DecisionOpportunity,
|
||||
KernelError, MailboxError, NarrativeRun, OperationalRun, PrincipalCommandIntent,
|
||||
PrincipalId, SdkBinding, SeedOutcome, SeedPort, Statement, SubjectKind,
|
||||
SubmissionDisposition, SubmitReceipt, TickMinutes, VaultEvidenceSource, WorldMailbox,
|
||||
WorldPhase, WorldSnapshot, derive_cover, open_controller_work, open_inference,
|
||||
},
|
||||
};
|
||||
use anyhow::{Context, bail, ensure};
|
||||
|
|
@ -443,7 +443,7 @@ fn open_controller(
|
|||
sidecar_entry,
|
||||
caller_runtime_id: runtime_id.to_owned(),
|
||||
model_prefix: std::env::var("GHOSTLIGHT_SDK_MODEL_PREFIX")
|
||||
.unwrap_or_else(|_| "claude".into()),
|
||||
.unwrap_or_else(|_| DEFAULT_SDK_MODEL_PREFIX.into()),
|
||||
});
|
||||
let inference = open_inference(connector, sdk, &models)?;
|
||||
let work = open_controller_work(service_root.join("controller-work.cc"))?;
|
||||
|
|
@ -3634,7 +3634,7 @@ mod tests {
|
|||
sidecar_entry,
|
||||
caller_runtime_id: runtime_id,
|
||||
model_prefix: std::env::var("GHOSTLIGHT_SDK_MODEL_PREFIX")
|
||||
.unwrap_or_else(|_| "claude".into()),
|
||||
.unwrap_or_else(|_| DEFAULT_SDK_MODEL_PREFIX.into()),
|
||||
}),
|
||||
models: ControllerModels {
|
||||
projector: env("GHOSTLIGHT_CONTROLLER_PROJECTOR_MODEL"),
|
||||
|
|
|
|||
|
|
@ -6749,7 +6749,7 @@ mod tests {
|
|||
#[async_trait]
|
||||
impl InferencePort for RecordingPort {
|
||||
fn prepare(&self, request: InferenceRequest) -> Result<PreparedInference, InferenceFault> {
|
||||
fixture_prepared(request)
|
||||
fixture_prepared_inference(request)
|
||||
}
|
||||
|
||||
async fn infer(
|
||||
|
|
@ -6785,25 +6785,6 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
fn fixture_prepared(request: InferenceRequest) -> Result<PreparedInference, InferenceFault> {
|
||||
let native_request_sha256 = Sha256::digest(
|
||||
serde_json::to_vec(&request).map_err(|error| InferenceFault::new(error.to_string()))?,
|
||||
)
|
||||
.into();
|
||||
let purpose = request.purpose;
|
||||
let invocation = CodexTransportInvocation::new(
|
||||
"ghostlight-controller-test",
|
||||
4_102_444_800_000,
|
||||
native_request_sha256,
|
||||
request.provider,
|
||||
)
|
||||
.map_err(|error| InferenceFault::new(error.to_string()))?;
|
||||
Ok(PreparedInference {
|
||||
purpose,
|
||||
invocation,
|
||||
})
|
||||
}
|
||||
|
||||
/// The digest-bound components a fixture subject carries. A literal rather
|
||||
/// than a constructor on `ScopeComponents`: the kernel derives these from
|
||||
/// state and owes no test builder.
|
||||
|
|
@ -6868,7 +6849,7 @@ mod tests {
|
|||
opportunity: opportunity.clone(),
|
||||
granted,
|
||||
completed,
|
||||
invocation: fixture_prepared(request).unwrap(),
|
||||
invocation: fixture_prepared_inference(request).unwrap(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -7522,7 +7503,7 @@ mod tests {
|
|||
opportunity: opportunity.clone(),
|
||||
granted: vec![speak_snapshot(opportunity.affordance_ids[0])],
|
||||
completed,
|
||||
invocation: fixture_prepared(request).unwrap(),
|
||||
invocation: fixture_prepared_inference(request).unwrap(),
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -8571,7 +8552,7 @@ mod tests {
|
|||
#[async_trait]
|
||||
impl InferencePort for ElaborationScript {
|
||||
fn prepare(&self, request: InferenceRequest) -> Result<PreparedInference, InferenceFault> {
|
||||
fixture_prepared(request)
|
||||
fixture_prepared_inference(request)
|
||||
}
|
||||
|
||||
async fn infer(
|
||||
|
|
@ -11785,7 +11766,7 @@ mod tests {
|
|||
#[async_trait]
|
||||
impl InferencePort for InterruptingPort {
|
||||
fn prepare(&self, request: InferenceRequest) -> Result<PreparedInference, InferenceFault> {
|
||||
fixture_prepared(request)
|
||||
fixture_prepared_inference(request)
|
||||
}
|
||||
|
||||
async fn infer(
|
||||
|
|
@ -12458,7 +12439,7 @@ mod tests {
|
|||
opportunity: moved.clone(),
|
||||
granted: vec![speak_snapshot(moved.affordance_ids[0])],
|
||||
completed: Vec::new(),
|
||||
invocation: fixture_prepared(
|
||||
invocation: fixture_prepared_inference(
|
||||
interpreter_request(command_id, 1, "interpreter", Vec::new()).unwrap(),
|
||||
)
|
||||
.unwrap(),
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ const ELABORATION_INSTRUCTIONS: &str = "Use only the supplied tools to author st
|
|||
/// The answer a session is bound to, plus the ancestry it was built against.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(crate) struct ElaboratorSession {
|
||||
pub(super) struct ElaboratorSession {
|
||||
pub(super) world_id: WorldId,
|
||||
pub(super) jurisdiction: JurisdictionKey,
|
||||
pub(super) answer: PatchAnswer,
|
||||
|
|
@ -73,7 +73,7 @@ pub(crate) struct ElaboratorSession {
|
|||
/// came from the kernel, not the model.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(tag = "stage", rename_all = "snake_case")]
|
||||
pub(crate) enum ElaborationCheckpoint {
|
||||
pub(super) enum ElaborationCheckpoint {
|
||||
ElaboratorInFlight {
|
||||
command_id: CommandId,
|
||||
session: ElaboratorSession,
|
||||
|
|
@ -1174,7 +1174,7 @@ const SEED_INSTRUCTIONS: &str = "Use only the supplied tools to author living st
|
|||
/// answer field it must never submit would be a field that lies.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(deny_unknown_fields)]
|
||||
pub(crate) struct SeedSession {
|
||||
pub(super) struct SeedSession {
|
||||
pub(super) world_id: WorldId,
|
||||
pub(super) jurisdiction: JurisdictionKey,
|
||||
pub(super) kind: SubjectKind,
|
||||
|
|
@ -1202,7 +1202,7 @@ fn seed_command_id(session: &SeedSession) -> Result<CommandId, ControllerError>
|
|||
/// the conversation does not produce.
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
|
||||
#[serde(tag = "stage", rename_all = "snake_case")]
|
||||
pub(crate) enum SeedCheckpoint {
|
||||
pub(super) enum SeedCheckpoint {
|
||||
SeedInFlight {
|
||||
command_id: CommandId,
|
||||
session: SeedSession,
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ use patch::{
|
|||
};
|
||||
#[cfg(test)]
|
||||
pub(crate) use patch::{AuthorityGrantRef, AuthorityTargetRef};
|
||||
pub(crate) use sdk_inference::SdkBinding;
|
||||
pub(crate) use sdk_inference::{DEFAULT_SDK_MODEL_PREFIX, SdkBinding};
|
||||
pub(crate) use vault::VaultEvidenceSource;
|
||||
// Test-only narrowing of the controller organ's inference and work-store
|
||||
// seams, so `runtime`'s own spec tests can drive `ControllerRunner` over a
|
||||
|
|
|
|||
|
|
@ -352,7 +352,7 @@ const SDK_RECEIPT_SCHEMA: &str = "ghostlight.sdk_inference_receipt.v1";
|
|||
/// one. It holds even with no SDK port built, so a `claude-`prefixed lane on a
|
||||
/// connector-only deployment is refused at open instead of quietly reaching the
|
||||
/// wrong backend.
|
||||
pub(super) const DEFAULT_SDK_MODEL_PREFIX: &str = "claude";
|
||||
pub(crate) const DEFAULT_SDK_MODEL_PREFIX: &str = "claude";
|
||||
|
||||
/// Everything the SDK sidecar needs to open, gathered so `open_inference` takes
|
||||
/// a binding rather than reading the environment itself.
|
||||
|
|
@ -675,6 +675,10 @@ impl InferencePort for SdkInferencePort {
|
|||
}
|
||||
|
||||
async fn infer(&self, request: PreparedInference) -> Result<InferenceOutput, InferenceFault> {
|
||||
// Above every gate, so the lend is reclaimed on every exit path. An
|
||||
// oracle left behind by a refused invocation would keep a dead lane's
|
||||
// tool-result owner alive under a request id nothing will call again.
|
||||
let oracle = self.take_oracle(&request.invocation.request.request_id);
|
||||
if request.invocation.caller_runtime_id != self.caller_runtime_id {
|
||||
return Err(InferenceFault::integrity_violation(
|
||||
"persisted inference caller does not match the configured runtime identity",
|
||||
|
|
@ -685,7 +689,6 @@ impl InferencePort for SdkInferencePort {
|
|||
"persisted inference invocation expired before it reached the SDK sidecar",
|
||||
));
|
||||
}
|
||||
let oracle = self.take_oracle(&request.invocation.request.request_id);
|
||||
let has_tools = !request.invocation.request.tools.is_empty();
|
||||
let turn_cap = match (&oracle, has_tools) {
|
||||
(Some(oracle), true) => oracle.remaining_rounds(),
|
||||
|
|
@ -1516,13 +1519,10 @@ mod tests {
|
|||
assert!(fault.integrity_was_violated(), "{fault:?}");
|
||||
}
|
||||
|
||||
/// Soul: a lend whose `infer` is refused before the oracle is taken leaves
|
||||
/// the entry in the map. The port's own doc says the entry is removed on
|
||||
/// every exit path of `infer`; the caller-identity and expiry gates run
|
||||
/// before the take, so it is not. Bounded by the request id's uniqueness
|
||||
/// and therefore not a leak that grows, but the claim as written is false.
|
||||
/// Soul: the take runs above every gate, so a refused `infer` reclaims the
|
||||
/// lend rather than leaving a dead lane's tool-result owner in the map.
|
||||
#[tokio::test]
|
||||
async fn soul_a_lend_refused_before_the_take_is_not_reclaimed() {
|
||||
async fn soul_a_lend_refused_before_the_query_is_still_reclaimed() {
|
||||
let port = SdkInferencePort::new(ScriptedLink::new(Vec::new()), TEST_RUNTIME);
|
||||
let stale = prepare_invocation(TEST_RUNTIME, 1_000, prose_request("Say something true."))
|
||||
.expect("the stale invocation builds");
|
||||
|
|
@ -1531,13 +1531,12 @@ mod tests {
|
|||
Box::new(ElaborationOracle::new(&[], SEED_ROUND_BUDGET)),
|
||||
);
|
||||
assert!(port.infer(stale.clone()).await.is_err());
|
||||
assert_eq!(
|
||||
port.oracles.lock().unwrap().len(),
|
||||
1,
|
||||
"the expiry gate now reclaims the lend; update this test's claim"
|
||||
assert!(
|
||||
port.oracles.lock().unwrap().is_empty(),
|
||||
"the expiry gate left the lend behind"
|
||||
);
|
||||
|
||||
// A caller-identity mismatch does the same.
|
||||
// A caller-identity mismatch reclaims it too.
|
||||
let other = SdkInferencePort::new(ScriptedLink::new(Vec::new()), "ghostlight-other");
|
||||
other.lend_tool_results(
|
||||
&stale,
|
||||
|
|
@ -1548,7 +1547,10 @@ mod tests {
|
|||
.await
|
||||
.expect_err("a foreign caller's invocation ran");
|
||||
assert!(fault.integrity_was_violated(), "{fault:?}");
|
||||
assert_eq!(other.oracles.lock().unwrap().len(), 1);
|
||||
assert!(
|
||||
other.oracles.lock().unwrap().is_empty(),
|
||||
"the caller-identity gate left the lend behind"
|
||||
);
|
||||
|
||||
// A completed query does reclaim its own lend.
|
||||
let link = ScriptedLink::new(vec![SidecarFrame::Output {
|
||||
|
|
|
|||
Loading…
Reference in a new issue