From 551ccf5d883337da523a6943951c3102b5e925e3 Mon Sep 17 00:00:00 2001 From: Yasyf Mohamedali Date: Wed, 16 Sep 2026 18:45:19 -0700 Subject: [PATCH] =?UTF-8?q?tests:=20=F0=9F=90=9B=20arm=20the=20fake=20CLI'?= =?UTF-8?q?s=20TERM=20trap=20before=20it=20publishes=20its=20pid?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Context: cancelling_run_reaps_the_child_with_sigterm failed intermittently in CI, timing out after 10s waiting for the child to record that it was signalled. Summary: the fake claude CLI installs its TERM trap before writing its pid. Motivation: the pid is what the test waits on before calling abort, so the two lines bracket the exact window in which the test signals. A TERM landing there took the shell's default action, so the child died without writing the term file and the wait loop spun to its timeout. The test was reporting a race in its own fixture, not in the reaping under test. Details: reordering is the whole fix; nothing else observes the pid before the trap matters. Widening the gap with a sleep reproduces the failure against the old order and never against the new one. Claude-Session: https://claude.ai/code/session_015yr73szXYEmbjtNVLxnetK --- rust/spawnllm/tests/common/mod.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rust/spawnllm/tests/common/mod.rs b/rust/spawnllm/tests/common/mod.rs index 0ebe409..6fa3c38 100644 --- a/rust/spawnllm/tests/common/mod.rs +++ b/rust/spawnllm/tests/common/mod.rs @@ -17,8 +17,11 @@ static FIXTURES: OnceLock = OnceLock::new(); const CLAUDE_FAKE: &str = r#"#!/bin/sh if [ "$1" = "auth" ]; then exit 0; fi -if [ -n "$SPAWNLLM_FAKE_PID_OUT" ]; then printf '%s' "$$" > "$SPAWNLLM_FAKE_PID_OUT"; fi +# The pid is what a test waits on before signalling, so the trap is armed first: +# a TERM arriving between the two takes the shell's default action and the run +# dies without recording it. if [ -n "$SPAWNLLM_FAKE_TERM_OUT" ]; then trap 'printf term > "$SPAWNLLM_FAKE_TERM_OUT"; exit 0' TERM; fi +if [ -n "$SPAWNLLM_FAKE_PID_OUT" ]; then printf '%s' "$$" > "$SPAWNLLM_FAKE_PID_OUT"; fi if [ -n "$SPAWNLLM_FAKE_ENV_OUT" ]; then printf 'ANTHROPIC_API_KEY=%s\nANTHROPIC_AUTH_TOKEN=%s\n' "${ANTHROPIC_API_KEY-}" "${ANTHROPIC_AUTH_TOKEN-}" > "$SPAWNLLM_FAKE_ENV_OUT"; fi if [ -n "$SPAWNLLM_FAKE_EXIT_BEFORE_STDIN" ]; then exit 0; fi if [ -n "$SPAWNLLM_FAKE_SPIN" ]; then sleep 3600 & wait "$!"; fi