From 23d7269772a5338d0c5e3d0166b3af7a2fd9ff15 Mon Sep 17 00:00:00 2001 From: Pavel Isaev Date: Wed, 11 Nov 2026 21:24:50 +0300 Subject: [PATCH] Discover: report phase progress and reduce transient observation contention --- src/service/events.rs | 21 ++++++++++++++++++++- src/service/observation.rs | 15 ++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/service/events.rs b/src/service/events.rs index a76a153..3df9995 100644 --- a/src/service/events.rs +++ b/src/service/events.rs @@ -4,6 +4,25 @@ use archipelago_contracts::system_bus::{ErrorCode, Phase}; use serde_json::{json, Value}; use std::sync::{Arc, Mutex}; +/// Coarse, monotonic progress percentage derived from the operation phase. +/// Discover renders this as its transaction progress bar; the daemon does not +/// currently report a byte-accurate percentage, so the phase is the durable cue. +fn phase_percent(phase: Phase) -> u64 { + match phase { + Phase::Admission => 2, + Phase::Metadata => 5, + Phase::Details => 15, + Phase::Planning => 30, + Phase::Downloading => 40, + Phase::Composing => 55, + Phase::Finalizing => 70, + Phase::Validating => 80, + Phase::Staging => 90, + Phase::Reconciling => 95, + Phase::Finished => 100, + } +} + pub struct OperationEvents { id: String, journal: Arc>, @@ -32,7 +51,7 @@ impl Events for OperationEvents { journal.update(&self.id, |record| { record.phase = phase; record.can_cancel = can_cancel; - record.progress = json!({"message": message, "unit": "steps", "completed": 0}); + record.progress = json!({"message": message, "unit": "steps", "completed": 0, "percent": phase_percent(phase)}); Ok(()) }).map_err(unavailable)?; Ok(()) diff --git a/src/service/observation.rs b/src/service/observation.rs index f2d3bca..3a1ac7a 100644 --- a/src/service/observation.rs +++ b/src/service/observation.rs @@ -103,7 +103,20 @@ impl Store { pub fn observe() -> Result { let lock = OpenOptions::new().create(true).truncate(false).write(true).mode(0o600) .open("/run/archipelago-compose.lock").map_err(|e| e.to_string())?; - lock.try_lock().map_err(|_| "host engine busy; cached observation remains reconciling")?; + // Mutations hold this same lock; wait through the short ones (a refresh or + // a small package plan) instead of immediately degrading the observation to + // "reconciling", which Discover surfaces as a transient error. Long writers + // (staging, downloads) still fail fast after the short budget. + let deadline = std::time::Instant::now() + std::time::Duration::from_secs(2); + loop { + match lock.try_lock() { + Ok(()) => break, + Err(std::fs::TryLockError::WouldBlock) if std::time::Instant::now() < deadline => { + std::thread::sleep(std::time::Duration::from_millis(50)); + } + Err(_) => return Err("host engine busy; cached observation remains reconciling".into()), + } + } let result = Command::new("timeout").args(["--kill-after=2", "10", "ostree", "admin", "status", "--json"]) .env("LC_ALL", "C").output().map_err(|e| e.to_string())?; if !result.status.success() || result.stdout.len() > 1024 * 1024 { return Err("local OSTree status unavailable".into()); }