Add versioned script library, reconcile permit refusals and compact helper captures

This commit is contained in:
2026-11-17 15:45:56 +01:00
parent a576c10e8a
commit 8e2fef7007
29 changed files with 1225 additions and 50 deletions
+24
View File
@@ -260,6 +260,30 @@ pub fn recover_interrupted_outcome_with(
Ok(Some(saved))
}
/// A refusal carries no execution authority. An unbound or ambiguous refusal
/// remains local uncertainty until the signed reconciliation resolves it.
pub fn denied_request(db: &Connection, offer: &JobOffer, permit: &ExecutionPermit) -> Result<()> {
ensure!(
!permit.denial_code.is_empty() && permit.payload_bytes.is_empty() && permit.signature.is_empty(),
"INVALID_PERMIT_DENIAL"
);
let Some(request) = &permit.unreserved_request else {
return interrupted_request(db, offer);
};
let job: JobPayload = serde_json::from_slice(&offer.payload_bytes)?;
ensure!(
request.job_id == offer.job_id && request.attempt_id == offer.attempt_id
&& request.job_payload_hash == offer.job_payload_hash
&& request.assignment_version == job.assignment_version,
"PERMIT_DENIAL_BINDING"
);
ensure!(db.execute(
"UPDATE job_attempts SET state='accepted' WHERE job=?1 AND attempt=?2 AND state='requesting' AND grant_id=''",
params![offer.job_id, offer.attempt_id],
)? == 1, "PERMIT_DENIAL_STATE");
Ok(())
}
pub fn interrupted_request(db: &Connection, offer: &JobOffer) -> Result<()> {
ensure!(
db.execute(