Use balanced civic reconciliation for rejected destinations

This commit is contained in:
Meta Vens 2026-08-27 19:05:56 +02:00
commit 2427f24010
9 changed files with 1237 additions and 178 deletions

View file

@ -13,6 +13,7 @@ fn final_wave_field(
async fn main() -> anyhow::Result<()> {
use chrono::Utc;
use ghostlight_dungeon::{
compiler::DestinationCompilationFailure,
domain::{TickSource, WorldCommand},
kernel::{CommandResult, WorldKernel},
model_runtime::ModelRuntimeSelection,
@ -170,9 +171,51 @@ async fn main() -> anyhow::Result<()> {
}))?,
)?;
let request = strategic_locality_request(&location_name, location_id, &pressure);
let (preview, receipts) = compiler
let compilation = compiler
.compile_destination(&campaign, location_id, &request)
.await?;
.await;
let (preview, receipts) = match compilation {
Ok(compilation) => compilation,
Err(error) => {
let failure_receipts = error
.downcast_ref::<DestinationCompilationFailure>()
.map(|failure| failure.model_receipts.clone())
.unwrap_or_default();
let receipt_hashes = failure_receipts
.iter()
.map(|receipt| receipt.storage_key().to_owned())
.collect::<Vec<_>>();
let persistence_error = if failure_receipts.is_empty() {
None
} else {
store
.persist_model_stage_receipts(&failure_receipts)
.err()
.map(|error| error.to_string())
};
std::fs::write(
root.join(format!(
"elaboration-{:02}-terminal-failure.json",
index + 1
)),
serde_json::to_vec_pretty(&serde_json::json!({
"schema":"ghostlight.strategic_elaboration_failure.v1",
"location_id":location_id,
"location_name":location_name,
"request":request,
"error":error.to_string(),
"model_receipt_hashes":receipt_hashes,
"receipt_persistence_error":&persistence_error,
}))?,
)?;
if let Some(persistence_error) = persistence_error {
return Err(anyhow::anyhow!(
"{error}; model-receipt persistence failed: {persistence_error}"
));
}
return Err(error);
}
};
let command = match &preview {
ghostlight_dungeon::domain::DestinationCompilationPreview::LocalityElaboration(
preview,

File diff suppressed because it is too large Load diff

View file

@ -15,7 +15,10 @@ use chrono::{DateTime, Utc};
use ghostlight_dungeon::domain::WorldCompilePreview;
use ghostlight_dungeon::{
assessor::ActionAssessor,
compiler::{GestaltFissionRequest, OpeningRequest, OpeningSuggestion, WorldCompiler},
compiler::{
DestinationCompilationFailure, GestaltFissionRequest, OpeningRequest, OpeningSuggestion,
WorldCompiler,
},
domain::{
ActionIntent, Campaign, DestinationCompilationPreview, GestaltFissionPreview,
RejectedProposalReceipt, WorldCommand,
@ -4023,7 +4026,23 @@ async fn compile_destination(
}))
.into_response()
}
Err(error) => (StatusCode::UNPROCESSABLE_ENTITY, error.to_string()).into_response(),
Err(error) => {
if let Some(failure) = error.downcast_ref::<DestinationCompilationFailure>()
&& let Err(persistence_error) = runtime
.store
.persist_model_stage_receipts(&failure.model_receipts)
{
return (
StatusCode::INTERNAL_SERVER_ERROR,
format!(
"{}; model-receipt persistence failed: {persistence_error}",
failure.message
),
)
.into_response();
}
(StatusCode::UNPROCESSABLE_ENTITY, error.to_string()).into_response()
}
}
}
@ -6527,6 +6546,7 @@ mod tests {
model_status: ModelRuntimeStatus {
provider: "fixture".into(),
fast_model: "fixture".into(),
balanced_model: "fixture".into(),
capable_model: "fixture".into(),
readiness: "ready".into(),
},

View file

@ -686,6 +686,7 @@ mod tests {
ModelRuntimeStatus {
provider: "fixture".into(),
fast_model: "fixture-fast".into(),
balanced_model: "fixture-balanced".into(),
capable_model: "fixture-capable".into(),
readiness: "ready".into(),
}

View file

@ -7,6 +7,7 @@ use std::time::Instant;
use zeroize::Zeroizing;
pub const MODEL_FAST: &str = "ghostlight.fast.v1";
pub const MODEL_BALANCED: &str = "ghostlight.balanced.v1";
pub const MODEL_CAPABLE: &str = "ghostlight.capable.v1";
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
@ -14,6 +15,7 @@ pub const MODEL_CAPABLE: &str = "ghostlight.capable.v1";
pub struct ModelRuntimeStatus {
pub provider: String,
pub fast_model: String,
pub balanced_model: String,
pub capable_model: String,
pub readiness: String,
}
@ -1063,6 +1065,17 @@ mod tests {
openrouter_request_body(&capable, "stealth/ox-alpha")["reasoning"]["effort"],
"medium"
);
let mut balanced = capable;
balanced.model = MODEL_BALANCED.into();
assert_eq!(
openrouter_request_body(&balanced, "stealth/ox-alpha")["reasoning"]["effort"],
"medium"
);
assert_eq!(
resolve_model(&balanced, "fixture-fast", "fixture-capable"),
"fixture-capable"
);
}
#[test]
@ -1431,7 +1444,7 @@ fn openrouter_request_body(request: &ModelStageRequest, resolved_model: &str) ->
"messages": [{"role": "user", "content": request.lived_stream}],
"stream": false,
"reasoning": {
"effort": if request.model == MODEL_CAPABLE { "medium" } else { "low" },
"effort": if matches!(request.model.as_str(), MODEL_BALANCED | MODEL_CAPABLE) { "medium" } else { "low" },
"exclude": true
}
});
@ -1470,6 +1483,7 @@ impl ModelPort for OpenRouterPort {
fn resolve_model(request: &ModelStageRequest, fast_model: &str, capable_model: &str) -> String {
match request.model.as_str() {
MODEL_FAST => fast_model.to_owned(),
MODEL_BALANCED => capable_model.to_owned(),
MODEL_CAPABLE => capable_model.to_owned(),
explicit => explicit.to_owned(),
}

View file

@ -15,12 +15,14 @@ use tokio::sync::Semaphore;
use zeroize::Zeroizing;
use crate::model::{
MODEL_CAPABLE, MODEL_FAST, ModelPort, ModelProviderOutput, ModelStageRequest, ModelTokenUsage,
MODEL_BALANCED, MODEL_CAPABLE, MODEL_FAST, ModelPort, ModelProviderOutput, ModelStageRequest,
ModelTokenUsage,
};
const MAX_FRAME_BYTES: usize = 1_052_672;
const REQUEST_EXPIRY: Duration = Duration::from_secs(150);
const FAST_ATTEMPT_TIMEOUT: Duration = Duration::from_secs(120);
const BALANCED_ATTEMPT_TIMEOUT: Duration = Duration::from_secs(180);
const CAPABLE_ATTEMPT_TIMEOUT: Duration = Duration::from_secs(300);
#[derive(Clone)]
@ -29,6 +31,7 @@ pub struct CodexConnectorModelPort {
request_gate: std::sync::Arc<Semaphore>,
caller_runtime_id: String,
fast_model: String,
balanced_model: String,
capable_model: String,
}
@ -38,6 +41,7 @@ impl CodexConnectorModelPort {
connection_key: String,
caller_runtime_id: impl Into<String>,
fast_model: impl Into<String>,
balanced_model: impl Into<String>,
capable_model: impl Into<String>,
max_concurrent_requests: usize,
) -> Result<Self> {
@ -54,6 +58,7 @@ impl CodexConnectorModelPort {
request_gate: std::sync::Arc::new(Semaphore::new(max_concurrent_requests)),
caller_runtime_id,
fast_model: fast_model.into(),
balanced_model: balanced_model.into(),
capable_model: capable_model.into(),
})
}
@ -63,6 +68,7 @@ impl CodexConnectorModelPort {
path: impl AsRef<Path>,
caller_runtime_id: impl Into<String>,
fast_model: impl Into<String>,
balanced_model: impl Into<String>,
capable_model: impl Into<String>,
max_concurrent_requests: usize,
) -> Result<Self> {
@ -77,6 +83,7 @@ impl CodexConnectorModelPort {
connection_key.to_owned(),
caller_runtime_id,
fast_model,
balanced_model,
capable_model,
max_concurrent_requests,
)
@ -86,6 +93,7 @@ impl CodexConnectorModelPort {
let request_id = format!("ghostlight-model-{}", uuid::Uuid::new_v4());
let resolved_model = match request.model.as_str() {
MODEL_FAST => self.fast_model.clone(),
MODEL_BALANCED => self.balanced_model.clone(),
MODEL_CAPABLE => self.capable_model.clone(),
explicit => explicit.to_string(),
};
@ -99,7 +107,7 @@ impl CodexConnectorModelPort {
text: request.lived_stream.clone(),
}];
provider_request.reasoning_effort = Some(
if request.model == MODEL_CAPABLE {
if matches!(request.model.as_str(), MODEL_BALANCED | MODEL_CAPABLE) {
"medium"
} else {
"low"
@ -156,10 +164,10 @@ impl ModelPort for CodexConnectorModelPort {
}
fn attempt_timeout(&self, request: &ModelStageRequest) -> Duration {
if request.model == MODEL_CAPABLE {
CAPABLE_ATTEMPT_TIMEOUT
} else {
FAST_ATTEMPT_TIMEOUT
match request.model.as_str() {
MODEL_BALANCED => BALANCED_ATTEMPT_TIMEOUT,
MODEL_CAPABLE => CAPABLE_ATTEMPT_TIMEOUT,
_ => FAST_ATTEMPT_TIMEOUT,
}
}
}
@ -618,6 +626,7 @@ mod tests {
"connector-test-key".to_string(),
"ghostlight-dungeon-yggdrasil",
"gpt-5.6-luna",
"gpt-5.6-terra",
"gpt-5.6-luna",
1,
)?;
@ -625,7 +634,7 @@ mod tests {
let output = port
.run_observed(&ModelStageRequest {
stage: "test_interpreter".to_string(),
model: MODEL_CAPABLE.to_string(),
model: MODEL_BALANCED.to_string(),
snapshot_binding: "revision:7".to_string(),
lived_stream: "Return the typed answer.".to_string(),
output_schema: Some(serde_json::json!({
@ -640,7 +649,7 @@ mod tests {
})
.await?;
let invocation = server.join().expect("server thread")?;
assert_eq!(invocation.request.model, "gpt-5.6-luna");
assert_eq!(invocation.request.model, "gpt-5.6-terra");
assert_eq!(invocation.request.max_output_tokens, Some(512));
assert_eq!(
invocation.request.output_format_name.as_deref(),
@ -708,6 +717,7 @@ mod tests {
"bounded-test-key".to_string(),
"ghostlight-test",
"gpt-5.6-luna",
"gpt-5.6-terra",
"gpt-5.6-sol",
1,
)?;
@ -723,6 +733,10 @@ mod tests {
};
assert_eq!(port.attempt_timeout(&request), CAPABLE_ATTEMPT_TIMEOUT);
request.stage = "destination_civic_reconciliation".to_string();
request.model = MODEL_BALANCED.to_string();
assert_eq!(port.attempt_timeout(&request), BALANCED_ATTEMPT_TIMEOUT);
request.stage = "cell_interpreter".to_string();
request.model = MODEL_FAST.to_string();
assert_eq!(port.attempt_timeout(&request), FAST_ATTEMPT_TIMEOUT);

View file

@ -13,6 +13,7 @@ use std::{
pub struct ModelRuntimeSelection {
pub provider: String,
pub fast_model: String,
pub balanced_model: String,
pub capable_model: String,
pub credential_path: PathBuf,
pub connector_endpoint: SocketAddr,
@ -25,17 +26,38 @@ impl ModelRuntimeSelection {
let provider = std::env::var("GHOSTLIGHT_MODEL_PROVIDER")
.unwrap_or_else(|_| "deepseek".into())
.to_ascii_lowercase();
let (default_fast_model, default_capable_model, default_secret_name) =
match provider.as_str() {
"deepseek" => ("deepseek-v4-flash", "deepseek-v4-pro", "deepseek.dpapi"),
"openrouter" => ("stealth/ox-alpha", "stealth/ox-alpha", "openrouter.key"),
"codex-connector" => ("gpt-5.6-luna", "gpt-5.6-luna", "codex-connector.key"),
unsupported => bail!("unsupported model provider {unsupported}"),
};
let (
default_fast_model,
default_balanced_model,
default_capable_model,
default_secret_name,
) = match provider.as_str() {
"deepseek" => (
"deepseek-v4-flash",
"deepseek-v4-pro",
"deepseek-v4-pro",
"deepseek.dpapi",
),
"openrouter" => (
"stealth/ox-alpha",
"stealth/ox-alpha",
"stealth/ox-alpha",
"openrouter.key",
),
"codex-connector" => (
"gpt-5.6-luna",
"gpt-5.6-terra",
"gpt-5.6-luna",
"codex-connector.key",
),
unsupported => bail!("unsupported model provider {unsupported}"),
};
Ok(Self {
provider,
fast_model: std::env::var("GHOSTLIGHT_MODEL_FAST")
.unwrap_or_else(|_| default_fast_model.into()),
balanced_model: std::env::var("GHOSTLIGHT_MODEL_BALANCED")
.unwrap_or_else(|_| default_balanced_model.into()),
capable_model: std::env::var("GHOSTLIGHT_MODEL_CAPABLE")
.unwrap_or_else(|_| default_capable_model.into()),
credential_path: std::env::var_os("GHOSTLIGHT_MODEL_CREDENTIAL")
@ -65,6 +87,7 @@ impl ModelRuntimeSelection {
ModelRuntimeStatus {
provider: self.provider.clone(),
fast_model: self.fast_model.clone(),
balanced_model: self.balanced_model.clone(),
capable_model: self.capable_model.clone(),
readiness: readiness.into(),
}
@ -90,6 +113,7 @@ impl ModelRuntimeSelection {
&self.credential_path,
self.runtime_id.clone(),
self.fast_model.clone(),
self.balanced_model.clone(),
self.capable_model.clone(),
self.connector_max_concurrent_requests,
)?),

View file

@ -426,7 +426,8 @@ performs her own exact CAS.
- **Model transport:** Ghostlight defines an async stage-runner port. Epiphany
implements it with `EpiphanyModelRequest`, Codex/OpenAI-compatible auth,
runtime jobs, and private model-event recovery. GhostlightDungeon implements
it with the selected provider port and logical fast/capable model classes.
it with the selected provider port and logical fast/balanced/capable model
classes.
- **Receipts:** Ghostlight owns portable stage and terminal fields. Epiphany's
adapter augments them with `EpiphanyReasoningBasis`, sealed decision contexts,
brake evidence, and runtime-spine identities.
@ -926,12 +927,15 @@ acceptance can reject stages that spend heavily while producing no meaningful
appraisal, state proposal, or player-facing consequence.
Model allocation is provider-neutral inside Ghostlight. Stages request the
logical classes `ghostlight.fast.v1` or `ghostlight.capable.v1`; the selected
provider port alone maps those classes to physical model IDs. Receipts record
the resolved provider and physical model so a routing change cannot masquerade
as the same inference.
logical classes `ghostlight.fast.v1`, `ghostlight.balanced.v1`, or
`ghostlight.capable.v1`; the selected provider port alone maps those classes to
physical model IDs. The fast class owns high-volume work, the balanced class
owns bounded reconciliation and routine elaboration, and the capable class owns
frontier invention and editorial judgment. Receipts record the resolved
provider and physical model so a routing change cannot masquerade as the same
inference.
The `epiphany-codex` profile maps both logical classes to an operator-admitted
The `epiphany-codex` profile maps all three logical classes to operator-admitted
Codex model through Epiphany's independently supervised model connector. The
Ghostlight port constructs the native model request, exact output schema,
reasoning-effort hint, maximum output budget, and a stable prompt-cache key;
@ -944,15 +948,15 @@ receipts. It does not see campaign stores, run its Mind or swarm, interpret
results, or admit world state. Ghostlight cannot read the Codex credential and
the connector cannot commit a campaign mutation.
OpenRouter remains a supported test profile. It can map both classes to
`stealth/ox-alpha`, using low reasoning for fast stages and high reasoning for
capable stages. OpenRouter is instructed to exclude reasoning from its
response, and the decoder never reads or retains that field.
OpenRouter remains a supported test profile. It maps the balanced class to its
configured capable model, using low reasoning for fast stages and medium
reasoning for balanced or capable stages. OpenRouter is instructed to exclude
reasoning from its response, and the decoder never reads or retains that field.
DeepSeek remains a supported provider profile: its flash model serves the fast
class and its pro model serves the capable class with thinking disabled. A
provider switch changes configuration and credentials, not compiler, Persona,
Interpreter, scheduler, or kernel ownership.
class and its pro model serves the balanced and capable classes with thinking
disabled. A provider switch changes configuration and credentials, not
compiler, Persona, Interpreter, scheduler, or kernel ownership.
## Hosting and security

View file

@ -249,6 +249,13 @@ neither side. Yggdrasil runs CodexConnector as the independent
systemd ordering edge to that daemon and cannot build, configure, restart,
select, or roll it back.
Ghostlight exposes three provider-neutral logical classes. `ghostlight.fast.v1`
owns high-volume cells and retrieval, `ghostlight.balanced.v1` owns bounded
reconciliation and routine elaboration, and `ghostlight.capable.v1` owns
frontier invention and editorial judgment. Only the selected `ModelPort` maps
those classes to physical models or assigns their attempt deadlines; compilers
and harnesses never pass physical model IDs as logical stage authority.
Vault availability is typed at the provider boundary. When the configured
Vault cannot return evidence, SessionZeroKernel returns the exact draft to
`drafting`, records one stable resolved material blocker, and publishes no
@ -910,11 +917,22 @@ the office, procedure, or answer. Inhabited proposals must expose current
authority, selection or succession, public resources, and redress through a
typed civic manifest whose exact fact references are shared by each resident
population. A separate model stage verifies their semantic legibility; it may
reject but cannot rewrite or commit the proposal. The kernel rebinds that
verdict to the exact candidate before mutation admission. Accepted civic
systems persist as versioned component state, so a later pass receives the
current institutions, populations, facts, and relations and must extend that
apparatus instead of inventing a parallel government.
reject but cannot rewrite or commit the proposal. One false verdict is
independently rechecked against the same frozen candidate. A sustained rejection
invokes one balanced reconciliation over a civic-only replacement schema:
candidate-owned civic facts, resident civic fact references, candidate
institutions, local political relations, and the civic manifest. Geography,
routes, migration, population identity, non-civic facts, branch assumptions,
gaps, civic version, and semantic receipt binding have no writable field in
that pass. The merged candidate must survive the ordinary destination validators
and a fresh independent verdict; the expensive `destination_compile` stage is
not rerun. The kernel rebinds the accepted verdict to the exact candidate before
mutation admission. Completed compiler, reconciliation, and verifier receipts
survive terminal failure and are persisted by both the strategic harness and
the Dungeon API. Accepted civic systems persist as versioned component state,
so a later pass receives the current institutions, populations, facts, and
relations and must extend that apparatus instead of inventing a parallel
government.
Both destination paths synthesize the smallest compatible branch-local routes,
geometry, people, supplies, procedures, capacity, responsibility, and doctrine