Skip to content

Probe agent host before re-using#322635

Draft
osortega wants to merge 1 commit into
mainfrom
agents/agents-workbench-integrated-browser-b1abd7bf
Draft

Probe agent host before re-using#322635
osortega wants to merge 1 commit into
mainfrom
agents/agents-workbench-integrated-browser-b1abd7bf

Conversation

@osortega

Copy link
Copy Markdown
Contributor

Created from agents/agents-workbench-integrated-browser-b1abd7bf targeting main.

Copilot AI review requested due to automatic review settings June 23, 2026 22:56
@osortega osortega changed the title agents: agents workbench integrated browser b1abd7bf Probe agent host before re-using Jun 23, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves agent host supervisor reuse in the CLI by adding a lightweight health endpoint and introducing a TCP/HTTP responsiveness probe before deciding to reuse a lockfile-recorded supervisor.

Changes:

  • Added a supervisor-side GET /_agent_host_health endpoint that responds before any backend download/start, enabling cheap reuse probing.
  • Implemented probe_agent_host_responsive() to verify the supervisor responds to an HTTP request within a fixed timeout.
  • Updated agent host command flow to probe a reuse candidate and reap/restart when it appears unresponsive.
Show a summary per file
File Description
cli/src/tunnels/agent_host.rs Adds the health endpoint and the new responsiveness probe function (plus tests).
cli/src/commands/agent_host.rs Uses the probe during lockfile reuse resolution to decide whether to reuse or start fresh.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 3

Comment on lines +1336 to +1339
let path = match token {
Some(t) => format!("{AGENT_HOST_HEALTH_PATH}?tkn={t}"),
None => AGENT_HOST_HEALTH_PATH.to_string(),
};
Comment on lines +1341 to +1362
let probe = async {
let stream = TcpStream::connect(&target).await.ok()?;
let (mut sender, conn) = hyper::client::conn::http1::handshake(TokioIo::new(stream))
.await
.ok()?;
// Drive the connection in the background; it completes once the
// (single) request/response exchange finishes.
tokio::spawn(async move {
let _ = conn.await;
});
let req = Request::builder()
.method(::http::Method::GET)
.uri(&path)
.header(::http::header::HOST, "localhost")
.body(empty_body())
.ok()?;
// Any complete response — regardless of status — proves the
// supervisor is responsive.
sender.send_request(req).await.ok().map(|_res| ())
};

matches!(tokio::time::timeout(timeout, probe).await, Ok(Some(())))
Comment on lines +482 to +491
warning!(
log,
"Agent host (PID {}, port {}) is registered but not responding within {}s; \
reaping it and starting fresh",
pid,
port,
HEALTH_PROBE_TIMEOUT.as_secs()
);
let _ = replace_existing(log, lockfile_path, *pid).await;
AgentHostLockfileDecision::SpawnFresh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants