interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / src / fabric / fab_dispatch.h

111 lines · 5555 bytes Raw Blame History
1/* SPDX-License-Identifier: Apache-2.0
2 * Copyright 2026 Drake Stapleton (AIEN / aien-dev)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 * fab_dispatch.h -- the Fabric side of a living composition (F5-0, loopback).
19 *
20 * rx_compose runs a candidate whose route is remote (SR_E_REMOTE: the Skill
21 * Router chose a CQ_SRC_FABRIC provider) through an RxcRemoteRun hook; this
22 * is that hook for F5-0. Before every dispatch, under one lock:
23 * 1. waiting Fabric traffic is applied (fab_poll) and the clock with it
24 * (fab_tick), so a LEAVE or a lease that ended since routing withdraws
25 * the machine's entries first;
26 * 2. the route is revalidated against the Capability Graph: sr_route_check
27 * must still say SR_E_REMOTE (entry live, same generation, version and
28 * digest, machine identity unchanged, lease live at now);
29 * 3. the route's machine must be a live member of this node (fab_home ==
30 * JS_HOME_REMOTE_OWNED): never the local machine, never a lost one;
31 * 4. that machine must run exactly the procedure it advertised: its
32 * executor has the route's skill id with the advertised digest.
33 * Any failure refuses (nonzero) and the candidate proposes nothing; the
34 * result of a dispatch is only a candidate, checked by the AEGIS verifier.
35 *
36 * Stand-in, stated plainly: F5-0 has no work message (its wire carries JOIN,
37 * RENEW, ADVERTISE and LEAVE only), so step 4 calls the simulated machine's
38 * procedure table in this process. Checks 1-3 are the ones a real dispatch
39 * makes before it sends; sending the work and authenticating the reply is
40 * the job of the AIENOS M6 transport (through AEGIS as an outbound effect).
41 * The dispatcher mints no authority and touches no World (fabric-purity).
42 *
43 * Concurrency: fab_dispatch_run may be called by two candidate reactions at
44 * once; all Fabric traffic and catalog changes while a composition can run
45 * go through fab_dispatch_pump / fab_dispatch_run (same lock). The catalog
46 * belongs to the composition: rx_compose_run routes (reads it) before any
47 * candidate runs, and only candidates call fab_dispatch_run during a run, so
48 * nothing else may pump this node while rx_compose_run is active (a
49 * background pump would race the routing read). The procedure runs under
50 * the lock: it must not call back into the dispatcher. The route is checked
51 * at the goal's time (rx_compose_run now_us), the composition's only clock.
52 */
53#ifndef FAB_DISPATCH_H
54#define FAB_DISPATCH_H
55
56/* Lane 32: test-build only. The production program (docs/r16-production-entry-point.md)
57 * never compiles this; the build refuses it without -DAIEN_TEST_BUILD=1. */
58#ifndef AIEN_TEST_BUILD
59#error "fab_dispatch.h (in-process simulated-machine dispatcher) is test and simulation only: build with -DAIEN_TEST_BUILD=1, never in the production program"
60#endif
61
62#include "fabric.h"
63#include "runtime/rx_skillroute.h"
64
65#include <pthread.h>
66#include <stdint.h>
67
68#define FAB_DISPATCH_MAX 8u
69
70/* Refusal reasons (FabDispatch.refused[...], last_refusal). */
71enum {
72 FAB_DX_OK = 0,
73 FAB_DX_ARG, /* bad call, or the router's graph is not this node's catalog */
74 FAB_DX_ROUTE, /* sr_route_check is no longer SR_E_REMOTE (withdrawn, stale, lease) */
75 FAB_DX_TARGET, /* route has no canonical target machine */
76 FAB_DX_NOT_MEMBER, /* target is not a live member of this node (or is this machine) */
77 FAB_DX_NO_EXECUTOR, /* target runs no such Skill */
78 FAB_DX_DIGEST, /* target's procedure differs from what it advertised */
79 FAB_DX_FAILED, /* the procedure reported failure */
80 FAB_DX_TRANSPORT, /* applying waiting Fabric traffic failed (transport error) */
81 FAB_DX_N
82};
83
84typedef struct {
85 AienMachineId machine;
86 const AgSkillTable *skills; /* the procedures that machine runs */
87} FabExecutor;
88
89typedef struct {
90 FabNode *node; /* this machine's node; its catalog is the router's graph */
91 pthread_mutex_t mu;
92 uint32_t n_exec;
93 FabExecutor exec[FAB_DISPATCH_MAX];
94 uint64_t dispatched;
95 uint64_t refused[FAB_DX_N];
96 int last_refusal; /* FAB_DX_* of the last refusal */
97 uint64_t polled, refused_msgs; /* Fabric messages applied by the dispatcher / refused */
98} FabDispatch;
99
100int fab_dispatch_init(FabDispatch *d, FabNode *node);
101void fab_dispatch_destroy(FabDispatch *d);
102/* The simulated machine m runs `skills` (loopback stand-in for its executor). */
103int fab_dispatch_add(FabDispatch *d, const AienMachineId *m, const AgSkillTable *skills);
104/* Apply every waiting Fabric message and the clock, under the lock. Returns
105 * messages applied, or <0 on a transport error. */
106int fab_dispatch_pump(FabDispatch *d, uint64_t now_us);
107/* RxcRemoteRun (rx_compose.h): ctx is the FabDispatch. 0 = ran, else FAB_DX_*. */
108int fab_dispatch_run(void *ctx, const SrRouter *router, const SrRoute *route, uint64_t input,
109 uint64_t now_us, uint64_t *result);
110
111#endif /* FAB_DISPATCH_H */