From 5d92544f35273f1c5b13ce5a2ebc5356bde24b9f Mon Sep 17 00:00:00 2001 From: Oscar Nordstrom <13300531+n0rpan@users.noreply.github.com> Date: Wed, 18 Nov 2026 04:47:14 +0100 Subject: [PATCH 1/4] Cover native launch host refusal (#1199) --- oxa/oxa-cli/tests/work_queue.rs | 56 ++++++++++++++++++++++++--------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/oxa/oxa-cli/tests/work_queue.rs b/oxa/oxa-cli/tests/work_queue.rs index 39edebc50..e89da67f2 100644 --- a/oxa/oxa-cli/tests/work_queue.rs +++ b/oxa/oxa-cli/tests/work_queue.rs @@ -77,6 +77,9 @@ fn managed_native_worker_authenticates_its_handoff_and_uses_the_owner_goal() { ManagedCase::Accepted, ManagedCase::Expired, ManagedCase::WrongAttempt, + ManagedCase::MissingHost, + ManagedCase::DifferentHost, + ManagedCase::Unhosted, ] { managed_native_worker(case); } @@ -88,6 +91,9 @@ enum ManagedCase { Accepted, Expired, WrongAttempt, + MissingHost, + DifferentHost, + Unhosted, } #[cfg(all(target_os = "linux", feature = "managed-steering"))] @@ -147,10 +153,18 @@ fn managed_native_worker(case: ManagedCase) { claimed_at, ) .unwrap(); - let lease = claims - .claim_idle_for(&entry, &policy, &holder, claimed_at, 60) - .unwrap() - .unwrap(); + let lease = if case == ManagedCase::Unhosted { + claims + .claim_idle_for(&entry, &policy, &holder, claimed_at, 60) + .unwrap() + .unwrap() + } else { + claims + .claim_item_for(&entry, &policy, &holder, "host-a", (claimed_at, 60), |_| Ok(None)) + .unwrap() + .unwrap() + .lease + }; let binding = NativeBinding::new(42, &"a".repeat(64), &lease, "agent/42").unwrap(); assert!(claims.bind_native(&lease.holder, &binding).unwrap()); assert!(oxa_work::helper_queue::publish( @@ -168,15 +182,16 @@ fn managed_native_worker(case: ManagedCase) { &binding.native_task_id }; let config = controls.join("config.json"); - fs::write( - &config, - json!({"enabled":true,"nativeExecution":true,"worker":worker, - "queue":queue,"claims":claims_path,"pause":controls.join("pause"), - "nativeSteering":{"attempt":attempt,"objective":objective} - }) - .to_string(), - ) - .unwrap(); + let mut settings = json!({"enabled":true,"nativeExecution":true,"worker":worker, + "queue":queue,"claims":claims_path,"pause":controls.join("pause"), + "nativeSteering":{"attempt":attempt,"objective":objective} + }); + match case { + ManagedCase::MissingHost => {} + ManagedCase::DifferentHost => settings["host_id"] = "host-b".into(), + _ => settings["host_id"] = "host-a".into(), + } + fs::write(&config, settings.to_string()).unwrap(); fs::set_permissions(&config, fs::Permissions::from_mode(0o600)).unwrap(); let mut completion = ScriptTurn::tool( @@ -230,8 +245,21 @@ fn managed_native_worker(case: ManagedCase) { finish(child) }; if case != ManagedCase::Accepted { + assert!( + server.requests().is_empty(), + "refused case reached the model: {out:?}" + ); assert!(!out.status.success(), "{out:?}"); - assert!(server.requests().is_empty()); + if matches!( + case, + ManagedCase::MissingHost | ManagedCase::DifferentHost | ManagedCase::Unhosted + ) { + let ready = queue.join(format!("board-{}.txt", binding.key)); + assert!( + ready.is_file(), + "refused host must leave the original packet ready" + ); + } let state = &claims.assignments().unwrap()[&42].state; assert_eq!(state.lease.as_ref(), Some(&lease)); assert_eq!(state.attempts, 1); From 5f507cc6c003e19fd66b77ce7dc2b471736d6194 Mon Sep 17 00:00:00 2001 From: oxa agent <13300531+n0rpan@users.noreply.github.com> Date: Wed, 18 Nov 2026 06:31:06 +0100 Subject: [PATCH 2/4] refactor(work): share protected native registration decoding --- oxa/oxa-cli/src/work_board/refill.rs | 9 +---- oxa/oxa-cli/src/work_cmd.rs | 59 ++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/oxa/oxa-cli/src/work_board/refill.rs b/oxa/oxa-cli/src/work_board/refill.rs index cf0de677b..5e325a1a2 100644 --- a/oxa/oxa-cli/src/work_board/refill.rs +++ b/oxa/oxa-cli/src/work_board/refill.rs @@ -2,7 +2,7 @@ use super::refill_input::{text, Input, Prepared}; use super::*; use crate::work_refill::{Consumer, Packet, Partition}; -use oxa_work::board::{assignment::Worker, Action}; +use oxa_work::board::Action; use std::{fs, os::unix::fs::MetadataExt, path::PathBuf}; fn private(path: &Path, uid: u32) -> Result { @@ -86,12 +86,7 @@ pub(super) fn run( Err(_) => return Err("cannot establish board pause state".into()), } let claims = oxa_work::board::Claims::open(&owner_path("claims")?)?; - let worker: Worker = - serde_json::from_value(value["worker"].clone()).map_err(|_| "invalid authenticated worker export")?; - let host = value["host_id"] - .as_str() - .filter(|host| oxa_work::board::valid_worker_id(host)) - .ok_or("native refill requires an authenticated host_id")?; + let (worker, host) = crate::work_cmd::registered_native_worker(&value)?; let partition = Partition { modulus: value["partition"]["modulus"] .as_u64() diff --git a/oxa/oxa-cli/src/work_cmd.rs b/oxa/oxa-cli/src/work_cmd.rs index 520dad313..b472a7ad3 100644 --- a/oxa/oxa-cli/src/work_cmd.rs +++ b/oxa/oxa-cli/src/work_cmd.rs @@ -19,6 +19,65 @@ pub(crate) fn trusted(cwd: &Path, env: &Env, dirs: &Dirs) -> Result Result<(oxa_work::board::assignment::Worker, &str), String> { + use oxa_work::board::assignment::{valid_worker_id, Worker}; + let worker: Worker = + serde_json::from_value(value["worker"].clone()).map_err(|_| "invalid authenticated worker export")?; + if !valid_worker_id(&worker.id) { + return Err("invalid native worker identity".into()); + } + let host = value["host_id"] + .as_str() + .filter(|host| valid_worker_id(host)) + .ok_or("native work requires an authenticated host_id")?; + Ok((worker, host)) +} + +#[cfg(test)] +mod registration_tests { + use super::registered_native_worker; + use serde_json::json; + + #[test] + fn protected_registration_preserves_the_explicit_worker_and_adjacent_host() { + let value = json!({ + "worker":{"id":"worker-a","kind":"oxa","roles":["builder"],"skills":["rust"]}, + "host_id":"host-b" + }); + let (worker, host) = registered_native_worker(&value).unwrap(); + assert_eq!(worker.id, "worker-a"); + assert_eq!(host, "host-b"); + assert!(worker.roles.contains(&oxa_work::board::assignment::Role::Builder)); + assert!(worker.skills.contains("rust")); + } + + #[test] + fn protected_registration_refuses_missing_or_invalid_identities_without_fallback() { + let value = json!({ + "worker":{"id":"worker-a","kind":"oxa","roles":["builder"],"skills":[]}, + "host_id":"host-b" + }); + for field in ["worker", "host_id"] { + let mut missing = value.clone(); + missing.as_object_mut().unwrap().remove(field); + assert!(registered_native_worker(&missing).is_err(), "missing {field}"); + } + for host in [json!(null), json!(42), json!(""), json!("invalid host")] { + let mut invalid = value.clone(); + invalid["host_id"] = host; + assert!(registered_native_worker(&invalid).is_err()); + } + for id in [json!(null), json!(42), json!(""), json!("invalid worker")] { + let mut invalid = value.clone(); + invalid["worker"]["id"] = id; + assert!(registered_native_worker(&invalid).is_err()); + } + } +} + // Keep owner state outside every worker Git bind. pub(crate) fn protected_storage(storage: &Path, repo: &Path, common: &Path) -> Result<(), String> { if !storage.is_absolute() From 0f3f4184d8a4f291054125e2e7169eca2946b58b Mon Sep 17 00:00:00 2001 From: Oscar Nordstrom <13300531+n0rpan@users.noreply.github.com> Date: Wed, 18 Nov 2026 06:33:31 +0100 Subject: [PATCH 3/4] Fence native queue launch with the protected worker host (#1199) --- oxa/docs/work.md | 4 +++- oxa/oxa-cli/src/work_cmd/native_queue.rs | 21 +++++++++++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/oxa/docs/work.md b/oxa/docs/work.md index b7e4ed403..f59b75fa9 100644 --- a/oxa/docs/work.md +++ b/oxa/docs/work.md @@ -316,7 +316,9 @@ A controller lock prevents two queue controllers from exceeding the worker cap. The native board adapter runs one previously admitted packet from that board's existing spool. Use `oxa work --native-queue --config PATH` from the source repository with the same private config used by refill and `nativeExecution` -explicitly enabled. This execution path uses the offline policy. It moves the +explicitly enabled. The owner-protected config supplies the registered `worker` +and `host_id`. Launch requires a matching hosted claim and the original binding +before taking the packet. This execution path uses the offline policy. It moves the 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. diff --git a/oxa/oxa-cli/src/work_cmd/native_queue.rs b/oxa/oxa-cli/src/work_cmd/native_queue.rs index 12e3d0e82..611d4c3f4 100644 --- a/oxa/oxa-cli/src/work_cmd/native_queue.rs +++ b/oxa/oxa-cli/src/work_cmd/native_queue.rs @@ -1,9 +1,6 @@ //! Explicit one-shot execution of an existing, fully bound native board packet. -use super::{protected_storage, Context}; -use oxa_work::{ - board::{assignment::Worker, Claims}, - LockedTask, NativeQueueOwner, QueueOptions, QueueRun, Task, -}; +use super::{protected_storage, registered_native_worker, Context}; +use oxa_work::{board::Claims, LockedTask, NativeQueueOwner, QueueOptions, QueueRun, Task}; use serde_json::Value; use std::{ fs, @@ -96,11 +93,7 @@ pub(super) fn run( let directory = owner_path("queue")?; let claims_path = owner_path("claims")?; let claims = Claims::open(&claims_path)?; - let worker: Worker = - serde_json::from_value(value["worker"].clone()).map_err(|_| "invalid authenticated worker export")?; - if !oxa_work::board::assignment::valid_worker_id(&worker.id) { - return Err("invalid native worker identity".into()); - } + let (worker, host) = registered_native_worker(&value)?; let rows = claims.assignments()?; let mut owned = rows.into_values().filter(|row| { row.state @@ -112,6 +105,14 @@ pub(super) fn run( if owned.next().is_some() { return Err("native worker has multiple active assignments".into()); } + if !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()); + } let binding = row .data .native_binding From 0be27961da39f703c3ba2593a31027bbe608e1d2 Mon Sep 17 00:00:00 2001 From: Oscar Nordstrom <13300531+n0rpan@users.noreply.github.com> Date: Wed, 18 Nov 2026 07:14:12 +0100 Subject: [PATCH 4/4] Record verified native worker results on the bound lease (#1199) --- oxa/docs/work.md | 4 +++ oxa/oxa-cli/src/work_cmd.rs | 14 +++----- oxa/oxa-cli/src/work_cmd/native_queue.rs | 46 +++++++++++++++++++----- oxa/oxa-work/src/lib.rs | 8 +++++ 4 files changed, 55 insertions(+), 17 deletions(-) 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) {