Delete ToolResultOracle, InferencePort::lend_tool_results, and the four oracle structs
With SdkInferencePort removed, zero surviving inference ports consume lend_tool_results (only no-op defaults and forwarding wrappers remained). Remove the trait, method, forwarding arms, ElaborationOracle, InterpreterOracle, GroupedOracle, OperationalOracle, and their oracle tests.
This commit is contained in:
parent
ccf8533c6e
commit
2b25a2f766
6 changed files with 6 additions and 836 deletions
|
|
@ -426,36 +426,11 @@ pub(super) fn tool_name_is_valid(name: &str) -> bool {
|
|||
.all(|byte| byte.is_ascii_alphanumeric() || byte == b'_' || byte == b'-')
|
||||
}
|
||||
|
||||
/// One lane's own answer to "what does this tool call return", lent to the
|
||||
/// inference port for exactly one query. A port that runs the tool loop needs a
|
||||
/// real result before the model will take another turn, and the only correct
|
||||
/// result is the one the lane's evaluator will recompute when it re-derives the
|
||||
/// finished round from `completed`. So this is not a second implementation: it
|
||||
/// is the same fold, over the calls made so far, into fresh state. A port that
|
||||
/// computed its own answer would put a string in front of the model that no
|
||||
/// durable evidence records and no check can catch.
|
||||
pub trait ToolResultOracle: Send {
|
||||
/// The lane's remaining round budget, lowered to a transport's turn cap so
|
||||
/// one query cannot exceed what the evaluator would have allowed.
|
||||
fn remaining_rounds(&self) -> u32;
|
||||
|
||||
/// The next call in this query. Errors are the lane's own hard contract
|
||||
/// errors; the port aborts the query rather than inventing a string.
|
||||
fn answer(&mut self, name: &str, arguments: &str) -> Result<String, ControllerError>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait InferencePort: Send + Sync {
|
||||
fn prepare(&self, request: InferenceRequest) -> Result<PreparedInference, InferenceFault>;
|
||||
|
||||
async fn infer(&self, request: PreparedInference) -> Result<InferenceOutput, InferenceFault>;
|
||||
|
||||
/// Lends a lane's tool-result owner to the port for one query, keyed by the
|
||||
/// prepared request's own id. The default ignores it: the connector returns
|
||||
/// tool calls inert and the evaluator computes every result at
|
||||
/// re-derivation, so only a port that runs the tool loop needs one.
|
||||
fn lend_tool_results(&self, _prepared: &PreparedInference, _oracle: Box<dyn ToolResultOracle>) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Wraps any `InferencePort` and appends every prepared request and its output
|
||||
|
|
@ -552,10 +527,6 @@ impl InferencePort for TracingInferencePort {
|
|||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn lend_tool_results(&self, prepared: &PreparedInference, oracle: Box<dyn ToolResultOracle>) {
|
||||
self.inner.lend_tool_results(prepared, oracle);
|
||||
}
|
||||
}
|
||||
|
||||
impl PreparedInference {
|
||||
|
|
@ -3510,10 +3481,6 @@ impl ControllerRunner {
|
|||
};
|
||||
self.ensure_scope_unchanged(&opportunity).await?;
|
||||
let model = invocation.invocation.request.model.clone();
|
||||
self.inference.lend_tool_results(
|
||||
&invocation,
|
||||
Box::new(OperationalOracle::new(&granted, &completed)),
|
||||
);
|
||||
let output = match self.infer(invocation).await {
|
||||
Ok(output) => output,
|
||||
Err(error) => match inference_pending_reason(&error) {
|
||||
|
|
@ -3852,10 +3819,6 @@ impl ControllerRunner {
|
|||
));
|
||||
};
|
||||
let model = invocation.invocation.request.model.clone();
|
||||
self.inference.lend_tool_results(
|
||||
&invocation,
|
||||
Box::new(GroupedOracle::new(&constituents, &completed)),
|
||||
);
|
||||
let output = match self.infer(invocation).await {
|
||||
Ok(output) => output,
|
||||
Err(error) => match inference_pending_reason(&error) {
|
||||
|
|
@ -4307,10 +4270,6 @@ impl ControllerRunner {
|
|||
));
|
||||
};
|
||||
let model = invocation.invocation.request.model.clone();
|
||||
self.inference.lend_tool_results(
|
||||
&invocation,
|
||||
Box::new(InterpreterOracle::new(&turn, &completed)),
|
||||
);
|
||||
let output = match self.infer(invocation).await {
|
||||
Ok(output) => output,
|
||||
Err(error) => match inference_pending_reason(&error) {
|
||||
|
|
@ -6273,46 +6232,6 @@ pub(super) fn interpreter_tool_result(
|
|||
}
|
||||
}
|
||||
|
||||
/// Replays every completed round's calls into fresh state, then answers this
|
||||
/// query's calls in order. Construction is the replay: after it, `answer` is
|
||||
/// exactly the evaluator's next step.
|
||||
pub(super) struct InterpreterOracle {
|
||||
source: PersonaTurn,
|
||||
fold: InterpreterFold,
|
||||
remaining: u32,
|
||||
}
|
||||
|
||||
impl InterpreterOracle {
|
||||
pub(super) fn new(source: &PersonaTurn, completed: &[InferenceOutput]) -> Self {
|
||||
let mut fold = InterpreterFold::new(source.clone());
|
||||
for output in completed {
|
||||
for event in &output.events {
|
||||
if let InferenceEvent::ToolCall {
|
||||
name, arguments, ..
|
||||
} = event
|
||||
{
|
||||
let _ = interpreter_tool_result(&mut fold, name, arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
Self {
|
||||
source: source.clone(),
|
||||
fold,
|
||||
remaining: TOOL_STEP_BUDGET.saturating_sub(completed.len()) as u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolResultOracle for InterpreterOracle {
|
||||
fn remaining_rounds(&self) -> u32 {
|
||||
self.remaining
|
||||
}
|
||||
|
||||
fn answer(&mut self, name: &str, arguments: &str) -> Result<String, ControllerError> {
|
||||
Ok(interpreter_tool_result(&mut self.fold, name, arguments))
|
||||
}
|
||||
}
|
||||
|
||||
fn evaluate_interpreter_loop(
|
||||
source: &PersonaTurn,
|
||||
prompt: &str,
|
||||
|
|
@ -6599,45 +6518,6 @@ pub(super) fn grouped_tool_result(
|
|||
})
|
||||
}
|
||||
|
||||
/// The grouped lane's replay-then-answer oracle. Same shape as the
|
||||
/// interpreter's, over `CELL_TOOL_STEP_BUDGET`.
|
||||
pub(super) struct GroupedOracle {
|
||||
constituents: Vec<ConstituentWork>,
|
||||
fold: GroupedFold,
|
||||
remaining: u32,
|
||||
}
|
||||
|
||||
impl GroupedOracle {
|
||||
pub(super) fn new(constituents: &[ConstituentWork], completed: &[InferenceOutput]) -> Self {
|
||||
let mut fold = GroupedFold::new();
|
||||
for output in completed {
|
||||
for event in &output.events {
|
||||
if let InferenceEvent::ToolCall {
|
||||
name, arguments, ..
|
||||
} = event
|
||||
{
|
||||
let _ = grouped_tool_result(constituents, &mut fold, name, arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
Self {
|
||||
constituents: constituents.to_vec(),
|
||||
fold,
|
||||
remaining: CELL_TOOL_STEP_BUDGET.saturating_sub(completed.len()) as u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolResultOracle for GroupedOracle {
|
||||
fn remaining_rounds(&self) -> u32 {
|
||||
self.remaining
|
||||
}
|
||||
|
||||
fn answer(&mut self, name: &str, arguments: &str) -> Result<String, ControllerError> {
|
||||
grouped_tool_result(&self.constituents, &mut self.fold, name, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
fn evaluate_grouped_loop(
|
||||
prompt: &str,
|
||||
constituents: &[ConstituentWork],
|
||||
|
|
@ -6889,48 +6769,6 @@ pub(super) fn operational_tool_result(
|
|||
})
|
||||
}
|
||||
|
||||
/// The operational lane's replay-then-answer oracle. `begin_round` runs at
|
||||
/// every replayed round boundary and once more after the replay, so the live
|
||||
/// query's first call sees `terminal_choice: None` exactly as round *n* does.
|
||||
pub(super) struct OperationalOracle {
|
||||
granted: Vec<AffordanceSnapshot>,
|
||||
fold: OperationalFold,
|
||||
remaining: u32,
|
||||
}
|
||||
|
||||
impl OperationalOracle {
|
||||
pub(super) fn new(granted: &[AffordanceSnapshot], completed: &[InferenceOutput]) -> Self {
|
||||
let mut fold = OperationalFold::new();
|
||||
for output in completed {
|
||||
fold.begin_round();
|
||||
for event in &output.events {
|
||||
if let InferenceEvent::ToolCall {
|
||||
name, arguments, ..
|
||||
} = event
|
||||
{
|
||||
let _ = operational_tool_result(granted, &mut fold, name, arguments);
|
||||
}
|
||||
}
|
||||
}
|
||||
fold.begin_round();
|
||||
Self {
|
||||
granted: granted.to_vec(),
|
||||
fold,
|
||||
remaining: TOOL_STEP_BUDGET.saturating_sub(completed.len()) as u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolResultOracle for OperationalOracle {
|
||||
fn remaining_rounds(&self) -> u32 {
|
||||
self.remaining
|
||||
}
|
||||
|
||||
fn answer(&mut self, name: &str, arguments: &str) -> Result<String, ControllerError> {
|
||||
operational_tool_result(&self.granted, &mut self.fold, name, arguments)
|
||||
}
|
||||
}
|
||||
|
||||
fn evaluate_operational_loop(
|
||||
prompt: &str,
|
||||
granted: &[AffordanceSnapshot],
|
||||
|
|
@ -11367,40 +11205,6 @@ assert!(projector_text.contains("I ask about the hinge."), "the player's own tur
|
|||
)
|
||||
}
|
||||
|
||||
/// A tool-call event as the SDK port would report one.
|
||||
fn oracle_call(call_id: &str, name: &str, arguments: &str) -> InferenceEvent {
|
||||
InferenceEvent::ToolCall {
|
||||
call_id: call_id.into(),
|
||||
name: name.into(),
|
||||
arguments: arguments.into(),
|
||||
}
|
||||
}
|
||||
|
||||
fn oracle_round(calls: &[(&str, &str, &str)], receipt: &str) -> InferenceOutput {
|
||||
InferenceOutput {
|
||||
events: calls
|
||||
.iter()
|
||||
.map(|(id, name, arguments)| oracle_call(id, name, arguments))
|
||||
.collect(),
|
||||
receipt_digest: format!("sha256:{receipt}"),
|
||||
usage: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn tool_results(conversation: &[InputItem]) -> Vec<String> {
|
||||
conversation
|
||||
.iter()
|
||||
.filter_map(|item| match item {
|
||||
InputItem::ToolResult { output, .. } => Some(output.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A quote the kernel would refuse as speech is a translation gap at
|
||||
/// capture, never an infrastructure fault at invocation: on the second SDK
|
||||
/// road run a mis-spanned utterance failed the canonical-text rule inside
|
||||
|
||||
/// The display tool is `speak`'s twin, and both take a turn's address as
|
||||
/// spans: an utterance split by narration is cited span by span and joins
|
||||
/// in prose order; several visible acts join into one display; a span
|
||||
|
|
@ -11516,147 +11320,6 @@ assert!(projector_text.contains("I ask about the hinge."), "the player's own tur
|
|||
assert_eq!(captured.source().start_byte(), source.find("The rain").unwrap());
|
||||
}
|
||||
|
||||
/// Spec test 1, interpreter lane. The string the oracle hands the model is
|
||||
/// the string the evaluator recomputes for the same call, in order.
|
||||
#[test]
|
||||
fn the_interpreter_oracle_answers_what_its_evaluator_recomputes() {
|
||||
let opportunity = fixture_opportunity(ControllerMode::NarrativePersona);
|
||||
let source = "I say, \"The rain has teeth tonight.\"";
|
||||
let turn = fixture_persona_turn(&opportunity, source);
|
||||
let speech = "The rain has teeth tonight.";
|
||||
let span = json!({ "source_quote": speech }).to_string();
|
||||
let calls: Vec<(&str, &str, &str)> = vec![
|
||||
("call-0", INTERPRETER_SPEAK_TOOL, span.as_str()),
|
||||
// The same words a second time: an overlap, so the fold's
|
||||
// ambiguity path is exercised.
|
||||
("call-1", INTERPRETER_SPEAK_TOOL, span.as_str()),
|
||||
("call-2", INTERPRETER_RECORD_GAP_TOOL, "not json at all"),
|
||||
("call-3", "speek", "{}"),
|
||||
];
|
||||
let mut oracle = InterpreterOracle::new(&turn, &[]);
|
||||
let answers: Vec<String> = calls
|
||||
.iter()
|
||||
.map(|(_, name, arguments)| oracle.answer(name, arguments).unwrap())
|
||||
.collect();
|
||||
let output = oracle_round(&calls, "interpreter-oracle");
|
||||
let InterpreterLoopEvaluation::Continue { conversation } =
|
||||
evaluate_interpreter_loop(&turn, "Translate the prose.", &[output]).unwrap()
|
||||
else {
|
||||
panic!("a non-terminal interpreter round finalized")
|
||||
};
|
||||
assert_eq!(answers, tool_results(&conversation));
|
||||
}
|
||||
|
||||
/// Spec test 1, operational lane, plus spec test 2's replay: an oracle
|
||||
/// seeded from a completed round continues the same fold, and its
|
||||
/// `terminal_choice` resets at the round boundary while `needs` does not.
|
||||
#[test]
|
||||
fn the_operational_oracle_answers_what_its_evaluator_recomputes() {
|
||||
let opportunity = fixture_opportunity(ControllerMode::OperationalAgent);
|
||||
let granted = vec![speak_snapshot(opportunity.affordance_ids[0])];
|
||||
let speak = granted[0].entry.kind.0.clone();
|
||||
let first: Vec<(&str, &str, &str)> = vec![
|
||||
("call-0", RECORD_NEED_TOOL, r#"{"detail":"no route"}"#),
|
||||
("call-1", RECORD_NEED_TOOL, "not json at all"),
|
||||
// A granted tool whose arguments do not decode: a need, not a
|
||||
// terminal choice, so the round stays open.
|
||||
("call-2", speak.as_str(), "not json at all"),
|
||||
("call-3", "speek", "{}"),
|
||||
];
|
||||
let mut oracle = OperationalOracle::new(&granted, &[]);
|
||||
let answers: Vec<String> = first
|
||||
.iter()
|
||||
.map(|(_, name, arguments)| oracle.answer(name, arguments).unwrap())
|
||||
.collect();
|
||||
let round_zero = oracle_round(&first, "operational-oracle");
|
||||
let OperationalLoopEvaluation::Continue { conversation } =
|
||||
evaluate_operational_loop("Hold the bridge.", &granted, &[round_zero.clone()]).unwrap()
|
||||
else {
|
||||
panic!("a non-terminal operational round finalized")
|
||||
};
|
||||
assert_eq!(answers, tool_results(&conversation));
|
||||
|
||||
// Round one, from an oracle constructed over round zero.
|
||||
let second: Vec<(&str, &str, &str)> = vec![
|
||||
("call-4", RECORD_NEED_TOOL, r#"{"detail":"still no route"}"#),
|
||||
("call-5", "speek", "{}"),
|
||||
];
|
||||
let mut resumed = OperationalOracle::new(&granted, &[round_zero.clone()]);
|
||||
let resumed_answers: Vec<String> = second
|
||||
.iter()
|
||||
.map(|(_, name, arguments)| resumed.answer(name, arguments).unwrap())
|
||||
.collect();
|
||||
let round_one = oracle_round(&second, "operational-oracle-one");
|
||||
let OperationalLoopEvaluation::Continue { conversation } =
|
||||
evaluate_operational_loop("Hold the bridge.", &granted, &[round_zero, round_one])
|
||||
.unwrap()
|
||||
else {
|
||||
panic!("a non-terminal operational round finalized")
|
||||
};
|
||||
assert_eq!(
|
||||
resumed_answers,
|
||||
tool_results(&conversation)[first.len()..].to_vec()
|
||||
);
|
||||
|
||||
// The one string a terminal choice owns, and the one the lane has no
|
||||
// string for at all.
|
||||
let mut terminal = OperationalOracle::new(&granted, &[]);
|
||||
let speech = json!({ "text": "Hold the bridge." }).to_string();
|
||||
assert_eq!(
|
||||
terminal.answer(&speak, &speech).unwrap(),
|
||||
"invocation captured"
|
||||
);
|
||||
assert_eq!(
|
||||
terminal.answer(&speak, &speech).unwrap(),
|
||||
"one terminal choice is already captured"
|
||||
);
|
||||
assert!(matches!(
|
||||
terminal.answer(FINISH_WITHOUT_PROPOSAL_TOOL, "{}"),
|
||||
Err(ControllerError::ProviderContract { .. })
|
||||
));
|
||||
}
|
||||
|
||||
/// Spec test 1, grouped lane. Two handles, and a tool that names none.
|
||||
#[test]
|
||||
fn the_grouped_oracle_answers_what_its_evaluator_recomputes() {
|
||||
let opportunity = fixture_opportunity(ControllerMode::OperationalAgent);
|
||||
let constituents = vec![
|
||||
ConstituentWork {
|
||||
subject: opportunity.scope.subject_id,
|
||||
opportunity: opportunity.clone(),
|
||||
granted: vec![speak_snapshot(opportunity.affordance_ids[0])],
|
||||
command_id: CommandId::new(),
|
||||
},
|
||||
ConstituentWork {
|
||||
subject: opportunity.scope.subject_id,
|
||||
opportunity: opportunity.clone(),
|
||||
granted: vec![speak_snapshot(opportunity.affordance_ids[0])],
|
||||
command_id: CommandId::new(),
|
||||
},
|
||||
];
|
||||
let speak = constituents[0].granted[0].entry.kind.0.clone();
|
||||
let handle_one = format!("c0__{speak}");
|
||||
let calls: Vec<(&str, &str, &str)> = vec![
|
||||
("call-0", "c99__carry", "{}"),
|
||||
("call-1", "c0__record_need", r#"{"detail":"no route"}"#),
|
||||
("call-2", "c1__record_need", "not json at all"),
|
||||
("call-3", handle_one.as_str(), "not json at all"),
|
||||
("call-4", "c1__notgranted", "{}"),
|
||||
];
|
||||
let mut oracle = GroupedOracle::new(&constituents, &[]);
|
||||
let answers: Vec<String> = calls
|
||||
.iter()
|
||||
.map(|(_, name, arguments)| oracle.answer(name, arguments).unwrap())
|
||||
.collect();
|
||||
let output = oracle_round(&calls, "grouped-oracle");
|
||||
let GroupedLoopEvaluation::Continue { conversation } =
|
||||
evaluate_grouped_loop("Decide together.", &constituents, &[output]).unwrap()
|
||||
else {
|
||||
panic!("a non-terminal grouped round finalized")
|
||||
};
|
||||
assert_eq!(answers, tool_results(&conversation));
|
||||
}
|
||||
|
||||
/// Spec test 4, and the reachable half of spec test 3: two ports that
|
||||
/// prepare under the same identity produce the same `PreparedInference`,
|
||||
/// and it satisfies the checkpoint's own identity check.
|
||||
|
|
@ -11809,251 +11472,12 @@ assert!(projector_text.contains("I ask about the hinge."), "the player's own tur
|
|||
);
|
||||
}
|
||||
|
||||
/// A tool argument long enough that nothing on either path can be carrying
|
||||
/// it in a fixed buffer, and shaped so it cannot decode for any lane.
|
||||
fn oversized_arguments() -> String {
|
||||
format!("{{\"detail\":\"{}\"", "\u{e9}bris ".repeat(4_096))
|
||||
}
|
||||
|
||||
/// Soul, interpreter lane. Every adversarial call the transport can carry —
|
||||
/// a decode failure, a duplicate state-changing call, an unknown tool name,
|
||||
/// and an argument far past any plausible buffer — is answered by the oracle
|
||||
/// with exactly the string the evaluator recomputes for the same transcript,
|
||||
/// call for call and in order.
|
||||
#[test]
|
||||
fn soul_the_interpreter_oracle_equals_its_evaluator_under_adversarial_calls() {
|
||||
let opportunity = fixture_opportunity(ControllerMode::NarrativePersona);
|
||||
let source = "I say, \"The rain has teeth tonight.\"";
|
||||
let turn = fixture_persona_turn(&opportunity, source);
|
||||
let speech = "The rain has teeth tonight.";
|
||||
let span = json!({ "source_quote": speech }).to_string();
|
||||
// A quote the prose does not contain: the capture is refused as a gap,
|
||||
// which is a real answer and not a decode failure.
|
||||
let past_end = json!({ "source_quote": "The rain has no teeth." }).to_string();
|
||||
let oversized = oversized_arguments();
|
||||
let calls: Vec<(&str, &str, &str)> = vec![
|
||||
("call-0", INTERPRETER_SPEAK_TOOL, span.as_str()),
|
||||
// The duplicate: the same span is already captured, so this one
|
||||
// is an overlap gap under a different string.
|
||||
("call-1", INTERPRETER_SPEAK_TOOL, span.as_str()),
|
||||
("call-2", INTERPRETER_SPEAK_TOOL, past_end.as_str()),
|
||||
("call-3", INTERPRETER_RECORD_GAP_TOOL, "not json at all"),
|
||||
("call-4", INTERPRETER_RECORD_GAP_TOOL, oversized.as_str()),
|
||||
("call-5", "speek", "{}"),
|
||||
("call-6", INTERPRETER_SPEAK_TOOL, "{\"source_quote\":7}"),
|
||||
];
|
||||
let mut oracle = InterpreterOracle::new(&turn, &[]);
|
||||
assert_eq!(oracle.remaining_rounds() as usize, TOOL_STEP_BUDGET);
|
||||
let answers: Vec<String> = calls
|
||||
.iter()
|
||||
.map(|(_, name, arguments)| oracle.answer(name, arguments).unwrap())
|
||||
.collect();
|
||||
let output = oracle_round(&calls, "soul-interpreter");
|
||||
let InterpreterLoopEvaluation::Continue { conversation } =
|
||||
evaluate_interpreter_loop(&turn, "Translate the prose.", &[output.clone()]).unwrap()
|
||||
else {
|
||||
panic!("a non-terminal interpreter round finalized")
|
||||
};
|
||||
assert_eq!(answers, tool_results(&conversation));
|
||||
|
||||
// Terminality and the remaining budget agree: the evaluator still has
|
||||
// rounds left, and the oracle seeded from the same evidence reports
|
||||
// exactly the rounds the evaluator would still allow.
|
||||
let seeded = InterpreterOracle::new(&turn, &[output.clone()]);
|
||||
assert_eq!(seeded.remaining_rounds() as usize, TOOL_STEP_BUDGET - 1);
|
||||
|
||||
// The one call the evaluator treats as terminal is terminal for the
|
||||
// oracle's budget too: a round carrying it finalizes.
|
||||
let finishing = vec![("call-7", FINISH_INTERPRETATION_TOOL, "{}")];
|
||||
let InterpreterLoopEvaluation::Complete { .. } = evaluate_interpreter_loop(
|
||||
&turn,
|
||||
"Translate the prose.",
|
||||
&[output, oracle_round(&finishing, "soul-interpreter-end")],
|
||||
)
|
||||
.unwrap() else {
|
||||
panic!("a finished interpretation stayed open")
|
||||
};
|
||||
}
|
||||
|
||||
/// Soul, operational lane. The lane's one round-local reset is the only
|
||||
/// thing the oracle could get wrong, so it is checked in both directions:
|
||||
/// a duplicate terminal inside one round is a gap, the same call opening a
|
||||
/// fresh round is a capture, and the transcript the oracle refuses is the
|
||||
/// transcript the evaluator refuses.
|
||||
#[test]
|
||||
fn soul_the_operational_oracle_equals_its_evaluator_under_adversarial_calls() {
|
||||
let opportunity = fixture_opportunity(ControllerMode::OperationalAgent);
|
||||
let granted = vec![speak_snapshot(opportunity.affordance_ids[0])];
|
||||
let speak = granted[0].entry.kind.0.clone();
|
||||
let oversized = oversized_arguments();
|
||||
let calls: Vec<(&str, &str, &str)> = vec![
|
||||
("call-0", RECORD_NEED_TOOL, r#"{"detail":"no route"}"#),
|
||||
("call-1", RECORD_NEED_TOOL, "not json at all"),
|
||||
("call-2", RECORD_NEED_TOOL, oversized.as_str()),
|
||||
// A granted tool whose arguments do not decode is a need, so the
|
||||
// round is still open after it.
|
||||
("call-3", speak.as_str(), "not json at all"),
|
||||
("call-4", "speek", "{}"),
|
||||
];
|
||||
let mut oracle = OperationalOracle::new(&granted, &[]);
|
||||
assert_eq!(oracle.remaining_rounds() as usize, TOOL_STEP_BUDGET);
|
||||
let answers: Vec<String> = calls
|
||||
.iter()
|
||||
.map(|(_, name, arguments)| oracle.answer(name, arguments).unwrap())
|
||||
.collect();
|
||||
let round_zero = oracle_round(&calls, "soul-operational");
|
||||
let OperationalLoopEvaluation::Continue { conversation } =
|
||||
evaluate_operational_loop("Hold the bridge.", &granted, &[round_zero.clone()]).unwrap()
|
||||
else {
|
||||
panic!("a non-terminal operational round finalized")
|
||||
};
|
||||
assert_eq!(answers, tool_results(&conversation));
|
||||
|
||||
// The duplicate terminal, and the same call in a new round. One fold,
|
||||
// two round boundaries, two different strings.
|
||||
let speech = json!({ "text": "Hold the bridge." }).to_string();
|
||||
let mut inside = OperationalOracle::new(&granted, &[]);
|
||||
assert_eq!(
|
||||
inside.answer(&speak, &speech).unwrap(),
|
||||
"invocation captured"
|
||||
);
|
||||
assert_eq!(
|
||||
inside.answer(&speak, &speech).unwrap(),
|
||||
"one terminal choice is already captured"
|
||||
);
|
||||
let terminal_round =
|
||||
oracle_round(&[("call-5", speak.as_str(), speech.as_str())], "soul-op-t");
|
||||
let mut across =
|
||||
OperationalOracle::new(&granted, &[round_zero.clone(), terminal_round.clone()]);
|
||||
assert_eq!(
|
||||
across.answer(&speak, &speech).unwrap(),
|
||||
"invocation captured",
|
||||
"the round boundary did not clear the terminal choice"
|
||||
);
|
||||
assert_eq!(across.remaining_rounds() as usize, TOOL_STEP_BUDGET - 2);
|
||||
|
||||
// A call after a terminal that contradicts it: the oracle refuses, and
|
||||
// so does the evaluator re-deriving the same transcript. The port's
|
||||
// abort therefore fires on exactly the transcripts re-derivation would
|
||||
// have hard-errored on.
|
||||
let mut contradicted = OperationalOracle::new(&granted, &[]);
|
||||
contradicted.answer(&speak, &speech).unwrap();
|
||||
assert!(matches!(
|
||||
contradicted.answer(FINISH_WITHOUT_PROPOSAL_TOOL, "{}"),
|
||||
Err(ControllerError::ProviderContract { .. })
|
||||
));
|
||||
let contradicting_round = oracle_round(
|
||||
&[
|
||||
("call-6", speak.as_str(), speech.as_str()),
|
||||
("call-7", FINISH_WITHOUT_PROPOSAL_TOOL, "{}"),
|
||||
],
|
||||
"soul-op-contradiction",
|
||||
);
|
||||
assert!(matches!(
|
||||
evaluate_operational_loop("Hold the bridge.", &granted, &[contradicting_round]),
|
||||
Err(ControllerError::ProviderContract { .. })
|
||||
));
|
||||
}
|
||||
|
||||
/// Soul, grouped lane. Two handles, so a terminal for one leaves the round
|
||||
/// open and the whole adversarial sequence — including a call after that
|
||||
/// handle's terminal — stays observable through the evaluator's own
|
||||
/// conversation.
|
||||
#[test]
|
||||
fn soul_the_grouped_oracle_equals_its_evaluator_under_adversarial_calls() {
|
||||
let opportunity = fixture_opportunity(ControllerMode::OperationalAgent);
|
||||
let constituents = vec![
|
||||
ConstituentWork {
|
||||
subject: opportunity.scope.subject_id,
|
||||
opportunity: opportunity.clone(),
|
||||
granted: vec![speak_snapshot(opportunity.affordance_ids[0])],
|
||||
command_id: CommandId::new(),
|
||||
},
|
||||
ConstituentWork {
|
||||
subject: opportunity.scope.subject_id,
|
||||
opportunity: opportunity.clone(),
|
||||
granted: vec![speak_snapshot(opportunity.affordance_ids[0])],
|
||||
command_id: CommandId::new(),
|
||||
},
|
||||
];
|
||||
let speak = constituents[0].granted[0].entry.kind.0.clone();
|
||||
let handle_zero = format!("c0__{speak}");
|
||||
let speech = json!({ "text": "Hold the bridge." }).to_string();
|
||||
let oversized = oversized_arguments();
|
||||
let calls: Vec<(&str, &str, &str)> = vec![
|
||||
("call-0", "c99__carry", "{}"),
|
||||
("call-1", "c0__record_need", r#"{"detail":"no route"}"#),
|
||||
("call-2", "c1__record_need", "not json at all"),
|
||||
("call-3", "c1__record_need", oversized.as_str()),
|
||||
// Handle zero takes its terminal, then keeps calling.
|
||||
("call-4", handle_zero.as_str(), speech.as_str()),
|
||||
("call-5", handle_zero.as_str(), speech.as_str()),
|
||||
("call-6", "c0__finish_without_proposal", "{}"),
|
||||
("call-7", "c1__notgranted", "{}"),
|
||||
];
|
||||
let mut oracle = GroupedOracle::new(&constituents, &[]);
|
||||
assert_eq!(oracle.remaining_rounds() as usize, CELL_TOOL_STEP_BUDGET);
|
||||
// The one call with no answer at all, taken on a throwaway oracle so
|
||||
// the ordered comparison below is not disturbed.
|
||||
let mut refusing = GroupedOracle::new(&constituents, &[]);
|
||||
for (_, name, arguments) in &calls[..6] {
|
||||
refusing.answer(name, arguments).unwrap();
|
||||
}
|
||||
assert!(matches!(
|
||||
refusing.answer("c0__finish_without_proposal", "{}"),
|
||||
Err(ControllerError::ProviderContract { .. })
|
||||
));
|
||||
let open: Vec<(&str, &str, &str)> = calls
|
||||
.iter()
|
||||
.filter(|(id, _, _)| *id != "call-6")
|
||||
.copied()
|
||||
.collect();
|
||||
let answers: Vec<String> = open
|
||||
.iter()
|
||||
.map(|(_, name, arguments)| oracle.answer(name, arguments).unwrap())
|
||||
.collect();
|
||||
let round_zero = oracle_round(&open, "soul-grouped");
|
||||
let GroupedLoopEvaluation::Continue { conversation } =
|
||||
evaluate_grouped_loop("Decide together.", &constituents, &[round_zero.clone()])
|
||||
.unwrap()
|
||||
else {
|
||||
panic!("a grouped round with one handle still open finalized")
|
||||
};
|
||||
assert_eq!(answers, tool_results(&conversation));
|
||||
|
||||
// And the evaluator refuses the transcript the oracle refuses.
|
||||
let contradicting = oracle_round(
|
||||
&[
|
||||
("call-8", handle_zero.as_str(), speech.as_str()),
|
||||
("call-9", "c0__finish_without_proposal", "{}"),
|
||||
],
|
||||
"soul-grouped-contradiction",
|
||||
);
|
||||
assert!(matches!(
|
||||
evaluate_grouped_loop("Decide together.", &constituents, &[contradicting]),
|
||||
Err(ControllerError::ProviderContract { .. })
|
||||
));
|
||||
|
||||
// Seeding: the fold carries across rounds and the budget shrinks with
|
||||
// it, so `maxTurns` can never exceed what the evaluator would allow.
|
||||
let seeded = GroupedOracle::new(&constituents, &[round_zero.clone(), round_zero]);
|
||||
assert_eq!(
|
||||
seeded.remaining_rounds() as usize,
|
||||
CELL_TOOL_STEP_BUDGET - 2
|
||||
);
|
||||
}
|
||||
|
||||
/// Soul: the arguments the SDK path can hand an evaluator are the stripped
|
||||
/// ones the SDK's own validation produced, and the connector path refuses
|
||||
/// what that validation quietly admits. Both strings are recorded here so
|
||||
/// the divergence is a fact rather than a guess (see the sidecar's
|
||||
/// `soul-zod-liability.test.ts` for the other half of the chain).
|
||||
/// Operational tool calls with unknown properties are recorded as needs.
|
||||
#[test]
|
||||
fn soul_a_property_outside_the_schema_is_a_need_on_the_connector_path() {
|
||||
let opportunity = fixture_opportunity(ControllerMode::OperationalAgent);
|
||||
let granted = vec![speak_snapshot(opportunity.affordance_ids[0])];
|
||||
let mut fold = OperationalFold::new();
|
||||
// What a model writes, and what the connector's decoder does with it.
|
||||
assert_eq!(
|
||||
operational_tool_result(
|
||||
&granted,
|
||||
|
|
@ -12064,7 +11488,6 @@ assert!(projector_text.contains("I ask about the hinge."), "the player's own tur
|
|||
.unwrap(),
|
||||
"arguments recorded as a need",
|
||||
);
|
||||
// What the SDK's validation hands the oracle for the same call.
|
||||
assert_eq!(
|
||||
operational_tool_result(
|
||||
&granted,
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
use super::controllers::{
|
||||
ControllerError, ControllerNeed, ControllerWork, ControllerWorkLookup, ControllerWorkStore,
|
||||
ControllerWorkWrite, InferenceEvent, InferenceOutput, InferencePort, InferencePurpose,
|
||||
InferenceRequest, PreparedInference, RequestShape, ToolResultOracle, canonical_model,
|
||||
InferenceRequest, PreparedInference, RequestShape, canonical_model,
|
||||
prepared_matches_request, tool_decode_need, tool_request,
|
||||
};
|
||||
#[cfg(test)]
|
||||
|
|
@ -574,10 +574,6 @@ impl ElaborationRunner {
|
|||
invocation: invocation.clone(),
|
||||
})
|
||||
.await?;
|
||||
self.inference.lend_tool_results(
|
||||
&invocation,
|
||||
Box::new(ElaborationOracle::new(&completed, &refusals, ELABORATION_ROUND_BUDGET)),
|
||||
);
|
||||
let output =
|
||||
self.inference
|
||||
.infer(invocation.clone())
|
||||
|
|
@ -1608,50 +1604,6 @@ impl DraftFold {
|
|||
}
|
||||
}
|
||||
|
||||
/// The authoring lanes' replay-then-answer oracle. The budget is an argument
|
||||
/// because elaboration and seed share one `InferencePurpose` and differ only in
|
||||
/// how many rounds they may spend, which is why the cap rides here and not on
|
||||
/// the purpose.
|
||||
pub(super) struct ElaborationOracle {
|
||||
fold: DraftFold,
|
||||
remaining: u32,
|
||||
}
|
||||
|
||||
impl ElaborationOracle {
|
||||
pub(super) fn new(completed: &[InferenceOutput], refusals: &[Refusal], budget: usize) -> Self {
|
||||
let mut fold = DraftFold::default();
|
||||
let mut attempt_start = 0;
|
||||
for (round, output) in completed.iter().enumerate() {
|
||||
for event in &output.events {
|
||||
if let InferenceEvent::ToolCall {
|
||||
name, arguments, ..
|
||||
} = event
|
||||
{
|
||||
let _ = fold.apply(name, arguments);
|
||||
}
|
||||
}
|
||||
if refusal_after(refusals, round + 1).is_some() {
|
||||
fold = DraftFold::default();
|
||||
attempt_start = round + 1;
|
||||
}
|
||||
}
|
||||
Self {
|
||||
fold,
|
||||
remaining: budget.saturating_sub(completed.len() - attempt_start) as u32,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToolResultOracle for ElaborationOracle {
|
||||
fn remaining_rounds(&self) -> u32 {
|
||||
self.remaining
|
||||
}
|
||||
|
||||
fn answer(&mut self, name: &str, arguments: &str) -> Result<String, ControllerError> {
|
||||
Ok(self.fold.apply(name, arguments))
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) fn apply_tool_call(
|
||||
name: &str,
|
||||
arguments: &str,
|
||||
|
|
@ -2197,10 +2149,6 @@ impl SeedRunner {
|
|||
invocation: invocation.clone(),
|
||||
})
|
||||
.await?;
|
||||
self.inference.lend_tool_results(
|
||||
&invocation,
|
||||
Box::new(ElaborationOracle::new(&completed, &refusals, SEED_ROUND_BUDGET)),
|
||||
);
|
||||
let output = self.inference.infer(invocation).await.map_err(|source| {
|
||||
ControllerError::Inference {
|
||||
purpose: InferencePurpose::Elaboration,
|
||||
|
|
@ -2548,155 +2496,6 @@ mod tests {
|
|||
.expect("the loop finalizes")
|
||||
}
|
||||
|
||||
/// Soul, the authoring lanes. The oracle's answer for every call in an
|
||||
/// adversarial sequence — a decode failure, a duplicate terminal, a call
|
||||
/// after the terminal, an unknown tool name, and an oversized argument —
|
||||
/// equals the string the evaluator recomputes for the same transcript, and
|
||||
/// the budget the oracle reports is the budget the evaluator still allows.
|
||||
#[test]
|
||||
fn soul_the_elaboration_oracle_equals_its_evaluator_under_adversarial_calls() {
|
||||
let oversized = serde_json::json!({
|
||||
"detail": "\u{e9}bris ".repeat(4_096),
|
||||
"unexpected": true,
|
||||
});
|
||||
let calls: Vec<(&str, Value)> = vec![
|
||||
("declare_place", place("shed")),
|
||||
(
|
||||
RECORD_GAP_PATCH_TOOL,
|
||||
serde_json::json!({"detail": "no route"}),
|
||||
),
|
||||
// A `detail` that is not a string: a decode failure under the
|
||||
// lane's own rule.
|
||||
(RECORD_GAP_PATCH_TOOL, serde_json::json!({"detail": 5})),
|
||||
(RECORD_GAP_PATCH_TOOL, oversized),
|
||||
// A declaration whose arguments the kernel vocabulary refuses.
|
||||
("declare_place", serde_json::json!({"handle": "shed"})),
|
||||
("speek", serde_json::json!({})),
|
||||
];
|
||||
let round_zero = output(calls.clone());
|
||||
|
||||
let mut oracle = ElaborationOracle::new(&[], &[], SEED_ROUND_BUDGET);
|
||||
assert_eq!(oracle.remaining_rounds() as usize, SEED_ROUND_BUDGET);
|
||||
let answers: Vec<String> = calls
|
||||
.iter()
|
||||
.map(|(name, arguments)| oracle.answer(name, &arguments.to_string()).unwrap())
|
||||
.collect();
|
||||
let ElaborationLoopEvaluation::Continue { conversation } =
|
||||
evaluate_elaboration_loop("prompt", &[], &[round_zero.clone()], SEED_ROUND_BUDGET)
|
||||
.unwrap()
|
||||
else {
|
||||
panic!("a round with no submit finalized")
|
||||
};
|
||||
let recomputed: Vec<String> = conversation
|
||||
.iter()
|
||||
.filter_map(|item| match item {
|
||||
InputItem::ToolResult { output, .. } => Some(output.clone()),
|
||||
_ => None,
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(answers, recomputed);
|
||||
|
||||
// The terminal, the duplicate terminal, and a call after it. The
|
||||
// evaluator finalizes that round, so its strings are compared against
|
||||
// the same fold run straight through both rounds.
|
||||
let terminal: Vec<(&str, Value)> = vec![
|
||||
(SUBMIT_PATCH_TOOL, serde_json::json!({})),
|
||||
(SUBMIT_PATCH_TOOL, serde_json::json!({})),
|
||||
(
|
||||
RECORD_GAP_PATCH_TOOL,
|
||||
serde_json::json!({"detail": "after"}),
|
||||
),
|
||||
];
|
||||
let mut seeded = ElaborationOracle::new(&[round_zero.clone()], &[], SEED_ROUND_BUDGET);
|
||||
assert_eq!(
|
||||
seeded.remaining_rounds() as usize,
|
||||
SEED_ROUND_BUDGET - 1,
|
||||
"the oracle offered a turn cap the evaluator would not allow"
|
||||
);
|
||||
let seeded_answers: Vec<String> = terminal
|
||||
.iter()
|
||||
.map(|(name, arguments)| seeded.answer(name, &arguments.to_string()).unwrap())
|
||||
.collect();
|
||||
assert_eq!(
|
||||
seeded_answers,
|
||||
vec![
|
||||
"patch submitted".to_string(),
|
||||
"a submit is already captured".to_string(),
|
||||
"gap recorded".to_string(),
|
||||
]
|
||||
);
|
||||
let mut replayed = ElaborationOracle::new(&[], &[], SEED_ROUND_BUDGET);
|
||||
let straight: Vec<String> = calls
|
||||
.iter()
|
||||
.chain(terminal.iter())
|
||||
.map(|(name, arguments)| replayed.answer(name, &arguments.to_string()).unwrap())
|
||||
.collect();
|
||||
assert_eq!(straight[..calls.len()], answers[..]);
|
||||
assert_eq!(straight[calls.len()..], seeded_answers[..]);
|
||||
|
||||
// The evaluator finalizes the terminal round, and what it captured is
|
||||
// what the oracle's own fold accumulated over the same calls.
|
||||
let mut draft = WorldPatch {
|
||||
declarations: Vec::new(),
|
||||
operations: Vec::new(),
|
||||
evidence: Vec::new(),
|
||||
};
|
||||
let mut gaps = Vec::new();
|
||||
let mut submitted = false;
|
||||
for (name, arguments) in calls.iter().chain(terminal.iter()) {
|
||||
apply_tool_call(
|
||||
name,
|
||||
&arguments.to_string(),
|
||||
&mut draft,
|
||||
&mut gaps,
|
||||
&mut submitted,
|
||||
);
|
||||
}
|
||||
let ElaborationLoopEvaluation::Complete { capture } = evaluate_elaboration_loop(
|
||||
"prompt",
|
||||
&[],
|
||||
&[round_zero, output(terminal)],
|
||||
SEED_ROUND_BUDGET,
|
||||
)
|
||||
.unwrap() else {
|
||||
panic!("a submitted round stayed open")
|
||||
};
|
||||
assert!(capture.submitted && submitted);
|
||||
assert_eq!(capture.draft.declarations, draft.declarations);
|
||||
assert_eq!(capture.gaps, gaps);
|
||||
}
|
||||
|
||||
/// Soul: the elaboration lane and the seed lane share one
|
||||
/// `InferencePurpose`, so the only thing that distinguishes their turn caps
|
||||
/// is the budget the oracle was built with.
|
||||
#[test]
|
||||
fn soul_the_two_authoring_lanes_carry_different_budgets_on_the_oracle() {
|
||||
assert_ne!(ELABORATION_ROUND_BUDGET, SEED_ROUND_BUDGET);
|
||||
assert_eq!(
|
||||
ElaborationOracle::new(&[], &[], ELABORATION_ROUND_BUDGET).remaining_rounds() as usize,
|
||||
ELABORATION_ROUND_BUDGET
|
||||
);
|
||||
assert_eq!(
|
||||
ElaborationOracle::new(&[], &[], SEED_ROUND_BUDGET).remaining_rounds() as usize,
|
||||
SEED_ROUND_BUDGET
|
||||
);
|
||||
// A spent budget reports zero rather than wrapping. Zero is outside the
|
||||
// sidecar's accepted turn-cap range, so an exhausted lane that somehow
|
||||
// reached the port is refused rather than quietly granted a turn.
|
||||
let spent: Vec<InferenceOutput> = (0..ELABORATION_ROUND_BUDGET + 2)
|
||||
.map(|_| {
|
||||
output(vec![(
|
||||
RECORD_GAP_PATCH_TOOL,
|
||||
serde_json::json!({"detail": "x"}),
|
||||
)])
|
||||
})
|
||||
.collect();
|
||||
assert_eq!(
|
||||
ElaborationOracle::new(&spent, &[], ELABORATION_ROUND_BUDGET).remaining_rounds(),
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
/// Each declaration tool call appends a `Declaration`; each operation call
|
||||
/// appends a `ComponentOp`; `submit` is terminal.
|
||||
#[test]
|
||||
|
|
@ -2775,13 +2574,6 @@ mod tests {
|
|||
matches!(&conversation[1], InputItem::ToolCall { name, .. } if name == "declare_place"),
|
||||
"the refused round's calls left the conversation"
|
||||
);
|
||||
assert_eq!(
|
||||
ElaborationOracle::new(&[first.clone()], &refusals, ELABORATION_ROUND_BUDGET)
|
||||
.fold
|
||||
.draft,
|
||||
WorldPatch::default(),
|
||||
"the oracle kept the refused draft"
|
||||
);
|
||||
|
||||
// Repaired: the capture is exactly the calls after the refusal.
|
||||
let second = output(vec![
|
||||
|
|
@ -3136,8 +2928,8 @@ mod tests {
|
|||
));
|
||||
}
|
||||
/// The refusal that follows a round which spent the whole budget is still
|
||||
/// repairable: the repair attempt has the whole budget again, and the oracle
|
||||
/// reports it, rather than the session dying at "exceeded its round budget".
|
||||
/// repairable: the repair attempt has the whole budget again, rather than the
|
||||
/// session dying at "exceeded its round budget".
|
||||
#[test]
|
||||
fn a_refusal_opens_a_fresh_round_budget_for_the_repair() {
|
||||
let drafting = || output(vec![("declare_place", place("shed"))]);
|
||||
|
|
@ -3153,11 +2945,6 @@ mod tests {
|
|||
evaluate_elaboration_loop("p", &refusals, &completed, ELABORATION_ROUND_BUDGET),
|
||||
Ok(ElaborationLoopEvaluation::Continue { .. })
|
||||
));
|
||||
assert_eq!(
|
||||
ElaborationOracle::new(&completed, &refusals, ELABORATION_ROUND_BUDGET).remaining_rounds()
|
||||
as usize,
|
||||
ELABORATION_ROUND_BUDGET
|
||||
);
|
||||
// The repair submits in one round and finalizes.
|
||||
completed.push(submitting());
|
||||
assert!(matches!(
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ pub use controllers::{
|
|||
GroupedCheckpoint, InferenceEvent, InferenceFault, InferenceFaultClass, InferenceFaultDisposition, InferenceOutput,
|
||||
InferencePort,
|
||||
InferencePurpose, InferenceRequest, NarrativeCheckpoint, NarrativeRun, OperationalCheckpoint,
|
||||
OperationalRun, PersonaLane, PreparedInference, SubmissionDisposition, TokenUsage, ToolResultOracle,
|
||||
OperationalRun, PersonaLane, PreparedInference, SubmissionDisposition, TokenUsage,
|
||||
TracingInferencePort, open_controller_work, open_inference,
|
||||
};
|
||||
pub(crate) use cover::{CellId, Constituent, Resolution};
|
||||
|
|
|
|||
|
|
@ -6,7 +6,6 @@
|
|||
|
||||
use super::controllers::{
|
||||
InferenceFault, InferenceOutput, InferencePort, InferenceRequest, PreparedInference,
|
||||
ToolResultOracle,
|
||||
};
|
||||
use async_trait::async_trait;
|
||||
use std::sync::Arc;
|
||||
|
|
@ -67,12 +66,6 @@ impl InferencePort for RoutedInferencePort {
|
|||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn lend_tool_results(&self, prepared: &PreparedInference, oracle: Box<dyn ToolResultOracle>) {
|
||||
if let Some(port) = self.route(&prepared.invocation.request.model) {
|
||||
port.lend_tool_results(prepared, oracle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
use crate::controllers::{
|
||||
ControllerError, InferenceEvent, InferenceFault, InferenceOutput, InferencePort,
|
||||
InferencePurpose, InferenceRequest, PreparedInference, REQUEST_EXPIRY, TokenUsage,
|
||||
ToolResultOracle, request_id_prefix, unix_ms,
|
||||
request_id_prefix, unix_ms,
|
||||
};
|
||||
use crate::{FrozenCell, NodeId, TickIndex, WorldId};
|
||||
use async_trait::async_trait;
|
||||
|
|
@ -841,10 +841,6 @@ impl InferencePort for RecordingInferencePort {
|
|||
let result = self.inner.infer(request).await;
|
||||
self.settle(lane, bound, identity, result)
|
||||
}
|
||||
|
||||
fn lend_tool_results(&self, prepared: &PreparedInference, oracle: Box<dyn ToolResultOracle>) {
|
||||
self.inner.lend_tool_results(prepared, oracle);
|
||||
}
|
||||
}
|
||||
|
||||
/// What the calls of one wave cost, by lane and by node. The port never learns
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ type Script = Vec<Result<InferenceOutput, InferenceFault>>;
|
|||
struct ScriptedPort {
|
||||
replies: Mutex<VecDeque<Result<InferenceOutput, InferenceFault>>>,
|
||||
calls: AtomicUsize,
|
||||
lent: AtomicUsize,
|
||||
gate: Option<Arc<tokio::sync::Semaphore>>,
|
||||
}
|
||||
|
||||
|
|
@ -25,7 +24,6 @@ impl ScriptedPort {
|
|||
Arc::new(Self {
|
||||
replies: Mutex::new(replies.into()),
|
||||
calls: AtomicUsize::new(0),
|
||||
lent: AtomicUsize::new(0),
|
||||
gate: None,
|
||||
})
|
||||
}
|
||||
|
|
@ -34,7 +32,6 @@ impl ScriptedPort {
|
|||
Arc::new(Self {
|
||||
replies: Mutex::new(replies.into()),
|
||||
calls: AtomicUsize::new(0),
|
||||
lent: AtomicUsize::new(0),
|
||||
gate: Some(gate),
|
||||
})
|
||||
}
|
||||
|
|
@ -50,10 +47,6 @@ impl InferencePort for ScriptedPort {
|
|||
PreparedInference::prepare("verse-test", 4_102_444_800_000, request)
|
||||
}
|
||||
|
||||
fn lend_tool_results(&self, _: &PreparedInference, _: Box<dyn ToolResultOracle>) {
|
||||
self.lent.fetch_add(1, Ordering::SeqCst);
|
||||
}
|
||||
|
||||
async fn infer(&self, _: PreparedInference) -> Result<InferenceOutput, InferenceFault> {
|
||||
self.calls.fetch_add(1, Ordering::SeqCst);
|
||||
if let Some(gate) = &self.gate {
|
||||
|
|
@ -358,28 +351,6 @@ async fn calls_on_the_wire_hold_their_bound() {
|
|||
first.await.unwrap().expect("the first call completes");
|
||||
}
|
||||
|
||||
struct NoTools;
|
||||
|
||||
impl ToolResultOracle for NoTools {
|
||||
fn remaining_rounds(&self) -> u32 {
|
||||
0
|
||||
}
|
||||
|
||||
fn answer(&mut self, _: &str, _: &str) -> Result<String, crate::ControllerError> {
|
||||
Ok(String::new())
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_results_are_lent_to_the_port_underneath() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
let (store, _) = store_in(&directory);
|
||||
let inner = ScriptedPort::new(Vec::new());
|
||||
let port = recording(&inner, &store, "run-lend", u64::MAX);
|
||||
port.lend_tool_results(&prepared_for("lend", 1_200), Box::new(NoTools));
|
||||
assert_eq!(inner.lent.load(Ordering::SeqCst), 1);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_reply_with_no_usage_is_charged_its_bound() {
|
||||
let directory = tempfile::tempdir().unwrap();
|
||||
|
|
|
|||
Loading…
Reference in a new issue