Skip to content

Bound shutdown waits and retain Node cleanup - #23

Open
ChrisKrawczyk wants to merge 11 commits into
mainfrom
feature/rust-dotnet-lifecycle
Open

ChrisKrawczyk wants to merge 11 commits into
mainfrom
feature/rust-dotnet-lifecycle

Conversation

@ChrisKrawczyk

@ChrisKrawczyk ChrisKrawczyk commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Bound Node shutdown waits without discarding native cleanup, and expose passive stop observation. Successful shutdown still returns Promise<void> and resolves to undefined.

  • Use fallible core startup and retain partial-startup ownership.
  • Validate durations before accepting stop. Repeated calls retain the first deadlines and observe the original operation.
  • Keep registry/preparation failures as sanitized startup errors without changing registration policy.
  • Release obsolete callback/core holders on the JavaScript thread only after proven cleanup; retain terminal results and deadlines separately.
  • Add runtime.stopObserver(), metadata-only state/change observation and isolated lifecycle/observation controls, including repeated races and native provenance.

The latest commit, 8396c89, updates three documents after real-binding qualification against the cleanup-policy implementation in microsoft/duroxide#64 at cc06a9e. No production Node correction, dependency change or new public API was needed for that increment. The earlier lifecycle/observation implementation and upstream reconciliations remain in this PR.

flowchart TD
    Stop["First valid stop"] --> Cleanup["Keep native cleanup owned"]
    Stop --> Wait["Wait within grace plus 5000 ms"]
    Cleanup -->|Cleanup proven| Release["Release callback and core holders on the JavaScript thread"]
    Cleanup -->|Cleanup unproven| Retain["Retain ownership"]
    Release -->|Release fails| Retain
    Wait -->|Total expires first| Timeout["Reject timeout; keep cleanup owned"]
    Timeout --> Terminate["Application or supervisor must terminate the process"]
Loading

Behavior and review focus

Omitted grace remains 1000 ms, with a total of grace plus 5000 ms. Zero requests force, not instant cleanup. Pre-start shutdown is terminal. Serialize lifecycle/registration calls on each Runtime; metrics remain unavailable after stop or accepted startup failure.

Timeout still requires application- or supervisor-owned process termination, even after later cleanup. The SDK never exits the process itself. lifecycle_shutdown_failed alone does not prove cleanup; it can also mean owner loss or failed callback-reference release. Independent providers and Clients keep their lifetimes, and the global orchestration-handler map is unchanged.

An SDK-invoked, awaited JavaScript Promise can outlive native cleanup. It is not necessarily application-detached work. This binding does not gain .NET's registered foreign-completion barrier; native drop and callback-release proof remain separate. Arbitrary application-detached continuations also remain outside native cleanup guarantees.

The matching core contains only named user-cleanup failures. Eligible late destruction preserves actual outer outcomes or valid finalized decisions, not an inner success followed by outer failure. Core, reporting, finalization and registered-cleanup failures remain fatal. Valid output/decisions do not establish provider commit.

Each contained incident uses native tracing target duroxide::runtime::cleanup, category contained_user_cleanup; it does not itself set Faulted. The observer is not an incident feed or a health check. At most two protected payload-disposal attempts can still block; cleanup-skipped means an allocation was left undisposed. Containment does not repair state or recover process abort. Returned lifecycle errors exclude panic payloads, but the separate process-wide Rust panic hook can print them.

stopObserver() retains metadata rather than Runtime/provider/registry ownership. Read state before waitForChange; NotRequested is not readiness and Faulted is sticky. Each observer permits one pending wait. Canceling a wait leaves it reusable; close() rejects pending/later operations. Source closure delivers an unseen final state before null. Neither closure nor a status proves cleanup, and a pending observation does not independently keep the Node process alive.

The lifecycle guide
documents callback ownership, observation and supervisor budget sizing. The latest documentation increment preserves executable examples and diagrams.

Current cleanup-policy qualification: November 18-20

Two fresh Windows x64 development/unwind native builds used the actual NAPI build/staging path and the reviewed core implementation.

Node selection Result
Instrumented real-binding probes 7 passed
Production-feature public controls and loaded-native identity 8 passed

Compiled features and loaded addon hashes were checked; production test-only exports are absent. Probes cover contained versus fatal failures, valid generator decisions/disposal, inner-success/outer-failure behavior and Promise lifetime. Follow-on cancellation progress retained the roughly ten-second grace; no budget or watchdog was relaxed.

The source-built graph uses the modified core declaring 0.1.32, Tokio 1.54.1, futures-util 0.3.34 and PG 0.1.38. Original pins, locks and native assets are unchanged. Published core 0.1.32 is not equivalent to that modified source.
The full cross-SDK selection passed 109 distinct cases / 112 executions across six native builds, with no final failures, skips, zero selections, aborts or watchdog timeouts. No production SDK correction was needed. This is local SQLite/in-memory development evidence, not optimized, PostgreSQL, platform or installed-package qualification.

The current core selection passed 372 distinct cases / 712 executions. The documentation audit and independent review/challenge found no blocking defect; optional Runtime-lifetime correlation for cleanup incidents was not added.

Earlier evidence and remaining gates

Earlier, pre-policy reconciliation checks passed 26 hook-free lifecycle cases with 11 expected hook-only skips, 37 instrumented lifecycle cases, 42 PostgreSQL-backed E2E cases including the SQLite control, and instrumented all-target Clippy. Both ordered races retained 100 iterations. That earlier graph used registry PG 0.1.37; those dev builds and PostgreSQL results are historical, not reruns of the new policy. The temporary database container and credentials were removed after those checks.
Later passive-observation evidence is summarized in microsoft/duroxide#64, separately from the fresh cleanup-policy matrix.

Depends on microsoft/duroxide#64. The earlier hosted registry failure records published core 0.1.32 missing the lifecycle/observer APIs. Current-head CI must be assessed separately.
Compatible core publication under maintainer authorization, final registry minima/provider graph/locks/native assets, and hosted, optimized/release-profile, supported-platform, PostgreSQL and installed-package checks remain gates. An imported provider version alone does not qualify a shared production database migration.

No release, package publication, publishing dispatch or merge into main was performed or requested. This delivery does not change dependency overrides or locks, and commits no binaries, workflow artifacts or unrelated work.

Generated with PAW.

chkraw and others added 2 commits October 6, 2026 14:33
Preserve the prepared core and startup failures across repeated lifecycle
calls, validate shutdown deadlines before mutation, and unref callbacks
only after proven core quiescence without changing Promise<void> results.
Add supervised lifecycle regressions, test-hook wiring, and migration docs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 73748d4f-2eb6-47d2-9dbc-af8681e80e83
Preserve upstream replay isolation, failed-race semantics, lock options, release metadata, and the Rust toolchain pin. Integrate options into protected startup preparation and add raw/typed lifecycle race regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 73748d4f-2eb6-47d2-9dbc-af8681e80e83
@ChrisKrawczyk

Copy link
Copy Markdown
Contributor Author

Conflict reconciliation is pushed in ff5f40e (a normal merge of main; no history rewrite). GitHub now reports this draft conflict-free. Upstream replay/race fixes, lock options, release metadata and the toolchain pin are retained, with option preparation still inside the protected lifecycle startup path.

The requested independent Claude Opus 5 integration review covered all four lifecycle PRs and returned PASS, with no blocking findings. The reviewed tree is exactly the committed tree; microsoft/duroxide#64 is unchanged. Non-blocking follow-ups include choosing a new sibling package version before release and the existing signed-to-unsigned negative-option validation gap. This supersedes the original conflict note only: the published core/provider graph, final registry pins, PostgreSQL, non-Windows/five-RID, broader regressions and hosted CI remain unwaived gates. The PR stays draft; nothing was merged, released or published.

