@consiliency/agent-board-schema 1.74.0 → 1.76.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/fixtures/already-applied.json +8 -0
  2. package/migrations/20261108000100_agent_board_send_outcome.sql +708 -0
  3. package/migrations/20261109000100_agent_board_step_up_groundwork.sql +343 -0
  4. package/package.json +1 -1
  5. package/schema-manifest.json +21 -3
  6. package/src/deployment-drift-main.test.mjs +20 -3
  7. package/src/deployment-drift-script.test.mjs +77 -2
  8. package/src/deployment-drift.test.mjs +60 -0
  9. package/src/tooling.test.mjs +4 -2
  10. package/tests/agent_board_667_history_class.test.sql +2 -0
  11. package/tests/agent_board_717_native_surface.test.sql +223 -0
  12. package/tests/agent_board_delegate_role_class.test.sql +2 -2
  13. package/tests/agent_board_delivery_writer_execute.test.sql +4 -2
  14. package/tests/agent_board_enrollment_audit_content.test.sql +6 -1
  15. package/tests/agent_board_hosted_delegates.test.sql +8 -1
  16. package/tests/agent_board_send_outcome.test.sql +805 -0
  17. package/tests/agent_board_step_up_helper.test.sql +711 -0
  18. package/tests/agent_board_write_enforcement_class.test.sql +12 -5
  19. package/tests/catalog/function_execute_privileges.json +96 -0
  20. package/tests/catalog/p_metadata_parameters.json +40 -0
  21. package/tests/fixtures/isolation-substrate.sql +8 -0
  22. package/tests/fixtures/pgtap-unexposed.sql +61 -0
  23. package/tests/isolation/expected/send_outcome_cross_board.out +40 -0
  24. package/tests/isolation/expected/send_outcome_independence.out +295 -0
  25. package/tests/isolation/expected/send_outcome_membership.out +140 -0
  26. package/tests/isolation/expected/send_outcome_overlap.out +89 -0
  27. package/tests/isolation/expected/send_outcome_reader.out +87 -0
  28. package/tests/isolation/expected/send_outcome_recovery.out +107 -0
  29. package/tests/isolation/specs/send_outcome_cross_board.spec +66 -0
  30. package/tests/isolation/specs/send_outcome_independence.spec +95 -0
  31. package/tests/isolation/specs/send_outcome_membership.spec +73 -0
  32. package/tests/isolation/specs/send_outcome_overlap.spec +69 -0
  33. package/tests/isolation/specs/send_outcome_reader.spec +61 -0
  34. package/tests/isolation/specs/send_outcome_recovery.spec +68 -0
  35. package/tests/mutations/669/M10_service_role_blanket.sql +10 -0
  36. package/tests/mutations/669/M12a_no_parse_wrapper.sql +17 -0
  37. package/tests/mutations/669/M12b_no_session_wrapper.sql +23 -0
  38. package/tests/mutations/669/M12c_no_claim_type_guard.sql +13 -0
  39. package/tests/mutations/669/M12d_no_amr_element_guards.sql +15 -0
  40. package/tests/mutations/669/M14_now_not_clock.sql +9 -0
  41. package/tests/mutations/669/M15_classifier_reads_metadata.sql +17 -0
  42. package/tests/mutations/669/M17_skip_ledger.sql +15 -0
  43. package/tests/mutations/669/M18_service_role_sub_insensitive.sql +9 -0
  44. package/tests/mutations/669/M18b_drop_uid_conjunct.sql +9 -0
  45. package/tests/mutations/669/M23_definer_wrapper_over_writer.sql +5 -0
  46. package/tests/mutations/669/M3_age_from_iat.sql +9 -0
  47. package/tests/mutations/669/M4_window_900.sql +9 -0
  48. package/tests/mutations/669/M4b_lt_to_le.sql +9 -0
  49. package/tests/mutations/669/M5_no_skew_bound.sql +9 -0
  50. package/tests/mutations/669/M6a_user_metadata_amr.sql +9 -0
  51. package/tests/mutations/669/M6b_app_metadata_claim.sql +9 -0
  52. package/tests/mutations/669/M6c_legacy_guc.sql +9 -0
  53. package/tests/mutations/669/M7_either_claim_any_human.sql +9 -0
  54. package/tests/mutations/669/M8_any_amr_method.sql +9 -0
  55. package/tests/mutations/669/M8b_accept_aal2.sql +9 -0
  56. package/tests/mutations/669/M9_every_kind.sql +9 -0
  57. package/tests/mutations/669/MAL_allowlist_nonempty.sql +9 -0
  58. package/tests/mutations/669/MAR_writer_arg_renamed.sql +14 -0
  59. package/tests/mutations/669/MAU_audit_mode_retyped.sql +2 -0
  60. package/tests/mutations/669/MA_helper_always_raises.sql +10 -0
  61. package/tests/mutations/669/MDX_dynamic_execute_definer.sql +5 -0
  62. package/tests/mutations/669/MD_detail_carries_value.sql +12 -0
  63. package/tests/mutations/669/MEC0_caller_of_helper.sql +4 -0
  64. package/tests/mutations/669/MEC0b_overload_caller.sql +4 -0
  65. package/tests/mutations/669/MG1_helper_granted_authenticated.sql +2 -0
  66. package/tests/mutations/669/MG2_ledger_insert_authenticated.sql +2 -0
  67. package/tests/mutations/669/MG3_ledger_policy.sql +2 -0
  68. package/tests/mutations/669/MR1_writer_no_class_check.sql +9 -0
  69. package/tests/mutations/669/MR2_writer_wide_window.sql +9 -0
  70. package/tests/mutations/669/MR3_writer_prunes_everyone.sql +11 -0
  71. package/tests/mutations/669/MR4_writer_lower_exclusive.sql +9 -0
  72. package/tests/mutations/669/MR5_writer_upper_exclusive.sql +9 -0
  73. package/tests/mutations/669/MR6_writer_upper_61.sql +9 -0
  74. package/tests/mutations/669/MW2_second_ledger_writer.sql +4 -0
  75. package/tests/mutations/669/MXS_cross_schema_wrapper.sql +4 -0
  76. package/tests/mutations/669/run.sh +72 -0
  77. package/tests/mutations/670/E1_helper_author_from_message.sql +7 -0
  78. package/tests/mutations/670/E2_helper_no_null_check.sql +13 -0
  79. package/tests/mutations/670/M10_lock_removed.sql +10 -0
  80. package/tests/mutations/670/M11_table_granted_to_authenticated.sql +2 -0
  81. package/tests/mutations/670/M12_helper_granted_to_service_role.sql +2 -0
  82. package/tests/mutations/670/M13_message_fk_no_cascade.sql +8 -0
  83. package/tests/mutations/670/M14_post_message_mints_from_metadata.sql +11 -0
  84. package/tests/mutations/670/M15_second_receipt_writer.sql +9 -0
  85. package/tests/mutations/670/M16_read_no_btrim.sql +7 -0
  86. package/tests/mutations/670/M17_read_volatile.sql +2 -0
  87. package/tests/mutations/670/M1_helper_no_service_role_guard.sql +13 -0
  88. package/tests/mutations/670/M3_helper_on_replay_branch.sql +10 -0
  89. package/tests/mutations/670/M4_read_checks_thread_existence.sql +10 -0
  90. package/tests/mutations/670/M5a_read_requires_thread_access.sql +10 -0
  91. package/tests/mutations/670/M5b_read_requires_board_membership.sql +11 -0
  92. package/tests/mutations/670/M6_read_admits_service_role.sql +14 -0
  93. package/tests/mutations/670/M7_confirmed_adds_message_sequence.sql +12 -0
  94. package/tests/mutations/670/M8_delivery_swallows_errors.sql +19 -0
  95. package/tests/mutations/670/M9_lock_key_includes_board.sql +10 -0
  96. package/tests/mutations/670/run.sh +84 -0
