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
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
@@ -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"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user