Skip to content

release: v3.6.0 - #90

Merged
Shinrai merged 16 commits into
masterfrom
release/3.6.0
May 19, 2026
Merged

Shinrai merged 16 commits into
masterfrom
release/3.6.0

Conversation

@cldmv-bot

@cldmv-bot cldmv-bot Bot commented May 18, 2026 •

Copy link
Copy Markdown
Contributor

🚀 What's Changed

💥 Breaking Changes

No breaking changes

✨ Features

  • feat(hooks): auto-pin the registering module's caller identity onto hooks (a629c25)
  • feat(runtime): add self.slothlet.lockCaller() and self.slothlet.bind() (fee72e4)

🐛 Bug Fixes

  • fix(runtime): make lockCaller a true no-op passthrough with no caller context (af809d8)
  • fix(context): preserve original errors thrown by locked callbacks (bb25e2f)
  • fix(tests): only treat delimited PID segments as owned in tmp sweep (33318c6)
  • fix(types): expose lockCaller and bind on the SlothletAPI typedef (eba3bcc)
  • fix(tests): sweep tmp artifacts by PID ownership, not mtime (029d908)

🔧 Other Changes

  • docs(hooks): correct live-mode caller-identity wording; cover reload re-pin (1c89c6e)
  • test(runtime): cover hook auto-pin, bind context freeze, locked errors (e12fc8d)
  • docs(hooks): document hook auto-pin; fix bind/live-mode contradiction (397b8ec)
  • test(runtime): assert exact identity in live-mode lockCaller test (8e2bd90)
  • test(runtime): cover async-await identity in lockCaller; fix PERMISSIONS snippet (3527738)
  • docs: clarify lockCaller live-mode async limitation and fix permissions link (564e857)
  • chore: bump version to 3.6.0 (44f9490)
  • test: sweep stale per-run temp folders in test/build prechecks (233841a)
👥 Contributors

coverage

Metric Coverage
Statements 100.0%
Branches 100.0%
Functions 100.0%
Lines 100.0%

