-
Notifications
You must be signed in to change notification settings - Fork 0
fix(browser): prove exact crash-root termination before crash credit #151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
seonghobae
merged 10 commits into
test/agent-task-browser-crash-recovery-evidence
from
test/agent-task-browser-crash-exact-exit-detection
Aug 24, 2026
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
8f87e85
test(browser): require exact crash root exit evidence
seonghobae f45a637
fix(browser): bind crash detection to exact process exit
seonghobae d4b175d
test(browser): prove unreaped crash termination boundary
seonghobae add43cb
test(browser): reject stale pidfd crash identity
seonghobae 7e218fc
test(browser): distinguish pidfd exit from signal delivery
seonghobae b30c9fa
fix(browser): observe crash termination through pidfd
seonghobae 43d3919
docs: record exact browser crash termination evidence
seonghobae a73f0c2
chore(stack): absorb corrected crash-recovery prerequisite
seonghobae 9e3d499
Merge a73f0c2b0d9e88df3df7fcbc963226e029940eed into dd45158f230420b75…
seonghobae 4f03d45
Merge branch 'test/agent-task-browser-crash-recovery-evidence' into t…
seonghobae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
151 changes: 151 additions & 0 deletions
151
tests/test_agent_task_browser_crash_exact_exit_detection.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,151 @@ | ||
| """Contract for exact browser-root termination evidence before crash credit.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import contextlib | ||
| import pathlib | ||
| import runpy | ||
| import signal | ||
| import subprocess | ||
| import sys | ||
| import unittest | ||
|
|
||
| ROOT = pathlib.Path(__file__).resolve().parents[1] | ||
| RUNNER = ROOT / "scripts" / "ci" / "run_mv3_compatibility.py" | ||
|
|
||
|
|
||
| class AgentTaskBrowserCrashExactExitDetectionContractTests(unittest.TestCase): | ||
| """Prevent transport failures or unreaped zombies from faking crash evidence.""" | ||
|
|
||
| def test_crash_detection_uses_exact_pidfd_termination_observation(self) -> None: | ||
| """Signal and observe termination through one exact kernel process handle.""" | ||
|
|
||
| runner = RUNNER.read_text(encoding="utf-8") | ||
| start = runner.index("def _run_agent_task_browser_crash_browser_pass(") | ||
| end = runner.index("\ndef _run_agent_task_browser_crash_trial(", start) | ||
| browser_pass = runner[start:end] | ||
|
|
||
| termination_call = browser_pass.index( | ||
| "_signal_and_wait_for_linux_process_identity_termination(" | ||
| ) | ||
| crash_credit = browser_pass.index( | ||
| "browser_process_crash_detected = True", termination_call | ||
| ) | ||
|
|
||
| self.assertLess(termination_call, crash_credit) | ||
| self.assertNotIn( | ||
| "_wait_for_linux_process_identity_exit(", | ||
| browser_pass[termination_call:crash_credit], | ||
| ) | ||
| self.assertNotIn( | ||
| "except (OSError, RuntimeError, json.JSONDecodeError):", | ||
| browser_pass[termination_call:crash_credit], | ||
| ) | ||
|
|
||
| def test_pidfd_termination_observes_killed_unreaped_child(self) -> None: | ||
| """Kernel termination evidence must not require the parent to reap the child.""" | ||
|
|
||
| namespace = runpy.run_path( | ||
| str(RUNNER), | ||
| run_name="agent_task_browser_crash_exact_termination_contract", | ||
| ) | ||
| signal_and_wait = namespace[ | ||
| "_signal_and_wait_for_linux_process_identity_termination" | ||
| ] | ||
| read_identity = namespace["_read_linux_proc_stat_process_identity"] | ||
|
|
||
| child = subprocess.Popen( | ||
| [sys.executable, "-c", "import time; time.sleep(60)"], | ||
| stdout=subprocess.DEVNULL, | ||
| stderr=subprocess.DEVNULL, | ||
| ) | ||
| try: | ||
| identity = read_identity(child.pid) | ||
| self.assertIsNotNone(identity) | ||
| assert identity is not None | ||
|
|
||
| self.assertTrue( | ||
| signal_and_wait(identity, signal.SIGKILL, timeout_seconds=1.0) | ||
| ) | ||
| self.assertEqual( | ||
| read_identity(child.pid), | ||
| identity, | ||
| "the killed child should still be observable as unreaped procfs identity", | ||
| ) | ||
| finally: | ||
| with contextlib.suppress(ProcessLookupError): | ||
| child.kill() | ||
| child.wait(timeout=5) | ||
|
|
||
| def test_pidfd_termination_does_not_credit_signal_delivery_as_exit(self) -> None: | ||
| """A successfully delivered non-terminating signal is not termination evidence.""" | ||
|
|
||
| namespace = runpy.run_path( | ||
| str(RUNNER), | ||
| run_name="agent_task_browser_crash_nonterminating_signal_contract", | ||
| ) | ||
| signal_and_wait = namespace[ | ||
| "_signal_and_wait_for_linux_process_identity_termination" | ||
| ] | ||
| read_identity = namespace["_read_linux_proc_stat_process_identity"] | ||
|
|
||
| child = subprocess.Popen( | ||
| [sys.executable, "-c", "import time; time.sleep(60)"], | ||
| stdout=subprocess.DEVNULL, | ||
| stderr=subprocess.DEVNULL, | ||
| ) | ||
| try: | ||
| identity = read_identity(child.pid) | ||
| self.assertIsNotNone(identity) | ||
| assert identity is not None | ||
|
|
||
| self.assertFalse( | ||
| signal_and_wait(identity, signal.SIGCONT, timeout_seconds=0.05) | ||
| ) | ||
| self.assertIsNone( | ||
| child.poll(), | ||
| "signal delivery without process exit must not be credited as termination", | ||
| ) | ||
| finally: | ||
| with contextlib.suppress(ProcessLookupError): | ||
| child.kill() | ||
| child.wait(timeout=5) | ||
|
|
||
| def test_pidfd_termination_refuses_stale_identity_without_signalling(self) -> None: | ||
| """A stale PID/start-time identity must never signal the current process owner.""" | ||
|
|
||
| namespace = runpy.run_path( | ||
| str(RUNNER), | ||
| run_name="agent_task_browser_crash_stale_identity_contract", | ||
| ) | ||
| signal_and_wait = namespace[ | ||
| "_signal_and_wait_for_linux_process_identity_termination" | ||
| ] | ||
| read_identity = namespace["_read_linux_proc_stat_process_identity"] | ||
|
|
||
| child = subprocess.Popen( | ||
| [sys.executable, "-c", "import time; time.sleep(60)"], | ||
| stdout=subprocess.DEVNULL, | ||
| stderr=subprocess.DEVNULL, | ||
| ) | ||
| try: | ||
| identity = read_identity(child.pid) | ||
| self.assertIsNotNone(identity) | ||
| assert identity is not None | ||
| stale_identity = (identity[0], identity[1] + 1) | ||
|
|
||
| self.assertFalse( | ||
| signal_and_wait(stale_identity, signal.SIGKILL, timeout_seconds=0.1) | ||
| ) | ||
| self.assertIsNone( | ||
| child.poll(), | ||
| "stale identity validation must happen before any signal is delivered", | ||
| ) | ||
| finally: | ||
| with contextlib.suppress(ProcessLookupError): | ||
| child.kill() | ||
| child.wait(timeout=5) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Info: pidfd poll coverage gap for non-child processes
The termination check relies on
select.selectreporting the pidfd readable when the target process exits. In production the browser is a grandchild of the runner (child of ChromeDriver), not a direct child; the contract testtest_pidfd_termination_observes_killed_unreaped_child(test_agent_task_browser_crash_exact_exit_detection.py) only exercises a direct child. Modern kernels notify pidfd waiters for any process, so this works, but the non-child production path is untested. A kernel without that notification would make the trial fail closed rather than mis-credit.Was this helpful? React with 👍 or 👎 to provide feedback.