refactor(code-execution): session kernels always on — kernel_mode knob retired (#96787)

* refactor(code-execution): retire kernel_mode — session kernels always on for local runs (remote per-call is a tracked gap, not a mode)

* test(code-execution): env-filtering probes use reset=true — kernel env is frozen at spawn, so env rules are only observable on a fresh kernel

* test(code-execution): kernel-aware fixes for mode/pythonpath suites — reset=true on frozen-at-spawn probes, per-test kernel disposal, abort-after-capture fake Popen

* test(code-execution): strict-mode cwd is a behavior contract (staging tmpdir, not session cwd) — kernel stages in hermes_kernel_*, per-call in hermes_sandbox_*
This commit is contained in:
Teknium
2026-08-27 22:22:39 -07:00
committed by GitHub
parent 99c3cad857
commit 4e7eb39947
6 changed files with 119 additions and 56 deletions
+20 -20
View File
@@ -65,18 +65,21 @@ def _run(code, **kwargs):
class TestKernelModeResolution(unittest.TestCase):
def test_default_is_per_call(self):
self.assertEqual(DEFAULT_KERNEL_MODE, "per-call")
"""kernel_mode is retired: session kernels are always on for local runs.
_get_kernel_mode() survives only as a compat shim; a leftover
kernel_mode key in user config (any value) must be ignored."""
def test_session_is_always_on(self):
self.assertEqual(DEFAULT_KERNEL_MODE, "session")
with patch("tools.code_execution_tool._load_config", return_value={}):
self.assertEqual(_get_kernel_mode(), "per-call")
self.assertEqual(_get_kernel_mode(), "session")
def test_kernel_modes_tuple(self):
self.assertEqual(KERNEL_MODES, ("per-call", "session"))
def test_invalid_value_falls_back(self):
with patch("tools.code_execution_tool._load_config",
return_value={"kernel_mode": "forever"}):
self.assertEqual(_get_kernel_mode(), "per-call")
def test_leftover_config_key_is_ignored(self):
for stale in ("per-call", "forever", "", None):
with patch("tools.code_execution_tool._load_config",
return_value={"kernel_mode": stale}):
self.assertEqual(_get_kernel_mode(), "session")
class TestSessionStatePersistence(unittest.TestCase):
@@ -91,13 +94,6 @@ class TestSessionStatePersistence(unittest.TestCase):
self.assertEqual(second["kernel"]["reused"], True)
self.assertEqual(second["kernel"]["execution_count"], 2)
def test_per_call_default_shares_nothing(self):
with _kernel_config(kernel_mode="per-call"):
_run("x = 41")
second = _run("print(x + 1)")
self.assertEqual(second["status"], "error", second)
self.assertNotIn("kernel", second)
def test_reset_discards_state(self):
with _kernel_config():
_run("x = 41")
@@ -163,13 +159,17 @@ class TestSchemaSurface(unittest.TestCase):
schema = build_execute_code_schema(mode="strict")
self.assertIn("reset", schema["parameters"]["properties"])
def test_session_note_only_when_active(self):
def test_session_note_is_always_present(self):
"""The schema's kernel note is unconditional now — session kernels
are always on for local execution (kernel_mode retired), so every
session is told about persistence and reset=true."""
with _kernel_config():
session_schema = build_execute_code_schema(mode="strict")
self.assertIn("Session kernel is active", session_schema["description"])
# Even with a stale per-call key in config, the note stays.
with _kernel_config(kernel_mode="per-call"):
per_call_schema = build_execute_code_schema(mode="strict")
self.assertNotIn("Session kernel is active", per_call_schema["description"])
stale_schema = build_execute_code_schema(mode="strict")
self.assertIn("Session kernel is active", stale_schema["description"])
if __name__ == "__main__":