Skip to content

Let child exit gracefully on Ctrl-C to astabench eval#83

Merged
mdarcy220 merged 2 commits into
mainfrom
miked/fix-sigint-cleanup
May 12, 2026
Merged

Let child exit gracefully on Ctrl-C to astabench eval#83
mdarcy220 merged 2 commits into
mainfrom
miked/fix-sigint-cleanup

Conversation

@mdarcy220

Copy link
Copy Markdown
Contributor

This is the fix I was referring to in allenai/agent-baselines#25 (comment)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Updates agenteval eval’s subprocess execution so that a Ctrl-C allows the child inspect eval-set process to perform sandbox cleanup instead of being force-killed immediately.

Changes:

  • Replaces subprocess.run(...) with subprocess.Popen(...)/wait() to implement custom Ctrl-C behavior.
  • On first Ctrl-C, prints guidance and waits for the child to finish cleanup; on second Ctrl-C, SIGKILLs the child.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/agenteval/cli.py
Comment on lines +1090 to 1118
try:
returncode = proc.wait()
except KeyboardInterrupt:
click.echo(
f"\nInterrupt received; waiting for inspect (pid {proc.pid}) to "
f"finish sandbox cleanup.\n"
f" - If Ctrl-C went to the whole process group (the usual case "
f"when running `astabench eval` directly in a terminal), inspect "
f"already received SIGINT and is cleaning up -- just wait.\n"
f" - If only this process was signalled (e.g. a wrapper script "
f"forwarded SIGINT by PID rather than to the process group), "
f"inspect did NOT receive SIGINT and will not exit on its own; "
f"in another terminal run `kill -INT {proc.pid}` to trigger its "
f"cleanup.\n"
f" - Press Ctrl-C again to give up and SIGKILL inspect (may "
f"leave orphan sandbox containers).",
err=True,
)
try:
returncode = proc.wait()
except KeyboardInterrupt:
click.echo("Aborting: sending SIGKILL to inspect.", err=True)
proc.kill()
returncode = proc.wait()

if proc.returncode != 0:
if returncode != 0:
raise click.ClickException(
f"inspect eval-set failed while running {config_path}"
)
Comment thread src/agenteval/cli.py
Comment on lines +1087 to +1113
# Popen + our own Ctrl-C handling; `subprocess.run` would automatically
# SIGKILL the child and skip cleanup
proc = subprocess.Popen(inspect_command)
try:
returncode = proc.wait()
except KeyboardInterrupt:
click.echo(
f"\nInterrupt received; waiting for inspect (pid {proc.pid}) to "
f"finish sandbox cleanup.\n"
f" - If Ctrl-C went to the whole process group (the usual case "
f"when running `astabench eval` directly in a terminal), inspect "
f"already received SIGINT and is cleaning up -- just wait.\n"
f" - If only this process was signalled (e.g. a wrapper script "
f"forwarded SIGINT by PID rather than to the process group), "
f"inspect did NOT receive SIGINT and will not exit on its own; "
f"in another terminal run `kill -INT {proc.pid}` to trigger its "
f"cleanup.\n"
f" - Press Ctrl-C again to give up and SIGKILL inspect (may "
f"leave orphan sandbox containers).",
err=True,
)
try:
returncode = proc.wait()
except KeyboardInterrupt:
click.echo("Aborting: sending SIGKILL to inspect.", err=True)
proc.kill()
returncode = proc.wait()

@jbragg jbragg left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

thanks!

@mdarcy220 mdarcy220 merged commit dedd44b into main May 12, 2026
4 checks passed
@mdarcy220 mdarcy220 deleted the miked/fix-sigint-cleanup branch May 12, 2026 20:01
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.

3 participants