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
13 changes: 8 additions & 5 deletions .agents/skills/launch-openshell-gator/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ For gator's PR/issue validation policy, load `gator-gate` inside the launched sa
| `scripts/agents/gator/policy.yaml` | Sandbox policy for the gator agent. |
| `scripts/agents/gator/bin/gh` | Gator-specific `gh` wrapper and same-SHA duplicate-post guard. |
| `scripts/agents/gator/bin/review-feedback-ledger` | Builds tree-aware review scope, durable findings, convergence telemetry, and review-budget state. |
| `scripts/agents/gator/bin/resolve-gator-review-threads` | Resolves addressed Gator-owned inline review threads by ledger finding ID. |
| `scripts/agents/gator/bin/validate-review-findings` | Enforces the blocker evidence schema and downgrades unsupported hypotheses. |
| `scripts/agents/gator/prompts/gator.md` | Rendered top-level prompt template baked into the payload. |
| `scripts/agents/gator/skills/gator-gate/SKILL.md` | In-sandbox gator state-machine skill. |
Expand Down Expand Up @@ -157,7 +158,7 @@ sandbox_name="gator-pr-${pr_number}-supervised"
"Review and monitor PR #${pr_number} through the gator-gate workflow. Scope this invocation only to PR #${pr_number}."
```

The launcher builds the gator sandbox image when needed, stages the immutable payload, imports provider profiles, configures provider credentials and refresh, creates the sandbox, and writes a background log under `scripts/agents/gator/logs/`.
The launcher builds the gator sandbox image when needed, stages the immutable payload, imports provider profiles, configures provider credentials and refresh, creates and uploads the sandbox payload, then starts the agent supervisor with `sandbox exec`. It writes a background log under `scripts/agents/gator/logs/`.

### Launch An Issue Or Issue/PR Pair

Expand Down Expand Up @@ -317,10 +318,10 @@ Restart when the payload must change, the sandbox is wedged without a sentinel,

Increment `payload_version` in `scripts/agents/gator/agent.yaml` whenever a
merged change alters the Gator prompt, gate skill, reviewer contract, write
guard, ledger, or bundled validator. Existing immutable watchers cannot replace
their own payload. New-version watchers detect later published versions and
stop with `stale_gator_payload`; relaunch every still-active older watcher after
the version bump is published.
guard, ledger, thread resolver, or bundled validator. Existing immutable
watchers cannot replace their own payload. New-version watchers detect later
published versions and stop with `stale_gator_payload`; relaunch every
still-active older watcher after the version bump is published.

Before deleting, check that the sandbox is truly stale or that the operator asked for a restart. If a bounded review cycle is actively running and still producing useful output, prefer leaving it alone.

Expand Down Expand Up @@ -368,7 +369,9 @@ Symptoms: host `gh` auth fails, Codex refresh fails, in-sandbox GitHub calls rep
Actions:

- Re-run the GitHub and Codex preflight checks.
- Existing refresh-managed providers are reused without an ordinary credential update; the launcher rotates their gateway-managed credential instead.
- If host Codex auth changed, relaunch with `--reset-refresh` once.
- `--reset-refresh` removes the old refresh ownership before rediscovering host credentials, then configures and rotates the replacement refresh state.
- If Entra or Microsoft auth is involved in a future provider, use the relevant auth skill. Gator's default providers are GitHub and Codex.

### Unsupported `gh pr view --json` Field
Expand Down
46 changes: 46 additions & 0 deletions crates/openshell-sandbox/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -852,6 +852,21 @@ pub async fn run_sandbox(
}
});

let (ssh_exit_tx, ssh_exit_rx) = if ssh_socket_path.is_some() {
let (tx, rx) = tokio::sync::oneshot::channel::<()>();
(Some(tx), Some(rx))
} else {
(None, None)
};
let ssh_exited: Pin<Box<dyn Future<Output = ()> + Send>> = if let Some(rx) = ssh_exit_rx {
Box::pin(async {
let _ = rx.await;
})
} else {
Box::pin(std::future::pending())
};
tokio::pin!(ssh_exited);

let entrypoint_started_tx =
if process_uses_sidecar_control && let Some(writer) = process_control_writer.clone() {
let (tx, rx) = tokio::sync::oneshot::channel();
Expand Down Expand Up @@ -914,6 +929,7 @@ pub async fn run_sandbox(
openshell_endpoint.as_deref(),
ssh_socket_path,
sidecar_network_enforcement,
ssh_exit_tx,
&process_policy,
resolved_process_identity,
process_enforcement_mode,
Expand Down Expand Up @@ -965,6 +981,21 @@ pub async fn run_sandbox(
"proxy accept loop exited unexpectedly"
));
}
() = &mut ssh_exited => {
ocsf_emit!(
AppLifecycleBuilder::new(ocsf_ctx())
.activity(ActivityId::Fail)
.severity(SeverityId::High)
.status(StatusId::Failure)
.message(
"SSH accept loop exited unexpectedly; terminating sandbox"
)
.build()
);
return Err(miette::miette!(
"SSH accept loop exited unexpectedly"
));
}
}
} else {
tokio::select! {
Expand All @@ -984,6 +1015,21 @@ pub async fn run_sandbox(
"proxy accept loop exited unexpectedly"
));
}
() = &mut ssh_exited => {
ocsf_emit!(
AppLifecycleBuilder::new(ocsf_ctx())
.activity(ActivityId::Fail)
.severity(SeverityId::High)
.status(StatusId::Failure)
.message(
"SSH accept loop exited unexpectedly; terminating sandbox"
)
.build()
);
return Err(miette::miette!(
"SSH accept loop exited unexpectedly"
));
}
}
}
} else {
Expand Down
2 changes: 2 additions & 0 deletions crates/openshell-supervisor-process/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pub async fn run_process(
openshell_endpoint: Option<&str>,
ssh_socket_path: Option<String>,
shared_ssh_socket: bool,
ssh_exit_tx: Option<tokio::sync::oneshot::Sender<()>>,
policy: &SandboxPolicy,
resolved_process_identity: ResolvedProcessIdentity,
enforcement_mode: ProcessEnforcementMode,
Expand Down Expand Up @@ -292,6 +293,7 @@ pub async fn run_process(
let (ssh_ready_tx, ssh_ready_rx) = tokio::sync::oneshot::channel();

tokio::spawn(async move {
let _ssh_exit_guard = ssh_exit_tx;
if let Err(err) = crate::ssh::run_ssh_server(
listen_path,
ssh_ready_tx,
Expand Down
216 changes: 180 additions & 36 deletions crates/openshell-supervisor-process/src/ssh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use crate::process::{
drop_privileges_with_identity, is_supervisor_only_env_var, session_user_and_home,
};
use crate::sandbox;
#[cfg(unix)]
use libc;
use miette::{IntoDiagnostic, Result};
use nix::pty::{Winsize, openpty};
use nix::unistd::setsid;
Expand Down Expand Up @@ -143,44 +145,186 @@ pub async fn run_ssh_server(
}
};

loop {
let (stream, _peer) = listener.accept().await.into_diagnostic()?;
let config = config.clone();
let policy = policy.clone();
let workspace = workspace.clone();
let proxy_url = proxy_url.clone();
let ca_paths = ca_paths.clone();
let provider_credentials = provider_credentials.clone();
let user_environment = user_environment.clone();
let main_session = Arc::clone(&main_session);
let mut consecutive_resource_errors: u32 = 0;
let mut consecutive_unknown_errors: u32 = 0;

tokio::spawn(async move {
if let Err(err) = handle_connection(
stream,
config,
policy,
workspace,
netns_fd,
proxy_url,
ca_paths,
provider_credentials,
user_environment,
resolved_identity,
enforcement_mode,
main_session,
)
.await
{
ocsf_emit!(
SshActivityBuilder::new(openshell_ocsf::ctx::ctx())
.activity(ActivityId::Fail)
.severity(SeverityId::Low)
.status(StatusId::Failure)
.message(format!("SSH connection failed: {err}"))
.build()
);
loop {
match listener.accept().await {
Ok((stream, _peer)) => {
consecutive_resource_errors = 0;
consecutive_unknown_errors = 0;
let config = config.clone();
let policy = policy.clone();
let workspace = workspace.clone();
let proxy_url = proxy_url.clone();
let ca_paths = ca_paths.clone();
let provider_credentials = provider_credentials.clone();
let user_environment = user_environment.clone();
let main_session = Arc::clone(&main_session);

tokio::spawn(async move {
if let Err(err) = handle_connection(
stream,
config,
policy,
workspace,
netns_fd,
proxy_url,
ca_paths,
provider_credentials,
user_environment,
resolved_identity,
enforcement_mode,
main_session,
)
.await
{
ocsf_emit!(
SshActivityBuilder::new(openshell_ocsf::ctx::ctx())
.activity(ActivityId::Fail)
.severity(SeverityId::Low)
.status(StatusId::Failure)
.message(format!("SSH connection failed: {err}"))
.build()
);
}
});
}
});
Err(err) => {
match classify_ssh_accept_error(
&err,
&mut consecutive_resource_errors,
&mut consecutive_unknown_errors,
) {
SshAcceptAction::Terminal => {
ocsf_emit!(
SshActivityBuilder::new(openshell_ocsf::ctx::ctx())
.activity(ActivityId::Fail)
.severity(SeverityId::High)
.status(StatusId::Failure)
.message(format!(
"SSH accept loop exiting on terminal error: {err}"
))
.build()
);
break;
}
SshAcceptAction::Retry { backoff, severity } => {
ocsf_emit!(
SshActivityBuilder::new(openshell_ocsf::ctx::ctx())
.activity(ActivityId::Fail)
.severity(severity)
.status(StatusId::Failure)
.message(format!(
"SSH accept error (retrying in {}ms): {err}",
backoff.as_millis(),
))
.build()
);
tokio::time::sleep(backoff).await;
}
}
}
}
}

Ok(())
}

const MAX_CONSECUTIVE_UNKNOWN_SSH_ACCEPT_ERRORS: u32 = 10;

#[derive(Debug, PartialEq)]
enum SshAcceptAction {
Terminal,
Retry {
backoff: Duration,
severity: SeverityId,
},
}

fn classify_ssh_accept_error(
err: &std::io::Error,
consecutive_resource_errors: &mut u32,
consecutive_unknown_errors: &mut u32,
) -> SshAcceptAction {
#[cfg(unix)]
if matches!(
err.raw_os_error(),
Some(libc::EBADF | libc::EINVAL | libc::ENOTSOCK)
) {
return SshAcceptAction::Terminal;
}

#[cfg(unix)]
if matches!(
err.raw_os_error(),
Some(
libc::EMFILE
| libc::ENFILE
| libc::ENOBUFS
| libc::ENOMEM
| libc::ECONNABORTED
| libc::ECONNRESET
| libc::EINTR
| libc::ENETDOWN
| libc::EPROTO
| libc::ENOPROTOOPT
| libc::EHOSTDOWN
| libc::EHOSTUNREACH
| libc::EOPNOTSUPP
| libc::ENETUNREACH
| libc::ENOSR
| libc::ESOCKTNOSUPPORT
| libc::EPROTONOSUPPORT
| libc::ETIMEDOUT
)
) {
*consecutive_unknown_errors = 0;

#[cfg(unix)]
let is_resource_pressure = matches!(
err.raw_os_error(),
Some(libc::EMFILE | libc::ENFILE | libc::ENOBUFS | libc::ENOMEM | libc::ENOSR)
);
#[cfg(not(unix))]
let is_resource_pressure = false;

if is_resource_pressure {
*consecutive_resource_errors = consecutive_resource_errors.saturating_add(1);
let backoff_ms = 100u64
.saturating_mul(1u64 << (*consecutive_resource_errors).min(7).saturating_sub(1))
.min(5_000);
return SshAcceptAction::Retry {
backoff: Duration::from_millis(backoff_ms),
severity: SeverityId::Medium,
};
}

*consecutive_resource_errors = 0;
return SshAcceptAction::Retry {
backoff: Duration::from_millis(100),
severity: SeverityId::Low,
};
}

#[cfg(unix)]
#[cfg(target_os = "linux")]
if matches!(err.raw_os_error(), Some(libc::ENONET)) {
*consecutive_unknown_errors = 0;
*consecutive_resource_errors = 0;
return SshAcceptAction::Retry {
backoff: Duration::from_millis(100),
severity: SeverityId::Low,
};
}

*consecutive_unknown_errors = consecutive_unknown_errors.saturating_add(1);
if *consecutive_unknown_errors >= MAX_CONSECUTIVE_UNKNOWN_SSH_ACCEPT_ERRORS {
return SshAcceptAction::Terminal;
}
SshAcceptAction::Retry {
backoff: Duration::from_millis(100),
severity: SeverityId::Low,
}
}

Expand Down
2 changes: 2 additions & 0 deletions scripts/agents/gator/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@ RUN mkdir -p /etc/openshell
COPY policy.yaml /etc/openshell/policy.yaml
COPY bin/gh /usr/local/bin/gh-gator
COPY bin/review-feedback-ledger /usr/local/bin/review-feedback-ledger
COPY bin/resolve-gator-review-threads /usr/local/bin/resolve-gator-review-threads
COPY bin/validate-review-findings /usr/local/bin/validate-review-findings
RUN rm -f /usr/local/bin/gh && \
cp /usr/local/bin/gh-gator /usr/local/bin/gh && \
chmod 755 /usr/local/bin/gh /usr/local/bin/review-feedback-ledger \
/usr/local/bin/resolve-gator-review-threads \
/usr/local/bin/validate-review-findings

RUN printf 'export PATH="/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin"\nexport PS1="\\u@\\h:\\w\\$ "\n' \
Expand Down
Loading
Loading