Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions changelog.d/3803-verify-execute-owned-process.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<!-- section: Fixed -->
- `ripr agent verify-execute` spawns its child through the shared owned-process authority. On Windows a timeout, cancellation, output overflow or exit now ends the child's whole Job Object tree before the output is read, and `descendant_containment` reports `job_object` there (`owned_child_only` elsewhere). The xtask Windows timeout control now fails when a pipe-holding descendant survives the timeout (#3803).
46 changes: 29 additions & 17 deletions crates/ripr/src/app/verification_execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
//! pointing at anything that is not a provenance-valid producer artifact is
//! refused.
//!
//! Descendant containment is a declared limitation: the workspace forbids
//! `unsafe_code` and the dependency policy admits neither `libc` nor
//! `windows-sys`, so no process-group or job-object substrate is available.
//! The authority boundary compensates structurally — the only executable route
//! is one leaf `ripr agent verify` invocation, and termination is asserted
//! against that owned child.
//! The child is spawned through the shared [`OwnedProcess`] owner (#3803). On
//! Windows a Job Object owns the whole tree, so timeout, cancellation, output
//! overflow and normal exit all end any descendant before the output readers
//! are joined. Other platforms keep the direct-child kill: no process-group
//! substrate is available under the workspace `unsafe_code` and dependency
//! policy. There the authority boundary compensates structurally — the only
//! executable route is one leaf `ripr agent verify` invocation, and
//! termination is asserted against that owned child.

use crate::agent::artifact::current_git_head;
use crate::agent::command_specs::{agent_command_spec_from_display, agent_verify_command_spec};
Expand All @@ -43,13 +45,14 @@ use crate::domain::{
EnvironmentPolicy, ExpectedResultParser, NetworkPolicy, StdinPolicy, VerificationCurrentnessV1,
VerificationExecutionResultV1, VerificationProcessDispositionV1,
};
use crate::process_owner::OwnedProcess;
use serde::Serialize;
use serde_json::Value;
use sha2::{Digest, Sha256};
use std::fs::{self, OpenOptions};
use std::io::{Read, Write};
use std::path::{Component, Path, PathBuf};
use std::process::{Child, Command, Stdio};
use std::process::{Command, Stdio};
use std::sync::mpsc::{self, Receiver};
use std::thread;
use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
Expand All @@ -62,7 +65,10 @@ const RESPONSE_SCHEMA_VERSION: &str = "1";
const CLAIM_BOUNDARY: &str = "Process observation only; this does not prove mutation adequacy, correctness, coverage, requirement satisfaction, or merge approval.";
const STATIC_EVIDENCE_BOUNDARY: &str =
"Static before/after movement remains separate from verification process disposition.";
const DESCENDANT_CONTAINMENT: &str = "owned_child_only: no process-group or job-object substrate is available under the workspace unsafe_code and dependency policy; the authority boundary admits only one leaf verify route.";
#[cfg(windows)]
const DESCENDANT_CONTAINMENT: &str = "job_object: the owned child runs inside a Windows Job Object assigned before execution; timeout, cancellation, output overflow and exit terminate every process in it.";
#[cfg(not(windows))]
const DESCENDANT_CONTAINMENT: &str = "owned_child_only: no process-group substrate is available under the workspace unsafe_code and dependency policy; the authority boundary admits only one leaf verify route.";

/// Variable names allowed to cross into the child, values taken from the parent.
///
Expand Down Expand Up @@ -811,16 +817,16 @@ fn run_process(
cancel_after_ms: Option<u64>,
) -> Result<ProcessObservation, Refusal> {
let started = Instant::now();
let mut child = match Command::new(executable)
let mut command = Command::new(executable);
command
.args(&spec.args)
.current_dir(root)
.env_clear()
.envs(child_environment())
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
{
.stderr(Stdio::piped());
let mut child = match OwnedProcess::spawn(command) {
Ok(child) => child,
Err(error) => {
return Ok(ProcessObservation {
Expand All @@ -842,11 +848,11 @@ fn run_process(
}
};
let stdout = child
.stdout
.stdout_pipe()
.take()
.ok_or_else(|| rejected("stdout pipe unavailable"))?;
let stderr = child
.stderr
.stderr_pipe()
.take()
.ok_or_else(|| rejected("stderr pipe unavailable"))?;
let (stdout_rx, stdout_thread) = spawn_capture(stdout);
Expand Down Expand Up @@ -890,7 +896,13 @@ fn run_process(
}
thread::sleep(Duration::from_millis(10));
}
let _ = child.wait();
// Every terminal path ends the owned tree and reaps the primary before
// the reader joins: on Windows the Job Object takes down a descendant
// that still holds an output pipe, so the joins reach EOF instead of
// waiting on it. A failed termination refuses rather than joining behind
// a process that may never close the pipe.
kill_child(&mut child)?;
drop(child);
Comment thread
EffortlessSteven marked this conversation as resolved.
Resolved
let stdout = stdout_thread
.join()
.map_err(|_panic| rejected("stdout reader panicked"))?
Expand Down Expand Up @@ -966,9 +978,9 @@ fn spawn_capture<R: Read + Send + 'static>(
(rx, handle)
}

fn kill_child(child: &mut Child) -> Result<(), Refusal> {
fn kill_child(child: &mut OwnedProcess) -> Result<(), Refusal> {
child
.kill()
.terminate_tree()
.map_err(|error| rejected(format!("terminate child failed: {error}")))
}

Expand Down
16 changes: 10 additions & 6 deletions docs/OUTPUT_SCHEMA.md
Original file line number Diff line number Diff line change
Expand Up @@ -8407,12 +8407,16 @@ tightening, not a current guarantee.

### Declared limitations

- **Descendant containment.** Only the owned child is terminated. The workspace
forbids `unsafe_code` and the dependency policy admits neither `libc` nor
`windows-sys`, so no process-group or job-object substrate is available. The
authority boundary compensates structurally: the only executable route is one
leaf `ripr agent verify` invocation, which spawns no long-lived descendants.
The posture is disclosed as `descendant_containment` in the response.
- **Descendant containment.** The child is spawned through the shared owned
process authority (#3803). On Windows a Job Object owns the whole tree and
every terminal path (timeout, cancellation, output overflow, exit) ends it
before the output is read. On other platforms only the owned child is
terminated: the workspace forbids `unsafe_code` and the dependency policy
admits neither `libc` nor `windows-sys`, so no process-group substrate is
available. The authority boundary compensates structurally: the only
executable route is one leaf `ripr agent verify` invocation, which spawns no
long-lived descendants. The posture is disclosed as `descendant_containment`
in the response (`job_object` or `owned_child_only`).
- **`verification_executed_fail`**, **`verification_timed_out`**, and
**`verification_command_not_found`** are mapped and unit-tested but are not
reachable end-to-end today. The only executable route is `ripr agent verify`
Expand Down
10 changes: 10 additions & 0 deletions xtask/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2373,6 +2373,16 @@ mod tests {
let _ = fs::remove_file(&marker);
return Err("timed-out process tree should not run its continuation".to_string());
}
// The marker is written by the parent, so a direct-child-only kill
// also leaves it absent. The descendant is what holds the captured
// pipes: when the job ends it the readers reach EOF, and when it
// survives the bounded drain gives up with a truncation diagnostic.
for (stream, text) in [("stdout", &output.stdout), ("stderr", &output.stderr)] {
assert!(
!text.contains("output truncated"),
"{stream} drain was abandoned, so the pipe-holding descendant outlived the timeout: {text:?}"
);
}
Ok(())
}

Expand Down
Loading