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 / synapse / core / review.om

307 lines · 8025 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note protocol/synapse/core/review.om: exact-head review and landing policy engine:
3note binds reviewer verdicts (MERGE, CHANGES_REQUESTED, REJECT) to exact 32-byte changeset digests,
4note automatically invalidates prior verdicts when a new head arrives on a branch, refuses self-review,
5note refuses stale-head verdicts, blocks landing on any non-MERGE verdict or missing exact-head MERGE,
6note enforces strict fast-forward from main (never automerges), and logs transitions to ledger.
7note Composed OM-2 library unit (no om2 directive, no main).
8
9const RV_MAX ulong 512
10const RV_FIELDS ulong 8
11
12const RV_MERGE ulong 1
13const RV_CHANGES_REQUESTED ulong 2
14const RV_REJECT ulong 3
15
16const RVF_CS_IDX ulong 0
17const RVF_REV_OFF ulong 1
18const RVF_REV_LEN ulong 2
19const RVF_VERDICT ulong 3
20const RVF_TS ulong 4
21const RVF_VALID ulong 5
22const RVF_BR_OFF ulong 6
23const RVF_BR_LEN ulong 7
24
25global g_rv_tab ulong 4096
26global g_rv_head uchar 16384
27global g_rv_hdr ulong 8
28
29text t_rv_merge "MERGE"
30text t_rv_chg "CHANGES_REQUESTED"
31text t_rv_rej "REJECT"
32text t_rv_land "LAND_MAIN"
33
34fn rv_reset to void
35put g_rv_hdr 0 0
36put g_rv_hdr 1 0
37end
38
39fn rv_count to ulong
40ret get g_rv_hdr 0
41end
42
43fn rv_set_time ts ulong to void
44put g_rv_hdr 1 ts
45end
46
47fn rv_mget idx ulong f ulong to ulong
48ret get g_rv_tab add mul idx RV_FIELDS f
49end
50
51fn rv_mput idx ulong f ulong v ulong to void
52put g_rv_tab add mul idx RV_FIELDS f v
53end
54
55fn rv_head_matches ridx ulong target_id view uchar * to bool
56if ne len target_id 32
57ret false
58end
59base = mul ridx 32
60for i ulong 32
61if ne get g_rv_head add base i get target_id i
62ret false
63end
64end
65ret true
66end
67
68note Called automatically when a new changeset head is committed on a branch:
69note invalidates all prior review verdicts whose branch matches and whose bound head differs.
70fn rv_invalidate_branch bo ulong bl ulong new_cs_idx ulong to void
71new_id = new uchar 32 0
72cs_get_id new_cs_idx new_id
73cnt = get g_rv_hdr 0
74for i ulong cnt
75if eq rv_mget i RVF_VALID 1
76if syn_arena_eq rv_mget i RVF_BR_OFF rv_mget i RVF_BR_LEN bo bl
77if eq rv_head_matches i new_id false
78rv_mput i RVF_VALID 0
79end
80end
81end
82end
83end
84
85note Counts valid exact-head MERGE verdicts for cs_idx.
86fn rv_valid_merge_count cs_idx ulong to ulong
87cur_id = new uchar 32 0
88if ge cs_idx cs_count
89ret 0
90end
91cs_get_id cs_idx cur_id
92cnt = get g_rv_hdr 0
93merges = ulong 0
94for i ulong cnt
95if eq rv_mget i RVF_VALID 1
96if eq rv_mget i RVF_CS_IDX cs_idx
97if rv_head_matches i cur_id
98if eq rv_mget i RVF_VERDICT RV_MERGE
99merges = add merges 1
100end
101end
102end
103end
104end
105ret merges
106end
107
108note Counts valid exact-head blocking verdicts (CHANGES_REQUESTED or REJECT) for cs_idx.
109fn rv_valid_block_count cs_idx ulong to ulong
110cur_id = new uchar 32 0
111if ge cs_idx cs_count
112ret 0
113end
114cs_get_id cs_idx cur_id
115cnt = get g_rv_hdr 0
116blocks = ulong 0
117for i ulong cnt
118if eq rv_mget i RVF_VALID 1
119if eq rv_mget i RVF_CS_IDX cs_idx
120if rv_head_matches i cur_id
121if ne rv_mget i RVF_VERDICT RV_MERGE
122blocks = add blocks 1
123end
124end
125end
126end
127end
128ret blocks
129end
130
131fn rv_log_verdict cs_id view uchar * ro ulong rl ulong verdict ulong ts ulong to ulong
132lg_set_subject cs_id
133if eq verdict RV_MERGE
134ret lg_append_view 6 ts ro rl t_rv_merge
135end
136if eq verdict RV_CHANGES_REQUESTED
137ret lg_append_view 6 ts ro rl t_rv_chg
138end
139ret lg_append_view 6 ts ro rl t_rv_rej
140end
141
142note Internal commit of a verified review verdict for cs_idx (already validated against exact head).
143fn rv_store_verdict cs_idx ulong reviewer view uchar * verdict ulong ts ulong to ulong
144cur_id = new uchar 32 0
145if or eq len reviewer 0 gt len reviewer 128
146ret SYN_ERR_MALFORMED
147end
148if or lt verdict RV_MERGE gt verdict RV_REJECT
149ret SYN_ERR_VERDICT_INVALID
150end
151st = cs_get_state cs_idx
152if and ne st CS_STATE_PROPOSED ne st CS_STATE_REVIEWED
153ret SYN_ERR_STATE_INVALID
154end
155note Self-review refusal: author cannot review their own changeset.
156if syn_arena_eq_view cs_get_author_off cs_idx cs_get_author_len cs_idx reviewer
157ret SYN_ERR_SELF_REVIEW
158end
159cnt = get g_rv_hdr 0
160if ge cnt RV_MAX
161ret SYN_ERR_CAPACITY
162end
163ro = syn_arena_put reviewer
164if eq ro SYN_NONE
165ret SYN_ERR_CAPACITY
166end
167cs_get_id cs_idx cur_id
168base = mul cnt 32
169for i ulong 32
170put g_rv_head add base i get cur_id i
171end
172rv_mput cnt RVF_CS_IDX cs_idx
173rv_mput cnt RVF_REV_OFF ro
174rv_mput cnt RVF_REV_LEN len reviewer
175rv_mput cnt RVF_VERDICT verdict
176rv_mput cnt RVF_TS ts
177rv_mput cnt RVF_VALID 1
178rv_mput cnt RVF_BR_OFF cs_get_branch_off cs_idx
179rv_mput cnt RVF_BR_LEN cs_get_branch_len cs_idx
180put g_rv_hdr 0 add cnt 1
181seq = rv_log_verdict cur_id ro len reviewer verdict ts
182if eq seq 0
183ret SYN_ERR_CAPACITY
184end
185if eq verdict RV_MERGE
186if eq st CS_STATE_PROPOSED
187if eq rv_valid_block_count cs_idx 0
188rc = cs_transition cs_idx CS_STATE_REVIEWED ts
189if ne rc SYN_OK
190ret rc
191end
192end
193end
194end
195ret SYN_OK
196end
197
198note Records a review verdict bound to exact 32-byte head_id.
199note Refuses unknown changeset, stale branch head (superseded by newer head), self-review,
200note invalid verdict, or non-PROPOSED/REVIEWED state.
201fn rv_record head_id view uchar * reviewer view uchar * verdict ulong ts ulong to ulong
202if ne len head_id 32
203ret SYN_ERR_MALFORMED
204end
205cs_idx = cs_find_by_id head_id
206if eq cs_idx SYN_NONE
207ret SYN_ERR_NOT_FOUND
208end
209note Check if this non-main branch already moved to a newer head (stale-head refusal).
210bo = cs_get_branch_off cs_idx
211bl = cs_get_branch_len cs_idx
212if eq syn_arena_eq_view bo bl t_br_main false
213bpos = gr_branch_find_arena bo bl
214if ne bpos SYN_NONE
215bhead = get g_gr_br add mul bpos 3 2
216if ne bhead cs_idx
217ret SYN_ERR_STALE_HEAD
218end
219end
220end
221ret rv_store_verdict cs_idx reviewer verdict ts
222end
223
224note Records a review verdict explicitly checking expected_head against cs_idx's exact digest.
225note Uses timestamp from rv_set_time (or cs_ts + 1 if unset). Refuses with SYN_ERR_STALE_HEAD on mismatch.
226fn rv_record_bound cs_idx ulong expected_head view uchar * reviewer view uchar * verdict ulong to ulong
227cur_id = new uchar 32 0
228if ge cs_idx cs_count
229ret SYN_ERR_NOT_FOUND
230end
231cs_get_id cs_idx cur_id
232if eq syn_digest_eq cur_id expected_head false
233ret SYN_ERR_STALE_HEAD
234end
235ts = get g_rv_hdr 1
236if eq ts 0
237ts = add cs_get_ts cs_idx 1
238end
239ret rv_store_verdict cs_idx reviewer verdict ts
240end
241
242note Strict landing policy check without mutating state.
243note Requires:
244note 1. cs_idx exists and is not already LANDED or ABANDONED
245note 2. expected_head matches cs_id(cs_idx) byte-for-byte
246note 3. At least one valid exact-head MERGE verdict and ZERO blocking verdicts
247note 4. Current main head (if any) is an ancestor of cs_idx (strict fast-forward; never automerges)
248fn rv_can_land cs_idx ulong expected_head view uchar * to ulong
249cur_id = new uchar 32 0
250if ge cs_idx cs_count
251ret SYN_ERR_NOT_FOUND
252end
253st = cs_get_state cs_idx
254if or eq st CS_STATE_LANDED eq st CS_STATE_ABANDONED
255ret SYN_ERR_STATE_INVALID
256end
257cs_get_id cs_idx cur_id
258if eq syn_digest_eq cur_id expected_head false
259ret SYN_ERR_STALE_HEAD
260end
261if gt rv_valid_block_count cs_idx 0
262ret SYN_ERR_REVIEW_BLOCKED
263end
264if eq rv_valid_merge_count cs_idx 0
265ret SYN_ERR_REVIEW_BLOCKED
266end
267mh = gr_main_head
268if ne mh SYN_NONE
269if eq gr_is_fast_forward mh cs_idx false
270ret SYN_ERR_NON_FF
271end
272end
273ret SYN_OK
274end
275
276note Executes strict landing policy: verifies exact-head MERGE receipt, zero blocking verdicts,
277note and fast-forward from main (never automerges). Advances state to LANDED, updates main head,
278note and appends LG_EV_LAND (7) to the hash-chained ledger.
279fn rv_land cs_idx ulong expected_head view uchar * ts ulong to ulong
280cur_id = new uchar 32 0
281rc = rv_can_land cs_idx expected_head
282if ne rc SYN_OK
283ret rc
284end
285st = cs_get_state cs_idx
286if eq st CS_STATE_PROPOSED
287rc2 = cs_transition cs_idx CS_STATE_REVIEWED ts
288if ne rc2 SYN_OK
289ret rc2
290end
291end
292rc3 = cs_transition cs_idx CS_STATE_LANDED ts
293if ne rc3 SYN_OK
294ret rc3
295end
296rc4 = gr_branch_set t_br_main cs_idx
297if ne rc4 SYN_OK
298ret rc4
299end
300cs_get_id cs_idx cur_id
301lg_set_subject cur_id
302seq = lg_append_view 7 ts cs_get_author_off cs_idx cs_get_author_len cs_idx t_rv_land
303if eq seq 0
304ret SYN_ERR_CAPACITY
305end
306ret SYN_OK
307end