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 Value | Backing Collection | Operational Context | Behavior on decide |
|---|---|---|---|
business | latticeApprovalRequests | Policy-driven record approval bound to latticeApprovalPolicies. | Evaluates the active stage's M-of-N quorum and advances or completes the request. |
ai_hitl | latticeAiApprovalQueue | High-risk AI tool calls or Digital Twin setpoints exceeding 2.0°C delta. | Approves or rejects execution of the queued AI/IIoT action. |
flow | latticeAutomationRuns | LatticeFlow v2 execution paused at a control.approval node. | Verifies authority via verifyApprovalResumeAuthority and resumes loopCursors. |
proposals | latticeAgentProposals | Incident triage or operational recommendations generated by AI agents. | Records reviewer verdict and updates proposal state. |
/api/dxosApprovals:listInboxThe 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.
| Parameter | Type | Default | Description |
|---|---|---|---|
moderequired | string | sequential | Stage 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 | integer | 1 | Quorum 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 | boolean | true | Allows 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).
/api/dxosApprovals:decidedxosApprovals Endpoint | Method | Required Scope | Responsibility |
|---|---|---|---|
/api/dxosApprovals:listInbox | GET | read, write, ai | Queries unified approval items filtered by source and status. |
/api/dxosApprovals:request | POST | write | Submits a new approval request bound to a policy key or inline stages. |
/api/dxosApprovals:decide | POST | write | Records approve or reject across any of the four inbox sources. |
/api/dxosApprovals:cancel | POST | write | Cancels a pending approval request with an audit note. |
/api/dxosApprovals:listPolicies | GET | read, write | Lists active approval policies in the organization. |
/api/dxosApprovals:savePolicy | POST | write | Creates or updates an M-of-N policy on a business collection. |
/api/dxosApprovals:deletePolicy | POST | write | Deletes a policy by policyId or policyKey. |
/api/dxosApprovals:evaluateSlaNow | POST | write (Admin/Root) | Evaluates overdue stages and triggers SLA escalation (supports dryRun). |
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 Invariant | Enforcement Rule & Error Code |
|---|---|
| 90-day duration ceiling | endsAt must be strictly later than startsAt, and endsAt - startsAt cannot exceed MAX_DELEGATION_MS = 90 days (DELEGATION_WINDOW_EXCEEDED). |
| Self-delegation prohibition | delegateUserId cannot match delegatorUserId (DELEGATION_SELF_FORBIDDEN). |
| Privilege escalation block | Non-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 ownership | Non-root delegators must currently hold roleName in rolesUsers (DELEGATION_ROLE_NOT_HELD). |
| Same-organization membership | Both delegator and delegate must have active: true latticeEmployees records in the same organizationId (DELEGATION_CROSS_ORG_FORBIDDEN). |
| Optional collection scoping | Providing scopeCollection restricts delegated authority strictly to decisions targeting that collection. |
/api/dxosDelegations:create| Parameter | Type | Default | Description |
|---|---|---|---|
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 | datetime | now() | Delegation activation timestamp. |
scopeCollection | string | — | Optional collection constraint limiting where the delegated role applies. |
reason | string | — | Audit justification string (max 500 characters). |
dxosDelegations Endpoint | Method | Required Scope | Responsibility |
|---|---|---|---|
/api/dxosDelegations:list | GET | read, write | Lists delegations involving the caller (or all org delegations for admins). |
/api/dxosDelegations:create | POST | write | Creates an active DLG-* delegation bounded to <= 90 days. |
/api/dxosDelegations:revoke | POST | write | Immediately revokes an active delegation (status = 'revoked', active = false). |
/api/dxosDelegations:activeForMe | GET | read, write | Resolves currently active delegated roles and matching records for the caller. |
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 Code | HTTP | Source Engine | Trigger Condition |
|---|---|---|---|
APPROVAL_COLLECTION_FORBIDDEN | 400 | approval-engine.js | Policy targets a table in PROTECTED_TARGET_COLLECTIONS or violates ^lattice[A-Z].... |
DELEGATION_WINDOW_EXCEEDED | 400 | delegation-engine.js | Duration endsAt - startsAt exceeds 90 days (MAX_DELEGATION_MS). |
DELEGATION_SELF_FORBIDDEN | 400 | delegation-engine.js | delegateUserId matches delegatorUserId. |
DELEGATION_ESCALATION_FORBIDDEN | 403 | delegation-engine.js | Attempted delegation of root, admin, ldx_admin, or elevated snippets (pm*/acl*/app*/ui*/*). |
DELEGATION_ROLE_NOT_HELD | 403 | delegation-engine.js | Delegator does not hold roleName in rolesUsers. |
DELEGATION_CROSS_ORG_FORBIDDEN | 403 | delegation-engine.js | Delegator or delegate lacks an active latticeEmployees record in the same organization. |
