Skip to content

bug: event-rule conditions receive the raw context store instead of the user context #511

Closed

Description

@Shinrai

Summary

A conditional event rule's condition(ctx) receives the whole AsyncLocalStorage store ({ instanceID, context: { actor }, currentWrapper, … }), while a conditional call rule's condition(ctx, meta) receives the user context ({ actor }). docs/EVENTS.md says event rules take "the same condition shape permission rules accept", so the same condition function behaves differently depending on which rule type it's attached to.

Where

  • src/lib/handlers/event-manager.mjs:257 (resolveLevel) and :282 (per-emit re-resolve) pass this.slothlet.contextManager?.tryGetContext?.() ?? null, which is the store.
  • src/lib/builders/api_builder.mjs:1159 and :3100 (the call-side checks, e.g. permissions.global.checkAccess) pass tryGetContext?.()?.context ?? null, which is the user context.

Repro

const api = await slothlet({
	base,
	permissions: {
		defaultPolicy: "deny",
		events: {
			default: "deny",
			rules: [{ caller: "remote.renderer", event: "jobs.*", effect: "allow", condition: (ctx) => ctx?.actor?.id === "u1" }]
		}
	}
});
await api.slothlet.context.run({ actor: { id: "u1" } }, () => api.slothlet.event.resolveLevel("remote.renderer", "jobs.done"));
// → "deny": ctx is the store, so ctx.actor is undefined (ctx.context.actor is "u1").
// The same condition on a call rule, checked with global.checkAccess inside the same run(), sees ctx.actor.

Expected

Pass tryGetContext()?.context ?? null at both event-manager sites so event and call conditions see the same ctx. Existing event conditions that read ctx.context.* would need to move to ctx.*. That makes this a behavior change worth a changelog note, though it matches the documented contract.

Found by

Building the channel principal for CLDMV/slothlet-vine#33. That branch's e2e test works around it with ctx.actor ?? ctx.context?.actor.

Activity

  1. added
    type: bug
    priority: medium
    on Sep 28, 2026
  2. added theissue type on Sep 28, 2026
  3. added
    status: confirmed
    area: core
    status: in progress
    status: implemented
    and removed
    status: confirmed
    status: in progress
    on Sep 28, 2026
  4. Shinrai commented on Sep 29, 2026

    @Shinrai
    ContributorAuthor

    Landed on next in #514 (7654b712). Ships in the next release (3.22.0); this closes when it reaches master.

  5. cldmv-bot commented on Oct 3, 2026

    @cldmv-bot
    Contributor

    Closed in v3.22.0 — resolved by #514.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: corepriority: mediumstatus: implementedtype: bug

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions