Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
3 changes: 3 additions & 0 deletions oxa/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## [Unreleased]

### Fixed

- `oxa work` starts a new task branch at its published head (`origin/<branch>`) when that tip descends from the captured base, instead of always at the base. A task for an already pushed pull-request branch now audits and continues that head rather than redoing work from a tree that predates it; several diverging tips or an unrelated one keep the base. See [work.md](docs/work.md).
### Added

- `oxa work --pr N --model MODEL` (#1019): the unattended packet for a pull request carries its title, body, reviews, issue comments and the names of failing checks at the current head, and the task branch is the pull request's own head branch. Review text and check names are labelled as data and bounded (reviews to 16 KiB, 40 check names); only failing checks travel, never passing ones. Malformed review or check lists are refused, never silently dropped.
Expand Down
7 changes: 6 additions & 1 deletion oxa/docs/work.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ Finished successful work is returned without another worker or check run; add
change requires a new ID. Unsupported or corrupt checkpoints are preserved and
refused. A matching linked worktree is reused; the
source checkout is never used as the task worktree. An existing branch checked
out elsewhere is blocked. Dirty retained work is preserved and saved before
out elsewhere is blocked. A new task branch that is already published starts at
its pushed head instead of the base: the branch is created at the lone
remote-tracking tip of the same name when that tip descends from the captured
base (never for several diverging tips or an unrelated one), so reviewing or
continuing a pull request works from its head. Fetch first; no fetch is run here.
Dirty retained work is preserved and saved before
retrying. A clean retained branch gets an ordinary sandboxed
merge of the captured base; no reset, stash, force checkout or automatic fetch runs.

Expand Down
12 changes: 11 additions & 1 deletion oxa/oxa-cli/src/netguard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ use std::sync::Arc;
/// O-167(b): the process sandbox with the bash network decision (`oxa.sandbox.net`, default
/// on; always off while offline). Read once at startup.
pub(crate) fn with_net(sandbox: Arc<dyn Sandbox>, settings: &Settings) -> Arc<dyn Sandbox> {
with_policy(sandbox, settings, true)
}

/// Acceptance commands keep the user's network policy without GitHub authentication.
pub(crate) fn without_github(sandbox: Arc<dyn Sandbox>, settings: &Settings) -> Arc<dyn Sandbox> {
with_policy(sandbox, settings, false)
}

fn with_policy(sandbox: Arc<dyn Sandbox>, settings: &Settings, github_auth: bool) -> Arc<dyn Sandbox> {
let runner_owns_github = std::env::var_os(oxa_work::RUNNER_GITHUB_ENV).is_some_and(|value| value == "1");
let on = !runner_owns_github && sandbox_net_setting(settings.string(SETTING_SANDBOX_NET).as_deref());
let offline = oxa_proto::offline();
// The `gh` lookup can stall (a mise shim may try to install gh): run it lazily, at the first
// bash command that has the network, never at startup.
let lookup = on
let lookup = github_auth
&& on
&& !offline
&& !test_isolated(
std::env::var(oxa_proto::names::ENV_TEST_ISOLATION)
Expand Down
41 changes: 25 additions & 16 deletions oxa/oxa-cli/src/work_checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,27 +65,36 @@ pub(crate) fn run(
SupervisorOperation::Checkout {
branch,
create,
adopted,
normalize,
} => {
let sandbox = crate::netguard::with_net(Arc::new(b), &settings);
// Adopted content is materialized without ambient GitHub authority.
// The ordinary checkout path retains its existing hook policy.
let sandbox: Arc<dyn Sandbox> = if adopted {
Arc::new(b)
} else {
crate::netguard::with_net(Arc::new(b), &settings)
};
let git = if adopted {
"git --no-replace-objects -c core.hooksPath=/dev/null -c credential.helper="
} else {
"git --no-replace-objects"
};
let mut command = if let Some(update) = normalize {
// Materialize filters first, then advance under the caller's Git
// worktree hold. All reference and checkout hooks stay sandboxed.
format!("git --no-replace-objects read-tree --reset -u HEAD && test $(git symbolic-ref --quiet {}; echo $?) = 1 && git --no-replace-objects update-ref --no-deref {} {} {} && checkout_head=$(git rev-parse HEAD) && git hook run --ignore-missing post-checkout -- \"$checkout_head\" \"$checkout_head\" 0", sh_quote(&update.reference), sh_quote(&update.reference), sh_quote(&update.new), sh_quote(&update.old))
// worktree hold, with the selected checkout callback policy.
format!("{git} read-tree --reset -u HEAD && test $({git} symbolic-ref --quiet {}; echo $?) = 1 && {git} update-ref --no-deref {} {} {} && checkout_head=$({git} rev-parse HEAD) && {git} hook run --ignore-missing post-checkout -- \"$checkout_head\" \"$checkout_head\" 0", sh_quote(&update.reference), sh_quote(&update.reference), sh_quote(&update.new), sh_quote(&update.old))
} else {
"git --no-replace-objects checkout HEAD -- .".into()
format!("{git} checkout HEAD -- .")
};
if create {
command.push_str(&format!(
" && git --no-replace-objects checkout -b {} HEAD",
sh_quote(&branch)
));
command.push_str(&format!(" && {git} checkout -b {} HEAD", sh_quote(&branch)));
}
let spec = ExecSpec {
command,
cwd: root,
writable: true,
net: sandbox.network(),
net: !adopted && sandbox.network(),
timeout_s: Some(600),
env: git_environment(),
};
Expand All @@ -104,17 +113,17 @@ pub(crate) fn run(
return Ok(0);
}
SupervisorOperation::Merge { base } => {
let sandbox = crate::netguard::with_net(Arc::new(b), &settings);
// Local Git callbacks do not need repository network authority.
let spec = ExecSpec {
command: format!("git --no-replace-objects merge --no-edit -- {}", sh_quote(&base)),
cwd: root,
writable: true,
net: sandbox.network(),
net: false,
timeout_s: Some(600),
env: git_environment(),
};
let mut tail = Vec::new();
let result = sandbox.run_streaming(&spec, &CancelToken::default(), &mut |bytes| {
let result = b.run_streaming(&spec, &CancelToken::default(), &mut |bytes| {
keep_tail(&mut tail, bytes, 8192);
});
err.write_all(&tail).map_err(|e| e.to_string())?;
Expand All @@ -124,7 +133,7 @@ pub(crate) fn run(
return Ok(i32::from(result.exit != Some(0)));
}
SupervisorOperation::Save { task_id } => {
let sandbox = crate::netguard::with_net(Arc::new(b), &settings);
// Keep save callbacks local, including content from an adopted head.
let message = sh_quote(&format!("oxa work: save task {task_id}"));
let spec = ExecSpec {
command: format!(
Expand All @@ -144,12 +153,12 @@ git --no-replace-objects commit -m {message}
),
cwd: root,
writable: true,
net: sandbox.network(),
net: false,
timeout_s: Some(600),
env: git_environment(),
};
let mut tail = Vec::new();
let result = sandbox.run_streaming(&spec, &CancelToken::default(), &mut |bytes| {
let result = b.run_streaming(&spec, &CancelToken::default(), &mut |bytes| {
keep_tail(&mut tail, bytes, 8192);
});
if result.exit != Some(0) || result.timed_out {
Expand All @@ -170,7 +179,7 @@ git --no-replace-objects commit -m {message}
shell_path: settings.shell_path(&dirs.home),
command_prefix: settings.shell_command_prefix(),
};
let sandbox = crate::netguard::with_net(Arc::new(b), &settings);
let sandbox = crate::netguard::without_github(Arc::new(b), &settings);
let mut failed = false;
let mut diagnostics = Vec::new();
for entry in commands {
Expand Down
Loading
Loading