Avg: 100.0% · 0c30d5d · Node lts/*

Shinrai and others added 3 commits May 18, 2026 10:36
Test suites and the TypeScript validator copy fixtures / generate .d.ts
files into uniquely-named directories under tmp/. A crashed worker or a
SIGINT mid-run leaves those behind, so they accumulated indefinitely
(42 stale folders had piled up).

- Add tests/lib/clean-tmp-artifacts.mjs: a shared precheck that sweeps
  api_test_collisions_multi_*, slothlet-test-types-*, and ts-validate-*
  directories out of tmp/, with a minAgeMs guard so it never touches a
  folder a sibling process just created.
- Wire the precheck into run-all-vitest.mjs (covers vitest/coverage/
  baseline) and validate-typescript.mjs (covers test:types).
- Fix the root-cause leak: api-assignment-collision-lazy.test.vitest.mjs
  copied a fixture into tmp/ in beforeAll but never removed it; it now
  cleans up in afterAll.
Callbacks stored in plain arrays — Fastify addHook handlers, third-party
event registries — never pass through slothlet's EventEmitter patch, so
they run with whatever module's async context is ambient when they fire.
A self.* call inside such a callback is then attributed to the wrong
module and permission rules keyed to the registering module fail.

- lockCaller(fn): captures the registering module's currentWrapper at
  call time and, on every invocation, overrides only the caller identity
  on the live context store. Request-scoped context stays live; this is
  forwarded. A thin wrapper over contextManager.runInContext().
- bind(fn): convenience re-export of AsyncResource.bind — freezes the
  whole async context captured at registration.
- Both are added to the slothlet namespace in api_builder.mjs and are
  permission-gated routes like every other slothlet.* member.

Fixture api_tests/api_test_lock_caller/ (producer + consumer modules)
and tests/vitests/suites/runtime/lock-caller.test.vitest.mjs cover the
repro, permission matching, live-context visibility, this forwarding,
the no-context no-op, non-function rejection, and bind across the
eager/lazy x async/live matrix. Docs: new v3.6.0 changelog, HOOKS.md
"Caller Identity in Callbacks" section, PERMISSIONS.md gated-route note,
README "What's New".
@cldmv-bot cldmv-bot Bot added release Marks a pull request as a pending release — merge to publish a new version semver: minor This release adds new functionality in a backwards-compatible way labels May 18, 2026
@Shinrai
Shinrai requested a review from Copilot May 18, 2026 17:58
@Shinrai Shinrai self-assigned this May 18, 2026

This comment was marked as resolved.

Shinrai added 2 commits May 18, 2026 11:30
Non-coverage test runs are not globally serialized, so the mtime-only
sweep in cleanTmpArtifacts could delete a temp fixture/output directory
still in use by a concurrent run-all-vitest or validate-typescript
process. Each per-run temp folder now embeds the creating process's PID
right after its prefix, and the sweep removes a folder only when that
PID is no longer alive. A live owner is always seen as alive, so a live
run's folder can never be deleted; the worst case is leaving a genuinely
stale folder one run longer. Legacy folders with no PID segment fall
back to the existing minAgeMs mtime guard.
…ns link

In live runtime mode lockCaller pins caller identity only for the
synchronous portion of the callback — the live context manager restores
the ambient caller as soon as the callback returns, so an async callback
that awaits before calling self.* resumes under the ambient caller. Live
mode keeps no per-async-task context, so this cannot be preserved across
awaits; document the limitation in the JSDoc and HOOKS.md and point
async callbacks at async runtime mode (where the pinned identity
propagates through AsyncLocalStorage).

Also fix the HOOKS.md permission-gating link, which pointed at a stale
anchor instead of the new "Other slothlet.* Routes Are Gated Too"
section in PERMISSIONS.md.

This comment was marked as resolved.

Shinrai added 2 commits May 18, 2026 12:35
Add @Property entries for slothlet.lockCaller and slothlet.bind to the
SlothletAPI JSDoc typedef in src/slothlet.mjs so that tsc includes them
in the generated types/src/slothlet.d.mts. TypeScript consumers
previously got a missing-property error when accessing either method
despite both being documented and present at runtime since v3.6.0.
…ONS snippet

Add makeLockedAsyncIdentityProbe to the lock-caller fixture: it awaits
a microtask before calling self.*, exercising the most important
Fastify-style async-hook use case. Two new it.skipIf tests in the suite
verify the runtime split documented since the last fix:
- async runtime: lockCaller propagates caller identity past the await
  (AsyncLocalStorage carries it through).
- live runtime: lockCaller loses identity after the first await (the live
  context manager restores the ambient caller as soon as fn.apply()
  returns the Promise). Asserts .not.toBe("consumer") to document the
  known limitation without hard-coding which module ends up as caller.

Also fix the PERMISSIONS.md code snippet that showed two adjacent object
literals without a separator, making it invalid JavaScript if copy-pasted
into a rules array. Wrap in an array with a trailing comma.

This comment was marked as resolved.

Shinrai added 2 commits May 18, 2026 13:28
ownerPidOf parsed any leading digits after the prefix as a PID, so
legacy timestamp-only folder names (slothlet-test-types-<ts>,
api_test_collisions_multi_<ts>) were misclassified as PID-stamped.
That skipped the minAgeMs mtime guard and let an in-use legacy temp
directory be deleted out from under an active sibling process.

Require a `-` or `_` delimiter after the digits (`^(\d+)[-_]`) so only
the current `<prefix><pid><delimiter>...` shape is read as PID-owned;
bare-timestamp legacy names parse as null and fall back to the age
guard.
The live-mode regression test used `.not.toBe("consumer")`, which would
still pass if the post-await call resumed with no caller or an unexpected
one. Assert the exact value instead: in live mode the locked callback's
identity is fully unwound by the time the post-await self.* call runs, so
the probe reports "unknown" — assert that so a leak to "consumer" or a
shift to "producer" is caught.

Also add the always-present versioning.setVersionMetadata method to the
diagnostics endpoint-availability summary and its assertion list, which
previously omitted it.

This comment was marked as resolved.

Shinrai added 4 commits May 18, 2026 15:14
runInContext() re-typed any non-SlothletError thrown by fn as
CONTEXT_EXECUTION_FAILED. For a lockCaller-wrapped framework callback
(and the documented no-active-context passthrough), that changed the
caller-visible error semantics — the original type, code, and status
were lost.

Add a `rawErrors` parameter to runInContext() in both context managers
that lets a non-SlothletError propagate unchanged, and have lockCaller
pass it. Internal API calls keep the existing CONTEXT_EXECUTION_FAILED
wrapping.
…ooks

A hook handler fires during the API call it intercepts, so it ran under
whichever caller triggered that call rather than the module that
registered the hook — its self.* calls and permission checks were
misattributed, and a before-hook handler had no slothlet context at all.

hook.on() now pins the registering module's caller identity onto the
handler by default (the same mechanism as self.slothlet.lockCaller),
routing it through runInContext with rawErrors so handler errors still
reach the error-hook pipeline unchanged. Pass { lockCaller: false } to
opt out. Pinning is skipped when the hook is registered outside a module
or the handler is already locked, which also keeps re-registration after
a full reload idempotent.
The lockCaller live-mode caveat suggested bind as an alternative for
preserving slothlet caller identity across an await, but the bind
section states AsyncResource.bind does not meaningfully capture slothlet
caller/context in live mode — so a live-mode reader could pick bind
expecting a fix it does not provide. Both notes now make clear async
runtime mode is the only fix.

Also add a "Hooks auto-pin caller identity" section and the
options.lockCaller parameter to the hook.on() reference.
- hook auto-pin: a module-registered hook resolves to the registering
  module's identity; { lockCaller: false } opts out; an already-locked
  handler is respected, not double-wrapped.
- bind: a callback bound inside a module keeps the module's slothlet
  caller identity when invoked later from another module (async runtime).
- lockCaller errors: a thrown error propagates unchanged with no active
  context and when nested inside another locked callback, exercising both
  rawErrors branches of runInContext.

Drop the unused makeBound() fixture in favor of makeBoundIdentityProbe().

This comment was marked as resolved.

…re-pin

Align lockCaller/hook live-mode docs with tested behavior: after the
synchronous runInContext() stack unwinds, an awaited callback resumes
with no slothlet caller at all (identity probe sees `unknown`), not an
ambient triggering caller. Updated HOOKS.md, api_builder.mjs JSDoc,
slothlet.mjs typedef, and the v3.6.0 changelog (snippet now shows the
rawErrors argument; adds a Compatibility section calling the auto-pin
default a behavior change).

Add a regression test asserting an auto-pinned hook keeps the
registering module's caller identity across a full reload(), with the
matching probe helper.

This comment was marked as resolved.

… context

When lockCaller() is called outside any module context there is no
wrapper to capture, yet the returned wrapper still routed through
runInContext() — creating/switching to this instance's context instead
of leaving fn's own ambient context untouched. Return fn directly in
that case, matching HookManager#pinHandler and the documented no-op
passthrough behavior.

Strengthen the hook lockCaller:false opt-out test to assert the probed
identity is non-null, so it fails (rather than passes vacuously) if the
hook never fires. Drop the misleading 'below' from a HOOKS.md
cross-reference that points to an earlier section.

This comment was marked as resolved.

The v3.6.0 changelog called the hook auto-pin a behavior change that
required existing handlers to opt out, contradicting the PR summary's
no-breaking-changes claim. Reframe it as a correctness fix for a
previously misattributed caller identity, with { lockCaller: false }
documented as an escape hatch rather than a required migration.
@Shinrai
Shinrai merged commit 4968255 into master May 19, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release Marks a pull request as a pending release — merge to publish a new version semver: minor This release adds new functionality in a backwards-compatible way

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants