Files

200 lines
14 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Plugin generations, stable C ABI and reload protocol plan
Status: PLANNED feature work; no new ABI is delivered. Baseline:
`f1f9ba375b22abf1adcc7c550ec21ac20895c0a4`, inspected 2026-11-24.
Requirements R-004, R-009, R-010 and R-013–R-016 apply. Preserve
[architecture](../ARCHITECTURE.md) C-03–C-05, C-09, C-10 and C-13.
## Existing source baseline and compatibility classes
[Plugin.hpp](../../../include/Void/Plugin/Plugin.hpp) defines `Void::Plugin::IPlugin`,
`PluginInfo`, `ABI_VERSION == 1`, C-linkage create/destroy/info symbols and optional
configuration/readiness/state-transfer exports. The serialized-state protocol carries
a state schema version and plugin-owned string release. Existing factory output is
still an IPlugin C++ object; its vtable, RTTI and callbacks require compatible toolchains.
The source's v2 state protocol is not a new general stable C ABI version.
[Loader.hpp](../../../include/Void/Plugin/Loader.hpp) owns one instance and is not
thread-safe. [Manager.hpp](../../../include/Void/Plugin/Manager.hpp) exposes pinned
`PluginHandle`, acquire/load/unload/reload/replace, validators, watching, observers and
state snapshots. [Manager.cpp](../../../src/Plugin/Manager.cpp) stages a fresh inode,
configures/restores/activates/checks readiness before atomic current-instance publication.
Acquisition also takes the registry mutex; do not infer a completely lock-free path
from the header's atomic-load description. Reload observers run after unlocking, but
candidate validation and plugin activation currently occur inside reload's map lock.
`dlclose_on_swap` defaults false to keep code mapped when arbitrary frames/callbacks
may survive; a new protocol must prove async quiescence before changing that default.
[Module.hpp](../../../include/Void/Plugin/Module.hpp) already supplies C++
`ModuleDescriptor`, `ModuleDependency`, `ActivationPolicy`, `ModuleHost`, `IModule`,
`ModuleReadiness`, activate/quiesce/checkpoint/restore/readiness/deactivate. The descriptor
contains STL, Json, Semver and unique_ptr factory types: it is explicitly a C++ descriptor.
Its default methods are not proof that a coordinated reload host exists.
[module.cmake](../../../src/Plugin/module.cmake) declares Functional/System/Data and
Unix dl; target declaration versus public descriptor includes needs isolated-consumer
validation under the shared dependency plan.
[Manager tests](../../../tests/standalone/Plugin/Manager.cpp),
[load-under-reload test](../../../tests/standalone/Plugin/HotReloadUnderLoad.cpp),
[configuration tests](../../../tests/standalone/Plugin/Configure.cpp), and
[module descriptor test](../../../tests/standalone/Plugin/Module.cpp) are existing
fixtures, not evidence of a stable C-only boundary or async pin protocol. Scoped graph
coverage was checked; Manager declarations/test helper ranges were directly read.
The initial loader remains native platform dynamic loading (`dlopen` on Linux), with
Void-owned descriptors and lifecycle; no external plugin framework is introduced.
Portability adapters must satisfy the same pin/release conformance before enabling unload.
## NEW stable C boundary
NEW proposed path: `include/Void/Plugin/CAbi.h`; use a separately named export
`void_module_query_v1`. Do not change the layout or reinterpret the meaning of
`void_plugin_info`, existing ModuleDescriptor or the frozen [ShortUrl V1](../../short-url.md).
The following is an illustrative C header shape, not an available ABI:
```c
typedef struct void_module_handle void_module_handle;
typedef struct void_operation_handle void_operation_handle;
typedef struct { const uint8_t *data; uint64_t size; } void_bytes_v1;
typedef struct {
uint32_t struct_size;
uint32_t abi_major;
uint32_t abi_minor;
uint32_t reserved;
uint64_t capabilities;
int32_t (*create)(const void *host_api, void_module_handle **out);
int32_t (*activate)(void_module_handle *, void_bytes_v1 config);
int32_t (*readiness)(void_module_handle *, uint32_t *out_ready);
int32_t (*request_stop)(void_module_handle *);
int32_t (*destroy)(void_module_handle *);
} void_module_api_v1;
/* int32_t void_module_query_v1(uint32_t host_size, void_module_api_v1 *out); */
```
Complete this table with versioned quiesce/resume, checkpoint/restore, interface
query/release and async-operation functions in M-PLUGIN-03 before freezing ABI V1.
Tail capabilities use size-checked extension tables; reject unknown major, truncated
required prefix and required capability mismatch. Copy descriptor metadata into host
ownership while the generation is pinned. Reserved fields are zero; lengths are checked
before conversion to size_t. Interface identifiers are fixed 128-bit byte values with
independent interface major/minor and a function-table size; they are not typeid hashes.
All boundary functions use fixed-width status codes and explicit error detail access
with owner-specific release. No exceptions, STL, reflection objects, standard-library
stop tokens or C++ allocation cross the C boundary. C++ adapters catch exceptions and
map operational failure; unknown exceptions become `internal_error` without unwinding
through C. The host passes a versioned host function table instead of an untyped payload
in the final header; the void pointer above stands for that separately sized table.
Input byte spans borrow only for the call. Checkpoint output is an opaque plugin-owned
buffer with `data/size/release`; the host copies within its cap before releasing through
the plugin. No allocator mismatch. Async submission copies required descriptors and
returns an opaque operation handle plus exactly one terminal callback. Host cancellation
maps its Async OperationOptions into explicit C request-stop/deadline fields relative
to the negotiated host monotonic clock; it never copies std::stop_token into C memory.
Release of an operation handle requires terminal acknowledgement and callback return.
The final ABI conformance specification defines callback thread/reentrancy and null-output
rules for every status; output handles are null on failed admission.
## Generation pins and unload invariants
Each loaded generation owns its mapping, instance, host registrations, service records,
subscriptions and an Async scope. Two independent counts matter: external generation
references (handles/function-table leases) and admitted async activities. Every callback,
coroutine frame, deferred destructor and operation allocated by a plugin retains an
activity pin until it and its terminal callback have returned. Capturing a raw plugin
function pointer in a host queue without a pin is forbidden by the adapter contract.
Retirement stops new generation admission, asks its scope/subscriptions to stop, joins
operations, releases provider references, calls deactivate/destroy once, then unmaps
only after no code/data reference remains. Host-side reclamation executes after a
plugin callback returns; never dlclose from the final callback's stack. Plugin-supplied
threads must register activity pins and join during quiescence. Native code is trusted
in-process code; it cannot be forcefully sandboxed by this ABI. Uncooperative code stays
mapped and is reported as pinned; optional process isolation belongs to [IPC](../subsystems/IPC.md).
Default: 64 modules, 256 interfaces/module, four retained generations/module, 64 MiB
retained mapped-image budget/module based on file accounting, 4 MiB checkpoint,
1 MiB configuration, 1,024 async activities/generation and 256 pending callbacks.
Mapped-image accounting is not an exact RSS measurement. Refuse further reload when
retention budget cannot accommodate old + candidate; never unmap to recover the budget.
Defaults for prepare/quiesce/readiness are 5/5/10 seconds within a 30-second total
reload deadline. Every phase shares Async's absolute total deadline and injected Time
clock; phase budgets can shorten it, never restart it.
## Reload state machine and rollback
Per-module transitions are serialized by a reload coordinator, outside the manager map
lock. The short lock reserves a generation/expected epoch; expensive filesystem work,
all validators, plugin code and release/destructor callbacks run after unlocking.
Publication rechecks the epoch. Dependency reload batches topologically order modules;
cycles or unsupported mixed activation policies fail before activating anything.
1. Verify immutable candidate identity/path, ABI and declared dependencies. Create and
configure a private candidate using a scoped unpublished Service registry. Activation
may prepare resources, but externally visible writes/registration are prohibited
until publication. A module unable to stage safely is RestartRequired.
2. For a stateless compatible replacement, candidate readiness can overlap old calls.
For stateful writers, close old mutation admission and call quiesce: complete all
admitted mutations and owned async writes, then checkpoint at Fsm/application state
boundaries. Old acquired handles remain valid but new mutation attempts receive
`quiescing`; they never run on freed objects. Reads can continue only if declared safe.
3. Restore the bounded versioned checkpoint into the candidate, activate deferred parts,
and await readiness without registry locks. The adapter requires an explicit resume
operation for the old generation; existing IModule's no-op quiesce alone is insufficient.
State migration is pure candidate construction; no destructive migration of the old
persistent state is permitted during a reversible reload.
4. Publish one Service-owned registry snapshot containing candidate interfaces and
generation metadata. Host `acquire` and service lookup use that same publication epoch,
avoiding inconsistent manager-current versus service-current swaps. Standalone legacy
PluginManager keeps its existing local publication until explicitly adapted.
5. Retire the old generation and drain pins. Before publication, any failure disposes
candidate registrations/activities and resumes old mutation admission after validating
its state. Resume failure yields degraded/not-ready status and requests a controlled
restart; it never falsely reports the old service healthy. Failed-candidate cleanup
errors retain its mapping and are reported separately from the original rejection.
Publication is a reversible in-memory switch only while old state remains a valid
continuation. After new writes, reverting requires a compatible reverse migration or
recovery from authoritative persistent state; do not silently discard them. Durable
release activation follows Update's healthy marker, as detailed in
[ReloadableApplications](../platforms/ReloadableApplications.md).
## Ordered implementation backlog
All feature rows are PLANNED.
| ID | Phase / depends on | Intended scope | Acceptance / recommended role |
| --- | --- | --- | --- |
| M-PLUGIN-01 | P0 / baseline | Inventory existing exports, descriptor includes, load/reload locks and compatibility fixtures | Existing C++ ABI/state protocol and frozen ShortUrl V1 documented independently / sol_implementer |
| M-PLUGIN-02 | P1 / M-PLUGIN-01; M-ASYNC-03 | Explicit generation/activity leases and host-owned retirement queue | Callback/operation/frame held through replacement prevents unmap; late completion releases once / astra_implementer |
| M-PLUGIN-03 | P2 / M-PLUGIN-02; Functional errors | Full CAbi.h specification, size/version negotiation, byte ownership, host clock/cancellation bridge and C++ adapter | C-only producer/consumer fixture, truncation/unknown-major rejection, throwing C++ shim contained / astra_implementer |
| M-PLUGIN-04 | P2 / M-PLUGIN-03; M-SERVICE-03 | Unlocked staged validation, dependency activation and coherent registry publication | Reentrant validator does not deadlock; failed candidate changes no active lookup / astra_implementer |
| M-PLUGIN-05 | P3 / M-PLUGIN-04; M-FSM-04 | Quiesce/checkpoint/restore/readiness/resume protocol with phase/total budgets | Outstanding writer drained; every prepublication phase failure resumes old state or reports degraded / astra_implementer |
| M-PLUGIN-06 | P3 / M-PLUGIN-05; Update activation gate | Retention accounting, safe unload capability, reloadable-host integration and migration kit | Stuck pins refuse new reload; post-commit cleanup never triggers invalid rollback / astra_implementer |
## Validation and migration
CURRENT aggregate command is
`ctest --test-dir /tmp/voidlibrary-discovery-f1f9ba3 --output-on-failure --timeout 60`;
not rerun here. PROPOSED tests need the NEW ABI and host adapters: C compiler headers,
different supported compiler producer/consumer matrix, layout/size checks, hostile length
fields, missing release, cancelled async callback after generation retirement, queued
std::function/frame pins, failed quiesce/restore/readiness/resume, reentrant observers,
rapid replacement epoch conflict, and immutable-path replacement under sustained calls.
Compile compatibility claims only for observed matrix entries. Native malicious code
is outside the in-process fault model; do not fuzz arbitrary plugins in the host process.
Measure acquire/reload/quiescence p50/p95/p99, call throughput, allocations, retained
generation count, image bytes, peak RSS/CPU and adapter build cost under
[PERFORMANCE](../PERFORMANCE.md). No measured reload downtime is claimed.
Keep current IPlugin/ModuleDescriptor APIs as same-toolchain adapters. A stable C module
opts into the new query symbol and tables; existing symbols do not silently change.
Existing `PluginHandle::raw_symbol` remains valid only while its handle lives; replace
manager-wide borrowed-symbol usage with a pinned lease. Default dlclose stays disabled
until activity-pin conformance passes. Rollback can select the legacy manager for
legacy plugins before loading; it cannot replay external effects or free stuck code.
See [MIGRATION](../MIGRATION.md), [VALIDATION](../VALIDATION.md),
[DEPENDENCIES](../DEPENDENCIES.md), and [BUILD-AND-DISTRIBUTION](../BUILD-AND-DISTRIBUTION.md).