Elaboration: a clean patch that leaves its boundary standing is a refusal with what the answer needs, not a failed session
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
2c17cf8fa3
commit
2ac36ddc68
3 changed files with 115 additions and 40 deletions
|
|
@ -14383,6 +14383,43 @@ mod tests {
|
|||
task.await.unwrap();
|
||||
}
|
||||
|
||||
/// A patch the resolver admits but that leaves its boundary standing is
|
||||
/// refused with no site. The session is repaired like any refusal, and the
|
||||
/// repair turn says what the answer needs; it does not fail the session.
|
||||
#[tokio::test]
|
||||
async fn a_patch_that_leaves_its_boundary_standing_is_repaired_with_what_it_needs() {
|
||||
let (_directory, mailbox, task, commons, roads) = dead_end_world(
|
||||
crate::tests::stock_weights(),
|
||||
&["The Unwalked Road"],
|
||||
Roots::Commons,
|
||||
0,
|
||||
)
|
||||
.await;
|
||||
let good = shed_on_the_named_road(vec![("The Unwalked Road", roads[0])]);
|
||||
let port = Arc::new(SweepPort::new(move |call, request| {
|
||||
if call == 0 {
|
||||
// Admissible, and nowhere near the dead end.
|
||||
shed_round(
|
||||
json!({"ref": "existing", "value": serde_json::to_value(commons).unwrap()}),
|
||||
"The Shed Elsewhere",
|
||||
"elsewhere",
|
||||
)
|
||||
} else {
|
||||
good(call, request)
|
||||
}
|
||||
}));
|
||||
let runner = sweep_runner(&mailbox, port.clone(), fresh_store());
|
||||
let first = runner.sweep(pool(1), 1).await.unwrap();
|
||||
assert_eq!((first.rejected, first.failed.len()), (1, 0), "{first:?}");
|
||||
let second = runner.sweep(pool(1), 1).await.unwrap();
|
||||
assert_eq!(second.committed, 1, "{second:?}");
|
||||
let repair = wire_of(&port.seen.lock().unwrap()[1]);
|
||||
assert!(repair.contains(REFUSAL_TURN) && repair.contains("dead end"), "{repair}");
|
||||
drop(runner);
|
||||
drop(mailbox);
|
||||
task.await.unwrap();
|
||||
}
|
||||
|
||||
/// A session the world keeps refusing ends after `MAX_REFUSALS` repairs, is
|
||||
/// stored without a patch, counted in the report, and takes no slot after.
|
||||
#[tokio::test]
|
||||
|
|
|
|||
|
|
@ -630,51 +630,58 @@ impl ElaborationRunner {
|
|||
draft,
|
||||
)
|
||||
.await;
|
||||
return match submitted {
|
||||
Ok(_) => Ok(ElaborationOutcome::Committed),
|
||||
let mismatches = match submitted {
|
||||
Ok(_) => return Ok(ElaborationOutcome::Committed),
|
||||
Err(MailboxError::Kernel(KernelError::PatchRejected(mismatches))) => {
|
||||
// A rejected command mutates nothing, so reusing the
|
||||
// id is correct and the idempotency probe never sees
|
||||
// a conflicting commit.
|
||||
refusals.push(Refusal {
|
||||
after_round: completed.len(),
|
||||
mismatches,
|
||||
});
|
||||
if refusals.len() > MAX_REFUSALS {
|
||||
let last = refusals.last().map_or_else(String::new, |refusal| {
|
||||
render_refusal_sites(&refusal.mismatches)
|
||||
});
|
||||
tracing::error!(
|
||||
command_id = ?command_id,
|
||||
refusals = refusals.len(),
|
||||
last_refusal = %last,
|
||||
"elaboration session abandoned: the world kept refusing its patch"
|
||||
);
|
||||
self.persist(ElaborationCheckpoint::NoPatch {
|
||||
command_id,
|
||||
session,
|
||||
agent_prompt,
|
||||
refusals,
|
||||
completed,
|
||||
gaps: vec![ControllerNeed {
|
||||
detail: format!(
|
||||
"The world refused the patch {} times; last refusal: {last}",
|
||||
MAX_REFUSALS + 1
|
||||
),
|
||||
}],
|
||||
})
|
||||
.await?;
|
||||
return Ok(ElaborationOutcome::Abandoned);
|
||||
}
|
||||
self.persist_repair(command_id, &session, &agent_prompt, &refusals, &completed)
|
||||
.await?;
|
||||
Ok(ElaborationOutcome::Rejected)
|
||||
mismatches
|
||||
}
|
||||
// The patch resolved and the answer still stands: the
|
||||
// kernel names no site, so the repair is told what the
|
||||
// answer needs.
|
||||
Err(MailboxError::Kernel(KernelError::AnswerNotSatisfied)) => {
|
||||
vec![unsatisfied_answer(snapshot, &session.answer)]
|
||||
}
|
||||
Err(MailboxError::Kernel(KernelError::AnswerNotDerived)) => {
|
||||
Ok(ElaborationOutcome::Superseded)
|
||||
return Ok(ElaborationOutcome::Superseded);
|
||||
}
|
||||
Err(error) => Err(snapshot_error(error)),
|
||||
Err(error) => return Err(snapshot_error(error)),
|
||||
};
|
||||
// A rejected command mutates nothing, so reusing the
|
||||
// id is correct and the idempotency probe never sees
|
||||
// a conflicting commit.
|
||||
refusals.push(Refusal {
|
||||
after_round: completed.len(),
|
||||
mismatches,
|
||||
});
|
||||
if refusals.len() > MAX_REFUSALS {
|
||||
let last = refusals.last().map_or_else(String::new, |refusal| {
|
||||
render_refusal_sites(&refusal.mismatches)
|
||||
});
|
||||
tracing::error!(
|
||||
command_id = ?command_id,
|
||||
refusals = refusals.len(),
|
||||
last_refusal = %last,
|
||||
"elaboration session abandoned: the world kept refusing its patch"
|
||||
);
|
||||
self.persist(ElaborationCheckpoint::NoPatch {
|
||||
command_id,
|
||||
session,
|
||||
agent_prompt,
|
||||
refusals,
|
||||
completed,
|
||||
gaps: vec![ControllerNeed {
|
||||
detail: format!(
|
||||
"The world refused the patch {} times; last refusal: {last}",
|
||||
MAX_REFUSALS + 1
|
||||
),
|
||||
}],
|
||||
})
|
||||
.await?;
|
||||
return Ok(ElaborationOutcome::Abandoned);
|
||||
}
|
||||
self.persist_repair(command_id, &session, &agent_prompt, &refusals, &completed)
|
||||
.await?;
|
||||
return Ok(ElaborationOutcome::Rejected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1263,6 +1270,28 @@ pub(super) fn render_jurisdiction(snapshot: &WorldSnapshot, jurisdiction: Jurisd
|
|||
}
|
||||
}
|
||||
|
||||
/// What the world still lacks when a clean patch did not answer. The wording
|
||||
/// follows each boundary's own predicate: the repair is a patch that makes the
|
||||
/// predicate stop holding.
|
||||
fn unsatisfied_answer(snapshot: &WorldSnapshot, answer: &PatchAnswer) -> Mismatch {
|
||||
let needs = match answer {
|
||||
PatchAnswer::Boundary(CausalBoundary::MissingStructure { .. }) => {
|
||||
"the promise's counterparty must be able to command the promisor (grant_authority over it) or the promisor must fall under a standing forum (open_forum with standing over the counterparty); declaring more subjects or facts does not answer it"
|
||||
}
|
||||
PatchAnswer::Boundary(CausalBoundary::UnelaboratedDestination { .. }) => {
|
||||
"the place must stop being a dead end: put something in it, or give it a second route"
|
||||
}
|
||||
PatchAnswer::Boundary(_) => "the boundary's own structure must change",
|
||||
PatchAnswer::Deficit(_) => {
|
||||
"more subjects must qualify in this jurisdiction: each needs a controller, an affordance grant, a position inside it and a held goal"
|
||||
}
|
||||
};
|
||||
Mismatch::AnswerNotSatisfied {
|
||||
answered: render_answer(snapshot, answer),
|
||||
needs: needs.to_owned(),
|
||||
}
|
||||
}
|
||||
|
||||
fn render_answer(snapshot: &WorldSnapshot, answer: &PatchAnswer) -> String {
|
||||
let referents = answer_referents(snapshot, answer).join(", ");
|
||||
match answer {
|
||||
|
|
|
|||
|
|
@ -1444,6 +1444,15 @@ pub(crate) fn check_patch_caps(patch: &WorldPatch) -> Result<(), PatchDecodeErro
|
|||
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
#[serde(tag = "mismatch", rename_all = "snake_case")]
|
||||
pub enum Mismatch {
|
||||
/// The patch resolved cleanly and was admitted, and the boundary or deficit
|
||||
/// it answered still stands, so the world refused it with
|
||||
/// `KernelError::AnswerNotSatisfied`. That refusal names no site, so the
|
||||
/// elaboration runner states what the answer needs here, and the repair
|
||||
/// round has something to author against.
|
||||
AnswerNotSatisfied {
|
||||
answered: String,
|
||||
needs: String,
|
||||
},
|
||||
EmptyHandle {
|
||||
position: usize,
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in a new issue