Extension SPIs and how one is installed
What Karyo lets an implementer replace, how an implementation is discovered, and what "install an extension" actually means for a Quarkus fast-jar image.
1. Installation is a rebuild, and only a rebuild
There is no runtime plugin mechanism. Karyo ships as one Quarkus fast-jar layout copied into an image (Building), and CDI bean discovery happens at build-time augmentation, so a JAR placed beside a running process is invisible (ADR 0019).
The repository's own worked example says so at every layer. services/karyo-app/build.gradle.kts, providers.gradleProperty("karyoInventoryExample")
comments the example module's inclusion as "Deliberate build-time augmentation, never a runtime JAR
upload", and gates it behind a Gradle property (providers.gradleProperty("karyoInventoryExample")):
if (providers.gradleProperty("karyoInventoryExample").map(String::toBooleanStrict).getOrElse(false)) {
implementation(project(":services:inventory-service:karyo-inventory-ext-example"))
}
So ./gradlew :services:karyo-app:quarkusBuild -PkaryoInventoryExample=true builds an image with the
example's beans in it, and the same command without the property builds one without them. The
implementer guide walks the executable
route, including the negative control that proves the unaugmented build does not have the extension.
The KDocs of the three seams an implementer is most likely to extend say the same: LocationFilter,
StockSelectionFilter and JournalEnricher are discovered at build time, an extension is compiled
into the build, and a JAR placed beside a running application is not seen (ADR 0019).
2. The example, and the two priorities
services/inventory-service/karyo-inventory-ext-example/ is the canonical shape. Its build file
compiles against the API module and the CDI API with compileOnly and nothing else
(services/inventory-service/karyo-inventory-ext-example/build.gradle.kts, dependencies.compileOnly), so an extension
cannot accidentally reach into a -core. It carries
services/inventory-service/karyo-inventory-ext-example/src/main/resources/META-INF/beans.xml with
bean-discovery-mode="annotated".
HeldLotStockFilter is the live example. It is annotated @Alternative @Priority(1000) @ApplicationScoped and also overrides priority() = 500. Those two numbers do unrelated jobs, and
the codebase is careful about it: @Priority on an @Alternative is CDI's activation switch,
while priority() is the SPI's own chain ordering.
HazmatStockFilter is the counter-example, kept deliberately: @Alternative with no
@Priority, so it is never activated even in the augmented build, and its own KDoc says so.
3. Selection is per-seam, and spelled four ways
There is no single "how do I win" rule. Reading the declarations:
| Seam | Declaration | Rule |
|---|---|---|
StockSelectionFilter |
fun priority(): Int = 1000 |
Every implementation runs, ascending; the chain's output order is honoured |
LocationFilter |
fun priority(): Int = DEFAULT_PRIORITY (1000) |
Same, and the finder explicitly does not re-sort afterwards |
PackoutStrategy |
val priority: Int + val name: String |
Named match first, then ascending priority until one returns non-null; built-in sits at a high value |
ReplenishmentStrategy |
val priority: Int + val name: String |
Same shape |
CarrierAdapter |
val priority: Int + fun handles(carrierName) |
Claim by carrier, then ascending priority |
WorkDispatchStrategy, SequenceNumberGenerator, CountScopeStrategy |
selected by name from configuration | An unknown name is a hard failure, never a silent fallback |
WebhookSigner, DeliveryRetryPolicy |
no priority member at all | Direct CDI injection; a replacement must win through CDI selection |
LocationFilter's KDoc carries the strongest warning in the set: the finder honours the order the
filters return, and a maintainer must not add a post-filter sort, because a re-sort would silently
discard an extension's reordering (LocationFilter). It is the only place such a warning is
written down beside the seam it protects.
The priority contract is therefore spelled four different ways across the seams, and nothing states a rule for which one a new seam should use. The per-seam resolution rules are tabulated in Strategies and policies.
4. Ninety-two interfaces in the registry, and each names its kind
Counting top-level interface declarations under any spi package, sub-packages such as
spi.equipment included, outside test sources gives 95. Three are not extension points:
ReservationSourceState, the opaque value ReservationRefMover returns to its own caller,
LocationDistanceSnapshot, the read-only floor LocationDistanceLookup returns to its own caller, and
ConcurrentStateChange, a marker an exception carries. That leaves 92 declared interfaces across the
-api modules plus libs/karyo-sequence.
GET /api/v1/admin/extensions (AdminExtensionsResource.listExtensions, AdminExtensionsResource.resolve, declaring extensions.read,
which only the standard administrator profile holds) is the live
registry: it resolves a list of fully-qualified interface names via Class.forName and asks the CDI
BeanManager which beans satisfy each. Its design is honest about its own limits - an interface that
fails to resolve is dropped rather than fabricated, and one that resolves with zero beans is still
reported, "because a declared seam with no active implementation is itself useful information"
(AdminExtensionsResource).
The list (AdminExtensionsResource.resolve) holds all 92, and its comment states the rule that
makes it checkable: one row per top-level interface in a *.spi package, with the three exclusions
above, and "any other absence is a defect in this list" (AdminExtensionsResource.resolve).
AdminExtensionsResourceSeamListTest enforces the rule: it compares the list with every interface
declared in an spi package, so a new interface fails the build until it has a row. Every -api module and every
engine module is in every build, so the engine seams - cross-docking, waves, streaming, monitors,
forecasting and simulation - are listed with the engines' own implementations; a declared
interface that nothing implements is still listed, with an empty implementations (AdminExtensionsResource.resolve).
Each row names its kind
Every row carries a kind (ExtensionKind), so an implementer is no longer handed one list in which
the safe answers and the ones that break on the next release look identical:
| Kind | Count | Meaning | For implementation |
|---|---|---|---|
STRATEGY_SEAM |
35 | A contract an extension is meant to implement to add or replace a behaviour choice, not merely one whose beans are collected. Examples: StockSelectionFilter, LocationFilter, PackoutStrategy, Detector, JudgmentEngine. |
Yes |
LOOKUP |
36 | A read-only in-process contract between modules. Karyo's own modules implement it. Examples: RuntimePropertyLookup, ProductLookup, StockUnitLookup. |
No |
PORT |
21 | An in-process command or orchestration contract between modules, implemented by Karyo's own modules, with no chain. Examples: StockReceiver, StockReserver, UnitLoadMover, ReservationRefMover, LocationFinder. |
No |
The strategy register excludes lookups and ports from the seam concept for this reason: Karyo's own
modules implement them and they have no chain. Several of them say so about themselves, RuntimePropertyLookup
most bluntly: "This is a cross-module read contract, not a strategy seam: there is no plausible
second implementation, and none should be added."
The kind of a row is set by hand in the list (AdminExtensionsResource.resolve), from the interface's own KDoc
and from how its consumer finds it. The field has no default, so a row cannot be listed without one.
AdminExtensionsResourceSeamListTest also fails when a *Lookup is not a LOOKUP, a *Port is not a
PORT, or a *Strategy or *Resolver is not a STRATEGY_SEAM. The package name is still spi for all
three kinds: the kind is a field of the registry, not an annotation or a marker interface on the
declaration.
A STRATEGY_SEAM row is a statement about the interface, not a promise about every consumer.
JournalEnricher is declared as an extension seam in its KDoc and listed as one, but no code in this
repository calls it today, so an implementation would be discovered and never invoked.
5. One list, in the registry
The console keeps no list of the seams. AdminStrategiesPage renders the registry's answer and
nothing else, and AdminShell reads the same answer for the Extensions badge and the sidebar footer
(admin-strategies-page.tsx, AdminStrategiesPage, LiveExtensionsView; admin-shell.tsx, AdminShell).
- The page groups the rows by module, shows each row's kind, says on every lookup and port that it is not for implementation, and counts strategy seams apart from lookups and ports.
- The badge and the footer show the live count of registry rows. If the caller lacks
extensions.read, or the registry request fails or returns nothing, the badge and the footer are absent. The page shows the standard error state with a "Reload the registry" action, or the empty state when the registry answered with no rows.
There was once a static catalogue of nine seams in the console, kept as a fallback and as the source of the badge. It was deleted, because a second hand-kept list disagreed with the registry (ADR 0019).
The always-rendered page subtitle tells every visitor to add an implementation to the application
build and rebuild the image (admin-strategies-page.tsx, AdminStrategiesPage). That does not promise a JAR that a
running application picks up, which ยง1 and services/karyo-app/build.gradle.kts, providers.gradleProperty("karyoInventoryExample") rule out.
6. What an implementer is actually promised
An extension is recompiled and tested against each release it runs on. SPI versioning is
independent of the REST surface's /api/v1 URL versioning - they move separately and nothing ties
them - and no SPI carries a version marker of its own. Additive members with defaults are the way a
seam grows without breaking existing implementations, but nothing guarantees that an extension
survives a release unchanged.
There is no published Maven coordinate to build against: no module applies a publishing plugin, and an extension builds inside this repository's module graph, as the example does.
Related
- Strategies and runtime configuration - the knobs a seam reads
- Strategies and policies - each seam's actual resolution contract
- Implementer guide: extend the application - the executable installation route
- ADR 0019 - why extensions compile into the build