Keep one native cleanup operation independent of bounded Promise observers
and preserve the first SDK budget, callback roots and error categories.
Retain upstream release and replay fixes; distinguish cancellable provider
futures from non-yielding native frames in lifecycle coverage.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 73748d4f-2eb6-47d2-9dbc-af8681e80e83
@ChrisKrawczyk

Copy link
Copy Markdown
Contributor Author

Upstream-first reconciliation is pushed in 61e59d3 (normal merge of main; no history rewrite). GitHub reports this draft conflict-free. The adapter retains one native cleanup operation and observes it through the first SDK budget, preserving Promise, terminal-state/error behavior and JS-thread callback unref only after proven retirement. Upstream 0.2.1 release metadata and replay/KV fixes are retained. Tests distinguish cancellable fetch futures from non-yielding native frames; no guarantee for unregistered JavaScript continuations was added.

The independent scoped four-repository review is PASS, including the corrected inherited .NET concurrency-test defect. Node's instrumented lifecycle suite passed 20 cases, including 100 repetitions per force ordering and isolated timeout/late-retirement probes. Production lifecycle/lock/replay/typed selections passed 26 with nine expected hook/POSIX skips. Production assets are restored; the reviewed source tree exactly matches the commit.

Core microsoft/duroxide#64 now uses upstream task tracking and is about 32% smaller by feature changed-line count. The local core 0.1.32/provider 0.1.36 graph is development-only: published core lacks additive APIs. Registry delivery, PostgreSQL, non-Windows/five-RID, broader regression and hosted CI remain OPEN. The PR stays draft; nothing was merged, released or published.

chkraw and others added 3 commits October 21, 2026 13:57
Release obsolete native callback holders only after proven cleanup. Add isolated recurring lifecycle instrumentation, installed-addon provenance and stronger timing, registration and ownership regressions.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 73748d4f-2eb6-47d2-9dbc-af8681e80e83
Preserve unreleased lifecycle notes while integrating main package metadata and duroxide-pg 0.1.37. Rebuild both native modes against the retained local-core graph and preserve the separate compatible-core publication gate.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 73748d4f-2eb6-47d2-9dbc-af8681e80e83
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 73748d4f-2eb6-47d2-9dbc-af8681e80e83
@ChrisKrawczyk ChrisKrawczyk changed the title [Sibling Runtime Lifecycle] Add retained bounded shutdown for Node Bound shutdown waits and retain Node cleanup Oct 21, 2026
@ChrisKrawczyk
ChrisKrawczyk marked this pull request as ready for review October 22, 2026 04:55
chkraw and others added 5 commits October 22, 2026 13:36
Preserve unreleased lifecycle notes and upstream 0.2.3 metadata. Run instrumented lifecycle CI on Node 24.22.1.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 73748d4f-2eb6-47d2-9dbc-af8681e80e83
Expose retained stop/fault state through independently owned observers with isolated AbortSignal waits and terminal local close. Keep observation metadata separate from worker ownership and event-loop keepalive. Cover real faults, source retirement, collection and notification races, and document the contracts.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 73748d4f-2eb6-47d2-9dbc-af8681e80e83
Retain lifecycle and observation changes alongside the upstream package metadata, PostgreSQL provider 0.1.38 requirement, migration guidance, and both changelog histories.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 73748d4f-2eb6-47d2-9dbc-af8681e80e83
Explain the qualified core cleanup policy and the lifetime of an
SDK-invoked Promise separately from native cleanup and passive
stop observation. Preserve existing shutdown budgets.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 73748d4f-2eb6-47d2-9dbc-af8681e80e83
Align native dependency declarations with the core/provider 0.2.0
release line. Report unsupported stop states through observation errors
and retain callback resources when a shutdown outcome cannot prove
quiescence.

Add a focused instrumented observation regression and document the fully
drained PostgreSQL upgrade. The lifecycle APIs still require the matching
unreleased core; registry-only release qualification remains pending.

Ref: microsoft/duroxide#64 (comment)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 73748d4f-2eb6-47d2-9dbc-af8681e80e83
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.

2 participants