Skip to content

Unified Approvals & Delegations ​

The Unified Approvals engine (@latticedx/plugin-lattice-foundation, approval-engine.js) and time-bound Delegation engine (@latticedx/plugin-dxos-studio, delegation-engine.js) consolidate business approvals, AI human-in-the-loop (HITL) queues, paused LatticeFlow v2 nodes, and agent proposals into a single organizational inbox. Every approval policy supports stage-level M-of-N quorum rules, blocks self-approval by default, and writes Ed25519-signed decision records to latticeCryptoLedger.

Four-Source Unified Inbox and Direct-CRUD Guard ​

dxosApprovals:listInbox aggregates pending and historical items across four operational sources scoped to organizationId, supporting filtering by source, status, assignedToMe, and keyword search. Direct REST mutations on latticeApprovalPolicies and latticeApprovalRequests are blocked by dxosApprovalsDirectGuard; callers must use the dxosApprovals resource endpoints.

source ValueBacking CollectionOperational ContextBehavior on decide
businesslatticeApprovalRequestsPolicy-driven record approval bound to latticeApprovalPolicies.Evaluates the active stage's M-of-N quorum and advances or completes the request.
ai_hitllatticeAiApprovalQueueHigh-risk AI tool calls or Digital Twin setpoints exceeding 2.0°C delta.Approves or rejects execution of the queued AI/IIoT action.
flowlatticeAutomationRunsLatticeFlow v2 execution paused at a control.approval node.Verifies authority via verifyApprovalResumeAuthority and resumes loopCursors.
proposalslatticeAgentProposalsIncident triage or operational recommendations generated by AI agents.Records reviewer verdict and updates proposal state.
GET/api/dxosApprovals:listInbox
Bearer JWT | ldx_pat_*read, write, ai
Lists unified approval tasks across business, ai_hitl, flow, and proposals considering active delegations.

The engine enforces PROTECTED_TARGET_COLLECTIONS (25 system and security tables such as users, roles, latticeApiKeys, latticeCryptoLedger, latticeDelegations, and latticeConnectors) which cannot be attached to custom approval policies; valid target collections must match ^lattice[A-Z][A-Za-z0-9]{1,64}$.

Multi-Stage M-of-N Quorum Policies ​

Policies stored in latticeApprovalPolicies are keyed by policyKey (/^[a-z0-9][a-z0-9_-]{1,62}$/) and declare an ordered stagesJson array. Within each stage, sequential mode forces requiredApprovals = 1, whereas parallel mode enforces an M-of-N quorum (1..50 approvals from approverRoles or approverUserIds). When a parallel stage specifies approverUserIds without approverRoles, requiredApprovals cannot exceed approverUserIds.length.

Stage Schema in stagesJson (latticeApprovalPolicies)
ParameterTypeDefaultDescription
moderequired
stringsequentialStage evaluation mode: sequential or parallel.
approverRoles
string[]—Role names permitted to vote on this stage (e.g., ldx_manager, ldx_director).
approverUserIds
integer[]—Explicit user IDs permitted to vote on this stage.
requiredApprovals
integer1Quorum count M required to clear the stage (1..50; forced to 1 in sequential mode).
slaMinutes
integer—Stage SLA deadline in minutes (1..43200).
escalateToRole
string—Role notified when the stage exceeds its SLA threshold.
allowDelegation
booleantrueAllows active time-bound delegates to vote on behalf of eligible approvers.

By default, allowSelfApproval is false so requesters cannot approve their own submissions; only root or admin actors can enable self-approval at request creation. To prevent concurrent vote races in parallel quorum stages, withCanonicalDecisionLock serializes decisions per request key alongside optimistic persistence checks (repoUpdateCompat).

POST/api/dxosApprovals:decide
Bearer JWT | ldx_pat_*write
Submits an approve or reject vote, evaluates M-of-N progression, and records ledger proof.
dxosApprovals EndpointMethodRequired ScopeResponsibility
/api/dxosApprovals:listInboxGETread, write, aiQueries unified approval items filtered by source and status.
/api/dxosApprovals:requestPOSTwriteSubmits a new approval request bound to a policy key or inline stages.
/api/dxosApprovals:decidePOSTwriteRecords approve or reject across any of the four inbox sources.
/api/dxosApprovals:cancelPOSTwriteCancels a pending approval request with an audit note.
/api/dxosApprovals:listPoliciesGETread, writeLists active approval policies in the organization.
/api/dxosApprovals:savePolicyPOSTwriteCreates or updates an M-of-N policy on a business collection.
/api/dxosApprovals:deletePolicyPOSTwriteDeletes a policy by policyId or policyKey.
/api/dxosApprovals:evaluateSlaNowPOSTwrite (Admin/Root)Evaluates overdue stages and triggers SLA escalation (supports dryRun).
bash
curl -X POST https://app.example.com/api/dxosApprovals:savePolicy \
  -H "Authorization: Bearer ldx_pat_a1b2c3d4_..." \
  -H "Content-Type: application/json" \
  -d '{
    "policyKey": "coldchain-qa-release",
    "name": "Cold-Chain Lot QA Release",
    "targetCollection": "latticeStockLots",
    "operation": "custom",
    "stagesJson": [
      {
        "mode": "parallel",
        "approverRoles": ["ldx_manager", "ldx_director"],
        "requiredApprovals": 2,
        "slaMinutes": 120,
        "escalateToRole": "ldx_director",
        "allowDelegation": true
      }
    ]
  }'

