diff --git a/oxa/docs/work.md b/oxa/docs/work.md index f59b75fa9..64028ec6d 100644 --- a/oxa/docs/work.md +++ b/oxa/docs/work.md @@ -323,5 +323,9 @@ matching packet into `started` and resumes from the task checkpoint after interruption. The original claim releases after the whole task finishes and its worker process exits. +Set `nativeActivity` to `true` in the same protected config to record verified +worker results on the original hosted claim. The setting defaults to off. +A saved worker result keeps its launch identity across checkpoint replay. + Problem-report workflows hold a per-user kernel lease across drafting, duplicate search, match reads and writing, so concurrent workers share one reporting lane. diff --git a/oxa/oxa-cli/src/work_cmd.rs b/oxa/oxa-cli/src/work_cmd.rs index 42429c45e..3f6c67bb9 100644 --- a/oxa/oxa-cli/src/work_cmd.rs +++ b/oxa/oxa-cli/src/work_cmd.rs @@ -421,13 +421,14 @@ impl Context { Ok(locked) => locked, Err(error) => return Ok(blocked_plan(plan, error)), }; - self.planned_locked(plan, &mut locked) + self.planned_locked(plan, &mut locked, &|_: &oxa_work::Record| Ok(())) } fn planned_locked( &self, plan: &oxa_work::PlannedTask, locked: &mut oxa_work::LockedTask<'_>, + observer: &dyn oxa_work::CheckpointObserver, ) -> Result { let root = &self.cwd; let binary = &self.binary; @@ -444,14 +445,9 @@ impl Context { record } else { let ctx = crate::report_cmd::ScrubCtx::from_env(env, dirs); - match locked.run_with_notes( - root, - binary, - plan, - rerun, - &|_: &oxa_work::Record| Ok(()), - &|note| crate::work_reports::scrub_note(note, &ctx), - ) { + match locked.run_with_notes(root, binary, plan, rerun, observer, &|note| { + crate::work_reports::scrub_note(note, &ctx) + }) { Ok(record) => record, Err(oxa_work::RunError::Blocked(detail)) => blocked_plan(plan, detail), Err(oxa_work::RunError::Checkpoint(error)) => return Err(error), diff --git a/oxa/oxa-cli/src/work_cmd/native_queue.rs b/oxa/oxa-cli/src/work_cmd/native_queue.rs index 611d4c3f4..638414a98 100644 --- a/oxa/oxa-cli/src/work_cmd/native_queue.rs +++ b/oxa/oxa-cli/src/work_cmd/native_queue.rs @@ -1,6 +1,9 @@ //! Explicit one-shot execution of an existing, fully bound native board packet. use super::{protected_storage, registered_native_worker, Context}; -use oxa_work::{board::Claims, LockedTask, NativeQueueOwner, QueueOptions, QueueRun, Task}; +use oxa_work::{ + board::{Claims, ItemLease, LeaseSignal}, + CheckpointKind, LockedTask, NativeQueueOwner, QueueOptions, QueueRun, Record, Task, +}; use serde_json::Value; use std::{ fs, @@ -65,6 +68,10 @@ pub(super) fn run( if value["enabled"] != true || value["nativeExecution"] != true { return Ok(0); } + let activity = match value.get("nativeActivity") { + None => false, + Some(value) => value.as_bool().ok_or("nativeActivity must be a boolean")?, + }; let steering = value .get("nativeSteering") .map(|setting| { @@ -105,14 +112,11 @@ pub(super) fn run( if owned.next().is_some() { return Err("native worker has multiple active assignments".into()); } - if !row + let item_owner = row .data .item_owner - .as_ref() - .is_some_and(|owner| owner.host_id == host) - { - return Err("native claim does not belong to the authenticated host".into()); - } + .filter(|owner| owner.host_id == host) + .ok_or("native claim does not belong to the authenticated host")?; let binding = row .data .native_binding @@ -134,6 +138,32 @@ pub(super) fn run( ) .ok_or("no trusted disk-space executable outside the source project")?; let worker_context = Arc::clone(&context); + let activity_receipt = activity.then(|| ItemLease { + lease: binding.lease.clone(), + host_id: item_owner.host_id, + expires_at: item_owner.expires_at, + }); + let activity_claims = claims.clone(); + let activity_binding = binding.clone(); + let observe = move |record: &Record| { + let (Some(receipt), Some(revision)) = (&activity_receipt, record.worker_launch_revision) else { + return Ok(()); + }; + if record.checkpoint_kind == CheckpointKind::WorkerFinished + && record.id == activity_binding.native_task_id + && record.branch == activity_binding.branch + { + activity_claims.observe_item_for( + &receipt.lease.holder, + &receipt.host_id, + &activity_binding, + receipt, + oxa_proto::time::now_ms() / 1000, + LeaseSignal::Milestone(record, revision), + )?; + } + Ok(()) + }; #[cfg(all(target_os = "linux", feature = "managed-steering"))] let steering_objective = steering.map(|(_, objective)| objective.to_owned()); #[cfg(all(target_os = "linux", feature = "managed-steering"))] @@ -147,7 +177,7 @@ pub(super) fn run( lock.bind_managed_steering(&claims_path, &steering_binding, objective)?; } match lock.plan_native(&worker_context.cwd, worker_context.reports) { - Ok(plan) => worker_context.planned_locked(&plan, lock), + Ok(plan) => worker_context.planned_locked(&plan, lock, &observe), Err(error) => Ok(oxa_work::blocked_record(task, error)), } }); diff --git a/oxa/oxa-work/src/lib.rs b/oxa/oxa-work/src/lib.rs index 8fdeb6b56..55bcd5dbd 100644 --- a/oxa/oxa-work/src/lib.rs +++ b/oxa/oxa-work/src/lib.rs @@ -1206,6 +1206,14 @@ fn run_locked( return Err("task specification changed; use a new task id".into()); } writer.replay(&old, observer).map_err(RunError::Checkpoint)?; + if planned.native + && old.record.checkpoint_kind == CheckpointKind::WorkerFinished + && old.record.worker_launch_revision.is_some() + { + // Other tasks can acknowledge the shared repository cursor. The task lock + // still fences this exact worker result and the consumer deduplicates it. + observer.checkpoint(&old.record).map_err(RunError::Checkpoint)?; + } // Action recovery cannot turn a changed HEAD into fresh acceptance. // Only an explicit rerun starts a new execution for these checkpoints. if !rerun && matches!(old.record.step, Step::Publishing | Step::Reporting) {