@@ -0,0 +1,107 @@
1
+ Parsed test spec with 4 sessions
2
+
3
+ starting permutation: p_post fanout l_begin l_leave r_read l_commit r_read fanout check
4
+ set_config
5
+ --------------------------------------------------------------------------
6
+ {"role" : "authenticated", "sub" : "670b5000-0000-4000-8000-0000000000c1"}
7
+ (1 row)
8
+
9
+ step p_post: insert into public.so670_iso5_ret select 'p', message_id from agent_board.post_board_message('670b5000-0000-4000-8000-000000000012','670b5000-0000-4000-8000-000000000003','670b5000-0000-4000-8000-000000000020','iso','so670 body','comment','medium','K',jsonb_build_object());
10
+ step fanout: select (select count(*) from agent_board.delivery_recipients where recipient_agent_id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002')) as deliveries, (select count(*) from agent_board.inbox_items where recipient_agent_id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002')) as inbox, (select count(*) from agent_board.send_outcomes where thread_id = '670b5000-0000-4000-8000-000000000012') as receipts;
11
+ deliveries|inbox|receipts
12
+ ----------+-----+--------
13
+ 2| 2| 1
14
+ (1 row)
15
+
16
+ step l_begin: begin; set local role authenticated; select set_config('request.jwt.claim.role','',true), set_config('request.jwt.claim.sub','',true), set_config('request.jwt.claims',json_build_object('role','authenticated','sub','670b5000-0000-4000-8000-0000000000c1')::text,true);
17
+ set_config|set_config|set_config
18
+ ----------+----------+--------------------------------------------------------------------------
19
+ | |{"role" : "authenticated", "sub" : "670b5000-0000-4000-8000-0000000000c1"}
20
+ (1 row)
21
+
22
+ step l_leave: select count(*) as left_rows from agent_board.leave_board('670b5000-0000-4000-8000-000000000020','670b5000-0000-4000-8000-000000000003',jsonb_build_object());
23
+ left_rows
24
+ ---------
25
+ 1
26
+ (1 row)
27
+
28
+ step r_read: select status from agent_board.get_send_outcome('670b5000-0000-4000-8000-000000000012','K','post_board_message');
29
+ status
30
+ ---------
31
+ confirmed
32
+ (1 row)
33
+
34
+ step l_commit: commit;
35
+ step r_read: select status from agent_board.get_send_outcome('670b5000-0000-4000-8000-000000000012','K','post_board_message');
36
+ status
37
+ ---------
38
+ confirmed
39
+ (1 row)
40
+
41
+ step fanout: select (select count(*) from agent_board.delivery_recipients where recipient_agent_id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002')) as deliveries, (select count(*) from agent_board.inbox_items where recipient_agent_id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002')) as inbox, (select count(*) from agent_board.send_outcomes where thread_id = '670b5000-0000-4000-8000-000000000012') as receipts;
42
+ deliveries|inbox|receipts
43
+ ----------+-----+--------
44
+ 2| 2| 1
45
+ (1 row)
46
+
47
+ step check:
48
+ select (select count(*) from agent_board.messages where thread_id in ('670b5000-0000-4000-8000-000000000012')) as messages,
49
+ (select count(*) from agent_board.send_outcomes where thread_id in ('670b5000-0000-4000-8000-000000000012')) as receipts,
50
+ (select string_agg(so.operation || ':' || a.handle, ',' order by so.operation, a.handle) from agent_board.send_outcomes so join agent_board.agents a on a.id = so.author_agent_id where so.thread_id in ('670b5000-0000-4000-8000-000000000012')) as receipt_owners,
51
+ (select string_agg(r.s, ',' order by r.s) from public.so670_iso5_ret r) as returned_by,
52
+ (select count(distinct r.message_id) from public.so670_iso5_ret r) as distinct_returned,
53
+ (select coalesce(bool_and(exists (select 1 from agent_board.send_outcomes so where so.message_id = r.message_id)), false) from public.so670_iso5_ret r) as every_returned_has_receipt;
54
+
55
+ messages|receipts|receipt_owners |returned_by|distinct_returned|every_returned_has_receipt
56
+ --------+--------+---------------------------------+-----------+-----------------+--------------------------
57
+ 1| 1|post_board_message:so670-iso5-x-m|p | 1|t
58
+ (1 row)
59
+
60
+
61
+ starting permutation: p_post fanout d_begin d_delete r_read d_commit r_read fanout check
62
+ set_config
63
+ --------------------------------------------------------------------------
64
+ {"role" : "authenticated", "sub" : "670b5000-0000-4000-8000-0000000000c1"}
65
+ (1 row)
66
+
67
+ step p_post: insert into public.so670_iso5_ret select 'p', message_id from agent_board.post_board_message('670b5000-0000-4000-8000-000000000012','670b5000-0000-4000-8000-000000000003','670b5000-0000-4000-8000-000000000020','iso','so670 body','comment','medium','K',jsonb_build_object());
68
+ step fanout: select (select count(*) from agent_board.delivery_recipients where recipient_agent_id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002')) as deliveries, (select count(*) from agent_board.inbox_items where recipient_agent_id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002')) as inbox, (select count(*) from agent_board.send_outcomes where thread_id = '670b5000-0000-4000-8000-000000000012') as receipts;
69
+ deliveries|inbox|receipts
70
+ ----------+-----+--------
71
+ 2| 2| 1
72
+ (1 row)
73
+
74
+ step d_begin: begin;
75
+ step d_delete: delete from agent_board.messages where thread_id = '670b5000-0000-4000-8000-000000000012';
76
+ step r_read: select status from agent_board.get_send_outcome('670b5000-0000-4000-8000-000000000012','K','post_board_message');
77
+ status
78
+ ---------
79
+ confirmed
80
+ (1 row)
81
+
82
+ step d_commit: commit;
83
+ step r_read: select status from agent_board.get_send_outcome('670b5000-0000-4000-8000-000000000012','K','post_board_message');
84
+ status
85
+ -------
86
+ unknown
87
+ (1 row)
88
+
89
+ step fanout: select (select count(*) from agent_board.delivery_recipients where recipient_agent_id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002')) as deliveries, (select count(*) from agent_board.inbox_items where recipient_agent_id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002')) as inbox, (select count(*) from agent_board.send_outcomes where thread_id = '670b5000-0000-4000-8000-000000000012') as receipts;
90
+ deliveries|inbox|receipts
91
+ ----------+-----+--------
92
+ 0| 0| 0
93
+ (1 row)
94
+
95
+ step check:
96
+ select (select count(*) from agent_board.messages where thread_id in ('670b5000-0000-4000-8000-000000000012')) as messages,
97
+ (select count(*) from agent_board.send_outcomes where thread_id in ('670b5000-0000-4000-8000-000000000012')) as receipts,
98
+ (select string_agg(so.operation || ':' || a.handle, ',' order by so.operation, a.handle) from agent_board.send_outcomes so join agent_board.agents a on a.id = so.author_agent_id where so.thread_id in ('670b5000-0000-4000-8000-000000000012')) as receipt_owners,
99
+ (select string_agg(r.s, ',' order by r.s) from public.so670_iso5_ret r) as returned_by,
100
+ (select count(distinct r.message_id) from public.so670_iso5_ret r) as distinct_returned,
101
+ (select coalesce(bool_and(exists (select 1 from agent_board.send_outcomes so where so.message_id = r.message_id)), false) from public.so670_iso5_ret r) as every_returned_has_receipt;
102
+
103
+ messages|receipts|receipt_owners|returned_by|distinct_returned|every_returned_has_receipt
104
+ --------+--------+--------------+-----------+-----------------+--------------------------
105
+ 0| 0| |p | 1|f
106
+ (1 row)
107
+
@@ -0,0 +1,66 @@
1
+ # #670 D12 spec 6 (D6): one author, one thread, one key, posted concurrently to two different boards.
2
+ # D6 dropped the board from post_board_message's lock key, so the second post waits on the SAME advisory
3
+ # lock as the first (m_lockwait names it). After the first commits, the thread belongs to X, and the
4
+ # second -- addressed to Y -- is refused 42501 'thread belongs to a different board' by
5
+ # _associate_empty_thread (20261026000100) rather than replaying: one message, one receipt. A board in
6
+ # the lock key (D11 M9) still serializes the two on the thread row, but the waiter then waits on that
7
+ # row lock, not the advisory lock, and this trace changes.
8
+ setup
9
+ {
10
+ create table public.so670_iso6_pids(s text primary key, pid int not null);
11
+ create table public.so670_iso6_ret(s text not null, message_id uuid);
12
+ grant select, insert on public.so670_iso6_ret to authenticated, service_role;
13
+ insert into auth.users(id) values ('670b6000-0000-4000-8000-0000000000a1'),('670b6000-0000-4000-8000-0000000000b1'),('670b6000-0000-4000-8000-0000000000c1');
14
+ insert into agent_board.agents(id,agent_type,handle,display_name,status,auth_user_id)
15
+ values ('670b6000-0000-4000-8000-000000000001','agent','so670-iso6-x-a','SO670 iso A','active','670b6000-0000-4000-8000-0000000000a1'),
16
+ ('670b6000-0000-4000-8000-000000000002','agent','so670-iso6-x-b','SO670 iso B','active','670b6000-0000-4000-8000-0000000000b1'),
17
+ ('670b6000-0000-4000-8000-000000000003','agent','so670-iso6-x-m','SO670 iso M','active','670b6000-0000-4000-8000-0000000000c1');
18
+ insert into agent_board.boards(id,slug,name,created_by_agent_id,visibility,status)
19
+ values ('670b6000-0000-4000-8000-000000000020','so670-iso6-x','SO670 iso X','670b6000-0000-4000-8000-000000000001','private','active'),
20
+ ('670b6000-0000-4000-8000-000000000021','so670-iso6-y','SO670 iso Y','670b6000-0000-4000-8000-000000000001','private','active');
21
+ select set_config('request.jwt.claim.role','service_role',false);
22
+ insert into agent_board.board_memberships(board_id,agent_id,membership_state,created_by_agent_id,role)
23
+ values ('670b6000-0000-4000-8000-000000000020','670b6000-0000-4000-8000-000000000001','joined','670b6000-0000-4000-8000-000000000001','owner'),('670b6000-0000-4000-8000-000000000020','670b6000-0000-4000-8000-000000000002','joined','670b6000-0000-4000-8000-000000000001','member'),
24
+ ('670b6000-0000-4000-8000-000000000020','670b6000-0000-4000-8000-000000000003','joined','670b6000-0000-4000-8000-000000000001','member'),('670b6000-0000-4000-8000-000000000021','670b6000-0000-4000-8000-000000000001','joined','670b6000-0000-4000-8000-000000000001','owner');
25
+ select set_config('request.jwt.claim.role','',false);
26
+ insert into agent_board.threads(id,thread_type,created_by_agent_id,subject)
27
+ values ('670b6000-0000-4000-8000-000000000010','coordination','670b6000-0000-4000-8000-000000000001','so670 iso T'),('670b6000-0000-4000-8000-000000000011','coordination','670b6000-0000-4000-8000-000000000001','so670 iso T2'),
28
+ ('670b6000-0000-4000-8000-000000000012','coordination','670b6000-0000-4000-8000-000000000003','so670 iso TM');
29
+ }
30
+ teardown
31
+ {
32
+ delete from agent_board.inbox_items where recipient_agent_id in ('670b6000-0000-4000-8000-000000000001','670b6000-0000-4000-8000-000000000002','670b6000-0000-4000-8000-000000000003');
33
+ delete from agent_board.callback_outbox_events where recipient_agent_id in ('670b6000-0000-4000-8000-000000000001','670b6000-0000-4000-8000-000000000002','670b6000-0000-4000-8000-000000000003');
34
+ delete from agent_board.delivery_recipients where recipient_agent_id in ('670b6000-0000-4000-8000-000000000001','670b6000-0000-4000-8000-000000000002','670b6000-0000-4000-8000-000000000003');
35
+ delete from agent_board.messages where thread_id in ('670b6000-0000-4000-8000-000000000010','670b6000-0000-4000-8000-000000000011','670b6000-0000-4000-8000-000000000012');
36
+ delete from agent_board.threads where id in ('670b6000-0000-4000-8000-000000000010','670b6000-0000-4000-8000-000000000011','670b6000-0000-4000-8000-000000000012');
37
+ delete from agent_board.send_authz_telemetry where actor_agent_id in ('670b6000-0000-4000-8000-000000000001','670b6000-0000-4000-8000-000000000002','670b6000-0000-4000-8000-000000000003');
38
+ delete from agent_board.board_membership_events where board_id in ('670b6000-0000-4000-8000-000000000020','670b6000-0000-4000-8000-000000000021');
39
+ delete from agent_board.boards where id in ('670b6000-0000-4000-8000-000000000020','670b6000-0000-4000-8000-000000000021');
40
+ delete from agent_board.agents where id in ('670b6000-0000-4000-8000-000000000001','670b6000-0000-4000-8000-000000000002','670b6000-0000-4000-8000-000000000003');
41
+ delete from auth.users where id in ('670b6000-0000-4000-8000-0000000000a1','670b6000-0000-4000-8000-0000000000b1','670b6000-0000-4000-8000-0000000000c1');
42
+ drop table public.so670_iso6_pids;
43
+ drop table public.so670_iso6_ret;
44
+ }
45
+ session "p"
46
+ setup { reset role; insert into public.so670_iso6_pids values ('p', pg_backend_pid()) on conflict (s) do update set pid = excluded.pid; }
47
+ step "p_begin" { begin; set local role authenticated; select set_config('request.jwt.claim.role','',true), set_config('request.jwt.claim.sub','',true), set_config('request.jwt.claims',json_build_object('role','authenticated','sub','670b6000-0000-4000-8000-0000000000a1')::text,true); }
48
+ step "p_post" { insert into public.so670_iso6_ret select 'p', message_id from agent_board.post_board_message('670b6000-0000-4000-8000-000000000010','670b6000-0000-4000-8000-000000000001','670b6000-0000-4000-8000-000000000020','iso','so670 body','comment','medium','K',jsonb_build_object()); }
49
+ step "p_commit" { commit; }
50
+ session "w"
51
+ setup { reset role; insert into public.so670_iso6_pids values ('w', pg_backend_pid()) on conflict (s) do update set pid = excluded.pid; }
52
+ step "w_begin" { begin; set local role authenticated; select set_config('request.jwt.claim.role','',true), set_config('request.jwt.claim.sub','',true), set_config('request.jwt.claims',json_build_object('role','authenticated','sub','670b6000-0000-4000-8000-0000000000a1')::text,true); }
53
+ step "w_post_y" { insert into public.so670_iso6_ret select 'w', message_id from agent_board.post_board_message('670b6000-0000-4000-8000-000000000010','670b6000-0000-4000-8000-000000000001','670b6000-0000-4000-8000-000000000021','iso','so670 body','comment','medium','K',jsonb_build_object()); }
54
+ step "w_end" { end; }
55
+ session "m"
56
+ step "m_lockwait" { select l.locktype, l.mode from pg_locks l join public.so670_iso6_pids p on p.pid = l.pid where p.s = 'w' and not l.granted order by 1, 2; }
57
+ session "check"
58
+ step "check" {
59
+ select (select count(*) from agent_board.messages where thread_id in ('670b6000-0000-4000-8000-000000000010')) as messages,
60
+ (select count(*) from agent_board.send_outcomes where thread_id in ('670b6000-0000-4000-8000-000000000010')) as receipts,
61
+ (select string_agg(so.operation || ':' || a.handle, ',' order by so.operation, a.handle) from agent_board.send_outcomes so join agent_board.agents a on a.id = so.author_agent_id where so.thread_id in ('670b6000-0000-4000-8000-000000000010')) as receipt_owners,
62
+ (select string_agg(r.s, ',' order by r.s) from public.so670_iso6_ret r) as returned_by,
63
+ (select count(distinct r.message_id) from public.so670_iso6_ret r) as distinct_returned,
64
+ (select coalesce(bool_and(exists (select 1 from agent_board.send_outcomes so where so.message_id = r.message_id)), false) from public.so670_iso6_ret r) as every_returned_has_receipt;
65
+ }
66
+ permutation "p_begin" "p_post" "w_begin" "w_post_y" "m_lockwait" "p_commit" "w_end" "check"
@@ -0,0 +1,95 @@
1
+ # #670 D12 spec 4: which same-key sends share an idempotency domain and which do not.
2
+ # independent (each mints its own receipt; any wait is the thread row, never the advisory lock):
3
+ # two authors, one key, one thread; one author, one key, post vs direct message; one author,
4
+ # one key, two threads (no wait at all);
5
+ # one domain (the second waits on the ADVISORY lock and replays the first; one receipt):
6
+ # the by-slug addressing overload vs the UUID core; two signing-client session retries with
7
+ # fresh signed_write envelopes;
8
+ # service-only (D4): a signed wrapper as service_role for A never mints. If it goes first, A's
9
+ # session send replays its message and still mints nothing; if A goes first, the wrapper replays.
10
+ # T is seeded in setup with one UNKEYED post (a direct postgres session: service_role, so no receipt):
11
+ # it stamps T to X and delivers to B, which is what gives B (not T's creator) access to T. The seed
12
+ # is the extra message on T in every check row.
13
+ setup
14
+ {
15
+ create table public.so670_iso4_pids(s text primary key, pid int not null);
16
+ create table public.so670_iso4_ret(s text not null, message_id uuid);
17
+ grant select, insert on public.so670_iso4_ret to authenticated, service_role;
18
+ insert into auth.users(id) values ('670b4000-0000-4000-8000-0000000000a1'),('670b4000-0000-4000-8000-0000000000b1'),('670b4000-0000-4000-8000-0000000000c1');
19
+ insert into agent_board.agents(id,agent_type,handle,display_name,status,auth_user_id)
20
+ values ('670b4000-0000-4000-8000-000000000001','agent','so670-iso4-x-a','SO670 iso A','active','670b4000-0000-4000-8000-0000000000a1'),
21
+ ('670b4000-0000-4000-8000-000000000002','agent','so670-iso4-x-b','SO670 iso B','active','670b4000-0000-4000-8000-0000000000b1'),
22
+ ('670b4000-0000-4000-8000-000000000003','agent','so670-iso4-x-m','SO670 iso M','active','670b4000-0000-4000-8000-0000000000c1');
23
+ insert into agent_board.boards(id,slug,name,created_by_agent_id,visibility,status)
24
+ values ('670b4000-0000-4000-8000-000000000020','so670-iso4-x','SO670 iso X','670b4000-0000-4000-8000-000000000001','private','active'),
25
+ ('670b4000-0000-4000-8000-000000000021','so670-iso4-y','SO670 iso Y','670b4000-0000-4000-8000-000000000001','private','active');
26
+ select set_config('request.jwt.claim.role','service_role',false);
27
+ insert into agent_board.board_memberships(board_id,agent_id,membership_state,created_by_agent_id,role)
28
+ values ('670b4000-0000-4000-8000-000000000020','670b4000-0000-4000-8000-000000000001','joined','670b4000-0000-4000-8000-000000000001','owner'),('670b4000-0000-4000-8000-000000000020','670b4000-0000-4000-8000-000000000002','joined','670b4000-0000-4000-8000-000000000001','member'),
29
+ ('670b4000-0000-4000-8000-000000000020','670b4000-0000-4000-8000-000000000003','joined','670b4000-0000-4000-8000-000000000001','member'),('670b4000-0000-4000-8000-000000000021','670b4000-0000-4000-8000-000000000001','joined','670b4000-0000-4000-8000-000000000001','owner');
30
+ select set_config('request.jwt.claim.role','',false);
31
+ insert into agent_board.threads(id,thread_type,created_by_agent_id,subject)
32
+ values ('670b4000-0000-4000-8000-000000000010','coordination','670b4000-0000-4000-8000-000000000001','so670 iso T'),('670b4000-0000-4000-8000-000000000011','coordination','670b4000-0000-4000-8000-000000000001','so670 iso T2'),
33
+ ('670b4000-0000-4000-8000-000000000012','coordination','670b4000-0000-4000-8000-000000000003','so670 iso TM');
34
+ select count(*) as seeded from agent_board.post_board_message('670b4000-0000-4000-8000-000000000010','670b4000-0000-4000-8000-000000000001','670b4000-0000-4000-8000-000000000020','iso','seed','comment','medium',null,jsonb_build_object());
35
+ }
36
+ teardown
37
+ {
38
+ delete from agent_board.inbox_items where recipient_agent_id in ('670b4000-0000-4000-8000-000000000001','670b4000-0000-4000-8000-000000000002','670b4000-0000-4000-8000-000000000003');
39
+ delete from agent_board.callback_outbox_events where recipient_agent_id in ('670b4000-0000-4000-8000-000000000001','670b4000-0000-4000-8000-000000000002','670b4000-0000-4000-8000-000000000003');
40
+ delete from agent_board.delivery_recipients where recipient_agent_id in ('670b4000-0000-4000-8000-000000000001','670b4000-0000-4000-8000-000000000002','670b4000-0000-4000-8000-000000000003');
41
+ delete from agent_board.messages where thread_id in ('670b4000-0000-4000-8000-000000000010','670b4000-0000-4000-8000-000000000011','670b4000-0000-4000-8000-000000000012');
42
+ delete from agent_board.threads where id in ('670b4000-0000-4000-8000-000000000010','670b4000-0000-4000-8000-000000000011','670b4000-0000-4000-8000-000000000012');
43
+ delete from agent_board.send_authz_telemetry where actor_agent_id in ('670b4000-0000-4000-8000-000000000001','670b4000-0000-4000-8000-000000000002','670b4000-0000-4000-8000-000000000003');
44
+ delete from agent_board.board_membership_events where board_id in ('670b4000-0000-4000-8000-000000000020','670b4000-0000-4000-8000-000000000021');
45
+ delete from agent_board.boards where id in ('670b4000-0000-4000-8000-000000000020','670b4000-0000-4000-8000-000000000021');
46
+ delete from agent_board.agents where id in ('670b4000-0000-4000-8000-000000000001','670b4000-0000-4000-8000-000000000002','670b4000-0000-4000-8000-000000000003');
47
+ delete from auth.users where id in ('670b4000-0000-4000-8000-0000000000a1','670b4000-0000-4000-8000-0000000000b1','670b4000-0000-4000-8000-0000000000c1');
48
+ drop table public.so670_iso4_pids;
49
+ drop table public.so670_iso4_ret;
50
+ }
51
+ session "p"
52
+ setup { reset role; insert into public.so670_iso4_pids values ('p', pg_backend_pid()) on conflict (s) do update set pid = excluded.pid; }
53
+ step "p_begin" { begin; set local role authenticated; select set_config('request.jwt.claim.role','',true), set_config('request.jwt.claim.sub','',true), set_config('request.jwt.claims',json_build_object('role','authenticated','sub','670b4000-0000-4000-8000-0000000000a1')::text,true); }
54
+ step "p_post" { insert into public.so670_iso4_ret select 'p', message_id from agent_board.post_board_message('670b4000-0000-4000-8000-000000000010','670b4000-0000-4000-8000-000000000001','670b4000-0000-4000-8000-000000000020','iso','so670 body','comment','medium','K',jsonb_build_object()); }
55
+ step "p_post_env1" { insert into public.so670_iso4_ret select 'p', message_id from agent_board.post_board_message('670b4000-0000-4000-8000-000000000010','670b4000-0000-4000-8000-000000000001','670b4000-0000-4000-8000-000000000020','iso','env 1','comment','medium','K',jsonb_build_object('signed_write',jsonb_build_object('nonce','1'))); }
56
+ step "p_commit" { commit; }
57
+ session "w"
58
+ setup { reset role; insert into public.so670_iso4_pids values ('w', pg_backend_pid()) on conflict (s) do update set pid = excluded.pid; }
59
+ step "w_begin" { begin; set local role authenticated; select set_config('request.jwt.claim.role','',true), set_config('request.jwt.claim.sub','',true), set_config('request.jwt.claims',json_build_object('role','authenticated','sub','670b4000-0000-4000-8000-0000000000a1')::text,true); }
60
+ step "w_dm" { insert into public.so670_iso4_ret select 'w', message_id from agent_board.send_direct_message('670b4000-0000-4000-8000-000000000010','670b4000-0000-4000-8000-000000000001','670b4000-0000-4000-8000-000000000002','iso','dm body','comment','medium','K',jsonb_build_object()); }
61
+ step "w_slug" { insert into public.so670_iso4_ret select 'w', message_id from agent_board.post_board_message('670b4000-0000-4000-8000-000000000010','670b4000-0000-4000-8000-000000000001','so670-iso4-x','addressing_v1','iso','by slug','comment','medium','K',jsonb_build_object()); }
62
+ step "w_post_env2" { insert into public.so670_iso4_ret select 'w', message_id from agent_board.post_board_message('670b4000-0000-4000-8000-000000000010','670b4000-0000-4000-8000-000000000001','670b4000-0000-4000-8000-000000000020','iso','env 2','comment','medium','K',jsonb_build_object('signed_write',jsonb_build_object('nonce','2'))); }
63
+ step "w_post" { insert into public.so670_iso4_ret select 'w', message_id from agent_board.post_board_message('670b4000-0000-4000-8000-000000000010','670b4000-0000-4000-8000-000000000001','670b4000-0000-4000-8000-000000000020','iso','session','comment','medium','K',jsonb_build_object()); }
64
+ step "w_post_t2" { insert into public.so670_iso4_ret select 'w', message_id from agent_board.post_board_message('670b4000-0000-4000-8000-000000000011','670b4000-0000-4000-8000-000000000001','670b4000-0000-4000-8000-000000000020','iso','so670 body','comment','medium','K',jsonb_build_object()); }
65
+ step "w_commit" { commit; }
66
+ session "b"
67
+ setup { reset role; insert into public.so670_iso4_pids values ('b', pg_backend_pid()) on conflict (s) do update set pid = excluded.pid; }
68
+ step "b_begin" { begin; set local role authenticated; select set_config('request.jwt.claim.role','',true), set_config('request.jwt.claim.sub','',true), set_config('request.jwt.claims',json_build_object('role','authenticated','sub','670b4000-0000-4000-8000-0000000000b1')::text,true); }
69
+ step "b_post" { insert into public.so670_iso4_ret select 'b', message_id from agent_board.post_board_message('670b4000-0000-4000-8000-000000000010','670b4000-0000-4000-8000-000000000002','670b4000-0000-4000-8000-000000000020','iso','so670 body','comment','medium','K',jsonb_build_object()); }
70
+ step "b_commit" { commit; }
71
+ session "s"
72
+ setup { insert into public.so670_iso4_pids values ('s', pg_backend_pid()) on conflict (s) do update set pid = excluded.pid; }
73
+ step "s_begin" { begin; set local role service_role; select set_config('request.jwt.claims',json_build_object('role','service_role')::text,true); }
74
+ step "s_signed" { insert into public.so670_iso4_ret select 's', message_id from agent_board.signed_post_board_message(jsonb_build_object('p_thread_id','670b4000-0000-4000-8000-000000000010','p_author_agent_id','670b4000-0000-4000-8000-000000000001','p_board_id','670b4000-0000-4000-8000-000000000020','p_subject','iso','p_body','signed','p_idempotency_key','K'), jsonb_build_object('agent_id','670b4000-0000-4000-8000-000000000001','verification_status','verified','payload_digest','sha256:' || repeat('6',64),'enforcement_mode','warn')); }
75
+ step "s_commit" { commit; }
76
+ session "m"
77
+ step "m_lockwait_b" { select l.locktype, l.mode from pg_locks l join public.so670_iso4_pids p on p.pid = l.pid where p.s = 'b' and not l.granted order by 1, 2; }
78
+ step "m_lockwait_w" { select l.locktype, l.mode from pg_locks l join public.so670_iso4_pids p on p.pid = l.pid where p.s = 'w' and not l.granted order by 1, 2; }
79
+ step "m_lockwait_s" { select l.locktype, l.mode from pg_locks l join public.so670_iso4_pids p on p.pid = l.pid where p.s = 's' and not l.granted order by 1, 2; }
80
+ session "check"
81
+ step "check" {
82
+ select (select count(*) from agent_board.messages where thread_id in ('670b4000-0000-4000-8000-000000000010','670b4000-0000-4000-8000-000000000011')) as messages,
83
+ (select count(*) from agent_board.send_outcomes where thread_id in ('670b4000-0000-4000-8000-000000000010','670b4000-0000-4000-8000-000000000011')) as receipts,
84
+ (select string_agg(so.operation || ':' || a.handle, ',' order by so.operation, a.handle) from agent_board.send_outcomes so join agent_board.agents a on a.id = so.author_agent_id where so.thread_id in ('670b4000-0000-4000-8000-000000000010','670b4000-0000-4000-8000-000000000011')) as receipt_owners,
85
+ (select string_agg(r.s, ',' order by r.s) from public.so670_iso4_ret r) as returned_by,
86
+ (select count(distinct r.message_id) from public.so670_iso4_ret r) as distinct_returned,
87
+ (select coalesce(bool_and(exists (select 1 from agent_board.send_outcomes so where so.message_id = r.message_id)), false) from public.so670_iso4_ret r) as every_returned_has_receipt;
88
+ }
89
+ permutation "p_begin" "p_post" "b_begin" "b_post" "m_lockwait_b" "p_commit" "b_commit" "check"
90
+ permutation "p_begin" "p_post" "w_begin" "w_dm" "m_lockwait_w" "p_commit" "w_commit" "check"
91
+ permutation "p_begin" "p_post" "w_begin" "w_post_t2" "p_commit" "w_commit" "check"
92
+ permutation "p_begin" "p_post" "w_begin" "w_slug" "m_lockwait_w" "p_commit" "w_commit" "check"
93
+ permutation "p_begin" "p_post_env1" "w_begin" "w_post_env2" "m_lockwait_w" "p_commit" "w_commit" "check"
94
+ permutation "s_begin" "s_signed" "w_begin" "w_post" "m_lockwait_w" "s_commit" "w_commit" "check"
95
+ permutation "p_begin" "p_post" "s_begin" "s_signed" "m_lockwait_s" "p_commit" "s_commit" "check"
@@ -0,0 +1,73 @@
1
+ # #670 D12 spec 3: membership removal against the send and the read (author M, member of X, its own thread TM).
2
+ # (1) the send commits, then M leaves X: M's read is still confirmed, and a fresh send with a new key
3
+ # is refused 42501;
4
+ # (2) M leaves first: the send is refused 42501 and no receipt exists, so the read is unknown;
5
+ # (3) removal DURING a lock wait: h holds M's (thread, key) idempotency lock, M's send waits on it,
6
+ # M leaves and commits, h releases, and the send's post-wait access recheck refuses it (42501) --
7
+ # no message, no receipt.
8
+ setup
9
+ {
10
+ create table public.so670_iso3_pids(s text primary key, pid int not null);
11
+ create table public.so670_iso3_ret(s text not null, message_id uuid);
12
+ grant select, insert on public.so670_iso3_ret to authenticated, service_role;
13
+ insert into auth.users(id) values ('670b3000-0000-4000-8000-0000000000a1'),('670b3000-0000-4000-8000-0000000000b1'),('670b3000-0000-4000-8000-0000000000c1');
14
+ insert into agent_board.agents(id,agent_type,handle,display_name,status,auth_user_id)
15
+ values ('670b3000-0000-4000-8000-000000000001','agent','so670-iso3-x-a','SO670 iso A','active','670b3000-0000-4000-8000-0000000000a1'),
16
+ ('670b3000-0000-4000-8000-000000000002','agent','so670-iso3-x-b','SO670 iso B','active','670b3000-0000-4000-8000-0000000000b1'),
17
+ ('670b3000-0000-4000-8000-000000000003','agent','so670-iso3-x-m','SO670 iso M','active','670b3000-0000-4000-8000-0000000000c1');
18
+ insert into agent_board.boards(id,slug,name,created_by_agent_id,visibility,status)
19
+ values ('670b3000-0000-4000-8000-000000000020','so670-iso3-x','SO670 iso X','670b3000-0000-4000-8000-000000000001','private','active'),
20
+ ('670b3000-0000-4000-8000-000000000021','so670-iso3-y','SO670 iso Y','670b3000-0000-4000-8000-000000000001','private','active');
21
+ select set_config('request.jwt.claim.role','service_role',false);
22
+ insert into agent_board.board_memberships(board_id,agent_id,membership_state,created_by_agent_id,role)
23
+ values ('670b3000-0000-4000-8000-000000000020','670b3000-0000-4000-8000-000000000001','joined','670b3000-0000-4000-8000-000000000001','owner'),('670b3000-0000-4000-8000-000000000020','670b3000-0000-4000-8000-000000000002','joined','670b3000-0000-4000-8000-000000000001','member'),
24
+ ('670b3000-0000-4000-8000-000000000020','670b3000-0000-4000-8000-000000000003','joined','670b3000-0000-4000-8000-000000000001','member'),('670b3000-0000-4000-8000-000000000021','670b3000-0000-4000-8000-000000000001','joined','670b3000-0000-4000-8000-000000000001','owner');
25
+ select set_config('request.jwt.claim.role','',false);
26
+ insert into agent_board.threads(id,thread_type,created_by_agent_id,subject)
27
+ values ('670b3000-0000-4000-8000-000000000010','coordination','670b3000-0000-4000-8000-000000000001','so670 iso T'),('670b3000-0000-4000-8000-000000000011','coordination','670b3000-0000-4000-8000-000000000001','so670 iso T2'),
28
+ ('670b3000-0000-4000-8000-000000000012','coordination','670b3000-0000-4000-8000-000000000003','so670 iso TM');
29
+ }
30
+ teardown
31
+ {
32
+ delete from agent_board.inbox_items where recipient_agent_id in ('670b3000-0000-4000-8000-000000000001','670b3000-0000-4000-8000-000000000002','670b3000-0000-4000-8000-000000000003');
33
+ delete from agent_board.callback_outbox_events where recipient_agent_id in ('670b3000-0000-4000-8000-000000000001','670b3000-0000-4000-8000-000000000002','670b3000-0000-4000-8000-000000000003');
34
+ delete from agent_board.delivery_recipients where recipient_agent_id in ('670b3000-0000-4000-8000-000000000001','670b3000-0000-4000-8000-000000000002','670b3000-0000-4000-8000-000000000003');
35
+ delete from agent_board.messages where thread_id in ('670b3000-0000-4000-8000-000000000010','670b3000-0000-4000-8000-000000000011','670b3000-0000-4000-8000-000000000012');
36
+ delete from agent_board.threads where id in ('670b3000-0000-4000-8000-000000000010','670b3000-0000-4000-8000-000000000011','670b3000-0000-4000-8000-000000000012');
37
+ delete from agent_board.send_authz_telemetry where actor_agent_id in ('670b3000-0000-4000-8000-000000000001','670b3000-0000-4000-8000-000000000002','670b3000-0000-4000-8000-000000000003');
38
+ delete from agent_board.board_membership_events where board_id in ('670b3000-0000-4000-8000-000000000020','670b3000-0000-4000-8000-000000000021');
39
+ delete from agent_board.boards where id in ('670b3000-0000-4000-8000-000000000020','670b3000-0000-4000-8000-000000000021');
40
+ delete from agent_board.agents where id in ('670b3000-0000-4000-8000-000000000001','670b3000-0000-4000-8000-000000000002','670b3000-0000-4000-8000-000000000003');
41
+ delete from auth.users where id in ('670b3000-0000-4000-8000-0000000000a1','670b3000-0000-4000-8000-0000000000b1','670b3000-0000-4000-8000-0000000000c1');
42
+ drop table public.so670_iso3_pids;
43
+ drop table public.so670_iso3_ret;
44
+ }
45
+ session "p"
46
+ setup { reset role; insert into public.so670_iso3_pids values ('p', pg_backend_pid()) on conflict (s) do update set pid = excluded.pid; }
47
+ step "p_begin" { begin; set local role authenticated; select set_config('request.jwt.claim.role','',true), set_config('request.jwt.claim.sub','',true), set_config('request.jwt.claims',json_build_object('role','authenticated','sub','670b3000-0000-4000-8000-0000000000c1')::text,true); }
48
+ step "p_post" { insert into public.so670_iso3_ret select 'p', message_id from agent_board.post_board_message('670b3000-0000-4000-8000-000000000012','670b3000-0000-4000-8000-000000000003','670b3000-0000-4000-8000-000000000020','iso','so670 body','comment','medium','K',jsonb_build_object()); }
49
+ step "p_commit" { commit; }
50
+ step "p_end" { end; }
51
+ session "l"
52
+ setup { reset role; insert into public.so670_iso3_pids values ('l', pg_backend_pid()) on conflict (s) do update set pid = excluded.pid; set role authenticated; select set_config('request.jwt.claims',json_build_object('role','authenticated','sub','670b3000-0000-4000-8000-0000000000c1')::text,false); }
53
+ step "l_leave" { select count(*) as left_rows from agent_board.leave_board('670b3000-0000-4000-8000-000000000020','670b3000-0000-4000-8000-000000000003',jsonb_build_object()); }
54
+ step "r_read" { select status from agent_board.get_send_outcome('670b3000-0000-4000-8000-000000000012','K','post_board_message'); }
55
+ step "r_fresh" { insert into public.so670_iso3_ret select 'fresh', message_id from agent_board.post_board_message('670b3000-0000-4000-8000-000000000012','670b3000-0000-4000-8000-000000000003','670b3000-0000-4000-8000-000000000020','iso','so670 body','comment','medium','K2',jsonb_build_object()); }
56
+ session "h"
57
+ step "h_begin" { begin; }
58
+ step "h_lock" { select agent_board._lock_idempotency_key('post_board_message:' || '670b3000-0000-4000-8000-000000000012' || ':' || '670b3000-0000-4000-8000-000000000003', 'K'); }
59
+ step "h_commit" { commit; }
60
+ session "m"
61
+ step "m_lockwait" { select l.locktype, l.mode from pg_locks l join public.so670_iso3_pids p on p.pid = l.pid where p.s = 'p' and not l.granted order by 1, 2; }
62
+ session "check"
63
+ step "check" {
64
+ select (select count(*) from agent_board.messages where thread_id in ('670b3000-0000-4000-8000-000000000012')) as messages,
65
+ (select count(*) from agent_board.send_outcomes where thread_id in ('670b3000-0000-4000-8000-000000000012')) as receipts,
66
+ (select string_agg(so.operation || ':' || a.handle, ',' order by so.operation, a.handle) from agent_board.send_outcomes so join agent_board.agents a on a.id = so.author_agent_id where so.thread_id in ('670b3000-0000-4000-8000-000000000012')) as receipt_owners,
67
+ (select string_agg(r.s, ',' order by r.s) from public.so670_iso3_ret r) as returned_by,
68
+ (select count(distinct r.message_id) from public.so670_iso3_ret r) as distinct_returned,
69
+ (select coalesce(bool_and(exists (select 1 from agent_board.send_outcomes so where so.message_id = r.message_id)), false) from public.so670_iso3_ret r) as every_returned_has_receipt;
70
+ }
71
+ permutation "p_begin" "p_post" "p_commit" "l_leave" "r_read" "r_fresh" "check"
72
+ permutation "l_leave" "p_begin" "p_post" "p_end" "r_read" "check"
73
+ permutation "h_begin" "h_lock" "p_begin" "p_post" "m_lockwait" "l_leave" "h_commit" "p_end" "r_read" "check"
@@ -0,0 +1,69 @@
1
+ # #670 D12 spec 1: two same-author, same-thread, same-board, same-key post_board_message calls.
2
+ # The second waits on the (thread, author, key) advisory idempotency lock -- the lockwait step names the
3
+ # lock it waits on, so removing that lock (D11 M10) changes this trace even though the thread row lock
4
+ # would still serialize the two posts. First commit: the second returns the FIRST transaction's
5
+ # message_id (returned_by p,w with one distinct id), with one message and one receipt; its changed body
6
+ # is the #717-permitted replay (D2), and the replay re-fans out to the board without duplicating B's
7
+ # delivery. First rollback: the second succeeds once, as the only message and receipt.
8
+ setup
9
+ {
10
+ create table public.so670_iso1_pids(s text primary key, pid int not null);
11
+ create table public.so670_iso1_ret(s text not null, message_id uuid);
12
+ grant select, insert on public.so670_iso1_ret to authenticated, service_role;
13
+ insert into auth.users(id) values ('670b1000-0000-4000-8000-0000000000a1'),('670b1000-0000-4000-8000-0000000000b1'),('670b1000-0000-4000-8000-0000000000c1');
14
+ insert into agent_board.agents(id,agent_type,handle,display_name,status,auth_user_id)
15
+ values ('670b1000-0000-4000-8000-000000000001','agent','so670-iso1-x-a','SO670 iso A','active','670b1000-0000-4000-8000-0000000000a1'),
16
+ ('670b1000-0000-4000-8000-000000000002','agent','so670-iso1-x-b','SO670 iso B','active','670b1000-0000-4000-8000-0000000000b1'),
17
+ ('670b1000-0000-4000-8000-000000000003','agent','so670-iso1-x-m','SO670 iso M','active','670b1000-0000-4000-8000-0000000000c1');
18
+ insert into agent_board.boards(id,slug,name,created_by_agent_id,visibility,status)
19
+ values ('670b1000-0000-4000-8000-000000000020','so670-iso1-x','SO670 iso X','670b1000-0000-4000-8000-000000000001','private','active'),
20
+ ('670b1000-0000-4000-8000-000000000021','so670-iso1-y','SO670 iso Y','670b1000-0000-4000-8000-000000000001','private','active');
21
+ select set_config('request.jwt.claim.role','service_role',false);
22
+ insert into agent_board.board_memberships(board_id,agent_id,membership_state,created_by_agent_id,role)
23
+ values ('670b1000-0000-4000-8000-000000000020','670b1000-0000-4000-8000-000000000001','joined','670b1000-0000-4000-8000-000000000001','owner'),('670b1000-0000-4000-8000-000000000020','670b1000-0000-4000-8000-000000000002','joined','670b1000-0000-4000-8000-000000000001','member'),
24
+ ('670b1000-0000-4000-8000-000000000020','670b1000-0000-4000-8000-000000000003','joined','670b1000-0000-4000-8000-000000000001','member'),('670b1000-0000-4000-8000-000000000021','670b1000-0000-4000-8000-000000000001','joined','670b1000-0000-4000-8000-000000000001','owner');
25
+ select set_config('request.jwt.claim.role','',false);
26
+ insert into agent_board.threads(id,thread_type,created_by_agent_id,subject)
27
+ values ('670b1000-0000-4000-8000-000000000010','coordination','670b1000-0000-4000-8000-000000000001','so670 iso T'),('670b1000-0000-4000-8000-000000000011','coordination','670b1000-0000-4000-8000-000000000001','so670 iso T2'),
28
+ ('670b1000-0000-4000-8000-000000000012','coordination','670b1000-0000-4000-8000-000000000003','so670 iso TM');
29
+ }
30
+ teardown
31
+ {
32
+ delete from agent_board.inbox_items where recipient_agent_id in ('670b1000-0000-4000-8000-000000000001','670b1000-0000-4000-8000-000000000002','670b1000-0000-4000-8000-000000000003');
33
+ delete from agent_board.callback_outbox_events where recipient_agent_id in ('670b1000-0000-4000-8000-000000000001','670b1000-0000-4000-8000-000000000002','670b1000-0000-4000-8000-000000000003');
34
+ delete from agent_board.delivery_recipients where recipient_agent_id in ('670b1000-0000-4000-8000-000000000001','670b1000-0000-4000-8000-000000000002','670b1000-0000-4000-8000-000000000003');
35
+ delete from agent_board.messages where thread_id in ('670b1000-0000-4000-8000-000000000010','670b1000-0000-4000-8000-000000000011','670b1000-0000-4000-8000-000000000012');
36
+ delete from agent_board.threads where id in ('670b1000-0000-4000-8000-000000000010','670b1000-0000-4000-8000-000000000011','670b1000-0000-4000-8000-000000000012');
37
+ delete from agent_board.send_authz_telemetry where actor_agent_id in ('670b1000-0000-4000-8000-000000000001','670b1000-0000-4000-8000-000000000002','670b1000-0000-4000-8000-000000000003');
38
+ delete from agent_board.board_membership_events where board_id in ('670b1000-0000-4000-8000-000000000020','670b1000-0000-4000-8000-000000000021');
39
+ delete from agent_board.boards where id in ('670b1000-0000-4000-8000-000000000020','670b1000-0000-4000-8000-000000000021');
40
+ delete from agent_board.agents where id in ('670b1000-0000-4000-8000-000000000001','670b1000-0000-4000-8000-000000000002','670b1000-0000-4000-8000-000000000003');
41
+ delete from auth.users where id in ('670b1000-0000-4000-8000-0000000000a1','670b1000-0000-4000-8000-0000000000b1','670b1000-0000-4000-8000-0000000000c1');
42
+ drop table public.so670_iso1_pids;
43
+ drop table public.so670_iso1_ret;
44
+ }
45
+ session "p"
46
+ setup { reset role; insert into public.so670_iso1_pids values ('p', pg_backend_pid()) on conflict (s) do update set pid = excluded.pid; }
47
+ step "p_begin" { begin; set local role authenticated; select set_config('request.jwt.claim.role','',true), set_config('request.jwt.claim.sub','',true), set_config('request.jwt.claims',json_build_object('role','authenticated','sub','670b1000-0000-4000-8000-0000000000a1')::text,true); }
48
+ step "p_post" { insert into public.so670_iso1_ret select 'p', message_id from agent_board.post_board_message('670b1000-0000-4000-8000-000000000010','670b1000-0000-4000-8000-000000000001','670b1000-0000-4000-8000-000000000020','iso','first body','comment','medium','K',jsonb_build_object()); }
49
+ step "p_commit" { commit; }
50
+ step "p_rollback" { rollback; }
51
+ session "w"
52
+ setup { reset role; insert into public.so670_iso1_pids values ('w', pg_backend_pid()) on conflict (s) do update set pid = excluded.pid; }
53
+ step "w_begin" { begin; set local role authenticated; select set_config('request.jwt.claim.role','',true), set_config('request.jwt.claim.sub','',true), set_config('request.jwt.claims',json_build_object('role','authenticated','sub','670b1000-0000-4000-8000-0000000000a1')::text,true); }
54
+ step "w_post" { insert into public.so670_iso1_ret select 'w', message_id from agent_board.post_board_message('670b1000-0000-4000-8000-000000000010','670b1000-0000-4000-8000-000000000001','670b1000-0000-4000-8000-000000000020','iso','changed retry body','comment','medium','K',jsonb_build_object()); }
55
+ step "w_commit" { commit; }
56
+ session "m"
57
+ step "m_lockwait" { select l.locktype, l.mode from pg_locks l join public.so670_iso1_pids p on p.pid = l.pid where p.s = 'w' and not l.granted order by 1, 2; }
58
+ session "check"
59
+ step "check" {
60
+ select (select count(*) from agent_board.messages where thread_id in ('670b1000-0000-4000-8000-000000000010')) as messages,
61
+ (select count(*) from agent_board.send_outcomes where thread_id in ('670b1000-0000-4000-8000-000000000010')) as receipts,
62
+ (select string_agg(so.operation || ':' || a.handle, ',' order by so.operation, a.handle) from agent_board.send_outcomes so join agent_board.agents a on a.id = so.author_agent_id where so.thread_id in ('670b1000-0000-4000-8000-000000000010')) as receipt_owners,
63
+ (select string_agg(r.s, ',' order by r.s) from public.so670_iso1_ret r) as returned_by,
64
+ (select count(distinct r.message_id) from public.so670_iso1_ret r) as distinct_returned,
65
+ (select coalesce(bool_and(exists (select 1 from agent_board.send_outcomes so where so.message_id = r.message_id)), false) from public.so670_iso1_ret r) as every_returned_has_receipt;
66
+ }
67
+ step "b_deliveries" { select count(*) as b_deliveries from agent_board.delivery_recipients dr join agent_board.messages m on m.id = dr.source_message_id where m.thread_id = '670b1000-0000-4000-8000-000000000010' and dr.recipient_agent_id = '670b1000-0000-4000-8000-000000000002'; }
68
+ permutation "p_begin" "p_post" "w_begin" "w_post" "m_lockwait" "p_commit" "w_commit" "check" "b_deliveries"
69
+ permutation "p_begin" "p_post" "w_begin" "w_post" "m_lockwait" "p_rollback" "w_commit" "check" "b_deliveries"
@@ -0,0 +1,61 @@
1
+ # #670 D12 spec 2: the author reads get_send_outcome before, during and after its own writer commits.
2
+ # Before and during: unknown (the uncommitted receipt is invisible, and the read does not wait for it).
3
+ # After commit: confirmed. A read racing a rollback stays unknown before and after: absence is not a
4
+ # concurrency fence, and unknown never means "not sent".
5
+ setup
6
+ {
7
+ create table public.so670_iso2_pids(s text primary key, pid int not null);
8
+ create table public.so670_iso2_ret(s text not null, message_id uuid);
9
+ grant select, insert on public.so670_iso2_ret to authenticated, service_role;
10
+ insert into auth.users(id) values ('670b2000-0000-4000-8000-0000000000a1'),('670b2000-0000-4000-8000-0000000000b1'),('670b2000-0000-4000-8000-0000000000c1');
11
+ insert into agent_board.agents(id,agent_type,handle,display_name,status,auth_user_id)
12
+ values ('670b2000-0000-4000-8000-000000000001','agent','so670-iso2-x-a','SO670 iso A','active','670b2000-0000-4000-8000-0000000000a1'),
13
+ ('670b2000-0000-4000-8000-000000000002','agent','so670-iso2-x-b','SO670 iso B','active','670b2000-0000-4000-8000-0000000000b1'),
14
+ ('670b2000-0000-4000-8000-000000000003','agent','so670-iso2-x-m','SO670 iso M','active','670b2000-0000-4000-8000-0000000000c1');
15
+ insert into agent_board.boards(id,slug,name,created_by_agent_id,visibility,status)
16
+ values ('670b2000-0000-4000-8000-000000000020','so670-iso2-x','SO670 iso X','670b2000-0000-4000-8000-000000000001','private','active'),
17
+ ('670b2000-0000-4000-8000-000000000021','so670-iso2-y','SO670 iso Y','670b2000-0000-4000-8000-000000000001','private','active');
18
+ select set_config('request.jwt.claim.role','service_role',false);
19
+ insert into agent_board.board_memberships(board_id,agent_id,membership_state,created_by_agent_id,role)
20
+ values ('670b2000-0000-4000-8000-000000000020','670b2000-0000-4000-8000-000000000001','joined','670b2000-0000-4000-8000-000000000001','owner'),('670b2000-0000-4000-8000-000000000020','670b2000-0000-4000-8000-000000000002','joined','670b2000-0000-4000-8000-000000000001','member'),
21
+ ('670b2000-0000-4000-8000-000000000020','670b2000-0000-4000-8000-000000000003','joined','670b2000-0000-4000-8000-000000000001','member'),('670b2000-0000-4000-8000-000000000021','670b2000-0000-4000-8000-000000000001','joined','670b2000-0000-4000-8000-000000000001','owner');
22
+ select set_config('request.jwt.claim.role','',false);
23
+ insert into agent_board.threads(id,thread_type,created_by_agent_id,subject)
24
+ values ('670b2000-0000-4000-8000-000000000010','coordination','670b2000-0000-4000-8000-000000000001','so670 iso T'),('670b2000-0000-4000-8000-000000000011','coordination','670b2000-0000-4000-8000-000000000001','so670 iso T2'),
25
+ ('670b2000-0000-4000-8000-000000000012','coordination','670b2000-0000-4000-8000-000000000003','so670 iso TM');
26
+ }
27
+ teardown
28
+ {
29
+ delete from agent_board.inbox_items where recipient_agent_id in ('670b2000-0000-4000-8000-000000000001','670b2000-0000-4000-8000-000000000002','670b2000-0000-4000-8000-000000000003');
30
+ delete from agent_board.callback_outbox_events where recipient_agent_id in ('670b2000-0000-4000-8000-000000000001','670b2000-0000-4000-8000-000000000002','670b2000-0000-4000-8000-000000000003');
31
+ delete from agent_board.delivery_recipients where recipient_agent_id in ('670b2000-0000-4000-8000-000000000001','670b2000-0000-4000-8000-000000000002','670b2000-0000-4000-8000-000000000003');
32
+ delete from agent_board.messages where thread_id in ('670b2000-0000-4000-8000-000000000010','670b2000-0000-4000-8000-000000000011','670b2000-0000-4000-8000-000000000012');
33
+ delete from agent_board.threads where id in ('670b2000-0000-4000-8000-000000000010','670b2000-0000-4000-8000-000000000011','670b2000-0000-4000-8000-000000000012');
34
+ delete from agent_board.send_authz_telemetry where actor_agent_id in ('670b2000-0000-4000-8000-000000000001','670b2000-0000-4000-8000-000000000002','670b2000-0000-4000-8000-000000000003');
35
+ delete from agent_board.board_membership_events where board_id in ('670b2000-0000-4000-8000-000000000020','670b2000-0000-4000-8000-000000000021');
36
+ delete from agent_board.boards where id in ('670b2000-0000-4000-8000-000000000020','670b2000-0000-4000-8000-000000000021');
37
+ delete from agent_board.agents where id in ('670b2000-0000-4000-8000-000000000001','670b2000-0000-4000-8000-000000000002','670b2000-0000-4000-8000-000000000003');
38
+ delete from auth.users where id in ('670b2000-0000-4000-8000-0000000000a1','670b2000-0000-4000-8000-0000000000b1','670b2000-0000-4000-8000-0000000000c1');
39
+ drop table public.so670_iso2_pids;
40
+ drop table public.so670_iso2_ret;
41
+ }
42
+ session "p"
43
+ setup { reset role; insert into public.so670_iso2_pids values ('p', pg_backend_pid()) on conflict (s) do update set pid = excluded.pid; }
44
+ step "p_begin" { begin; set local role authenticated; select set_config('request.jwt.claim.role','',true), set_config('request.jwt.claim.sub','',true), set_config('request.jwt.claims',json_build_object('role','authenticated','sub','670b2000-0000-4000-8000-0000000000a1')::text,true); }
45
+ step "p_post" { insert into public.so670_iso2_ret select 'p', message_id from agent_board.post_board_message('670b2000-0000-4000-8000-000000000010','670b2000-0000-4000-8000-000000000001','670b2000-0000-4000-8000-000000000020','iso','so670 body','comment','medium','K',jsonb_build_object()); }
46
+ step "p_commit" { commit; }
47
+ step "p_rollback" { rollback; }
48
+ session "r"
49
+ setup { reset role; insert into public.so670_iso2_pids values ('r', pg_backend_pid()) on conflict (s) do update set pid = excluded.pid; set role authenticated; select set_config('request.jwt.claims',json_build_object('role','authenticated','sub','670b2000-0000-4000-8000-0000000000a1')::text,false); }
50
+ step "r_read" { select status from agent_board.get_send_outcome('670b2000-0000-4000-8000-000000000010','K','post_board_message'); }
51
+ session "check"
52
+ step "check" {
53
+ select (select count(*) from agent_board.messages where thread_id in ('670b2000-0000-4000-8000-000000000010')) as messages,
54
+ (select count(*) from agent_board.send_outcomes where thread_id in ('670b2000-0000-4000-8000-000000000010')) as receipts,
55
+ (select string_agg(so.operation || ':' || a.handle, ',' order by so.operation, a.handle) from agent_board.send_outcomes so join agent_board.agents a on a.id = so.author_agent_id where so.thread_id in ('670b2000-0000-4000-8000-000000000010')) as receipt_owners,
56
+ (select string_agg(r.s, ',' order by r.s) from public.so670_iso2_ret r) as returned_by,
57
+ (select count(distinct r.message_id) from public.so670_iso2_ret r) as distinct_returned,
58
+ (select coalesce(bool_and(exists (select 1 from agent_board.send_outcomes so where so.message_id = r.message_id)), false) from public.so670_iso2_ret r) as every_returned_has_receipt;
59
+ }
60
+ permutation "r_read" "p_begin" "p_post" "r_read" "p_commit" "r_read" "check"
61
+ permutation "p_begin" "p_post" "r_read" "p_rollback" "r_read" "check"
@@ -0,0 +1,68 @@
1
+ # #670 D12 spec 5: recovery racing a membership change and a content deletion.
2
+ # (1) M's receipt is committed; while M's own leave is in flight M reads confirmed, and after it
3
+ # commits M still reads confirmed (the read has no membership check and waits on nothing);
4
+ # (2) while a deletion of M's message is in flight the committed receipt still reads confirmed; once
5
+ # the deletion commits the receipt is gone with its message and M reads unknown;
6
+ # the reads write nothing and fan out nothing (fanout counts are equal before and after).
7
+ setup
8
+ {
9
+ create table public.so670_iso5_pids(s text primary key, pid int not null);
10
+ create table public.so670_iso5_ret(s text not null, message_id uuid);
11
+ grant select, insert on public.so670_iso5_ret to authenticated, service_role;
12
+ insert into auth.users(id) values ('670b5000-0000-4000-8000-0000000000a1'),('670b5000-0000-4000-8000-0000000000b1'),('670b5000-0000-4000-8000-0000000000c1');
13
+ insert into agent_board.agents(id,agent_type,handle,display_name,status,auth_user_id)
14
+ values ('670b5000-0000-4000-8000-000000000001','agent','so670-iso5-x-a','SO670 iso A','active','670b5000-0000-4000-8000-0000000000a1'),
15
+ ('670b5000-0000-4000-8000-000000000002','agent','so670-iso5-x-b','SO670 iso B','active','670b5000-0000-4000-8000-0000000000b1'),
16
+ ('670b5000-0000-4000-8000-000000000003','agent','so670-iso5-x-m','SO670 iso M','active','670b5000-0000-4000-8000-0000000000c1');
17
+ insert into agent_board.boards(id,slug,name,created_by_agent_id,visibility,status)
18
+ values ('670b5000-0000-4000-8000-000000000020','so670-iso5-x','SO670 iso X','670b5000-0000-4000-8000-000000000001','private','active'),
19
+ ('670b5000-0000-4000-8000-000000000021','so670-iso5-y','SO670 iso Y','670b5000-0000-4000-8000-000000000001','private','active');
20
+ select set_config('request.jwt.claim.role','service_role',false);
21
+ insert into agent_board.board_memberships(board_id,agent_id,membership_state,created_by_agent_id,role)
22
+ values ('670b5000-0000-4000-8000-000000000020','670b5000-0000-4000-8000-000000000001','joined','670b5000-0000-4000-8000-000000000001','owner'),('670b5000-0000-4000-8000-000000000020','670b5000-0000-4000-8000-000000000002','joined','670b5000-0000-4000-8000-000000000001','member'),
23
+ ('670b5000-0000-4000-8000-000000000020','670b5000-0000-4000-8000-000000000003','joined','670b5000-0000-4000-8000-000000000001','member'),('670b5000-0000-4000-8000-000000000021','670b5000-0000-4000-8000-000000000001','joined','670b5000-0000-4000-8000-000000000001','owner');
24
+ select set_config('request.jwt.claim.role','',false);
25
+ insert into agent_board.threads(id,thread_type,created_by_agent_id,subject)
26
+ values ('670b5000-0000-4000-8000-000000000010','coordination','670b5000-0000-4000-8000-000000000001','so670 iso T'),('670b5000-0000-4000-8000-000000000011','coordination','670b5000-0000-4000-8000-000000000001','so670 iso T2'),
27
+ ('670b5000-0000-4000-8000-000000000012','coordination','670b5000-0000-4000-8000-000000000003','so670 iso TM');
28
+ }
29
+ teardown
30
+ {
31
+ delete from agent_board.inbox_items where recipient_agent_id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002','670b5000-0000-4000-8000-000000000003');
32
+ delete from agent_board.callback_outbox_events where recipient_agent_id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002','670b5000-0000-4000-8000-000000000003');
33
+ delete from agent_board.delivery_recipients where recipient_agent_id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002','670b5000-0000-4000-8000-000000000003');
34
+ delete from agent_board.messages where thread_id in ('670b5000-0000-4000-8000-000000000010','670b5000-0000-4000-8000-000000000011','670b5000-0000-4000-8000-000000000012');
35
+ delete from agent_board.threads where id in ('670b5000-0000-4000-8000-000000000010','670b5000-0000-4000-8000-000000000011','670b5000-0000-4000-8000-000000000012');
36
+ delete from agent_board.send_authz_telemetry where actor_agent_id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002','670b5000-0000-4000-8000-000000000003');
37
+ delete from agent_board.board_membership_events where board_id in ('670b5000-0000-4000-8000-000000000020','670b5000-0000-4000-8000-000000000021');
38
+ delete from agent_board.boards where id in ('670b5000-0000-4000-8000-000000000020','670b5000-0000-4000-8000-000000000021');
39
+ delete from agent_board.agents where id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002','670b5000-0000-4000-8000-000000000003');
40
+ delete from auth.users where id in ('670b5000-0000-4000-8000-0000000000a1','670b5000-0000-4000-8000-0000000000b1','670b5000-0000-4000-8000-0000000000c1');
41
+ drop table public.so670_iso5_pids;
42
+ drop table public.so670_iso5_ret;
43
+ }
44
+ session "p"
45
+ setup { reset role; insert into public.so670_iso5_pids values ('p', pg_backend_pid()) on conflict (s) do update set pid = excluded.pid; set role authenticated; select set_config('request.jwt.claims',json_build_object('role','authenticated','sub','670b5000-0000-4000-8000-0000000000c1')::text,false); }
46
+ step "p_post" { insert into public.so670_iso5_ret select 'p', message_id from agent_board.post_board_message('670b5000-0000-4000-8000-000000000012','670b5000-0000-4000-8000-000000000003','670b5000-0000-4000-8000-000000000020','iso','so670 body','comment','medium','K',jsonb_build_object()); }
47
+ step "r_read" { select status from agent_board.get_send_outcome('670b5000-0000-4000-8000-000000000012','K','post_board_message'); }
48
+ session "l"
49
+ setup { reset role; insert into public.so670_iso5_pids values ('l', pg_backend_pid()) on conflict (s) do update set pid = excluded.pid; }
50
+ step "l_begin" { begin; set local role authenticated; select set_config('request.jwt.claim.role','',true), set_config('request.jwt.claim.sub','',true), set_config('request.jwt.claims',json_build_object('role','authenticated','sub','670b5000-0000-4000-8000-0000000000c1')::text,true); }
51
+ step "l_leave" { select count(*) as left_rows from agent_board.leave_board('670b5000-0000-4000-8000-000000000020','670b5000-0000-4000-8000-000000000003',jsonb_build_object()); }
52
+ step "l_commit" { commit; }
53
+ session "d"
54
+ step "d_begin" { begin; }
55
+ step "d_delete" { delete from agent_board.messages where thread_id = '670b5000-0000-4000-8000-000000000012'; }
56
+ step "d_commit" { commit; }
57
+ session "check"
58
+ step "fanout" { select (select count(*) from agent_board.delivery_recipients where recipient_agent_id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002')) as deliveries, (select count(*) from agent_board.inbox_items where recipient_agent_id in ('670b5000-0000-4000-8000-000000000001','670b5000-0000-4000-8000-000000000002')) as inbox, (select count(*) from agent_board.send_outcomes where thread_id = '670b5000-0000-4000-8000-000000000012') as receipts; }
59
+ step "check" {
60
+ select (select count(*) from agent_board.messages where thread_id in ('670b5000-0000-4000-8000-000000000012')) as messages,
61
+ (select count(*) from agent_board.send_outcomes where thread_id in ('670b5000-0000-4000-8000-000000000012')) as receipts,
62
+ (select string_agg(so.operation || ':' || a.handle, ',' order by so.operation, a.handle) from agent_board.send_outcomes so join agent_board.agents a on a.id = so.author_agent_id where so.thread_id in ('670b5000-0000-4000-8000-000000000012')) as receipt_owners,
63
+ (select string_agg(r.s, ',' order by r.s) from public.so670_iso5_ret r) as returned_by,
64
+ (select count(distinct r.message_id) from public.so670_iso5_ret r) as distinct_returned,
65
+ (select coalesce(bool_and(exists (select 1 from agent_board.send_outcomes so where so.message_id = r.message_id)), false) from public.so670_iso5_ret r) as every_returned_has_receipt;
66
+ }
67
+ permutation "p_post" "fanout" "l_begin" "l_leave" "r_read" "l_commit" "r_read" "fanout" "check"
68
+ permutation "p_post" "fanout" "d_begin" "d_delete" "r_read" "d_commit" "r_read" "fanout" "check"
@@ -0,0 +1,10 @@
1
+ -- every service_role call exempt (early return); must fail R-14 (#62)
2
+ do $m$
3
+ declare d text := pg_get_functiondef('agent_board._require_human_step_up(text)'::regprocedure); n text;
4
+ begin
5
+ n := d;
6
+ if strpos(n, ' -- (a) The operator key') = 0 then raise exception 'MUTATION ANCHOR MISS (1)'; end if;
7
+ n := replace(n, ' -- (a) The operator key', ' if v_service is true then return; end if;
8
+ -- (a) The operator key');
9
+ execute n;
10
+ end $m$;