Support CustomSlotSuppliers in WorkerTuner - #156
Draft
bauer-andreas wants to merge 5 commits into
Draft
Conversation
bauer-andreas
force-pushed
the
andreas-bauer/custom-slot-supplier
branch
2 times, most recently
from
July 10, 2026 22:13
da02f86 to
0123b58
Compare
Introduce the public API surface for user-defined slot suppliers: CustomSlotSupplier protocol, SlotType/SlotInfo (@nonexhaustive), SlotReserveContext, SlotMarkUsedContext<Permit>, SlotReleaseContext<Permit>. Not yet wired into SlotSupplier or the worker; the following commits integrate the protocol and land the FFI bridge.
bauer-andreas
force-pushed
the
andreas-bauer/custom-slot-supplier
branch
from
July 14, 2026 21:54
0123b58 to
06e39ca
Compare
Extend the package Kind enum with `case custom(any CustomSlotSupplier)` and add the public `custom<S>(_:)` factory so users can plug a CustomSlotSupplier into a WorkerTuner. The FFI bridge lands in the following commit; this intermediate commit does not build on its own.
BridgeCustomSlotSupplier owns a heap-allocated TemporalCoreCustomSlotSupplierCallbacks retained through user_data, and translates FFI callbacks to the user's protocol methods. Reservations are handled inside a structured task tree that races the user's reserveSlot against a cancel-watcher continuation the core resumes via its cancel_reserve callback. Permits are boxed into a PermitBox and their Unmanaged.passRetained pointer bits are used as the FFI permit ID, so the same permit value comes back in mark_used/release without a separate mapping table. BridgeWorker constructs a wrapper per custom-tuned slot supplier and retains them for its lifetime; if temporal_core_worker_new fails the wrappers are torn down explicitly via tearDownWithoutCore() so the Rust core never sees the callback pointers. The consumer task that drives each wrapper's reserve loop, and the shutdown wiring that finishes its stream, are added in the following commit.
BridgeWorkerProtocol gains `runSlotSupplierLoops()` (with a default no-op) and BridgeWorker's implementation spawns a discarding task group over its retained custom slot suppliers. BridgeWorker's initiateShutdown now calls markShutdown on each supplier so consumers exit once Rust drains their in-flight reservations. The worker's task group returns a WorkerRunTaskKind so a clean-return poller trips the existing fatalError while a clean-return slot supplier loop is expected on shutdown and drives the shutdown rerun. ReplayBridgeWorker gets an explicit no-op override — custom slot suppliers are not supported during replay — and the test forwarder protocol forwards the new requirement.
RecordingCustomSlotSupplier records every callback into a Mutex-guarded event log; the test runs a workflow end-to-end through a .custom-tuned worker and asserts reserve, markSlotUsed and releaseSlot all fire with matching permit identities.
bauer-andreas
force-pushed
the
andreas-bauer/custom-slot-supplier
branch
from
July 14, 2026 22:02
06e39ca to
71de3ea
Compare
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.
Motivation
[Explain here the context, and why you're making that change. What is the problem you're trying to solve.]
Modifications
[Describe the modifications you've made.]
Result
[After your change, what will change.]
Test Plan
[Describe the steps you took, or will take, to qualify the change - such as adjusting tests and manual testing.]