Time-Bound Delegations (dxosDelegations, Max 90 Days) ​

When an approver is unavailable, dxosDelegations issues a temporary role delegation to another active employee in the same organization. Server-side validation in delegation-engine.js enforces six security invariants before generating a DLG-... delegation record:

Security InvariantEnforcement Rule & Error Code
90-day duration ceilingendsAt must be strictly later than startsAt, and endsAt - startsAt cannot exceed MAX_DELEGATION_MS = 90 days (DELEGATION_WINDOW_EXCEEDED).
Self-delegation prohibitiondelegateUserId cannot match delegatorUserId (DELEGATION_SELF_FORBIDDEN).
Privilege escalation blockNon-root actors cannot delegate FORBIDDEN_DELEGATION_ROLES (root, admin, ldx_admin) or any role carrying allowAll, allowConfigure, or elevated snippets (pm*, acl*, app*, ui*, *), returning 403 DELEGATION_ESCALATION_FORBIDDEN.
Active role ownershipNon-root delegators must currently hold roleName in rolesUsers (DELEGATION_ROLE_NOT_HELD).
Same-organization membershipBoth delegator and delegate must have active: true latticeEmployees records in the same organizationId (DELEGATION_CROSS_ORG_FORBIDDEN).
Optional collection scopingProviding scopeCollection restricts delegated authority strictly to decisions targeting that collection.
POST/api/dxosDelegations:create
Bearer JWT | ldx_pat_*write
Issues a time-bound delegation (<= 90 days) with privilege-escalation checks and PKI ledger audit.
Input Parameters for dxosDelegations:create
ParameterTypeDefaultDescription
delegateUserIdrequired
integer—Target user ID receiving delegated authority (must differ from delegatorUserId and share the same org).
roleNamerequired
string—Role name to delegate (2..64 chars; excludes forbidden administrative roles).
endsAtrequired
datetime—Delegation expiration timestamp (later than startsAt and within 90 days).
startsAt
datetimenow()Delegation activation timestamp.
scopeCollection
string—Optional collection constraint limiting where the delegated role applies.
reason
string—Audit justification string (max 500 characters).
dxosDelegations EndpointMethodRequired ScopeResponsibility
/api/dxosDelegations:listGETread, writeLists delegations involving the caller (or all org delegations for admins).
/api/dxosDelegations:createPOSTwriteCreates an active DLG-* delegation bounded to <= 90 days.
/api/dxosDelegations:revokePOSTwriteImmediately revokes an active delegation (status = 'revoked', active = false).
/api/dxosDelegations:activeForMeGETread, writeResolves currently active delegated roles and matching records for the caller.
bash
curl -X POST https://app.example.com/api/dxosDelegations:create \
  -H "Authorization: Bearer ldx_pat_a1b2c3d4_..." \
  -H "Content-Type: application/json" \
  -d '{
    "delegateUserId": 14,
    "roleName": "ldx_manager",
    "scopeCollection": "latticeOrders",
    "startsAt": "2026-12-01T00:00:00Z",
    "endsAt": "2026-12-15T23:59:59Z",
    "reason": "Regional cold-storage site audit"
  }'

Audit Trails, Delegation Resolution, and Error Codes ​

When an actor calls dxosApprovals:decide or resumes a suspended LatticeFlow v2 control.approval node (verifyApprovalResumeAuthority), the engine calls resolveEffectiveDelegatedRoles to combine base roles from rolesUsers with currently active delegations (startsAt <= now < endsAt, status = 'active', matching scopeCollection when specified).

Every approval request, vote, cancellation, delegation creation (auth.delegation_created), and revocation (auth.delegation_revoked) appends an Ed25519-signed entry to latticeCryptoLedger via safeAppendApprovalLedger or appendAuditLedger, publishes a CloudEvent on latticeEventBus, and dispatches alerts through notification-center.js or dxosNotify. When a delegate casts a vote, the ledger payload records both delegationUid and delegatedFromUserId for attribution.

Error CodeHTTPSource EngineTrigger Condition
APPROVAL_COLLECTION_FORBIDDEN400approval-engine.jsPolicy targets a table in PROTECTED_TARGET_COLLECTIONS or violates ^lattice[A-Z]....
DELEGATION_WINDOW_EXCEEDED400delegation-engine.jsDuration endsAt - startsAt exceeds 90 days (MAX_DELEGATION_MS).
DELEGATION_SELF_FORBIDDEN400delegation-engine.jsdelegateUserId matches delegatorUserId.
DELEGATION_ESCALATION_FORBIDDEN403delegation-engine.jsAttempted delegation of root, admin, ldx_admin, or elevated snippets (pm*/acl*/app*/ui*/*).
DELEGATION_ROLE_NOT_HELD403delegation-engine.jsDelegator does not hold roleName in rolesUsers.
DELEGATION_CROSS_ORG_FORBIDDEN403delegation-engine.jsDelegator or delegate lacks an active latticeEmployees record in the same organization.

Apache-2.0 · LatticeDX v0.4.2 · Powered by NocoBase · v2.2.50 · Apache-2.0 (Clause 5.2)