Skip to content

Support CustomSlotSuppliers in WorkerTuner - #156

Draft
bauer-andreas wants to merge 5 commits into
mainfrom
andreas-bauer/custom-slot-supplier
Draft

Support CustomSlotSuppliers in WorkerTuner#156
bauer-andreas wants to merge 5 commits into
mainfrom
andreas-bauer/custom-slot-supplier

Conversation

@bauer-andreas

Copy link
Copy Markdown
Contributor

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.]

@bauer-andreas
bauer-andreas force-pushed the andreas-bauer/custom-slot-supplier branch 2 times, most recently from da02f86 to 0123b58 Compare July 10, 2026 22:13
@bauer-andreas bauer-andreas added the 🆕 semver/minor Adds new public API. label Jul 14, 2026
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
bauer-andreas force-pushed the andreas-bauer/custom-slot-supplier branch from 0123b58 to 06e39ca Compare July 14, 2026 21:54
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
bauer-andreas force-pushed the andreas-bauer/custom-slot-supplier branch from 06e39ca to 71de3ea Compare July 14, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🆕 semver/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant