Skip to content

fix: enforce cooperative invocation deadlines - #783

Open
zhongkechen wants to merge 4 commits into
mainfrom
fix/lmi-python-lifecycle-20261016
Open

zhongkechen wants to merge 4 commits into
mainfrom
fix/lmi-python-lifecycle-20261016

Conversation

@zhongkechen

@zhongkechen zhongkechen commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Expired Lambda invocations could start new user work, and SDK-owned waits could keep cooperative branches pinned during invocation cleanup. This change captures one monotonic invocation budget, rejects late work, and lets those waits unwind as a retryable invocation interruption while preserving checkpointed outcomes.

Related to #741. This is a partial implementation and intentionally does not close that issue. Regression test PR #743 remains separate and unchanged.

  • Capture the Lambda remaining time once and reserve 100 ms before its deadline. Check operation/user-code admission, checkpoint dispatch, and state-page dispatch; clamp checkpoint, scheduled-refresh, queue, and map/parallel coordinator waits to the same budget. Deadline exhaustion bypasses the user step retry strategy and does not persist a step failure.
  • Make new descendants inherit completed ancestry, including logical/virtual registrations, so a residual branch cannot start a new operation after its parent completes.
  • Preserve a terminal execution success/failure already acknowledged by the service. At the cutoff, stop further metadata pagination while retaining inline/already-read operations and finishing local delivery. Normal pagination still raises the deadline error; unrelated service errors keep their existing classification.
  • Keep invocation-owned workers confined and preserve branch-before-batcher cleanup ordering. An early winner with an orphan branch parked in an SDK refresh wait now unwinds and joins at the invocation cutoff. Healthy invocations and shared service-client configuration are untouched.

Remaining boundary: this does not provide a hard bound on the wrapper or guarantee LMI worker reclamation. Arbitrary user code/I/O, an already-running synchronous service call (including retries), and blocked plugin hooks still have to return before their threads can be joined. No threads are detached or forcibly interrupted. Non-cooperative worker retirement needs a runtime-supported strategy and real LMI validation; #741 remains open for that work. Shared conformance requirements for that complete contract should be coordinated separately.

Current head 6aed2267 also includes upstream main 04daf408. The incoming change touches only the standalone MicroVM worker and its tests; LMI/core/OTel source trees remain unchanged. That worker tree is identical in both refreshed Python PRs and passed 261 tests, type checking (13 files), and formatting/lint. Current-head CI is tracked separately.

Validation on the reviewed implementation:

  • Core: 1,859 tests pass, 98.48% coverage (98% gate), including 23 new deadline/lifecycle cases. Coverage includes initial expiry, replay of saved success and failure, step retry-policy bypass, public parallel/wait coordination, late orphan admission, cooperative cleanup, healthy-peer isolation, confined blocked transport/hooks/user I/O, and terminal acknowledgment/pagination races.
  • OpenTelemetry compatibility: 668 tests pass both in the workspace and against the built core/OTel wheels. 12 installed new-pair controls and 12 released-OTel-1.0/new-core controls also pass. Legacy Lambda-context and concurrency test doubles now supply the budget/deadline consumed by core, including the installed-wheel fixture; existing assertions remain intact.
  • Core type checks (85 files), core and OTel formatting/lint, wheel and sdist builds, commit lint, and git diff --check pass.
  • Composing the five unchanged local [Bug]: Missing invocation deadlines and unbounded branch cleanup can pin LMI workers #741 regressions from test: add LMI cloud lifecycle regressions #743 with this core yields 2 passes / 3 failures: expired invocation admission and late orphan rejection pass; the parallel/map/nested tests requiring reclamation of a branch blocked in non-cooperative user I/O remain unsatisfied.
  • No cloud deployment or real LMI acceptance run was performed. This PR is Draft pending that acceptance and review of the remaining shutdown contract.

Use an invocation-local monotonic budget for SDK admission and waits.
Reject newly registered descendants of completed contexts before user
code or checkpoint dispatch.

Preserve acknowledged terminal outcomes without issuing metadata reads
after the cutoff. Keep running threads confined and document the
unresolved non-cooperative cleanup boundary in #741.
@zhongkechen
zhongkechen marked this pull request as ready for review October 19, 2026 17:58
@zhongkechen
zhongkechen deployed to ai-pr-review-runtime October 19, 2026 17:58 — with GitHub Actions Active
@zhongkechen
zhongkechen deployed to ai-pr-review-runtime October 19, 2026 17:58 — with GitHub Actions Active
InvalidStateError: If the check result is in an invalid state
May raise operation-specific errors from check_result_status() or execute()
"""
self.state.check_operation_active(self.operation_identifier)

Copy link
Copy Markdown
Contributor

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 ReplayChildren result, 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_worker reports ORPHANED, causing the coordinator to exit and checkpoint a successful parent with missing branch results. Allow saved checkpoint reads and legitimate ReplayChildren reconstruction 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-scope on the first nonblank line. Add rationale on later lines. A new /ai verdict accepted allows future repeats again.

Comment on lines +869 to +873
operation_update is not None
and operation_update.operation_type is OperationType.EXECUTION
and operation_update.action
in {OperationAction.SUCCEED, OperationAction.FAIL}
and self._terminal_execution_acknowledged.is_set()

Copy link
Copy Markdown
Contributor

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_vgbpun25a2tdxgcw3ykxpyfpeq

[P2] Reconcile terminal acknowledgments received during cleanup

If an EXECUTION SUCCEED/FAIL request remains in flight at the cutoff, this flag is false and InvocationDeadlineExceeded escapes. Cleanup still joins the batcher, so the request can then succeed and set _terminal_execution_acknowledged, but the exception path skips both check_invocation_result() calls. The wrapper and invocation-end hook therefore report RETRY even though the terminal checkpoint is known to have succeeded before return. Reconcile that request's outcome after the mandatory join, or await its specific completion once dispatched, before propagating the deadline error. Add a regression test that holds the terminal checkpoint transport across the cutoff.

To suppress repeats, reply /ai verdict deferred, /ai verdict false-positive, or /ai verdict out-of-scope on the first nonblank line. Add rationale on later lines. A new /ai verdict accepted allows future repeats again.

@github-actions

Copy link
Copy Markdown
Contributor

Codex AI review

Two findings:

  • P1: Replay can silently lose branch results — packages/aws-durable-execution-sdk-python/src/aws_durable_execution_sdk_python/operation/base.py:182.
  • P2: Terminal checkpoint success can still produce RETRY — packages/aws-durable-execution-sdk-python/src/aws_durable_execution_sdk_python/state.py:873.

Tests were not executed under the read-only review constraints.

Reviewed commit 67eec850f73100d9f3e30f25b28df854490e8c37. Workflow run

This branch was successfully deployed

1 active deployment
ai-pr-review-runtime — 67eec850 Deployed Oct 19, 2026 by zhongkechen via ai-pr-review / Codex review / Generate Codex review #1861
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant