Collapse the two prepared-identity bodies and the two constructors

`prepare_invocation` is now the one place a `PreparedInference` is built:
the connector port's `prepare_request` and `fixture_prepared_inference`
were the same body twice, and a second transport would have made it three.

`ControllerRunner::open` takes its ports. `with_test_ports` existed only
to bypass the two transport-specific parameters `open` hard-coded, so
removing them deletes the `#[cfg(test)]` twin rather than adding a third
constructor. Runtime binds the transport and the controller-work owner
through `open_inference` and `open_controller_work`, and
`GHOSTLIGHT_CONTROLLER_CREDENTIAL` is no longer unconditionally required.

Each tool lane's per-call body moves whole into a named fold —
`interpreter_tool_result`, `operational_tool_result`,
`grouped_tool_result` — which the batch evaluator now calls. No result
string changes. `apply_tool_call` was already this shape.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-06 01:11:39 +02:00
commit 708d621c0c
4 changed files with 510 additions and 404 deletions

View file

@ -10,13 +10,14 @@ use crate::{
},
mesh::{self, MeshPublisher, MeshRuntimeIdentity},
world::{
AffordanceId, CONSUMER_BODY_LIMIT, CellRun, CommandBody, CommandId, ConsumerPort,
ConsumerRegistry, ControllerError, ControllerModels, ControllerPendingReason,
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, SeedOutcome, SeedPort,
Statement, SubjectKind, SubmissionDisposition, SubmitReceipt, TickMinutes,
VaultEvidenceSource, WorldMailbox, WorldPhase, WorldSnapshot, derive_cover,
open_controller_work, open_inference,
},
};
use anyhow::{Context, bail, ensure};
@ -414,29 +415,28 @@ fn open_controller(
runtime_id: &str,
endpoint: SocketAddr,
) -> anyhow::Result<ControllerRunner> {
let credential = std::env::var_os("GHOSTLIGHT_CONTROLLER_CREDENTIAL")
let models = ControllerModels {
projector: std::env::var("GHOSTLIGHT_CONTROLLER_PROJECTOR_MODEL")
.unwrap_or_else(|_| "gpt-5.6-luna".into()),
persona: std::env::var("GHOSTLIGHT_CONTROLLER_PERSONA_MODEL")
.unwrap_or_else(|_| "gpt-5.6-sol".into()),
interpreter: std::env::var("GHOSTLIGHT_CONTROLLER_INTERPRETER_MODEL")
.unwrap_or_else(|_| "gpt-5.6-terra".into()),
operational_agent: std::env::var("GHOSTLIGHT_CONTROLLER_OPERATIONAL_MODEL")
.unwrap_or_else(|_| "gpt-5.6-terra".into()),
elaborator: std::env::var("GHOSTLIGHT_CONTROLLER_ELABORATOR_MODEL")
.unwrap_or_else(|_| "gpt-5.6-terra".into()),
};
let connector = std::env::var_os("GHOSTLIGHT_CONTROLLER_CREDENTIAL")
.map(PathBuf::from)
.context("GHOSTLIGHT_CONTROLLER_CREDENTIAL is required")?;
ControllerRunner::open(
world.clone(),
endpoint,
credential,
runtime_id.to_owned(),
service_root.join("controller-work.cc"),
ControllerModels {
projector: std::env::var("GHOSTLIGHT_CONTROLLER_PROJECTOR_MODEL")
.unwrap_or_else(|_| "gpt-5.6-luna".into()),
persona: std::env::var("GHOSTLIGHT_CONTROLLER_PERSONA_MODEL")
.unwrap_or_else(|_| "gpt-5.6-sol".into()),
interpreter: std::env::var("GHOSTLIGHT_CONTROLLER_INTERPRETER_MODEL")
.unwrap_or_else(|_| "gpt-5.6-terra".into()),
operational_agent: std::env::var("GHOSTLIGHT_CONTROLLER_OPERATIONAL_MODEL")
.unwrap_or_else(|_| "gpt-5.6-terra".into()),
elaborator: std::env::var("GHOSTLIGHT_CONTROLLER_ELABORATOR_MODEL")
.unwrap_or_else(|_| "gpt-5.6-terra".into()),
},
)
.map_err(Into::into)
.map(|key_path| ConnectorBinding {
endpoint,
key_path,
caller_runtime_id: runtime_id.to_owned(),
});
let inference = open_inference(connector, &models)?;
let work = open_controller_work(service_root.join("controller-work.cc"))?;
ControllerRunner::open(world.clone(), inference, work, models).map_err(Into::into)
}
fn open_mesh(
@ -2500,15 +2500,18 @@ mod tests {
elaborator: "gpt-5.6-terra".into(),
},
});
let controllers = ControllerRunner::open(
world.clone(),
live.endpoint,
&live.credential,
live.runtime_id,
directory.path().join("controller-work.cc"),
live.models,
let inference = open_inference(
Some(ConnectorBinding {
endpoint: live.endpoint,
key_path: live.credential.clone(),
caller_runtime_id: live.runtime_id,
}),
&live.models,
)
.unwrap();
let work = open_controller_work(directory.path().join("controller-work.cc")).unwrap();
let controllers =
ControllerRunner::open(world.clone(), inference, work, live.models).unwrap();
let mesh = MeshPublisher::open(
directory.path().join("mesh.cc"),
None,
@ -3173,12 +3176,15 @@ mod tests {
let port = Arc::new(CountingInferencePort::new());
let mut state = fixture.state.clone();
state.controllers = Some(Arc::new(ControllerRunner::with_test_ports(
state.world.clone(),
port.clone(),
Arc::new(AlwaysFreshWorkStore),
test_controller_models(),
)));
state.controllers = Some(Arc::new(
ControllerRunner::open(
state.world.clone(),
port.clone(),
Arc::new(AlwaysFreshWorkStore),
test_controller_models(),
)
.expect("the fixture ports open"),
));
state.controller_permits = Arc::new(Semaphore::new(1));
run_cover_tick(&state).await;
@ -3239,12 +3245,15 @@ mod tests {
calls: AtomicUsize::new(0),
});
let mut state = fixture.state.clone();
state.controllers = Some(Arc::new(ControllerRunner::with_test_ports(
state.world.clone(),
port.clone(),
Arc::new(AlwaysFreshWorkStore),
test_controller_models(),
)));
state.controllers = Some(Arc::new(
ControllerRunner::open(
state.world.clone(),
port.clone(),
Arc::new(AlwaysFreshWorkStore),
test_controller_models(),
)
.expect("the fixture ports open"),
));
// One permit, two cells: the second cell cannot even attempt the
// port until the first has returned, which is what makes the
// post-acquire recheck deterministic rather than a race.
@ -3421,12 +3430,15 @@ mod tests {
interpreter_calls: AtomicUsize::new(0),
});
let mut state = fixture.state.clone();
state.controllers = Some(Arc::new(ControllerRunner::with_test_ports(
state.world.clone(),
port.clone(),
Arc::new(AlwaysFreshWorkStore),
test_controller_models(),
)));
state.controllers = Some(Arc::new(
ControllerRunner::open(
state.world.clone(),
port.clone(),
Arc::new(AlwaysFreshWorkStore),
test_controller_models(),
)
.expect("the fixture ports open"),
));
// One permit serializes the two cells' full runs (see
// `the_tick_driver_never_exceeds_its_controller_permit_pool`), so the
// operational agent's own turn — which this port declines on its

File diff suppressed because it is too large Load diff

View file

@ -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(super) struct ElaboratorSession {
pub(crate) struct ElaboratorSession {
pub(super) world_id: WorldId,
pub(super) jurisdiction: JurisdictionKey,
pub(super) answer: PatchAnswer,
@ -73,7 +73,7 @@ pub(super) struct ElaboratorSession {
/// came from the kernel, not the model.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "stage", rename_all = "snake_case")]
pub(super) enum ElaborationCheckpoint {
pub(crate) enum ElaborationCheckpoint {
ElaboratorInFlight {
command_id: CommandId,
session: ElaboratorSession,
@ -1111,7 +1111,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(super) struct SeedSession {
pub(crate) struct SeedSession {
pub(super) world_id: WorldId,
pub(super) jurisdiction: JurisdictionKey,
pub(super) kind: SubjectKind,
@ -1139,7 +1139,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(super) enum SeedCheckpoint {
pub(crate) enum SeedCheckpoint {
SeedInFlight {
command_id: CommandId,
session: SeedSession,

View file

@ -24,10 +24,11 @@ pub(crate) use consumer::{
CONSUMER_RECEIPT_SCHEMA, ConsumerRegistry, admit_document, encode_receipt,
};
pub(crate) use controllers::{
CellRun, ControllerError, ControllerModels, ControllerOpenError, ControllerPendingReason,
ControllerRunner, ControllerWorkCustody, NarrativeCapture, NarrativeDecision, NarrativePending,
NarrativeRun, OperationalCapture, OperationalDecision, OperationalPending, OperationalRun,
SourceRange, SubmissionDisposition, TranslationGapSummary,
CellRun, ConnectorBinding, ControllerError, ControllerModels, ControllerOpenError,
ControllerPendingReason, ControllerRunner, ControllerWorkCustody, NarrativeCapture,
NarrativeDecision, NarrativePending, NarrativeRun, OperationalCapture, OperationalDecision,
OperationalPending, OperationalRun, SourceRange, SubmissionDisposition, TranslationGapSummary,
open_controller_work, open_inference,
};
pub(crate) use cover::{
AgencyGraph, Cell, CellId, Constituent, Cover, CoverBudget, Resolution, TickIndex, derive_cover,