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 / protocol / aien-protocols / core / action_event.om

184 lines · 4638 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note protocol/aien-protocols/core/action_event.om: pure-Omega port of aien-action-protocol,
3note aien-event-protocol, and aien-agent-state-abi execution/budget/containment invariants.
4note Compose after si/directives/om2.om, om/tls/sha2.om, types.om, and provenance.om.
5
6const AE_OK ulong 0
7const AE_ERR_CONTAINMENT_WEAK ulong 1
8const AE_ERR_CAP_EXPIRED ulong 2
9const AE_ERR_CAP_BAD_WINDOW ulong 3
10const AE_ERR_CAP_EMPTY ulong 4
11const AE_ERR_BAD_TRANSITION ulong 5
12const AE_ERR_BAD_STATUS ulong 6
13const AE_ERR_SEQ_REGRESS ulong 7
14const AE_ERR_BUDGET_TOKENS ulong 8
15const AE_ERR_BUDGET_COST ulong 9
16const AE_ERR_BUDGET_DURATION ulong 10
17const AE_ERR_BUDGET_SUBAGENTS ulong 11
18
19const SECCOMP_NONE ulong 0
20const SECCOMP_STRICT ulong 1
21const SECCOMP_PERMISSIVE ulong 2
22
23const EXEC_IDLE ulong 0
24const EXEC_RUNNING ulong 1
25const EXEC_SUSPENDED ulong 2
26const EXEC_AWAITING_APPROVAL ulong 3
27const EXEC_TERMINATED ulong 4
28
29note --- ContainmentState (strict default: isolated_network=true, read_only_fs=true, seccomp=strict) ---
30
31fn containment_is_strict iso_net bool ro_fs bool seccomp ulong subproc_cnt ulong to bool
32if not iso_net
33ret false
34end
35if not ro_fs
36ret false
37end
38if ne seccomp SECCOMP_STRICT
39ret false
40end
41ret eq subproc_cnt ulong 0
42end
43
44fn containment_require_strict iso_net bool ro_fs bool seccomp ulong subproc_cnt ulong to ulong
45if containment_is_strict iso_net ro_fs seccomp subproc_cnt
46ret AE_OK
47end
48ret AE_ERR_CONTAINMENT_WEAK
49end
50
51note --- CapabilityGrant validation ---
52
53fn cap_grant_check cap view uchar * scope view uchar * to ulong
54if eq len cap ulong 0
55ret AE_ERR_CAP_EMPTY
56end
57if eq len scope ulong 0
58ret AE_ERR_CAP_EMPTY
59end
60ret AE_OK
61end
62
63fn cap_grant_window_check granted_us ulong has_exp bool exp_us ulong now_us ulong to ulong
64if has_exp
65if lt exp_us granted_us
66ret AE_ERR_CAP_BAD_WINDOW
67end
68if gt now_us exp_us
69ret AE_ERR_CAP_EXPIRED
70end
71end
72ret AE_OK
73end
74
75note --- AgentExecutionStatus state-machine invariants ---
76note Valid transitions:
77note Idle -> Running | Terminated
78note Running -> Idle | Suspended | AwaitingApproval | Terminated
79note Suspended -> Running | Terminated
80note AwaitingApproval -> Running | Idle | Terminated
81note Terminated -> (absorbing: no transitions allowed, not even to Terminated)
82
83fn exec_status_valid s ulong to bool
84ret le s EXEC_TERMINATED
85end
86
87fn exec_transition_check cur ulong nxt ulong to ulong
88if not exec_status_valid cur
89ret AE_ERR_BAD_STATUS
90end
91if not exec_status_valid nxt
92ret AE_ERR_BAD_STATUS
93end
94if eq cur EXEC_TERMINATED
95ret AE_ERR_BAD_TRANSITION
96end
97if eq cur EXEC_IDLE
98if or eq nxt EXEC_RUNNING eq nxt EXEC_TERMINATED
99ret AE_OK
100end
101ret AE_ERR_BAD_TRANSITION
102end
103if eq cur EXEC_RUNNING
104if or eq nxt EXEC_IDLE or eq nxt EXEC_SUSPENDED or eq nxt EXEC_AWAITING_APPROVAL eq nxt EXEC_TERMINATED
105ret AE_OK
106end
107ret AE_ERR_BAD_TRANSITION
108end
109if eq cur EXEC_SUSPENDED
110if or eq nxt EXEC_RUNNING eq nxt EXEC_TERMINATED
111ret AE_OK
112end
113ret AE_ERR_BAD_TRANSITION
114end
115if eq cur EXEC_AWAITING_APPROVAL
116if or eq nxt EXEC_RUNNING or eq nxt EXEC_IDLE eq nxt EXEC_TERMINATED
117ret AE_OK
118end
119ret AE_ERR_BAD_TRANSITION
120end
121ret AE_ERR_BAD_TRANSITION
122end
123
124note --- EventEnvelope sequence monotonicity & canonical digest ---
125
126fn event_seq_check prev_seq ulong next_seq ulong to ulong
127if le next_seq prev_seq
128ret AE_ERR_SEQ_REGRESS
129end
130ret AE_OK
131end
132
133fn event_hash_meta ctx edit ulong * eid view uchar 16 topic view uchar * to void
134sha256_init ctx
135sha256_update ctx eid
136sha256_update ctx topic
137end
138
139fn event_hash_body ctx edit ulong * producer view uchar * seq ulong ts_us ulong to void
140buf = new uchar 16 0
141w1 = pt_put_u64_le buf ulong 0 seq
142w2 = pt_put_u64_le buf ulong 8 ts_us
143if or ne w1 ulong 8 ne w2 ulong 16
144trap 8
145end
146sha256_update ctx producer
147sha256_update ctx buf
148end
149
150fn event_hash_finish ctx edit ulong * payload_dig view uchar 32 dst edit uchar 32 to void
151sha256_update ctx payload_dig
152sha256_final ctx dst
153end
154
155note --- ResourceBudget enforcement ---
156note A limit value of 0 means unbounded (None in Rust Option<u64>).
157
158fn budget_check_tokens used ulong max_lim ulong to ulong
159if and gt max_lim ulong 0 gt used max_lim
160ret AE_ERR_BUDGET_TOKENS
161end
162ret AE_OK
163end
164
165fn budget_check_cost used_micro_usd ulong max_lim ulong to ulong
166if and gt max_lim ulong 0 gt used_micro_usd max_lim
167ret AE_ERR_BUDGET_COST
168end
169ret AE_OK
170end
171
172fn budget_check_duration elapsed_s ulong max_lim ulong to ulong
173if and gt max_lim ulong 0 gt elapsed_s max_lim
174ret AE_ERR_BUDGET_DURATION
175end
176ret AE_OK
177end
178
179fn budget_check_subagents active ulong max_lim ulong to ulong
180if and gt max_lim ulong 0 gt active max_lim
181ret AE_ERR_BUDGET_SUBAGENTS
182end
183ret AE_OK
184end