Repository navigation
release: v3.6.0 - #90
Merged
Merged
Conversation
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".
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.
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.
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.
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().
…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.
… 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.
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
approved these changes
May 19, 2026
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
🐛 Bug Fixes
🔧 Other Changes
👥 Contributors
Avg: 100.0% ·
0c30d5d· Node lts/*