Add human WebUI closure of unknown jobs as final closed_unknown state (spec 1.31); bound agent sync restart interval
Rust development slice / linux (push) Failing after 7s

This commit is contained in:
2026-11-17 11:13:36 +01:00
parent 2660f6a88d
commit d6dfd01a9c
11 changed files with 363 additions and 29 deletions
+16 -2
View File
@@ -786,6 +786,14 @@ impl<V: Ed25519Verifier> HelperSync<V> {
validate_decision(row, local, d)?;
if d.unlock {
let bytes = unlock_outcome(row, d, current_boot)?;
if d.outcome_state == "closed_unknown" {
crate::ledger::retain_closure_original(
&tx,
row.grant_id,
&row.outcome_bytes,
&bytes,
)?;
}
let preserve = crate::windows_system_nonstart::preserve_original_unlock(
&tx,
&self.binding,
@@ -1523,6 +1531,7 @@ fn load_rows(
| "failed"
| "cancelled"
| "expired"
| "closed_unknown"
| "running"
),
"UNKNOWN_LOCAL_STATE"
@@ -1610,7 +1619,7 @@ fn load_rows(
fn definitive(row: &LocalAttempt) -> bool {
matches!(
row.state.as_str(),
"succeeded" | "failed" | "cancelled" | "expired"
"succeeded" | "failed" | "cancelled" | "expired" | "closed_unknown"
) && !row.outcome_bytes.is_empty()
}
fn validate_summary(row: &LocalAttempt, a: &AttemptView) -> Result<()> {
@@ -1670,7 +1679,7 @@ fn validate_decision(row: &LocalAttempt, a: &AttemptView, d: &AttemptDecision) -
!d.unlock
|| matches!(
d.outcome_state.as_str(),
"succeeded" | "failed" | "cancelled" | "expired"
"succeeded" | "failed" | "cancelled" | "expired" | "closed_unknown"
),
"UNKNOWN_CANNOT_UNLOCK"
);
@@ -1689,6 +1698,11 @@ fn unlock_outcome(row: &LocalAttempt, d: &AttemptDecision, current_boot: Uuid) -
&& o.state == d.outcome_state,
"ROOT_CANONICAL_UNLOCK_OUTCOME"
);
if bytes != row.outcome_bytes
&& crate::reconcile::operator_closure(&d.reason, &row.state, &o)
{
return Ok(bytes);
}
if bytes != row.outcome_bytes {
ensure!(
row.action == "reboot"
+31
View File
@@ -34,6 +34,37 @@ pub fn initialize_ledger(db: &rusqlite::Connection) -> Result<()> {
Ok(())
}
/// Before a human WebUI closure replaces the unresolved local outcome, keep the
/// exact original outcome bytes once. A differing second copy fails closed.
pub(crate) fn retain_closure_original(
db: &rusqlite::Connection,
grant: Uuid,
original: &[u8],
closure: &[u8],
) -> Result<()> {
db.execute_batch("CREATE TABLE IF NOT EXISTS unknown_closure_originals(grant_id TEXT PRIMARY KEY, original_outcome BLOB NOT NULL, closure_outcome BLOB NOT NULL);")?;
let existing: Option<(Vec<u8>, Vec<u8>)> = db
.query_row(
"SELECT original_outcome,closure_outcome FROM unknown_closure_originals WHERE grant_id=?1",
[grant.to_string()],
|r| Ok((r.get(0)?, r.get(1)?)),
)
.optional()?;
match existing {
Some((old, done)) => ensure!(
done == closure && (old == original || original == closure),
"CLOSURE_ORIGINAL_CHANGED"
),
None => {
db.execute(
"INSERT INTO unknown_closure_originals VALUES(?1,?2,?3)",
params![grant.to_string(), original, closure],
)?;
}
}
Ok(())
}
/// Legacy split reservation API retained for old fixtures/readers. Production
/// callers use begin_execution so a crash cannot lose the original start witness.
pub fn consume(db: &mut rusqlite::Connection, p: &ExecutionPermitPayload) -> Result<()> {
+64 -2
View File
@@ -1036,6 +1036,7 @@ impl<V: Ed25519Verifier> ClientSync<V> {
let previous = resolved
.or(previous)
.context("LOCAL_UNLOCK_PREVIOUS_OUTCOME_MISSING")?;
let original = previous.clone();
let prior = canonical_outcome_bytes(&serde_json::from_slice::<ReconciledOutcome>(
&previous,
)?)?;
@@ -1062,6 +1063,9 @@ impl<V: Ed25519Verifier> ClientSync<V> {
grant,
&bytes,
)?;
if outcome.state == "closed_unknown" {
crate::ledger::retain_closure_original(&tx, grant, &original, &bytes)?;
}
tx.execute(
"UPDATE consumed SET result=?2 WHERE grant_id=?1",
params![grant.to_string(), bytes],
@@ -1200,7 +1204,29 @@ pub(crate) fn outcome(r: &JobResult) -> Result<ReconciledOutcome> {
})
}
fn terminal(state: &str) -> bool {
matches!(state, "succeeded" | "failed" | "cancelled" | "expired")
matches!(
state,
"succeeded" | "failed" | "cancelled" | "expired" | "closed_unknown"
)
}
/// Server-signed final bytes of a human WebUI closure for an attempt whose
/// effect stayed unknown. They never claim success, failure or nonstart.
pub(crate) fn operator_closure(
reason: &str,
local_state: &str,
outcome: &ReconciledOutcome,
) -> bool {
reason == "OPERATOR_CLOSED_UNKNOWN"
&& local_state == "unknown"
&& outcome.state == "closed_unknown"
&& outcome.error_code == "OPERATOR_CLOSED_UNKNOWN"
&& outcome.exit_code.is_none()
&& outcome.stdout.is_empty()
&& outcome.stderr.is_empty()
&& outcome.evidence["postconditions_passed"] == false
&& outcome.evidence["effect"] == "unknown"
&& outcome.evidence["closed_by_human"] == true
&& outcome.evidence["retry"] == false
}
fn optional_uuid(s: &str) -> Result<Option<Uuid>> {
if s.is_empty() {
@@ -1861,7 +1887,7 @@ fn validate_attempt(
&& o.state == d.outcome_state,
"SYNC_CANONICAL_OUTCOME"
);
if bytes != local.outcome_bytes {
if bytes != local.outcome_bytes && !operator_closure(&d.reason, &local.state, &o) {
ensure!(
matches!(job.action, rmm_domain::jobs::Action::Reboot { .. })
&& d.outcome_state == "succeeded"
@@ -2166,3 +2192,39 @@ pub fn closed_control_contract(raw: &[u8]) -> Result<serde_json::Value> {
json!({"actual_closed_partial_edge_accepted":true,"mutated_agent_request_rejected":true,"mutated_server_signature_and_ack_rejected":true,"admission_read_only":true,"hidden_open_grant_rejected":true,"explicit_idle_attestation_required":true,"typed_precommit_clock_keeps_capture_without_writes":true,"fresh_request_keeps_both_heads":true,"old_authority_reused":false,"new_ready_or_unlock":false,"product_databases_opened":false,"effects":false}),
)
}
#[cfg(test)]
mod closure_tests {
use super::*;
#[test]
fn only_a_human_closure_of_a_locally_unknown_attempt_is_accepted() {
let closed = ReconciledOutcome {
state: "closed_unknown".into(),
stdout: vec![],
stderr: vec![],
exit_code: None,
output_truncated: false,
reboot_required: false,
evidence: serde_json::json!({"postconditions_passed":false,"effect":"unknown","closed_by_human":true,"retry":false}),
error_code: "OPERATOR_CLOSED_UNKNOWN".into(),
};
assert!(operator_closure("OPERATOR_CLOSED_UNKNOWN", "unknown", &closed));
assert!(!operator_closure("DEFINITIVE_OUTCOME_RECONCILED", "unknown", &closed));
assert!(!operator_closure("OPERATOR_CLOSED_UNKNOWN", "running", &closed));
assert!(!operator_closure("OPERATOR_CLOSED_UNKNOWN", "succeeded", &closed));
for case in 0..6 {
let mut other = closed.clone();
match case {
0 => other.state = "failed".into(),
1 => other.error_code = "SCRIPT_FAILED".into(),
2 => other.exit_code = Some(0),
3 => other.stdout = b"x".to_vec(),
4 => other.evidence["postconditions_passed"] = true.into(),
_ => other.evidence["retry"] = true.into(),
}
assert!(!operator_closure("OPERATOR_CLOSED_UNKNOWN", "unknown", &other));
}
assert!(terminal("closed_unknown"));
}
}