Prevent Windows daemon launches from retaining launcher stdio (#48272)

Detached Windows daemons can inherit the launcher's output pipes, leaving callers waiting for EOF after the launcher exits.

Clear inheritance flags on the launcher's standard handles before spawning managed Windows processes. Leave the flags cleared to protect concurrent launches while preserving the child's configured stdio, and tolerate missing or already-closed handles.

- Add a Windows regression test verifying that captured launcher output closes while the detached child remains alive and writes to its configured log.
- Give optional MCP startup grace tests more time to complete on slow runners while keeping the pending server's startup timeout longer than the turn timeout.

GitOrigin-RevId: 053e0417793db3c961e738476a05c7467978f339
This commit is contained in:
zm-oai
2026-09-25 20:58:51 -07:00
committed by Ian MacLeod
parent a8c5d7b554
commit 6afb26cf0e
4 changed files with 174 additions and 6 deletions
@@ -14,6 +14,9 @@ use test_case::test_case;
const SERVER_NAME: &str = "optional_startup";
const TOOL_NAMESPACE: &str = "mcp__optional_startup";
const TOOL_NAME: &str = "calendar_create_event";
// Allow the whole turn to finish on slow runners without reaching the server's own timeout.
const TURN_TIMEOUT: Duration = Duration::from_secs(5);
const PENDING_SERVER_TIMEOUT: Duration = Duration::from_secs(30);
#[derive(Clone, Copy)]
enum StartupGraceScenario {
@@ -46,9 +49,9 @@ async fn optional_mcp_startup_grace_controls_initial_turn_tool_catalog(
| StartupGraceScenario::DisabledGraceRespectsStartupTimeout => Duration::ZERO,
};
let startup_timeout = match scenario {
StartupGraceScenario::ShortGraceOmitsPending => PENDING_SERVER_TIMEOUT,
StartupGraceScenario::DisabledGraceRespectsStartupTimeout => Duration::from_millis(250),
StartupGraceScenario::ShortGraceOmitsPending
| StartupGraceScenario::CustomGraceIncludesReady
StartupGraceScenario::CustomGraceIncludesReady
| StartupGraceScenario::DisabledGraceWaitsForStartup => Duration::from_secs(1),
};
let responses_server = responses::start_mock_server().await;
@@ -101,7 +104,7 @@ async fn optional_mcp_startup_grace_controls_initial_turn_tool_catalog(
let mut turn = Box::pin(fixture.submit_turn("show optional MCP tools"));
match scenario {
StartupGraceScenario::ShortGraceOmitsPending => {
tokio::time::timeout(Duration::from_millis(500), &mut turn)
tokio::time::timeout(TURN_TIMEOUT, &mut turn)
.await
.context("the configured grace should omit the pending server")??;
release_startup
@@ -206,7 +209,7 @@ async fn running_thread_uses_refreshed_optional_mcp_startup_grace(
"url": server_url,
"http_headers": { "Authorization": "Bearer synthetic-test-token" },
"enabled_tools": [TOOL_NAME],
"startup_timeout_sec": 5,
"startup_timeout_sec": PENDING_SERVER_TIMEOUT.as_secs(),
}))
.expect("synthetic optional MCP server configuration"),
);
@@ -226,8 +229,10 @@ async fn running_thread_uses_refreshed_optional_mcp_startup_grace(
.await
.context("optional MCP initialization should begin before the initial turn")?;
// Allow for turn setup on remote workers while still finishing before the
// pending MCP startup timeout. The server remains gated throughout.
tokio::time::timeout(
Duration::from_millis(500),
TURN_TIMEOUT,
fixture.submit_turn("show initial optional MCP tools"),
)
.await