Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
30 changes: 30 additions & 0 deletions apps/lightcraft-web/src/wire.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,11 @@ impl WorkerCore {
}
}

/// Provenance of the original most recently decoded for this job, without transferring pixels.
pub fn colour_source(&self, job: &WireJob) -> Option<lightcraft_engine::pipeline::ColourSource> {
self.sources.peek(&job.source_key()).and_then(|src| src.info.as_ref()).and_then(|info| info.colour_source.clone())
}

/// Render `job`; `original` holds the file's bytes when [`WorkerCore::needs_original`] asked.
pub fn render(&mut self, job: &WireJob, original: Option<&[u8]>) -> Result<Rendered, String> {
let key = job.source_key();
Expand Down Expand Up @@ -367,6 +372,31 @@ mod tests {
use lightcraft_engine::Session;

// Issue #229: a failed worker attempt must not shift the positions of the workers after it
#[test]
fn worker_provenance_follows_the_decoded_source_identity() {
use lightcraft_engine::pipeline::{ColourBasis, ColourSource};
let mut session = lightcraft_engine::Session::with_demo();
let id = session.active().unwrap();
let job = session.thumb_job(id, 32).unwrap();
let mut wire = WireJob::from_job(&job, false, "Thumb");
let mut core = WorkerCore::default();
assert!(core.colour_source(&wire).is_none());
let source = ColourSource {
basis: ColourBasis::CameraProfile { model: "Test Camera".into(), local: false },
monochrome_tone: true,
dro_tone_removed: true,
};
let decoded = DecodedSource::new(
Arc::new(lightcraft_raster::Rgb32f::new(4, 4)),
Some(SourceInfo { colour_source: Some(source.clone()), ..Default::default() }),
);
core.sources.insert(wire.source_key(), decoded, 1024);
let transported = serde_json::to_string(&core.colour_source(&wire)).unwrap();
assert_eq!(serde_json::from_str::<Option<ColourSource>>(&transported).unwrap(), Some(source));
wire.source_identity = Some("changed original".into());
assert!(core.colour_source(&wire).is_none());
}

#[test]
fn a_failed_worker_attempt_leaves_no_gap_in_the_slots() {
let mut slots = WorkerSlots::default();
Expand Down
18 changes: 16 additions & 2 deletions apps/lightcraft-web/src/workers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ async fn handle(scope: &web_sys::DedicatedWorkerGlobalScope, backend: Option<Bac
None => None,
};
let rendered = CORE.with(|c| c.borrow_mut().render(&job, original.as_deref()))?;
if let Some(source) = CORE.with(|c| c.borrow().colour_source(&job)) {
let text = serde_json::to_string(&source).map_err(|e| e.to_string())?;
set(&out, "colourSource", &text.into());
}
let mut stored = 0;
if let (Some(b), Some(key)) = (&backend, job.thumb_key())
&& let Some(jpeg) = lightcraft_preview::encode_jpeg(&rendered.image)
Expand Down Expand Up @@ -151,6 +155,7 @@ async fn handle(scope: &web_sys::DedicatedWorkerGlobalScope, backend: Option<Bac
// main side

struct Busy {
source_key: Option<Hash128>,
disk_key: Option<String>,
namespace: u64,
request_id: u64,
Expand Down Expand Up @@ -290,13 +295,14 @@ impl Workers {
if let Some(b) = w.busy.take() {
let r = RenderResult {
request_id: b.request_id,
source_key: None,
source_key: b.source_key,
photo: b.photo,
level: b.level,
key: b.key,
rendered: Err(msg),
gpu_fallback: None,
loaded: None,
colour_source: None,
quick: None,
display: None,
};
Expand Down Expand Up @@ -369,18 +375,24 @@ impl Workers {
let _ = backend.remove(&thumb_storage_key(&key)).await;
});
}
let colour_source = if rendered.is_ok() && b.namespace == g.index.namespace() {
get(&data, "colourSource").as_string().and_then(|text| serde_json::from_str(&text).ok())
} else {
None
};
g.remote_done += 1;
g.done.push((
b.slot,
RenderResult {
request_id: b.request_id,
source_key: None,
source_key: b.source_key,
photo: b.photo,
level: b.level,
key: b.key,
rendered,
gpu_fallback: None,
loaded: None,
colour_source,
quick: None,
display: None,
},
Expand Down Expand Up @@ -435,6 +447,7 @@ impl RenderOffload for Workers {
rendered: Ok(Rendered { image, histogram, deep: None }),
gpu_fallback: None,
loaded: None,
colour_source: None,
quick: None,
display: None,
};
Expand Down Expand Up @@ -483,6 +496,7 @@ impl RenderOffload for Workers {
return Some(job);
}
w.busy = Some(Busy {
source_key: job.source_key,
disk_key,
namespace,
request_id: job.request_id,
Expand Down
3 changes: 1 addition & 2 deletions crates/catalog/src/tests_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,7 @@ fn dropping_the_lock_frees_the_library_while_another_thread_spawns_processes() {
std::thread::spawn(move || {
let mut spawned = 0usize;
while !stop.load(Ordering::Relaxed) {
if let Ok(mut c) =
std::process::Command::new("/bin/true").stdout(std::process::Stdio::null()).stderr(std::process::Stdio::null()).spawn()
if let Ok(mut c) = std::process::Command::new("true").stdout(std::process::Stdio::null()).stderr(std::process::Stdio::null()).spawn()
{
let _ = c.wait();
spawned += 1;
Expand Down
Loading