Let child exit gracefully on Ctrl-C to astabench eval#83
Merged
Conversation
There was a problem hiding this comment.
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(...)withsubprocess.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 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 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the fix I was referring to in allenai/agent-baselines#25 (comment)