Repository navigation
fix: enforce cooperative invocation deadlines #783
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
Open
zhongkechen
wants to merge
4
commits into
main
Choose a base branch
from
fix/lmi-python-lifecycle-20261016
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
f6ccf79
fix: enforce cooperative invocation deadlines
zhongkechen 5141c9c
test: supply deadline in wheel context fixture
zhongkechen 6aed226
chore: merge latest upstream main
67eec85
Merge branch 'main' into fix/lmi-python-lifecycle-20261016
zhongkechen 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
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
49 changes: 49 additions & 0 deletions
49
packages/aws-durable-execution-sdk-python/src/aws_durable_execution_sdk_python/deadline.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,49 @@ | ||
| """One monotonic time budget for cooperative invocation interruption.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import time | ||
| from dataclasses import dataclass | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| from aws_durable_execution_sdk_python.exceptions import InvocationDeadlineExceeded | ||
|
|
||
| if TYPE_CHECKING: | ||
| from aws_durable_execution_sdk_python.threading import CompletionEvent | ||
| from aws_durable_execution_sdk_python.types import LambdaContext | ||
|
|
||
| # Stop admitting work before the platform deadline to leave time for cooperative | ||
| # cleanup. This is not a bound on arbitrary user code, clients, or plugin hooks. | ||
| _CLEANUP_MARGIN_SECONDS = 0.1 | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class InvocationDeadline: | ||
| """Internal invocation-local deadline; None keeps standalone state unbounded.""" | ||
|
|
||
| expires_at: float | None = None | ||
|
|
||
| @classmethod | ||
| def from_lambda_context(cls, context: LambdaContext) -> InvocationDeadline: | ||
| # Capture once: wall-clock adjustments cannot extend this invocation. | ||
| started_at = time.monotonic() | ||
| remaining_seconds = context.get_remaining_time_in_millis() / 1000 | ||
| return cls(started_at + max(0.0, remaining_seconds - _CLEANUP_MARGIN_SECONDS)) | ||
|
|
||
| def remaining(self, timeout: float | None = None) -> float | None: | ||
| """Clamp an existing wait to the same budget, without resetting it.""" | ||
| if self.expires_at is None: | ||
| return timeout | ||
| remaining = max(0.0, self.expires_at - time.monotonic()) | ||
| return remaining if timeout is None else min(timeout, remaining) | ||
|
|
||
| def check(self) -> None: | ||
| if self.remaining() == 0: | ||
| raise InvocationDeadlineExceeded("Lambda invocation time budget exhausted") | ||
|
|
||
| def wait(self, event: CompletionEvent, timeout: float | None = None) -> bool: | ||
| """Do not turn an acknowledged checkpoint into an error after its wait.""" | ||
| completed = event.wait(self.remaining(timeout)) | ||
| if not completed: | ||
| self.check() | ||
| return completed |
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
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
Oops, something went wrong.
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.
Codex AI review · Finding
arf_v1_ygsoiugckiy5x5urrhaxumbgjl[P1] Preserve completed-child replay during in-process resumes
A parallel/map branch can complete a child context with a large
ReplayChildrenresult, then suspend on a wait while another branch remains running. When the coordinator resumes it within the same invocation, that child's terminal checkpoint has already marked its inner operations in_parent_done. This new check rejects those operations before their saved results can be read._branch_workerreports ORPHANED, causing the coordinator to exit and checkpoint a successful parent with missing branch results. Allow saved checkpoint reads and legitimateReplayChildrenreconstruction through the orphan guard while retaining checks before new work and checkpoints. Add an integration test covering this same-invocation resume.To suppress repeats, reply
/ai verdict deferred,/ai verdict false-positive, or/ai verdict out-of-scopeon the first nonblank line. Add rationale on later lines. A new/ai verdict acceptedallows future repeats again.