Repository navigation
fix(events): scope caller() and event.on identity to the querying instance - #436
Merged
Merged
Conversation
…tance `api.slothlet.caller()` (#431) and the EventManager `on()` owner-wrapper capture (#429/#407) read the caller identity from the raw active AsyncLocalStorage store. The async context manager is a process-level singleton and ALS propagates a store across `await` / `queueMicrotask`, so when one instance's module flow is active and code touches a DIFFERENT instance's api, that other instance saw the foreign module as its own caller. The concrete break: @cldmv/slothlet-vine's serving side subscribes to forward an event on behalf of a far subscriber. Over a same-process (loopback) transport the far subscriber's flow propagates into the serving instance's handler, so its forwarding listener captured the far module as `ownerWrapper` and was pinned to it on every emit — the host-only `event.resolveLevel` was then denied under that leaked identity and nothing was forwarded. A real (worker/process/socket) boundary can't propagate ALS, so it surfaced only in-process, but the loopback is the e2e reference. Both accessors now pass the querying instance's id to `getCallerIdentity(instanceID)` — the same instance-scoping the read-gate already applies for the nested-boot case (#290). A foreign flow resolves to the host (no caller); this instance's own flow still reports the real module. The permission gate already scoped this way, so it is now consistent with what `caller()` and event delivery report. Adds a cross-instance isolation regression test (caller() and listener host-pinning) across the full eager/lazy × async/live matrix, with an isolated fixture.
Shinrai
approved these changes
Sep 21, 2026
Shinrai
added a commit
to CLDMV/slothlet-vine
that referenced
this pull request
Sep 21, 2026
The loopback e2e (and any grow/serve pair sharing a process) needs the cross-instance caller-isolation fix (CLDMV/slothlet#436), not just the 3.18.0 enablers. 3.18.0 shipped `caller()` + `event.resolveLevel` but leaked a foreign instance's caller across the process-shared async context, so the serving side's forwarding listener was pinned to the far subscriber and the host-only re-resolve was denied at emit — same-process deliveries silently dropped. A real cross-process boundary (worker/process/socket) can't propagate that context and is unaffected, so the runtime enabler-presence guards stay at ≥ 3.18.0; only the same-process floor moves. Gate the loopback event suite on installed slothlet ≥ 3.18.1 so it skips cleanly on the broken 3.18.0 instead of running and failing, and document the floor + caveat in DESIGN.md.
cldmv-bot Bot
added a commit
that referenced
this pull request
Sep 21, 2026
# Slothlet v3.18.1 Changelog **Release Date**: September 2026 **Release Type**: Patch **Branch**: `release/3.18.1` --- ## Overview Version 3.18.1 fixes a cross-instance context-isolation bug that made the 3.18.0 event-forwarding enablers unreliable whenever two instances share a process. The enablers themselves are unchanged; this release makes them behave as documented across every transport — in particular the **same-process** case (a grow/serve pair inside one process, such as [`@cldmv/slothlet-vine`](https://github.com/CLDMV/slothlet-vine)'s loopback transport) that 3.18.0 silently broke. `api.slothlet.caller()` (#431) and the event manager's subscribe-time owner-wrapper capture (#429 / #407) read the caller identity straight from the active `AsyncLocalStorage` store **without scoping to the querying instance**. The async context manager is a process-level singleton and ALS propagates its store across `await` / `queueMicrotask`, so when one instance's module flow was active and code touched a **different** instance's api, that other instance saw the foreign module as its own caller. Concretely: a forwarding layer's serving side subscribes to re-emit an event on behalf of a far subscriber; over a same-process transport the far subscriber's flow propagated into the serving instance's handler, so its listener was pinned to the far subscriber's identity and the host-only `event.resolveLevel` was denied at emit — same-process deliveries were dropped. A real cross-process boundary (worker, process, socket) cannot propagate that context and was unaffected. Both accessors now pass the querying instance's id to `getCallerIdentity(instanceID)` — the same instance-scoping the permission read-gate already applied for the nested-boot case (#290). A foreign instance's flow resolves to the host (no caller); the instance's own flow still reports the real module, so `caller()` and event delivery are now consistent with what the gate already enforced. This is a drop-in patch with no api change. --- ## 🐛 Bug Fixes ### `caller()` and event delivery no longer leak a foreign instance's caller across the shared async context (#436) `api.slothlet.caller()` on instance A could return instance B's module path, and an event listener registered on A while B's flow was active was pinned to B's identity, when the two instances shared a process and B's flow reached A across an `await` / `queueMicrotask` (the async context manager is a process-level singleton whose store ALS propagates). For a cross-boundary event-forwarding layer this denied the host-only re-resolution at emit under the leaked identity, so a same-process forwarded subscription received nothing. Both `caller()` and the event manager's owner-wrapper capture now scope their identity read to the querying instance (`getCallerIdentity(instanceID)`), exactly as the permission read-gate already did — a foreign instance's active flow reports the host, while the instance's own flow still reports the real module. Same-process event forwarding (e.g. `@cldmv/slothlet-vine` over loopback) now delivers correctly; cross-process forwarding, already unaffected, is unchanged. --- ## 📚 Documentation - **NEW:** [docs/changelog/v3/v3.18.1.md](./v3.18.1.md) — this changelog. --- ## 🔧 Dependencies _No dependency updates._ --- ## Upgrade notes A drop-in for v3.18.0. The two event-forwarding enablers (`api.slothlet.event.resolveLevel`, `api.slothlet.caller()`) are unchanged; nothing about their signatures or return values moves. If you forward events across a **same-process** boundary — two slothlet instances in one process, including `@cldmv/slothlet-vine`'s loopback transport — upgrade to 3.18.1: on 3.18.0 those deliveries are silently dropped. Cross-process forwarding (worker / process / socket) already worked on 3.18.0 and is unaffected. Everything else is unchanged. <details> <summary>👥 Contributors</summary> - @Shinrai </details> --- <!-- coverage-start -->  | Metric | Coverage | |--------|----------| | Statements | 100.0% | | Branches | 100.0% | | Functions | 100.0% | | Lines | 100.0% | *Avg: **100.0%** · `fe594e8` · Node lts/** <!-- coverage-end --> <!-- co-authors --> Co-authored-by: Shinrai <[email protected]>
Shinrai
added a commit
to CLDMV/slothlet-vine
that referenced
this pull request
Sep 21, 2026
3.18.1 fixes the cross-instance caller leak (CLDMV/slothlet#436) that dropped same-process event deliveries, so the loopback event-forwarding e2e now runs and passes. This bump crosses the ≥ 3.18.1 gate, un-skipping the 7 e2e event tests (previously skipped on older slothlet). Full suite: 18 files / 416 tests green. Peer floor stays >=3.14.0 — call forwarding still supports older hosts, and event forwarding degrades gracefully below 3.18.0.
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.
🚀 What's Changed
💥 Breaking Changes
No breaking changes
✨ Features
No new features
🐛 Bug Fixes
📦 Dependencies
No dependency updates
🔧 Other Changes
No other changes
👥 Contributors