Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ All notable user-facing changes are recorded here. Format loosely follows
`rollback_source: 1` no longer refuses with `pending_confirm` once entry 0
has been confirmed, and the restart re-probe settles a crashed change-set
commit that was confirmed since without a new commit. (#632)
- `commit_check_config`, `load_and_commit_config`, `render_and_apply_j2_template`,
`rollback_config` and `apply_junos_change_set` now refuse with
`commit_confirmed_active` while a commit confirmed is pending. A commit check
or commit silently confirms it, so a validate-only call could cancel another
session's safety rollback. (#632)

## [2.7.3] - 2026-11-09

Expand Down
14 changes: 8 additions & 6 deletions docs/REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,14 @@ traceable after the fact.
**To confirm** a pending window (cancel the scheduled auto-rollback), call
the `confirm_commit` tool with the device name — it sends the confirming
commit the same way `confirm_junos_change_set` does for the change-set
path. Sending another `load_and_commit_config` (or `rollback_config` /
`render_and_apply_j2_template`) also confirms, since Junos treats any
commit against the candidate as confirmation regardless of which tool
issued it. While a commit-confirmed window is open, `upgrade_junos` refuses
to proceed (`commit_confirmed_active`) rather than reboot a device that
might still roll back its configuration underneath the new image.
path. A commit check or commit made against the candidate would also
confirm it silently, so while a window is open `commit_check_config`,
`load_and_commit_config`, `render_and_apply_j2_template`, `rollback_config`
(when it commits) and `apply_junos_change_set` refuse with
`commit_confirmed_active`, as does `upgrade_junos` (it would otherwise reboot
a device that might still roll back its configuration underneath the new
image). Confirm with `confirm_junos_change_set` or `confirm_commit`, or let
the commit roll back.

## File transfers (`transfer_file` / `fetch_file` / `list_staged_files`)

Expand Down
13 changes: 7 additions & 6 deletions rust-junosmcp-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,15 @@ pub enum JmcpError {
router: String,
},

/// Device has a pending `commit confirmed`. Upgrade would trigger an
/// automatic rollback mid-operation. Operator must confirm
/// Device has a pending `commit confirmed`. A commit check or commit would
/// silently confirm it, and an upgrade would trigger an automatic rollback
/// mid-operation. Operator must confirm
/// (`confirm_junos_change_set` or `confirm_commit`) or let the pending commit
/// roll back first.
#[error(
"active commit-confirmed window [code=commit_confirmed_active]: router '{router}' has a commit confirmed pending; confirm it (`confirm_junos_change_set` for a change set, `confirm_commit` otherwise) or let it roll back, then retry"
)]
UpgradeCommitConfirmedActive {
CommitConfirmedActive {
/// Name of the device with a pending commit-confirmed.
router: String,
},
Expand Down Expand Up @@ -876,7 +877,7 @@ impl JmcpError {
Self::TransferOuterTimeout(_) => "timeout",
Self::ConfirmationRequired { .. } => "confirmation_required",
Self::UpgradeClusterUnsupported { .. } => "unsupported",
Self::UpgradeCommitConfirmedActive { .. } => "commit_confirmed_active",
Self::CommitConfirmedActive { .. } => "commit_confirmed_active",
Self::UpgradeInstallTimeout { .. } => "timeout",
Self::UpgradeRebootTimeout { .. } => "timeout",
Self::UpgradePostVerifyMismatch { .. } => "verify_mismatch",
Expand Down Expand Up @@ -1371,8 +1372,8 @@ mod tests {
}

#[test]
fn upgrade_commit_confirmed_active_display_includes_code_and_confirm_commit() {
let s = JmcpError::UpgradeCommitConfirmedActive {
fn commit_confirmed_active_display_includes_code_and_confirm_commit() {
let s = JmcpError::CommitConfirmedActive {
router: "vsrx-test10".into(),
}
.to_string();
Expand Down
110 changes: 80 additions & 30 deletions rust-junosmcp-core/src/junos_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,23 @@ pub struct JunosTransaction {
allow_plane_owned_writes: bool,
/// Plane-guard warning recorded by `stage()` when the flag let a write through.
plane_warning: std::sync::Mutex<Option<String>>,
/// Plane-guard refusal from `stage()` as `(tool, device, authority, detail)`,
/// kept because the coordinator stringifies stage errors and the caller
/// needs the typed `PlaneManagedConfig` back for its audit kind and code.
plane_refusal: std::sync::Mutex<Option<(&'static str, String, String, String)>>,
/// Typed refusal from `stage()`, kept because the coordinator stringifies
/// stage errors and the caller needs the typed error back for its audit
/// kind and code.
stage_refusal: std::sync::Mutex<Option<StageRefusal>>,
}

/// A `stage()` refusal that must survive the coordinator's stringification.
enum StageRefusal {
/// Plane-guard refusal, the fields of `JmcpError::PlaneManagedConfig`.
Plane {
tool: &'static str,
device: String,
authority: String,
detail: String,
},
/// A commit confirmed is pending on the device (#632).
CommitConfirmedActive { router: String },
}

impl JunosTransaction {
Expand All @@ -279,7 +292,7 @@ impl JunosTransaction {
locked_session: tokio::sync::Mutex::new(None),
allow_plane_owned_writes: false,
plane_warning: std::sync::Mutex::new(None),
plane_refusal: std::sync::Mutex::new(None),
stage_refusal: std::sync::Mutex::new(None),
}
}

Expand All @@ -306,38 +319,56 @@ impl JunosTransaction {
.unwrap_or_else(|poisoned| poisoned.into_inner()) = Some(warning);
}

/// The plane-guard refusal `stage()` returned, rebuilt as the typed error.
pub fn take_plane_refusal(&self) -> Option<JmcpError> {
let (tool, device, authority, detail) = self
.plane_refusal
/// The refusal `stage()` returned, rebuilt as the typed error.
pub fn take_stage_refusal(&self) -> Option<JmcpError> {
let refusal = self
.stage_refusal
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner())
.take()?;
Some(JmcpError::PlaneManagedConfig {
tool,
device,
authority,
detail,
Some(match refusal {
StageRefusal::Plane {
tool,
device,
authority,
detail,
} => JmcpError::PlaneManagedConfig {
tool,
device,
authority,
detail,
},
StageRefusal::CommitConfirmedActive { router } => {
JmcpError::CommitConfirmedActive { router }
}
})
}

/// Remember `error` if it is a plane refusal. A `CandidateCleanupFailed`
/// wrapping one is not recorded: the cleanup failure must stay visible.
fn record_plane_refusal(&self, error: &JmcpError) {
let JmcpError::PlaneManagedConfig {
tool,
device,
authority,
detail,
} = error
else {
return;
/// Remember `error` if it is a plane or pending-commit refusal. A
/// `CandidateCleanupFailed` wrapping one is not recorded: the cleanup
/// failure must stay visible.
fn record_stage_refusal(&self, error: &JmcpError) {
let refusal = match error {
JmcpError::PlaneManagedConfig {
tool,
device,
authority,
detail,
} => StageRefusal::Plane {
tool,
device: device.clone(),
authority: authority.clone(),
detail: detail.clone(),
},
JmcpError::CommitConfirmedActive { router } => StageRefusal::CommitConfirmedActive {
router: router.clone(),
},
_ => return,
};
*self
.plane_refusal
.stage_refusal
.lock()
.unwrap_or_else(|poisoned| poisoned.into_inner()) =
Some((tool, device.clone(), authority.clone(), detail.clone()));
.unwrap_or_else(|poisoned| poisoned.into_inner()) = Some(refusal);
}

/// Revert anything loaded into the candidate and release the lock, then
Expand Down Expand Up @@ -653,12 +684,31 @@ impl DeviceTransaction for JunosTransaction {
let error = self
.revert_and_release(&mut dev, 0, refusal, "plane-owned refusal")
.await;
self.record_plane_refusal(&error);
self.record_stage_refusal(&error);
return Err(error);
}
}
}

// Under the candidate lock, before any commit check or commit: either
// would silently confirm another session's pending commit confirmed.
let pending_error = match dev.cli("show system commit").await {
Err(error) => Some(JmcpError::from(error)),
Ok(log) if crate::commit_attribution::commit_confirm_pending(&log) => {
Some(JmcpError::CommitConfirmedActive {
router: self.router.clone(),
})
}
Ok(_) => None,
};
if let Some(error) = pending_error {
let error = self
.revert_and_release(&mut dev, 0, error, "pending commit confirmed")
.await;
self.record_stage_refusal(&error);
return Err(error);
}

let mut cfg = dev.config()?;

// Load actions. Track success count for partial-failure revert.
Expand Down Expand Up @@ -816,7 +866,7 @@ impl DeviceTransaction for JunosTransaction {
let error = self
.revert_and_release(&mut dev, actions.len(), refusal, "plane-owned refusal")
.await;
self.record_plane_refusal(&error);
self.record_stage_refusal(&error);
return Err(error);
}
}
Expand Down
Loading
Loading