From cce370e0e415975b4c9aff5a5434f5ba0df1c560 Mon Sep 17 00:00:00 2001 From: Pooya Paridel Date: Fri, 23 Oct 2026 21:54:16 -0700 Subject: [PATCH 1/3] refactor(extras): drop the resume mode fallback Only builds from git main before #811 wrote a session launch checkpoint without resumeBeforeDelivery. The package was never published. So a missing field now reads as False, and replay ignores the current config. --- .../microvm/operation.py | 13 +--- .../microvm/session.py | 15 ++--- .../tests/microvm/operation_test.py | 11 ---- .../tests/microvm/session_test.py | 63 +++---------------- 4 files changed, 18 insertions(+), 84 deletions(-) diff --git a/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/operation.py b/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/operation.py index 60f7a78d7..4e9053109 100644 --- a/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/operation.py +++ b/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/operation.py @@ -156,25 +156,18 @@ class LaunchResult: """Whether each session job checks the MicroVM state, and resumes a suspended MicroVM, before delivery. Only a session launch records it. Replay reads it from the checkpoint. So every replay follows the mode that - the launch prepared the MicroVM for. A launch checkpoint from code that - predates this field does not have it.""" + the launch prepared the MicroVM for. A ``microvm`` launch leaves it + ``None``.""" @classmethod def from_dict(cls, data: dict[str, Any]) -> LaunchResult: # A checkpoint without a delivery gets an empty one. The operation # then terminates the MicroVM as for any delivery it does not know. - # Only a bool is a resume mode. In Python True == 1, so a check by - # equality would accept 1. Any other value reads as no resume mode. - resume_before_delivery = data.get("resumeBeforeDelivery") return cls( microvm_id=data["microvmId"], delivery=data.get("delivery", ""), endpoint=data.get("endpoint"), - resume_before_delivery=( - resume_before_delivery - if isinstance(resume_before_delivery, bool) - else None - ), + resume_before_delivery=data.get("resumeBeforeDelivery"), ) def to_dict(self) -> dict[str, Any]: diff --git a/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/session.py b/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/session.py index 1b61ef809..6b4e9a3b0 100644 --- a/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/session.py +++ b/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/session.py @@ -409,19 +409,14 @@ def run_session( # 502. The request step retries a 502 until both retry tiers end. # 5. So each job follows the resume mode that the launch recorded, # not the current config. - # A launch checkpoint from code that predates the resumeBeforeDelivery - # field has no such field. That code computed the mode from the - # current config on every replay. So the session does the same for - # such a checkpoint. - resume_before_delivery = ( - launched.resume_before_delivery - if launched.resume_before_delivery is not None - else self.resume_from_config - ) + # Every session launch records a bool. So a session checkpoint + # without the field reads as False. try: result = handler( MicrovmSession( - self, launched, resume_before_delivery=resume_before_delivery + self, + launched, + resume_before_delivery=launched.resume_before_delivery is True, ), child, ) diff --git a/packages/aws-durable-execution-sdk-python-extras/tests/microvm/operation_test.py b/packages/aws-durable-execution-sdk-python-extras/tests/microvm/operation_test.py index 12d977801..cf2505f51 100644 --- a/packages/aws-durable-execution-sdk-python-extras/tests/microvm/operation_test.py +++ b/packages/aws-durable-execution-sdk-python-extras/tests/microvm/operation_test.py @@ -496,17 +496,6 @@ def test_launch_result_writes_and_reads_a_resume_mode( assert operation.LaunchResult.from_dict(json.loads(json.dumps(data))) == launched -@pytest.mark.parametrize("value", ["false", "true", 1, 0, None, [], {}]) -def test_launch_result_reads_only_a_bool_as_a_resume_mode(value: Any) -> None: - # In Python True == 1. So a check by equality would read 1 as True. - launched = operation.LaunchResult.from_dict( - {"microvmId": "mvm-1", "delivery": "http", "resumeBeforeDelivery": value} - ) - - assert launched.resume_before_delivery is None - assert "resumeBeforeDelivery" not in launched.to_dict() - - def test_keeps_the_configured_ingress_for_http( run: Any, fake_client: Any, fake_endpoint: Any ) -> None: diff --git a/packages/aws-durable-execution-sdk-python-extras/tests/microvm/session_test.py b/packages/aws-durable-execution-sdk-python-extras/tests/microvm/session_test.py index 4d3c83a8e..39b478336 100644 --- a/packages/aws-durable-execution-sdk-python-extras/tests/microvm/session_test.py +++ b/packages/aws-durable-execution-sdk-python-extras/tests/microvm/session_test.py @@ -1240,16 +1240,15 @@ def two_jobs_with_a_wait_between( return {"build": build, "test": test, "microvm": vm.microvm_id} -def checkpoint_launch_as(monkeypatch: pytest.MonkeyPatch, **fields: Any) -> None: +def checkpoint_launch_without_a_resume_mode(monkeypatch: pytest.MonkeyPatch) -> None: """Make the launch step checkpoint the MicroVM fields of a real launch, - plus ``fields``, and no resume mode of its own. So a test controls the - launch checkpoint that every replay reads.""" + without ``resumeBeforeDelivery``. Every replay then reads that + checkpoint.""" original = operation._MicrovmScope._launch_call # noqa: SLF001 def launch(self: Any, *args: Any) -> Any: data = original(self, *args).to_dict() - data.pop("resumeBeforeDelivery", None) - data.update(fields) + del data["resumeBeforeDelivery"] return SimpleNamespace(to_dict=lambda: data) monkeypatch.setattr(operation._MicrovmScope, "_launch_call", launch) # noqa: SLF001 @@ -1351,25 +1350,17 @@ def test_makes_no_state_check_when_a_deploy_turns_suspending_on( assert launch_checkpoint(result)["resumeBeforeDelivery"] is False -@pytest.mark.parametrize( - ("suspend", "state_checks"), - [(True, 2), (False, 0)], - ids=["current-config-can-suspend", "current-config-cannot-suspend"], -) -def test_follows_the_current_config_for_a_launch_checkpoint_without_a_resume_mode( +def test_makes_no_state_check_for_a_launch_checkpoint_without_a_resume_mode( run: Any, fake_client: Any, fake_endpoint: Any, monkeypatch: pytest.MonkeyPatch, - suspend: bool, # noqa: FBT001 - a pytest parameter - state_checks: int, ) -> None: - # Code that predates the field checkpointed the launch without - # resumeBeforeDelivery. That code computed the mode from the current - # config on every replay. - checkpoint_launch_as(monkeypatch) + # The current config asks for suspending. So only the missing field can + # make the jobs skip the state check. + checkpoint_launch_without_a_resume_mode(monkeypatch) client = fake_client(endpoint=fake_endpoint().url) - config = session_config(client, auto_suspend_on_idle=suspend) + config = session_config(client, auto_suspend_on_idle=True) result = run( session_handler(config, two_jobs), @@ -1379,38 +1370,4 @@ def test_follows_the_current_config_for_a_launch_checkpoint_without_a_resume_mod assert outcome(result)["result"]["test"] == 2 assert "resumeBeforeDelivery" not in launch_checkpoint(result) - assert len(client.requests("get_microvm")) == state_checks - - -@pytest.mark.parametrize( - ("recorded", "suspend", "state_checks"), - [("false", False, 0), (1, False, 0), (0, True, 2)], - ids=["string-false", "one", "zero"], -) -def test_follows_the_current_config_for_a_resume_mode_that_is_not_a_bool( - run: Any, - fake_client: Any, - fake_endpoint: Any, - monkeypatch: pytest.MonkeyPatch, - recorded: Any, - suspend: bool, # noqa: FBT001 - a pytest parameter - state_checks: int, -) -> None: - # Only a bool is a resume mode. A truthy or falsy value of another type - # must not decide whether a job checks the MicroVM state. In Python - # True == 1, so a check by equality would read 1 as True and 0 as False. - checkpoint_launch_as(monkeypatch, resumeBeforeDelivery=recorded) - client = fake_client(endpoint=fake_endpoint().url) - config = session_config(client, auto_suspend_on_idle=suspend) - - result = run( - session_handler(config, two_jobs), - None, - [("build", succeed_with(1)), ("test", succeed_with(2))], - ) - - assert outcome(result)["result"]["test"] == 2 - checkpointed = launch_checkpoint(result)["resumeBeforeDelivery"] - assert type(checkpointed) is type(recorded) - assert checkpointed == recorded - assert len(client.requests("get_microvm")) == state_checks + assert client.requests("get_microvm") == [] From d08a9bdd5bfd892d11983e7b5ec2b780101b16af Mon Sep 17 00:00:00 2001 From: Pooya Paridel Date: Fri, 23 Oct 2026 22:44:18 -0700 Subject: [PATCH 2/3] test(extras): cover a non-bool resume mode The session test now covers a missing, "true", and 1 resume mode. The comment and docstring say only True is a resume mode, as the review asked. --- .../microvm/operation.py | 3 +- .../microvm/session.py | 4 +-- .../tests/microvm/session_test.py | 30 ++++++++++++++----- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/operation.py b/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/operation.py index 4e9053109..ba915d83c 100644 --- a/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/operation.py +++ b/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/operation.py @@ -157,7 +157,8 @@ class LaunchResult: suspended MicroVM, before delivery. Only a session launch records it. Replay reads it from the checkpoint. So every replay follows the mode that the launch prepared the MicroVM for. A ``microvm`` launch leaves it - ``None``.""" + ``None``. ``from_dict`` keeps the checkpointed value as it is. + ``run_session`` reads only ``True`` as a resume mode.""" @classmethod def from_dict(cls, data: dict[str, Any]) -> LaunchResult: diff --git a/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/session.py b/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/session.py index 6b4e9a3b0..43d15581a 100644 --- a/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/session.py +++ b/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/session.py @@ -409,8 +409,8 @@ def run_session( # 502. The request step retries a 502 until both retry tiers end. # 5. So each job follows the resume mode that the launch recorded, # not the current config. - # Every session launch records a bool. So a session checkpoint - # without the field reads as False. + # Every session launch records a boolean. So only `True` turns the + # state check on. A missing field, or any other value, reads as False. try: result = handler( MicrovmSession( diff --git a/packages/aws-durable-execution-sdk-python-extras/tests/microvm/session_test.py b/packages/aws-durable-execution-sdk-python-extras/tests/microvm/session_test.py index 39b478336..4af8af689 100644 --- a/packages/aws-durable-execution-sdk-python-extras/tests/microvm/session_test.py +++ b/packages/aws-durable-execution-sdk-python-extras/tests/microvm/session_test.py @@ -1240,15 +1240,16 @@ def two_jobs_with_a_wait_between( return {"build": build, "test": test, "microvm": vm.microvm_id} -def checkpoint_launch_without_a_resume_mode(monkeypatch: pytest.MonkeyPatch) -> None: +def checkpoint_launch_as(monkeypatch: pytest.MonkeyPatch, **fields: Any) -> None: """Make the launch step checkpoint the MicroVM fields of a real launch, - without ``resumeBeforeDelivery``. Every replay then reads that - checkpoint.""" + plus ``fields``, and no resume mode of its own. Every replay then reads + that checkpoint.""" original = operation._MicrovmScope._launch_call # noqa: SLF001 def launch(self: Any, *args: Any) -> Any: data = original(self, *args).to_dict() del data["resumeBeforeDelivery"] + data.update(fields) return SimpleNamespace(to_dict=lambda: data) monkeypatch.setattr(operation._MicrovmScope, "_launch_call", launch) # noqa: SLF001 @@ -1350,15 +1351,23 @@ def test_makes_no_state_check_when_a_deploy_turns_suspending_on( assert launch_checkpoint(result)["resumeBeforeDelivery"] is False -def test_makes_no_state_check_for_a_launch_checkpoint_without_a_resume_mode( +@pytest.mark.parametrize( + "fields", + [{}, {"resumeBeforeDelivery": "true"}, {"resumeBeforeDelivery": 1}], + ids=["missing", "string-true", "one"], +) +def test_makes_no_state_check_for_a_launch_checkpoint_without_a_bool_resume_mode( run: Any, fake_client: Any, fake_endpoint: Any, monkeypatch: pytest.MonkeyPatch, + fields: dict[str, Any], ) -> None: - # The current config asks for suspending. So only the missing field can - # make the jobs skip the state check. - checkpoint_launch_without_a_resume_mode(monkeypatch) + # The current config asks for suspending. So only the checkpoint can make + # these jobs skip the state check. In Python "true" and 1 are truthy. So a + # truthiness check would turn the state check on. A read of `is True` + # keeps it off. + checkpoint_launch_as(monkeypatch, **fields) client = fake_client(endpoint=fake_endpoint().url) config = session_config(client, auto_suspend_on_idle=True) @@ -1369,5 +1378,10 @@ def test_makes_no_state_check_for_a_launch_checkpoint_without_a_resume_mode( ) assert outcome(result)["result"]["test"] == 2 - assert "resumeBeforeDelivery" not in launch_checkpoint(result) + assert launch_checkpoint(result) == { + "microvmId": "mvm-1", + "endpoint": client.endpoint, + "delivery": "http", + **fields, + } assert client.requests("get_microvm") == [] From c18f693711bd34e5a5e14146b13961b632fee37f Mon Sep 17 00:00:00 2001 From: Pooya Paridel Date: Sat, 24 Oct 2026 14:09:11 -0700 Subject: [PATCH 3/3] fix(extras): keep only a bool resume mode LaunchResult.from_dict reads any non-bool resume mode as None again. This addresses the review, and the restored test covers the case. --- .../microvm/operation.py | 13 ++++++++++--- .../tests/microvm/operation_test.py | 11 +++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/operation.py b/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/operation.py index ba915d83c..564ccf4e1 100644 --- a/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/operation.py +++ b/packages/aws-durable-execution-sdk-python-extras/src/aws_durable_execution_sdk_python_extras/microvm/operation.py @@ -157,18 +157,25 @@ class LaunchResult: suspended MicroVM, before delivery. Only a session launch records it. Replay reads it from the checkpoint. So every replay follows the mode that the launch prepared the MicroVM for. A ``microvm`` launch leaves it - ``None``. ``from_dict`` keeps the checkpointed value as it is. - ``run_session`` reads only ``True`` as a resume mode.""" + ``None``. ``from_dict`` keeps only a bool, and reads any other value as + ``None``. ``run_session`` reads only ``True`` as a resume mode.""" @classmethod def from_dict(cls, data: dict[str, Any]) -> LaunchResult: # A checkpoint without a delivery gets an empty one. The operation # then terminates the MicroVM as for any delivery it does not know. + # The field is typed bool | None. to_dict() writes it back. So + # from_dict keeps only a bool, and reads any other value as None. + resume_before_delivery = data.get("resumeBeforeDelivery") return cls( microvm_id=data["microvmId"], delivery=data.get("delivery", ""), endpoint=data.get("endpoint"), - resume_before_delivery=data.get("resumeBeforeDelivery"), + resume_before_delivery=( + resume_before_delivery + if isinstance(resume_before_delivery, bool) + else None + ), ) def to_dict(self) -> dict[str, Any]: diff --git a/packages/aws-durable-execution-sdk-python-extras/tests/microvm/operation_test.py b/packages/aws-durable-execution-sdk-python-extras/tests/microvm/operation_test.py index cf2505f51..12d977801 100644 --- a/packages/aws-durable-execution-sdk-python-extras/tests/microvm/operation_test.py +++ b/packages/aws-durable-execution-sdk-python-extras/tests/microvm/operation_test.py @@ -496,6 +496,17 @@ def test_launch_result_writes_and_reads_a_resume_mode( assert operation.LaunchResult.from_dict(json.loads(json.dumps(data))) == launched +@pytest.mark.parametrize("value", ["false", "true", 1, 0, None, [], {}]) +def test_launch_result_reads_only_a_bool_as_a_resume_mode(value: Any) -> None: + # In Python True == 1. So a check by equality would read 1 as True. + launched = operation.LaunchResult.from_dict( + {"microvmId": "mvm-1", "delivery": "http", "resumeBeforeDelivery": value} + ) + + assert launched.resume_before_delivery is None + assert "resumeBeforeDelivery" not in launched.to_dict() + + def test_keeps_the_configured_ingress_for_http( run: Any, fake_client: Any, fake_endpoint: Any ) -> None: