Repository navigation
fix: apply invocation deadlines to SDK waits and cleanup - #733
Draft
zhongkechen wants to merge 15 commits into
Draft
zhongkechen wants to merge 15 commits into
zhongkechen wants to merge 15 commits into
Conversation
4 tasks done
zhongkechen
added this pull request to stack #732
September 25, 2026 17:28
zhongkechen
force-pushed
the
fix/lmi-invocation-lifecycle
branch
from
September 29, 2026 17:49
f38b98a to
d1b4331
Compare
zhongkechen
force-pushed
the
fix/lmi-invocation-lifecycle
branch
from
September 29, 2026 22:18
d1b4331 to
4ff9cea
Compare
zhongkechen
force-pushed
the
fix/lmi-invocation-lifecycle
branch
from
September 29, 2026 22:24
4ff9cea to
fdc6f40
Compare
4 tasks done
10 tasks
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue Link, if available
Partial fix for #726. Stacked on #731 (
feature/lmi-invocation-scope); keep this PR in Draft. Latest upstreammain(67bad28cd9ef1b0808bed193f8a15be75ce457ed) and #731 (d9b251c5003c03e997df6d07dd05116441509a88) are included.Description
An invocation deadline or interrupted cleanup must not leave the runtime caller in an unbounded SDK wait, return
PENDINGwhile cooperative root cleanup is still running, or turn an interruption into a durable business failure. This change adds deadline-aware admission and cleanup to #731's invocation-owned task tracking while preserving current main's worker-owned Start, handler, drain, result preparation, and End ordering.The runtime caller observes the handler outcome and separately waits for actual task exit. Graceful cleanup gives admitted work an opportunity to settle before requesting cooperative cancellation, closes ordinary admission atomically with the final empty task snapshot, and uses the remaining budget for checkpoint and batcher shutdown. A handler-drain interruption continues best-effort cleanup so an admitted late step can still checkpoint its result for replay; a caller interruption or deadline cancels invocation-owned work. Both paths attempt remaining cleanup and restore the interrupt flag.
Deadline checks cover user callbacks, checkpoint dispatch, metadata pagination, and response-critical large-result checkpoints. An accepted terminal execution result remains authoritative at a pagination cutoff without starting additional metadata requests. Unrelated service failures retain their classification, and an available JVM fatal keeps its original identity rather than being replaced by a timeout or an acknowledged-result shortcut.
If an uncooperative root exits after the caller has timed out, the original worker still runs its matching End hook once to restore Start-installed scopes. That late path cannot admit new durable work or prepare another result. Existing durable identities, stored success/failure replay, shared-executor ownership, token-revocation registration semantics, and fatal-error propagation are retained.
Internal limits are 500 ms execution headroom, 100 ms response headroom, up to 5 seconds graceful user-work drain, up to 1 second cancellation drain, and a 30-second local/null-context cleanup cap. A real Lambda deadline constrains these further; root result preparation and End use the remaining overall budget after the handler body exits.
This is a partial lifecycle fix, not an unconditional bounded-return or worker-reclamation guarantee. Arbitrary application I/O, synchronous initial-state reads, custom clients, and plugin hooks cannot be forcibly terminated. An executor that runs the root inline (including a saturated
CallerRunsPolicy) can block the runtime caller before it reaches the timeout-aware wait. Shared fixed-pool starvation remains separate work in #735; cloud LMI acceptance is still pending. The configuration guide documents these limits and the need for finite downstream I/O timeouts.Testing
Final head
242b88fcda0f1bdf92bb515809b95acdf2393c57additionally includes the reviewed #728 harness-only follow-up and an observer-only test stabilization. Production source at947daa1bc16cff037bbdd29ef6e38535f8d0131dincludes the atomic task-publication follow-up from #731:mvn -o -B clean verify: all 10 reactor modules passed; 3,022 tests passed, 34 conditional/cloud tests skipped. This includes 553 integration tests and 810 OTel tests.getwait and renamed drain helper. The final admission gate retains its observed BLOCKED state instead of racing a second snapshot; all admission/exit assertions remain. All 25 Java 25 cleanup/task-lifecycle controls and Spotless passed atc2e6c5ac; the final merge changes only Python harness files and their documentation.Cloud LMI execution was not run; #728 supplies the validation workflow. No PR merge or release is included.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.