Skip to content
ERPForAll DocsDevelopment

    Native human lifecycle engine

    Native composition can call ModuleSystem::upgrade_authorized with the same trusted InstallAuthorizer adapter used by installation. The historical adapter name remains for compatibility. It checks the primary session, active user and current system authority in the supplied transaction after the module lifecycle lock; adapters must not commit or open a separate transaction. The engine binds that human as the actor while running elevated module work.

    The request contains between one and 64 unique module names. Every target must be installed. Every upgraded target and installed reverse dependent must have a known matching installed artifact receipt. Linked native code also needs matching build provenance. Known data-only addons can participate in upgrades; newly installed dependencies still use the existing human-install data-only allowlist. Unattested, replaced or missing content refuses before effects. Unrelated pending CLI operations are refused and preserved.

    Both authorized install and upgrade write erp_module_lifecycle_audit inside the lifecycle transaction: actor, session, operation, requested names, sorted resolved names, separate installed and upgraded sets, and committed outcome. Installation also preserves its existing install audit. A failed operation or audit insert rolls back together. Runtime credentials have no access to the new table or its sequence. Post-commit failures remain explicit in OperationOutcome; they do not mean that committed state or audit rolled back. Callers must use the returned ORM generation.

    The sealed POST /erp/module/upgrade adapter accepts exactly {modules:["addon_name"]}. It requires the active primary administrator session and the accepted same-origin JSON protocol, then uses the same authorizer under engine ownership. API keys cannot authorize the route. Success contains separate upgraded and newly installed name sets, registry_version and asset_version, after runtime grants and complete Auth/RPC/assets publication.

    Native POST /erp/module/uninstall validates the primary administrator session and delegates to ModuleSystem::uninstall_authorized with its trusted session authorizer. It preserves the engine’s refusal, unknown commit outcome and committed recovery distinctions. The shipped composition has configured Signal, a package runtime and a host asset lifecycle service. Under ADR 0186, configured Signal stores backed by verified native storage are safely opened before lazy BEGIN and generation reads; complete package/host effects and the preview bridge are planned.

    ModuleSystem::uninstall_composition_blocker() reports the first static blocker in order: package runtime, custom data loader, registered lifecycle services. Configured Signal is safely admitted when backed by verified native storage (ADR 0186). The typed UninstallCompositionBlocker::message() returns a fixed diagnostic. This inspection performs no SQL or callbacks and grants no authority. None means that further transaction-bound admission is required, including schema, installed artifact identity, current authority and confirmed membership; it never establishes that uninstall will succeed.

    CompositionConfirmed-impact engine admission
    Minimal callback-free, unconfigured systemContinues transaction-bound schema, identity, authority and fingerprint checks; existing supported subset can succeed
    Configured SignalSafely admitted when backed by verified native storage (ADR 0186); non-native storage types or aggregate overloads refuse during idle source preflight
    Package runtime, including an empty runtimeRefuses undescribed package callbacks; CONFIRMED-EFFECTS prerequisite
    Custom data loaderRefuses undescribed purge callbacks; CONFIRMED-EFFECTS prerequisite
    Registered host lifecycle serviceRefuses before effects rather than skipping the service; CONFIRMED-EFFECTS prerequisite
    Full base addon schema/model compositionIndependent unsupported schema, model and callback effects still refuse; absence of a static blocker does not admit them

    Authorized addon detail and ir.module.module.erp_preview_uninstall report that composition reason. Preview returns no successful fingerprint. If a custom composition has no static blocker, the native JSON-2 preview binder still refuses because it lacks a trusted-session confirmed-impact bridge. It does not start an owner lifecycle operation inside the existing request transaction. The existing callback-free minimal engine seam remains separately callable through its trusted native API.

    ir.module.module.erp_addon_detail is an authorized Read RPC taking name, optional limit (default 50, maximum 100), and optional dependencies_cursor, dependents_cursor, menus_cursor and views_cursor. Its collections carry items and explicit nullable next_cursor. Installed metadata ownership comes from durable module provenance, and descriptions remain plain text. Cursors bind the addon, collection and metadata revision; changed or malformed cursors refuse. The complete response is limited to 65,536 bytes. These are admission bounds, not measured performance. The metadata snapshot additionally refuses more than 10,000 entries or more than 1 MiB before paging; per-field text bounds also apply. The Rust wire declarations and generated TypeScript own the contract.

    ADR 0120 preserves commit certainty through managed lifecycle execution. A typed unknown commit answer requires reconciliation and bypasses cleanup that assumes rollback. After known commit, failed post-commit work or publication returns a committed recovery error with a stage. Neither error is permission to replay the write. There is no addon-overridable lifecycle mutation RPC.

    Legacy bootstrap with no active administrator may predate private lifecycle audit storage. Grant publication permits complete absence until an authorized lifecycle operation creates it, revokes both private objects when present, and refuses an incomplete table/sequence pair with operator recovery. It does not silently grant audit access or perform a schema migration under the users-table lock.

    Lifecycle operations bind each installed addon to a durable content receipt, separate from the available catalog and the whole build identity. An unknown legacy receipt refuses upgrade/uninstall with identity unknown, run identity-enroll first; replacing files without changing the manifest version also refuses. A snapshot admitted within the operation supplies the consumed bytes; symlinks and hard-link aliases are refused. Device/inode checks apply only within that operation, so a copied release with identical content retains its identity.

    The confirming uninstall (ModuleSystem::uninstall_authorized) runs its operation transaction at READ COMMITTED, while preview stays at REPEATABLE READ. Confirmation takes ACCESS EXCLUSIVE membership locks after its opening statements, and a REPEATABLE READ snapshot taken before that wait would not see a writer that committed during it. A fixed snapshot would then pass the fingerprint check and drop the writer’s row. With every writer fenced out by the lock, per-statement snapshots are current and consistent. An InstallAuthorizer used for confirmation therefore runs raw statements only; record-API calls fail loudly with a Programming error. The authorizer’s session check also reads current state after the lock wait.

    An operator reviews the existing database’s artifact provenance before using erp module identity-enroll --config <protected-server.toml> --operator <identity> --note <reason> <addon>.... Enrollment is explicit and audited, including operator, database timestamp, note and per-addon hashes. No installed addon receives an automatic legacy exemption. Protect the owner credentials and enrollment command as database administration authority.

    A successful forward release activation can transition changed per-addon receipts atomically after migration, pointer switch and health verification. Unchanged receipts remain unchanged. Ordinary native runtime upgrade never re-stamps. A successful authorized forward package upgrade is a separate transition point: under the existing package lifecycle lock and fresh authorization, validate the old receipt against the current verified installed package and stored archive digest before applying the candidate. Commit its new verified archive digest with package storage, lifecycle effects and audit in the same transaction. Failed upgrades retain the prior receipt. Neither automatic restore nor manual rollback re-stamps. A receipt mismatch following recovery requires an explicit operator decision; do not treat enrollment as a substitute for reviewing database compatibility.

    File-content identity authorizes lifecycle operations on addon artifacts; it is not a database schema-version check (that admission check is planned).

    These changes do not widen the impact planner’s supported effect subset. The full base composition and unsupported effects retain their named refusals; no successful configured native uninstall is implied.

    Identity storage is owner-only: installed_addon_identity, installed_addon_identity_audit and the latter’s sequence are excluded from request-role grants. Schema-sync creates empty storage on an older database; it does not approve whichever files happen to be present. A first install creates its receipt atomically with installation, and uninstall removes it atomically with lifecycle effects.

    The release helper uses the candidate binary’s identity-activate administration command after a matching successful migration receipt, active-pointer verification and health check. Candidate migration uses the verified previous release to validate the installed preimage; it does not stamp new content early. An identity-publication error can mean that the transaction outcome is uncertain: keep the reported candidate state, inspect the owner-side outcome and reconcile before retrying. Do not infer rollback from an error returned after commit.

    An explicit native candidate upgrade with identity_previous commits per-addon migration evidence in installed_addon_identity_audit with operation forward-migrate, binding each changed upgraded addon’s previous installed hash and exact candidate hash. The installed receipt remains unchanged until activation. Activation requires that committed evidence for every changed installed addon; upgrading only selected modules does not authorize a changed sibling omitted from that upgrade.

    Durable receipts and lifecycle locking coordinate cooperating instances. Node admission/rollout integration remains subject to the actual serving path; a lifecycle lock does not fence older nodes that do not participate. Do not treat successful single-instance enrollment as proof of a safe mixed-version rollout. Product performance evidence is deferred under ADR 0065; the snapshot limits are safety admission bounds.

    Operator composition resolves configured search-directory prefixes once, including the release current pointer and a host temporary-directory alias. It preserves the final configured directory and every discovered addon root for no-follow admission; linked addon roots and descendants still refuse. Identity administration verifies stored packages into a fresh process without loading/replaying pending lifecycle work, then rechecks their stored archive identity under lifecycle ownership.

    Artifact identity follows release packaging: dependency/build caches and repository/desktop metadata named node_modules, target, .git, __pycache__ or .DS_Store are excluded. Do not reference these paths from lifecycle data; the engine refuses them. Ship generated runtime assets outside those reserved paths. Symlinks at excluded entries themselves still refuse, and excluded contents are never used as a fallback data source.

    Web client lifecycle interactions (SPEC-HUMAN-036)

    Section titled “Web client lifecycle interactions (SPEC-HUMAN-036)”

    The web client’s addon administration panel (addonsView) implements lifecycle interactions over the authorized transport:

    1. Authorized Detail View: Clicking any addon tile outside of direct action buttons navigates to an in-place authorized detail view. It queries ir.module.module.erp_addon_detail and displays complete manifest metadata, technical name, lifecycle state badge, icon, summary, rich description, and key facts (Author, Version, Installed version). Dependencies, reverse dependents, created menus, and created views are presented in separate sections with cursor pagination (“Load more”), querying the server with collection-specific cursors without reloading the view. The Back button and Escape restore the catalog grid and refocus the triggering card.

    2. Upgrade Confirmation Flow: Triggering the Upgrade button (from either the catalog tile or the detail header) displays a native confirmation dialog asking for explicit confirmation. On confirmation, it issues POST /erp/module/upgrade with { modules: [name] } and write: true. On successful upgrade publication, it alerts the user and reloads the application. When upgrade is refused by server metadata (e.g. unavailable source or transitional state), the button is disabled and displays the refusal reason note.

    3. Destructive Uninstall Modal: Clicking Uninstall first queries ir.module.module.erp_preview_uninstall to compute impacted reverse dependents, dropped models, and exact database record counts. It opens an accessible modal <dialog> with:

      • Warning alert regarding data deletion;
      • Complete list of resolved affected modules;
      • Dropped models table displaying Model name, SQL Table name, and exact Record count;
      • Total affected record count summary;
      • Accessible keyboard focus trap (Tab / Shift+Tab constrained between Cancel and Confirm) and Escape / Cancel dismissal restoring focus to the opener button.

      Confirming uninstallation submits the preview fingerprint to POST /erp/module/uninstall. If the database state changed between preview calculation and confirmation, the server responds with 409 Conflict; the client traps this condition, alerts the user that database state changed, and prompts for a fresh preview confirmation.

    Multi-node lifecycle coordination and integration (SPEC-HUMAN-024, SPEC-HUMAN-025, SPEC-HUMAN-026, SPEC-HUMAN-028)

    Section titled “Multi-node lifecycle coordination and integration (SPEC-HUMAN-024, SPEC-HUMAN-025, SPEC-HUMAN-026, SPEC-HUMAN-028)”

    In a multi-node topology where multiple application servers connect to a shared PostgreSQL database and shared addon repository:

    1. Global advisory lock serialization: ModuleSystem serializes lifecycle mutations using PostgreSQL transaction-bound advisory locks. Concurrent upgrade, install, or uninstall requests across different nodes are serialized in the database: a request that overlaps a running operation is refused with 422 UserError (“ERPForAll is currently processing another module operation. …”, SPEC-MOD-028), and the caller retries. On any individual node, re-entrant concurrent invocations are rejected immediately with a Concurrency error ("A native installation is already running").

    2. Authority revocation across nodes: Lifecycle administrative operations (erp_addon_detail, erp_preview_uninstall, POST /erp/module/upgrade, POST /erp/module/uninstall) require an active primary administrator session belonging to base.group_system. When administrative group membership or session validity is revoked in the database, all cluster nodes immediately deny subsequent operations with 403 AccessError or 401 Unauthorized, leaving durable database records, audit entries, and identities intact.

    3. Stale impact confirmation refusal: Uninstall execution recomputes the exact impact fingerprint within the lifecycle transaction under the database lock. If concurrent changes occur between preview and confirmation, or if an invalid/mismatched fingerprint is submitted, confirmation is refused across all nodes with 409 Conflict (or 422 ValidationError under configured Signal compositions), ensuring no unverified or widened schema/data deletion occurs.

    4. Node loss resilience: If an application node holding or waiting on a lifecycle lock terminates or crashes (SIGTERM/SIGKILL), PostgreSQL automatically closes the backend connection and releases all transaction and advisory locks. Surviving peer nodes proceed with lifecycle queries and operations without deadlocks or lingering orphaned locks.

    5. Survivor maintenance and refresh: When any node commits a lifecycle operation that advances erp_signal_generation(key='registry'), surviving peer nodes observe the superseded signal upon their next request. The request layer triggers NativeLifecycle::refresh to reload the updated registry, recompile runtime Auth/RPC services, and publish fresh assets. A POST that met the superseded registry (a JSON-2 call, a lifecycle request) is refused with 503 (“Server busy; retry later.”, Retry-After) and never replayed; a safe GET navigation is retried once on the new services (SPEC-HUMAN-006). If a survivor cannot complete publication (e.g. a module left in to upgrade, or runtime grants not published), it stays in maintenance and answers 503 until a rebuild succeeds; failed rebuilds back off from 1 s, doubling up to 60 s. It never serves inconsistent or corrupt state.