Skip to content

refactor(plugin)!: create one plugin instance per invocation - #782

Merged
zhongkechen merged 107 commits into
mainfrom
revert-781-revert-721-refactor/per-invocation-plugin-instances
Oct 21, 2026
Merged

zhongkechen merged 107 commits into
mainfrom
revert-781-revert-721-refactor/per-invocation-plugin-instances

Conversation

@nvasiu

@nvasiu nvasiu commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Description

Create plugin instances per invocation so concurrent Lambda Managed Instances executions do not share mutable plugin state. The 3.x factory receives the same InvocationInfo snapshot as Start, including the X-Ray header captured on the runtime caller before dispatch. Providers, exporters and other reusable resources retain their environment lifetime.

The handler owner runs Start, the body and scope cleanup, operation/continuation/checkpoint drain, output preparation, and End. End runs in reverse registration order on that owner; caller return also waits for outer MDC restoration. The integrated #731 actual-task registry drains work admitted by already-running descendants and closes admission atomically once no actual tasks remain. A queued operation whose wrapper never starts settles its private owner only after actual exit; cancelling a running operation cannot release the owner before its body exits.

Known JVM fatals stop admission and interrupt cooperative peers, while actual tasks, admitted continuations, scope callbacks and in-flight transport finish before End. Non-cooperative work has no hard return bound. HandlerScoped Javadoc and the migration guide state this selected lifecycle. Earlier selected PENDING/RETRYING outcomes, fatal identity, worker-context cleanup, checkpoint token revocation and replayed results/failures remain covered.

This includes main d64973f and preserves its released chained-invoke propagation, operation error/replay and sampling behavior. Outbound metadata comes from the current invocation's plugin instances. The OTel workflow uses main's d8b83992 orchestrator, 05960beb conformance revision and all 26 handlers.

Compatibility and merge order

This is a next-major factory/lifetime migration using 3.0.0-SNAPSHOT. Plugin providers and layers must be rebuilt for the factory API and matching 3.x artifacts; cross-major 2.x/3.x mixtures are unsupported. Use config.toBuilder() to retain an existing resolved factory list.

This PR includes the complete current #731 and #728 commits in its ancestry. The integrated registry fixes the inherited one-pass drain gap and passes the public nested-task regression. The approval and successful CI cover this combined change, so these prerequisites do not need a separate merge first. This PR targets main; the remaining lifecycle PRs will be synchronized with the resulting main.

The provider-reuse fixture waits for its test-owned OpenTelemetry BatchSpanProcessor to retire an earlier flush. It preserves ownership, export-at-return and flush assertions without claiming lossless immediate back-to-back delivery. The exporter starvation fixture keeps a successor record queued with explicit handshakes and retains its original 2,000 ms bound and progress checks.

Validation

  • Java 17 full reactor: 3,564 passed and 36 conditional skips on production-identical sources. The final test-only cancellation wait gate passed its eight lifecycle controls.
  • Java 25 full reactor on the final Java implementation: 3,569 passed, 34 conditional skips, zero failures/errors.
  • Installed 3.x API matrix 4/4, all 26 standalone OTel handlers, formatting and source checks passed. Independent review covered the conflict resolutions, nested admission and queued/running cancellation boundaries.
  • The final LMI harness update passed 202 tests and 22 independent completeness/cohort/verdict controls. Its five harness/docs files are the only changes after the validated Java tree; the final ancestry merge leaves the source tree identical.

Fresh deployed LMI acceptance is not claimed. The current published revision has passed its configured CI and received the required approval.

Frank Chen and others added 30 commits September 29, 2026 15:12
Pair request-local backend call/finally-exit IDs; require original peer task/wrapper occupancy at probe admission; establish a bounded child barrier before nested scheduling. Add counterexample and real-thread fixture tests, and align the fixture parent with the rebased 2.2.1 reactor. Locally reviewed and validated before publication.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Release admissionLock before checkpoint and poll enqueue calls, and wait for admitted enqueue calls before the final shutdown flush. Allow tasks belonging to already-registered operations while draining.

Add deterministic admission and shutdown regressions plus bounded map/parallel coverage in both nesting modes. Local review and all 10 Maven reactor modules passed before publishing.
@zhongkechen
zhongkechen deployed to ai-pr-review-runtime October 20, 2026 00:40 — with GitHub Actions Active
Comment thread sdk/src/main/java/software/amazon/lambda/durable/plugin/HandlerScoped.java Outdated
@github-actions

This comment has been minimized.

@zhongkechen
zhongkechen deployed to ai-pr-review-runtime October 20, 2026 23:39 — with GitHub Actions Active
@github-actions

Copy link
Copy Markdown
Contributor

Codex AI review

No actionable findings confirmed. Review was static; tests were not executed, leaving runtime concurrency and cloud behavior as residual test risks.

Reviewed commit a8e6b010606cf6b39bd3e4370dbc4b9201af7910. Workflow run

@zhongkechen
zhongkechen merged commit 953c377 into main Oct 21, 2026
89 of 91 checks passed
@zhongkechen
zhongkechen deleted the revert-781-revert-721-refactor/per-invocation-plugin-instances branch October 21, 2026 00:48

This branch was successfully deployed

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

Labels

BREAKING Something that is going to break existing users

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Shared OTel plugin state mixes concurrent LMI invocations

2 participants