Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
dc2216a
work: reuse bounded PR context for native packet sources (#1017)
n0rpan Nov 18, 2026
875a83f
test(work): require live App packet generation through refill (#1017)
n0rpan Nov 18, 2026
c48d04b
work: generate current native fix packets with the App reader (#1017)
n0rpan Nov 18, 2026
bbb7531
work: retain runner path when preparing live packets (#1017)
n0rpan Nov 18, 2026
ce237a5
test(work): refuse live packet publication for unknown attempts (#1017)
n0rpan Nov 18, 2026
7c394db
test(work): accept Markdown delimiters in live PR context (#1017)
n0rpan Nov 18, 2026
3e0bd8c
work: quote Markdown queue delimiters in live PR context (#1017)
n0rpan Nov 18, 2026
ad1037b
test(work): reach known live work past unknown and fork candidates (#…
n0rpan Nov 18, 2026
fa9cc54
fix(work): keep ineligible live candidates from blocking known work
n0rpan Nov 18, 2026
f61948b
Merge main to preserve #1356 readback alongside live packets
n0rpan Nov 18, 2026
57745d5
Merge main to preserve #1404 owner attempt policy in live refill
n0rpan Nov 18, 2026
a65279c
test(board): reproduce retained-lease and branch admission starvation
n0rpan Nov 18, 2026
9baf4a2
Expose the canonical native branch predicate
Nov 18, 2026
b9a0ab1
fix(board): exclude retained leases and invalid branches before packe…
n0rpan Nov 18, 2026
01bc9cf
test(board): reproduce published identities starving live packet prep…
n0rpan Nov 18, 2026
f8db93e
Share read-only published packet checks with the spool publisher (#1017)
n0rpan Nov 18, 2026
951f738
fix(board): exclude published identities before the live packet cap
n0rpan Nov 18, 2026
d083ea4
test(board): reproduce rich fork context exhausting live refill reads
n0rpan Nov 18, 2026
36a3f99
Reject live refill forks before fetching rich context (#1017)
oxa-agent[bot] Nov 18, 2026
58cac81
Bound rich PR context per refill candidate (#1017)
oxa-agent[bot] Nov 18, 2026
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
14 changes: 14 additions & 0 deletions oxa/docs/work.md
Original file line number Diff line number Diff line change
Expand Up @@ -329,3 +329,17 @@ 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.

Board refill can generate current PR fix packets with `live: true` and an explicit
`model` in its protected owner config. Omit `packets` and keep issue `intake` off.
The same config supplies the registered worker, host, Claims path, queue, pause
marker and item partition. Each round reads current assignment candidates and PR
context through the explicit App credential, then uses the existing admission and
publication path. A changed head or action cannot publish the prepared packet.
Set `pr_context_capture_bytes` in the same protected config to limit each live
PR context read. It defaults to 2 MiB within the unchanged 4 MiB round budget.
The reservation includes one byte to detect overflow. When the limit is reached,
refill logs the cause and prepares the packet with its verified identity and a
truncation notice. If the remaining round budget cannot verify a later identity,
refill keeps the packets already prepared and stops preparing further candidates.
This mode does not execute a worker or select a default host, model or Claims store.
131 changes: 110 additions & 21 deletions oxa/oxa-cli/src/work_board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ fn charge(bytes: &mut usize, read: usize) -> Result<(), String> {

enum QueryError {
Http(u16),
ContextLimit,
Other(&'static str),
}

Expand Down Expand Up @@ -131,11 +132,23 @@ impl QueryError {
fn message(self) -> String {
match self {
Self::Http(status) => format!("GitHub read failed (HTTP {status})"),
Self::ContextLimit => "GitHub PR context capture limit reached".into(),
Self::Other(message) => message.into(),
}
}
}

fn http_status(headers: &str) -> Result<u16, QueryError> {
headers
.lines()
.next()
.filter(|line| line.starts_with("HTTP/"))
.and_then(|line| line.split_whitespace().nth(1))
.and_then(|value| value.parse::<u16>().ok())
.filter(|value| (100..600).contains(value))
.ok_or(QueryError::Other("invalid GitHub HTTP status"))
}

impl<'a> Reader<'a> {
/// Callers must enforce trust/offline policy and supply an explicit App credential.
pub(crate) fn new(gh: &'a Path, path: &'a std::ffi::OsStr, repo: &'a str, token: &'a str) -> Self {
Expand All @@ -162,7 +175,15 @@ impl<'a> Reader<'a> {
/// Fixed repository fields from native callers share the bounded, redacted transport.
/// The byte count lets callers enforce an aggregate snapshot budget across queries.
pub(crate) fn repository_read(&self, fields: &str) -> Result<(Value, usize), String> {
self.query(fields).map_err(QueryError::message)
self.query(fields, None).map_err(QueryError::message)
}

fn repository_context(&self, fields: &str, limit: usize) -> Result<Option<Value>, String> {
match self.query(fields, Some(limit)) {
Ok((value, _)) => Ok(Some(value)),
Err(QueryError::ContextLimit) => Ok(None),
Err(error) => Err(error.message()),
}
}

fn listing(&self) -> Result<(Value, Value), SnapshotError> {
Expand Down Expand Up @@ -209,10 +230,10 @@ impl<'a> Reader<'a> {
}
}

fn query(&self, fields: &str) -> Result<(Value, usize), QueryError> {
fn query(&self, fields: &str, context_limit: Option<usize>) -> Result<(Value, usize), QueryError> {
let mut retries = 0;
loop {
match self.query_once(fields) {
match self.query_once(fields, context_limit) {
Err(error) if error.retryable() && retries < 2 => {
let pause = Duration::from_millis(200 << retries);
if self.time_left()? <= pause {
Expand All @@ -226,16 +247,13 @@ impl<'a> Reader<'a> {
}
}

fn query_once(&self, fields: &str) -> Result<(Value, usize), QueryError> {
fn query_once(&self, fields: &str, context_limit: Option<usize>) -> Result<(Value, usize), QueryError> {
let invalid = QueryError::Other;
let (owner, name) = self.repo.split_once('/').ok_or(invalid("expected OWNER/REPO"))?;
let query = format!("query{{repository(owner:{owner:?},name:{name:?}){{{fields}}}}}");
let mut command = self.api_command();
command.args(["--include", "graphql", "-f", &format!("query={query}")]);
let (remaining, duration) = self.read_budget()?;
let (code, text) = oxa_work::command_runner(command, Some(remaining), duration).ok_or(invalid(
"GitHub read failed: snapshot exceeds byte limit, capture refused or deadline reached",
))?;
let (code, text) = self.capture_query(command, context_limit)?;
// Charge captured bytes, including headers and non-2xx bodies, before interpreting them.
self.charge_capture(text.len())?;
let (status, body) = self.response(&text, GitHubResource::Graphql)?;
Expand All @@ -262,20 +280,60 @@ impl<'a> Reader<'a> {
Ok((repository, text.len()))
}

fn capture_query(
&self,
command: Command,
context_limit: Option<usize>,
) -> Result<(i32, String), QueryError> {
use oxa_work::BoundedOutput;
use std::os::unix::process::ExitStatusExt;

let failed = QueryError::Other(
"GitHub read failed: snapshot exceeds byte limit, capture refused or deadline reached",
);
let Some(limit) = context_limit else {
let (remaining, duration) = self.read_budget()?;
return oxa_work::command_runner(command, Some(remaining), duration).ok_or(failed);
};
let duration = oxa_work::COMMAND_DEADLINE.min(self.time_left()?);
let reservation = limit.min(self.remaining_capture());
if reservation < b"HTTP/1.1 200 OK\r\n".len() {
return Err(QueryError::ContextLimit);
}
match oxa_work::command_output_reserved(command, reservation, duration).map_err(|_| failed)? {
BoundedOutput::Complete(output) => Ok((
output.status.code().unwrap_or(1),
String::from_utf8(output.stdout).map_err(|_| QueryError::Other("invalid GitHub response"))?,
)),
BoundedOutput::Limit(output) => {
self.charge_capture(output.stdout.len())?;
// Use only the transport status. A partial JSON response is never a snapshot.
let status = output
.stdout
.split_inclusive(|&byte| byte == b'\n')
.next()
.filter(|line| line.ends_with(b"\n"))
.and_then(|line| std::str::from_utf8(line).ok())
.ok_or(QueryError::Other("missing GitHub HTTP status"))?;
let status = http_status(status)?;
if !(200..300).contains(&status) {
return Err(QueryError::Http(status));
}
if !output.status.success() && output.status.signal() != Some(signal_hook::consts::SIGPIPE) {
return Err(QueryError::Other("GitHub context command failed"));
}
Err(QueryError::ContextLimit)
}
}
}

fn response<'b>(&self, text: &'b str, resource: GitHubResource) -> Result<(u16, &'b str), QueryError> {
let invalid = QueryError::Other;
let (headers, body) = text
.split_once("\r\n\r\n")
.or_else(|| text.split_once("\n\n"))
.ok_or(invalid("GitHub command failed without an HTTP response"))?;
let status = headers
.lines()
.next()
.filter(|line| line.starts_with("HTTP/"))
.and_then(|line| line.split_whitespace().nth(1))
.and_then(|value| value.parse::<u16>().ok())
.filter(|value| (100..600).contains(value))
.ok_or(invalid("invalid GitHub HTTP status"))?;
let status = http_status(headers)?;
if let Some(quota) = &self.app_quota {
let headers = if (200..300).contains(&status) { headers } else { "" };
quota.borrow_mut().observe(GitHubIdentity::App, resource, headers);
Expand All @@ -284,13 +342,17 @@ impl<'a> Reader<'a> {
}

fn read_budget(&self) -> Result<(usize, Duration), QueryError> {
let remaining = MAX_RESPONSE
.checked_sub(self.bytes.get())
.filter(|n| *n > 0)
.ok_or(QueryError::Other("GitHub snapshot exceeds byte limit"))?;
let remaining = self.remaining_capture();
if remaining == 0 {
return Err(QueryError::Other("GitHub snapshot exceeds byte limit"));
}
Ok((remaining, oxa_work::COMMAND_DEADLINE.min(self.time_left()?)))
}

fn remaining_capture(&self) -> usize {
MAX_RESPONSE.saturating_sub(self.bytes.get())
}

fn charge_capture(&self, bytes: usize) -> Result<(), QueryError> {
let mut used = self.bytes.get();
charge(&mut used, bytes).map_err(|_| QueryError::Other("GitHub snapshot exceeds byte limit"))?;
Expand Down Expand Up @@ -422,7 +484,7 @@ impl Reader<'_> {
}}}}}}}}}}}}}}"#
));
}
let (page, _) = match self.query(&fields) {
let (page, _) = match self.query(&fields, None) {
Ok(page) => page,
Err(error) if error.retryable() && end - offset > 1 => {
size = (end - offset) / 2;
Expand Down Expand Up @@ -735,6 +797,33 @@ mod deadline_tests {
use oxa_fake::TestEnv;
use std::os::unix::fs::PermissionsExt;

#[test]
fn context_capture_charges_truncation_and_preserves_http_refusal() {
let reader = Reader::new(
Path::new("/bin/false"),
std::ffi::OsStr::new("/usr/bin:/bin"),
"example/repo",
"synthetic-app-token",
);
let mut accepted = Command::new("/bin/sh");
accepted.args(["-c", "printf 'HTTP/2.0 200 OK\\r\\n\\r\\nOrdinary project notes'"]);
assert!(matches!(
reader.capture_query(accepted, Some(32)),
Err(QueryError::ContextLimit)
));
assert_eq!(reader.bytes.get(), 32);
let mut refused = Command::new("/bin/sh");
refused.args([
"-c",
"printf 'HTTP/2.0 403 Forbidden\\r\\n\\r\\nAccess unavailable'; exit 1",
]);
assert!(matches!(
reader.capture_query(refused, Some(32)),
Err(QueryError::Http(403))
));
assert_eq!(reader.bytes.get(), 64);
}

#[test]
fn exhausted_budget_refuses_launch_and_remaining_time_bounds_the_child() {
let test = TestEnv::new();
Expand Down
45 changes: 38 additions & 7 deletions oxa/oxa-cli/src/work_board/refill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,36 @@ pub(super) fn run(
let claims = oxa_work::board::Claims::open(&owner_path("claims")?)?;
let (worker, host) = crate::work_cmd::registered_native_worker(&value)?;
let partition = partition(&value)?;
let rows = value["packets"]
.as_array()
.filter(|rows| rows.len() <= 20)
.ok_or("expected bounded prepared packets")?;
let live = value["live"] == true;
let model = if live {
if value.get("packets").is_some() || value["intake"] == true {
return Err("live fix packets cannot use prepared packets or issue intake".into());
}
let model = text(&value, "model")?;
if model.is_empty() || model.bytes().any(|b| b.is_ascii_whitespace() || b == 0) {
return Err("live model must be one task header field".into());
}
let capture_bytes = match value.get("pr_context_capture_bytes") {
Some(limit) => limit
.as_u64()
.filter(|&bytes| (1..=MAX_RESPONSE as u64).contains(&bytes))
.ok_or("pr_context_capture_bytes must be a positive integer within the snapshot budget")?
as usize,
None => MAX_RESPONSE / 2,
};
Some((model, capture_bytes))
} else {
None
};
let rows = if live {
&[][..]
} else {
value["packets"]
.as_array()
.filter(|rows| rows.len() <= 20)
.ok_or("expected bounded prepared packets")?
.as_slice()
};
let mut packets = vec![];
let mut seen = BTreeSet::new();
for row in rows {
Expand Down Expand Up @@ -179,12 +205,11 @@ pub(super) fn run(
crate::netguard::trusted_executable_for("gh", Some(&policy.host_path), Some(root), Some(&dirs.home))
.ok_or("no trusted gh executable")?;
let intake = value["intake"] == true;
let mut source = Input::new(&gh, &policy.host_path, repo, &token, &packets, intake).with_host(host);
let now = SystemTime::now()
.duration_since(SystemTime::UNIX_EPOCH)
.map_err(|_| "invalid system clock")?
.as_secs();
let policy = Policy {
let board_policy = Policy {
enabled: true,
max_attempts_per_day: attempt_limit(&value)?,
..Policy::default()
Expand All @@ -196,9 +221,15 @@ pub(super) fn run(
claims: &claims,
worker: &worker,
partition: &partition,
policy: &policy,
policy: &board_policy,
ttl: 1800,
};
if let Some((model, capture_bytes)) = model {
packets = Input::new(&gh, &policy.host_path, repo, &token, &[], false)
.with_host(host)
.prepare_live(&consumer, now, model, capture_bytes)?;
}
let mut source = Input::new(&gh, &policy.host_path, repo, &token, &packets, intake).with_host(host);
let inputs: Vec<_> = packets
.iter()
.map(|p| Packet {
Expand Down
Loading
Loading