Skip to content

fix(events): scope caller() and event.on identity to the querying instance - #436

Merged
Shinrai merged 1 commit into
nextfrom
fix/event-caller-instance-scope
Sep 21, 2026
Merged

Shinrai merged 1 commit into
nextfrom
fix/event-caller-instance-scope

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented Sep 21, 2026

Copy link
Copy Markdown
Contributor

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

No new features

🐛 Bug Fixes

  • fix(events): scope caller() and event.on identity to the querying instance (15ee526)

📦 Dependencies

No dependency updates

🔧 Other Changes

No other changes

👥 Contributors

…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.
@cldmv-bot cldmv-bot Bot added ! fix → next v4 flow: fix contributor PR targeting the next integration branch area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure labels Sep 21, 2026
@Shinrai
Shinrai merged commit eef9e07 into next Sep 21, 2026
24 checks passed
@cldmv-bot
cldmv-bot Bot deleted the fix/event-caller-instance-scope branch September 21, 2026 03:01
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 -->

![coverage](https://img.shields.io/badge/coverage-100.0%25-brightgreen?style=for-the-badge&logo=vitest&logoColor=white)

| 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: core Touches core library / runtime source code area: tests Touches test files, fixtures, or test infrastructure ! fix → next v4 flow: fix contributor PR targeting the next integration branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant