@consiliency/agent-board-schema 1.79.0 → 1.81.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 (113) hide show
  1. package/fixtures/already-applied.json +8 -0
  2. package/migrations/20261126000100_agent_board_membership_removal_requires_active.sql +243 -0
  3. package/migrations/20261201000100_agent_board_reply_to_message.sql +1241 -0
  4. package/package.json +1 -1
  5. package/schema-manifest.json +21 -3
  6. package/src/tooling.test.mjs +6 -2
  7. package/tests/agent_board_661_reply_delivery.test.sql +12 -12
  8. package/tests/agent_board_667_history_class.test.sql +31 -13
  9. package/tests/agent_board_717_message_replay_scope.test.sql +29 -16
  10. package/tests/agent_board_717_tasking_replay_scope.test.sql +3 -3
  11. package/tests/agent_board_bundle_endpoint_compat.test.sql +2 -2
  12. package/tests/agent_board_canary_signed_fleet_enforcement.test.sql +3 -3
  13. package/tests/agent_board_claim_subject_gate.test.sql +3 -1
  14. package/tests/agent_board_delegate_role_class.test.sql +1 -1
  15. package/tests/agent_board_delivery_writer_execute.test.sql +7 -7
  16. package/tests/agent_board_hosted_delegates.test.sql +3 -3
  17. package/tests/agent_board_inbox_rpcs.test.sql +6 -6
  18. package/tests/agent_board_membership_removal_state.test.sql +228 -0
  19. package/tests/agent_board_refusal_atomicity.test.sql +958 -0
  20. package/tests/agent_board_reply_to.test.sql +874 -0
  21. package/tests/agent_board_scoped_send_regrant.test.sql +8 -8
  22. package/tests/agent_board_send_outcome.test.sql +10 -10
  23. package/tests/agent_board_send_role_gate.test.sql +2 -2
  24. package/tests/agent_board_write_enforcement_class.test.sql +7 -7
  25. package/tests/catalog/function_execute_privileges.json +23 -14
  26. package/tests/catalog/p_metadata_parameters.json +12 -8
  27. package/tests/isolation/expected/reply_parent_vs_thread_delete.out +55 -0
  28. package/tests/isolation/expected/reply_vs_parent_author_delete.out +56 -0
  29. package/tests/isolation/specs/reply_parent_vs_thread_delete.spec +42 -0
  30. package/tests/isolation/specs/reply_vs_parent_author_delete.spec +46 -0
  31. package/tests/mutations/655/M01_no_writer_check.sql +22 -0
  32. package/tests/mutations/655/M02_drop_fk.sql +2 -0
  33. package/tests/mutations/655/M03_existence_only.sql +13 -0
  34. package/tests/mutations/655/M04_distinct_cross_thread_error.sql +17 -0
  35. package/tests/mutations/655/M05_view_no_thread_conjunct.sql +46 -0
  36. package/tests/mutations/655/M06_thread_feed_not_invoker.sql +46 -0
  37. package/tests/mutations/655/M06b_board_feed_not_invoker.sql +49 -0
  38. package/tests/mutations/655/M07_excerpt_via_definer.sql +49 -0
  39. package/tests/mutations/655/M08_excerpt_200.sql +46 -0
  40. package/tests/mutations/655/M09_fk_restrict.sql +4 -0
  41. package/tests/mutations/655/M10_post_message_drops_arg.sql +13 -0
  42. package/tests/mutations/655/M10b_post_message_passes_null.sql +12 -0
  43. package/tests/mutations/655/M11_slug_drops_arg.sql +15 -0
  44. package/tests/mutations/655/M11b_dm_descriptor_positional.sql +31 -0
  45. package/tests/mutations/655/M12_signed_pbm_nine_args.sql +19 -0
  46. package/tests/mutations/655/M12b_signed_mc_one_branch.sql +15 -0
  47. package/tests/mutations/655/M13_undriven_entrypoint.sql +8 -0
  48. package/tests/mutations/655/M14_second_writer.sql +6 -0
  49. package/tests/mutations/655/M15_insert_primitive_public.sql +2 -0
  50. package/tests/mutations/655/M16_comment_missing.sql +2 -0
  51. package/tests/mutations/655/M17_old_allow_set_rows.sql +5 -0
  52. package/tests/mutations/655/M18_board_excerpt_139.sql +49 -0
  53. package/tests/mutations/655/M19_column_in_middle.sql +47 -0
  54. package/tests/mutations/655/M20_projects_parent_id.sql +46 -0
  55. package/tests/mutations/655/M21_replay_applies_new_parent.sql +22 -0
  56. package/tests/mutations/655/M22_fk_not_valid.sql +4 -0
  57. package/tests/mutations/655/MB4a_no_readability.sql +13 -0
  58. package/tests/mutations/655/MB4b_own_readability_message.sql +20 -0
  59. package/tests/mutations/655/MB4c_service_role_reads_all.sql +12 -0
  60. package/tests/mutations/655/MB4d_delegate_uses_authenticated_arm.sql +12 -0
  61. package/tests/mutations/655/MB4f_no_board_member_branch.sql +14 -0
  62. package/tests/mutations/655/MB4g_helper_granted_authenticated.sql +2 -0
  63. package/tests/mutations/655/MB4j_writer_uses_current_agent.sql +12 -0
  64. package/tests/mutations/655/MB4k_delegate_policy_loses_initplan.sql +5 -0
  65. package/tests/mutations/655/MB4l_board_memberships_policy_narrowed.sql +3 -0
  66. package/tests/mutations/655/W1_auth_no_membership_state.sql +13 -0
  67. package/tests/mutations/655/W2_auth_no_agent_binding.sql +13 -0
  68. package/tests/mutations/655/W3_delivery_no_recipient_binding.sql +12 -0
  69. package/tests/mutations/655/W4_delegate_no_board_conjunct.sql +18 -0
  70. package/tests/mutations/655/W5_boardset_no_membership_state.sql +13 -0
  71. package/tests/mutations/655/W6_boardset_no_agent_binding.sql +14 -0
  72. package/tests/mutations/655/run.sh +93 -0
  73. package/tests/mutations/670/M10_lock_removed.sql +2 -2
  74. package/tests/mutations/670/M14_post_message_mints_from_metadata.sql +2 -2
  75. package/tests/mutations/670/M3-DM_helper_on_replay_branch.sql +2 -2
  76. package/tests/mutations/670/M3-MC_helper_on_replay_branch.sql +2 -2
  77. package/tests/mutations/670/M3_helper_on_replay_branch.sql +2 -2
  78. package/tests/mutations/670/M8_delivery_swallows_errors.sql +2 -2
  79. package/tests/mutations/670/M9_lock_key_includes_board.sql +2 -2
  80. package/tests/mutations/670/run.sh +1 -1
  81. package/tests/mutations/717-f1/M10_wrapper_stops_delegating.sql +1 -1
  82. package/tests/mutations/717-f1/M9_public_route_revoked_from_service_role.sql +1 -1
  83. package/tests/mutations/717-f2b/L1_dm_lock_split_by_recipient.sql +2 -2
  84. package/tests/mutations/717-f2b/L2_dm_lock_removed.sql +2 -2
  85. package/tests/mutations/717-f2b/L3_mc_lock_split_by_recipients.sql +2 -2
  86. package/tests/mutations/717-f2b/L4_mc_lock_removed.sql +2 -2
  87. package/tests/mutations/717-f2b/M0_prefix_definitions.sql +1 -1
  88. package/tests/mutations/717-f2b/M10_mc_lookup_any_author.sql +2 -2
  89. package/tests/mutations/717-f2b/M11_dm_swallow_refusal.sql +2 -2
  90. package/tests/mutations/717-f2b/M12_mc_swallow_refusal.sql +2 -2
  91. package/tests/mutations/717-f2b/M15_mc_any_source.sql +1 -1
  92. package/tests/mutations/717-f2b/M1_dm_drop_recipient_proof.sql +2 -2
  93. package/tests/mutations/717-f2b/M2_mc_drop_recipient_proof.sql +2 -2
  94. package/tests/mutations/717-f2b/M3_dm_metadata_as_proof.sql +2 -2
  95. package/tests/mutations/717-f2b/M4_mc_metadata_as_proof.sql +2 -2
  96. package/tests/mutations/717-f2b/M5_dm_any_mode.sql +2 -2
  97. package/tests/mutations/717-f2b/M6_dm_board_delivery_counts.sql +2 -2
  98. package/tests/mutations/717-f2b/M7_mc_any_mode.sql +2 -2
  99. package/tests/mutations/717-f2b/M8_dm_thread_stamp_as_proof.sql +2 -2
  100. package/tests/mutations/717-f2b/M9_dm_lookup_any_author.sql +2 -2
  101. package/tests/mutations/717-f2b/run.sh +2 -2
  102. package/tests/mutations/919/M10_quoted_net_http_post_scratch.sql +5 -0
  103. package/tests/mutations/919/M11_pbm_calls_public.sql +11 -0
  104. package/tests/mutations/919/M1_pbm_refusal_swallowed_after_write.sql +14 -0
  105. package/tests/mutations/919/M2_cof_refusal_swallowed_after_write.sql +13 -0
  106. package/tests/mutations/919/M3_pbm_receipt_fault_swallowed.sql +10 -0
  107. package/tests/mutations/919/M4_pg_notify_scratch.sql +5 -0
  108. package/tests/mutations/919/M5_dynamic_notify_scratch.sql +5 -0
  109. package/tests/mutations/919/M6_trigger_outside_schema.sql +3 -0
  110. package/tests/mutations/919/M7_pbm_step_up_gate.sql +10 -0
  111. package/tests/mutations/919/M8_pbm_positive_writes_nothing.sql +10 -0
  112. package/tests/mutations/919/M9_cof_positive_writes_nothing.sql +10 -0
  113. package/tests/mutations/919/run.sh +81 -0
@@ -66,22 +66,22 @@ $$;
66
66
 
67
67
  -- 1. The 8 core send-RPC overloads are re-granted execute to authenticated. --------
68
68
  select function_privs_are(
69
- 'agent_board', 'send_direct_message', array['uuid','uuid','uuid','text','text','text','text','text','jsonb'],
69
+ 'agent_board', 'send_direct_message', array['uuid','uuid','uuid','text','text','text','text','text','jsonb','uuid'],
70
70
  'authenticated', array['EXECUTE'], 'send_direct_message(uuid recipient) re-granted to authenticated');
71
71
  select function_privs_are(
72
- 'agent_board', 'send_direct_message', array['uuid','uuid','jsonb','text','text','text','text','text','text','jsonb'],
72
+ 'agent_board', 'send_direct_message', array['uuid','uuid','jsonb','text','text','text','text','text','text','jsonb','uuid'],
73
73
  'authenticated', array['EXECUTE'], 'send_direct_message(jsonb descriptor) re-granted to authenticated');
74
74
  select function_privs_are(
75
- 'agent_board', 'send_multicast_message', array['uuid','uuid','uuid[]','text','text','text','text','text','jsonb'],
75
+ 'agent_board', 'send_multicast_message', array['uuid','uuid','uuid[]','text','text','text','text','text','jsonb','uuid'],
76
76
  'authenticated', array['EXECUTE'], 'send_multicast_message(uuid[] recipients) re-granted to authenticated');
77
77
  select function_privs_are(
78
- 'agent_board', 'send_multicast_message', array['uuid','uuid','jsonb','text','text','text','text','text','text','jsonb'],
78
+ 'agent_board', 'send_multicast_message', array['uuid','uuid','jsonb','text','text','text','text','text','text','jsonb','uuid'],
79
79
  'authenticated', array['EXECUTE'], 'send_multicast_message(jsonb descriptors) re-granted to authenticated');
80
80
  select function_privs_are(
81
- 'agent_board', 'post_board_message', array['uuid','uuid','uuid','text','text','text','text','text','jsonb'],
81
+ 'agent_board', 'post_board_message', array['uuid','uuid','uuid','text','text','text','text','text','jsonb','uuid'],
82
82
  'authenticated', array['EXECUTE'], 'post_board_message(uuid board) re-granted to authenticated');
83
83
  select function_privs_are(
84
- 'agent_board', 'post_board_message', array['uuid','uuid','text','text','text','text','text','text','text','jsonb'],
84
+ 'agent_board', 'post_board_message', array['uuid','uuid','text','text','text','text','text','text','text','jsonb','uuid'],
85
85
  'authenticated', array['EXECUTE'], 'post_board_message(text board_slug) re-granted to authenticated');
86
86
  select function_privs_are(
87
87
  'agent_board', 'create_tasking_delivery', array['uuid','uuid','text','text','uuid[]','uuid','text','text','text','jsonb'],
@@ -134,11 +134,11 @@ select set_config('request.jwt.claim.sub', '', true);
134
134
  -- stripped, so a `-- no portal here` note can no longer satisfy them.
135
135
  select ok(
136
136
  position('portal' in lower(agent_board_test.stripped_body(
137
- 'agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)'::regprocedure, true))) = 0,
137
+ 'agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb,uuid)'::regprocedure, true))) = 0,
138
138
  'post_board_message references no Portal issuer/URL');
139
139
  select ok(
140
140
  position('jwks' in lower(agent_board_test.stripped_body(
141
- 'agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)'::regprocedure, true))) = 0,
141
+ 'agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb,uuid)'::regprocedure, true))) = 0,
142
142
  'post_board_message references no JWKS');
143
143
 
144
144
  select finish();
@@ -645,12 +645,12 @@ create temp table _so_fns as select * from pg_temp.so_fns();
645
645
  create temp table _so_class as select * from pg_temp.so_class();
646
646
  create temp table _so_disp(signature text primary key, disposition text not null);
647
647
  insert into _so_disp values
648
- ('post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)', 'MINTS'),
649
- ('send_direct_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)', 'MINTS'),
650
- ('send_multicast_message(uuid,uuid,uuid[],text,text,text,text,text,jsonb)', 'MINTS'),
651
- ('post_board_message(uuid,uuid,text,text,text,text,text,text,text,jsonb)', 'ROUTES'),
652
- ('send_direct_message(uuid,uuid,jsonb,text,text,text,text,text,text,jsonb)', 'ROUTES'),
653
- ('send_multicast_message(uuid,uuid,jsonb,text,text,text,text,text,text,jsonb)', 'ROUTES'),
648
+ ('post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb,uuid)', 'MINTS'),
649
+ ('send_direct_message(uuid,uuid,uuid,text,text,text,text,text,jsonb,uuid)', 'MINTS'),
650
+ ('send_multicast_message(uuid,uuid,uuid[],text,text,text,text,text,jsonb,uuid)', 'MINTS'),
651
+ ('post_board_message(uuid,uuid,text,text,text,text,text,text,text,jsonb,uuid)', 'ROUTES'),
652
+ ('send_direct_message(uuid,uuid,jsonb,text,text,text,text,text,text,jsonb,uuid)', 'ROUTES'),
653
+ ('send_multicast_message(uuid,uuid,jsonb,text,text,text,text,text,text,jsonb,uuid)', 'ROUTES'),
654
654
  ('signed_post_board_message(jsonb,jsonb)', 'SERVICE-ONLY'),
655
655
  ('signed_send_direct_message(jsonb,jsonb)', 'SERVICE-ONLY'),
656
656
  ('signed_send_multicast_message(jsonb,jsonb)', 'SERVICE-ONLY');
@@ -664,7 +664,7 @@ select is(
664
664
  select is(
665
665
  (select string_agg(d.signature || '=' || (f.body ~ agent_board_test.call_re('_record_send_outcome'))::text, ' ' order by d.signature)
666
666
  from _so_disp d join _so_fns f on f.signature = d.signature where d.disposition = 'MINTS'),
667
- 'post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)=true send_direct_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)=true send_multicast_message(uuid,uuid,uuid[],text,text,text,text,text,jsonb)=true',
667
+ 'post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb,uuid)=true send_direct_message(uuid,uuid,uuid,text,text,text,text,text,jsonb,uuid)=true send_multicast_message(uuid,uuid,uuid[],text,text,text,text,text,jsonb,uuid)=true',
668
668
  'SO-D9-2: MINTS: each UUID core calls _record_send_outcome');
669
669
  -- MINTS, behaviourally: exactly one receipt per covered core send, with its operation
670
670
  select is(
@@ -679,7 +679,7 @@ select is(
679
679
  and f.body !~ agent_board_test.call_re('_record_send_outcome')
680
680
  and f.body !~ agent_board_test.writes_any_re(array['send_outcomes']))::text, ' ' order by d.signature)
681
681
  from _so_disp d join _so_fns f on f.signature = d.signature where d.disposition = 'ROUTES'),
682
- 'post_board_message(uuid,uuid,text,text,text,text,text,text,text,jsonb)=true send_direct_message(uuid,uuid,jsonb,text,text,text,text,text,text,jsonb)=true send_multicast_message(uuid,uuid,jsonb,text,text,text,text,text,text,jsonb)=true',
682
+ 'post_board_message(uuid,uuid,text,text,text,text,text,text,text,jsonb,uuid)=true send_direct_message(uuid,uuid,jsonb,text,text,text,text,text,text,jsonb,uuid)=true send_multicast_message(uuid,uuid,jsonb,text,text,text,text,text,text,jsonb,uuid)=true',
683
683
  'SO-D9-4: ROUTES: each addressing overload calls its core and records nothing itself');
684
684
  -- ROUTES, behaviourally: a session send through each overload yields exactly one receipt
685
685
  select pg_temp.put('M.R1', pg_temp.val('A', format($$ select message_id::text from agent_board.post_board_message(%L::uuid, %L::uuid, 'so670-x', 'addressing_v1', 's', 'by slug', 'comment', 'medium', 'KR1', '{}'::jsonb) $$,
@@ -717,7 +717,7 @@ select is(
717
717
  'SO-M15: the only writer of send_outcomes is _record_send_outcome');
718
718
  select is(
719
719
  (select coalesce(string_agg(signature, ' ' order by signature), '(none)') from _so_fns where body ~ agent_board_test.call_re('_record_send_outcome')),
720
- 'post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb) send_direct_message(uuid,uuid,uuid,text,text,text,text,text,jsonb) send_multicast_message(uuid,uuid,uuid[],text,text,text,text,text,jsonb)',
720
+ 'post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb,uuid) send_direct_message(uuid,uuid,uuid,text,text,text,text,text,jsonb,uuid) send_multicast_message(uuid,uuid,uuid[],text,text,text,text,text,jsonb,uuid)',
721
721
  'SO-D9-8: the only callers of _record_send_outcome are the three UUID cores');
722
722
  select is(
723
723
  (select coalesce(string_agg(signature, ' ' order by signature), '(none)') from _so_fns where body ~ agent_board_test.qname_re('send_outcomes')),
@@ -782,7 +782,7 @@ select is(
782
782
  -- D6: the lock domain no longer includes the board
783
783
  -- source-scan: loud-literal a presence over ONE body: a spelling miss turns this red, never green
784
784
  select ok(
785
- agent_board_test.stripped_body('agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)'::regprocedure, true)
785
+ agent_board_test.stripped_body('agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb,uuid)'::regprocedure, true)
786
786
  ~ $re$_lock_idempotency_key\(\s*'post_board_message:'\s*\|\|\s*p_thread_id::text\s*\|\|\s*':'\s*\|\|\s*v_actor_agent_id::text\s*,$re$,
787
787
  'SO-D6: post_board_message locks (thread, actor, key), with no board component');
788
788
  -- every receipt names its own message's author, thread and created_at
@@ -167,13 +167,13 @@ select set_config('request.jwt.claim.role', '', true);
167
167
  -- 5. Enforcement live (MBSESSION): the 8 core sends are re-granted to
168
168
  -- authenticated; the board-role gate asserted above still governs who may send.
169
169
  select function_privs_are(
170
- 'agent_board', 'post_board_message', array['uuid','uuid','uuid','text','text','text','text','text','jsonb'],
170
+ 'agent_board', 'post_board_message', array['uuid','uuid','uuid','text','text','text','text','text','jsonb','uuid'],
171
171
  'authenticated', array['EXECUTE'], 'post_board_message execute is granted to authenticated (scoped send live)');
172
172
  select function_privs_are(
173
173
  'agent_board', 'create_tasking_delivery', array['uuid','uuid','text','text','uuid[]','uuid','text','text','text','jsonb'],
174
174
  'authenticated', array['EXECUTE'], 'create_tasking_delivery execute is granted to authenticated (scoped send live)');
175
175
  select function_privs_are(
176
- 'agent_board', 'send_direct_message', array['uuid','uuid','uuid','text','text','text','text','text','jsonb'],
176
+ 'agent_board', 'send_direct_message', array['uuid','uuid','uuid','text','text','text','text','text','jsonb','uuid'],
177
177
  'authenticated', array['EXECUTE'], 'send_direct_message execute is granted to authenticated (scoped send live)');
178
178
 
179
179
  select finish();
@@ -529,9 +529,9 @@ select is( -- pgtap-allow-raise-checked
529
529
  'agent_board.join_board(uuid,uuid,text,uuid,jsonb)',
530
530
  'agent_board.leave_board(uuid,uuid,jsonb)',
531
531
  'agent_board.mark_read(uuid,uuid,bigint)',
532
- 'agent_board.post_board_message(uuid,uuid,text,text,text,text,text,text,text,jsonb)',
533
- 'agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)',
534
- 'agent_board.post_message(uuid,uuid,text,text,uuid,jsonb)',
532
+ 'agent_board.post_board_message(uuid,uuid,text,text,text,text,text,text,text,jsonb,uuid)',
533
+ 'agent_board.post_board_message(uuid,uuid,uuid,text,text,text,text,text,jsonb,uuid)',
534
+ 'agent_board.post_message(uuid,uuid,text,text,uuid,jsonb,uuid)',
535
535
  'agent_board.provision_agent(text,text,jsonb,uuid)',
536
536
  'agent_board.raise_conflict(uuid,uuid,text,text,text,uuid,jsonb)',
537
537
  'agent_board.raise_escalation(uuid,uuid,text,text,text,uuid,uuid,jsonb)',
@@ -557,10 +557,10 @@ select is( -- pgtap-allow-raise-checked
557
557
  'agent_board.revoke_session_identity(uuid)',
558
558
  'agent_board.rotate_callback_signing_key(uuid,uuid,jsonb)',
559
559
  'agent_board.self_enroll_human(text)',
560
- 'agent_board.send_direct_message(uuid,uuid,jsonb,text,text,text,text,text,text,jsonb)',
561
- 'agent_board.send_direct_message(uuid,uuid,uuid,text,text,text,text,text,jsonb)',
562
- 'agent_board.send_multicast_message(uuid,uuid,jsonb,text,text,text,text,text,text,jsonb)',
563
- 'agent_board.send_multicast_message(uuid,uuid,uuid[],text,text,text,text,text,jsonb)',
560
+ 'agent_board.send_direct_message(uuid,uuid,jsonb,text,text,text,text,text,text,jsonb,uuid)',
561
+ 'agent_board.send_direct_message(uuid,uuid,uuid,text,text,text,text,text,jsonb,uuid)',
562
+ 'agent_board.send_multicast_message(uuid,uuid,jsonb,text,text,text,text,text,text,jsonb,uuid)',
563
+ 'agent_board.send_multicast_message(uuid,uuid,uuid[],text,text,text,text,text,jsonb,uuid)',
564
564
  'agent_board.set_board_authority_ceiling(uuid,text,uuid)',
565
565
  'agent_board.set_board_claim_policy(uuid,text)',
566
566
  'agent_board.set_board_member_label(uuid,uuid,text)',
@@ -10,6 +10,15 @@
10
10
  "authenticated": false
11
11
  }
12
12
  },
13
+ {
14
+ "name": "_actor_can_read_message",
15
+ "signature": "_actor_can_read_message(p_actor_agent_id uuid, p_message_id uuid)",
16
+ "executable_by": {
17
+ "anon": false,
18
+ "service_role": false,
19
+ "authenticated": false
20
+ }
21
+ },
13
22
  {
14
23
  "name": "_actor_fleet_revoked",
15
24
  "signature": "_actor_fleet_revoked(p_actor_agent_id uuid)",
@@ -516,7 +525,7 @@
516
525
  },
517
526
  {
518
527
  "name": "_insert_thread_message",
519
- "signature": "_insert_thread_message(p_thread_id uuid, p_author_agent_id uuid, p_body text, p_message_type text, p_task_id uuid, p_metadata jsonb)",
528
+ "signature": "_insert_thread_message(p_thread_id uuid, p_author_agent_id uuid, p_body text, p_message_type text, p_task_id uuid, p_metadata jsonb, p_reply_to_message_id uuid)",
520
529
  "executable_by": {
521
530
  "anon": false,
522
531
  "service_role": false,
@@ -1542,7 +1551,7 @@
1542
1551
  },
1543
1552
  {
1544
1553
  "name": "post_board_message",
1545
- "signature": "post_board_message(p_thread_id uuid, p_author_agent_id uuid, p_board_id uuid, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb)",
1554
+ "signature": "post_board_message(p_thread_id uuid, p_author_agent_id uuid, p_board_id uuid, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb, p_reply_to_message_id uuid)",
1546
1555
  "executable_by": {
1547
1556
  "anon": false,
1548
1557
  "service_role": true,
@@ -1551,7 +1560,7 @@
1551
1560
  },
1552
1561
  {
1553
1562
  "name": "post_board_message",
1554
- "signature": "post_board_message(p_thread_id uuid, p_author_agent_id uuid, p_board_slug text, p_addressing_mode text, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb)",
1563
+ "signature": "post_board_message(p_thread_id uuid, p_author_agent_id uuid, p_board_slug text, p_addressing_mode text, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb, p_reply_to_message_id uuid)",
1555
1564
  "executable_by": {
1556
1565
  "anon": false,
1557
1566
  "service_role": true,
@@ -1560,7 +1569,7 @@
1560
1569
  },
1561
1570
  {
1562
1571
  "name": "post_message",
1563
- "signature": "post_message(p_thread_id uuid, p_author_agent_id uuid, p_body text, p_message_type text, p_task_id uuid, p_metadata jsonb)",
1572
+ "signature": "post_message(p_thread_id uuid, p_author_agent_id uuid, p_body text, p_message_type text, p_task_id uuid, p_metadata jsonb, p_reply_to_message_id uuid)",
1564
1573
  "executable_by": {
1565
1574
  "anon": false,
1566
1575
  "service_role": true,
@@ -1956,7 +1965,7 @@
1956
1965
  },
1957
1966
  {
1958
1967
  "name": "send_direct_message",
1959
- "signature": "send_direct_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_agent_id uuid, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb)",
1968
+ "signature": "send_direct_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_agent_id uuid, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb, p_reply_to_message_id uuid)",
1960
1969
  "executable_by": {
1961
1970
  "anon": false,
1962
1971
  "service_role": true,
@@ -1965,7 +1974,7 @@
1965
1974
  },
1966
1975
  {
1967
1976
  "name": "send_direct_message",
1968
- "signature": "send_direct_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_descriptor jsonb, p_addressing_mode text, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb)",
1977
+ "signature": "send_direct_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_descriptor jsonb, p_addressing_mode text, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb, p_reply_to_message_id uuid)",
1969
1978
  "executable_by": {
1970
1979
  "anon": false,
1971
1980
  "service_role": true,
@@ -1974,7 +1983,7 @@
1974
1983
  },
1975
1984
  {
1976
1985
  "name": "send_multicast_message",
1977
- "signature": "send_multicast_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_agent_ids uuid[], p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb)",
1986
+ "signature": "send_multicast_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_agent_ids uuid[], p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb, p_reply_to_message_id uuid)",
1978
1987
  "executable_by": {
1979
1988
  "anon": false,
1980
1989
  "service_role": true,
@@ -1983,7 +1992,7 @@
1983
1992
  },
1984
1993
  {
1985
1994
  "name": "send_multicast_message",
1986
- "signature": "send_multicast_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_descriptors jsonb, p_addressing_mode text, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb)",
1995
+ "signature": "send_multicast_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_descriptors jsonb, p_addressing_mode text, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb, p_reply_to_message_id uuid)",
1987
1996
  "executable_by": {
1988
1997
  "anon": false,
1989
1998
  "service_role": true,
@@ -2532,17 +2541,17 @@
2532
2541
  {
2533
2542
  "kind": "rpc",
2534
2543
  "name": "post_board_message",
2535
- "signature": "post_board_message(uuid, uuid, text, text, text, text, text, text, text, jsonb)"
2544
+ "signature": "post_board_message(uuid, uuid, text, text, text, text, text, text, text, jsonb, uuid)"
2536
2545
  },
2537
2546
  {
2538
2547
  "kind": "rpc",
2539
2548
  "name": "post_board_message",
2540
- "signature": "post_board_message(uuid, uuid, uuid, text, text, text, text, text, jsonb)"
2549
+ "signature": "post_board_message(uuid, uuid, uuid, text, text, text, text, text, jsonb, uuid)"
2541
2550
  },
2542
2551
  {
2543
2552
  "kind": "rpc",
2544
2553
  "name": "post_message",
2545
- "signature": "post_message(uuid, uuid, text, text, uuid, jsonb)"
2554
+ "signature": "post_message(uuid, uuid, text, text, uuid, jsonb, uuid)"
2546
2555
  }
2547
2556
  ],
2548
2557
  "executable_functions": [
@@ -2554,9 +2563,9 @@
2554
2563
  "current_agent_id()",
2555
2564
  "get_schema_version()",
2556
2565
  "get_send_outcome(p_thread_id uuid, p_idempotency_key text, p_operation text)",
2557
- "post_board_message(p_thread_id uuid, p_author_agent_id uuid, p_board_id uuid, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb)",
2558
- "post_board_message(p_thread_id uuid, p_author_agent_id uuid, p_board_slug text, p_addressing_mode text, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb)",
2559
- "post_message(p_thread_id uuid, p_author_agent_id uuid, p_body text, p_message_type text, p_task_id uuid, p_metadata jsonb)",
2566
+ "post_board_message(p_thread_id uuid, p_author_agent_id uuid, p_board_id uuid, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb, p_reply_to_message_id uuid)",
2567
+ "post_board_message(p_thread_id uuid, p_author_agent_id uuid, p_board_slug text, p_addressing_mode text, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb, p_reply_to_message_id uuid)",
2568
+ "post_message(p_thread_id uuid, p_author_agent_id uuid, p_body text, p_message_type text, p_task_id uuid, p_metadata jsonb, p_reply_to_message_id uuid)",
2560
2569
  "sync_agent_principal_columns()"
2561
2570
  ],
2562
2571
  "selectable_relations": [
@@ -5,6 +5,10 @@
5
5
  "signature": "_active_board_membership_id(p_board_id uuid, p_agent_id uuid)",
6
6
  "declares_p_metadata": false
7
7
  },
8
+ {
9
+ "signature": "_actor_can_read_message(p_actor_agent_id uuid, p_message_id uuid)",
10
+ "declares_p_metadata": false
11
+ },
8
12
  {
9
13
  "signature": "_actor_fleet_revoked(p_actor_agent_id uuid)",
10
14
  "declares_p_metadata": false
@@ -230,7 +234,7 @@
230
234
  "declares_p_metadata": false
231
235
  },
232
236
  {
233
- "signature": "_insert_thread_message(p_thread_id uuid, p_author_agent_id uuid, p_body text, p_message_type text, p_task_id uuid, p_metadata jsonb)",
237
+ "signature": "_insert_thread_message(p_thread_id uuid, p_author_agent_id uuid, p_body text, p_message_type text, p_task_id uuid, p_metadata jsonb, p_reply_to_message_id uuid)",
234
238
  "declares_p_metadata": true
235
239
  },
236
240
  {
@@ -686,15 +690,15 @@
686
690
  "declares_p_metadata": false
687
691
  },
688
692
  {
689
- "signature": "post_board_message(p_thread_id uuid, p_author_agent_id uuid, p_board_id uuid, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb)",
693
+ "signature": "post_board_message(p_thread_id uuid, p_author_agent_id uuid, p_board_id uuid, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb, p_reply_to_message_id uuid)",
690
694
  "declares_p_metadata": true
691
695
  },
692
696
  {
693
- "signature": "post_board_message(p_thread_id uuid, p_author_agent_id uuid, p_board_slug text, p_addressing_mode text, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb)",
697
+ "signature": "post_board_message(p_thread_id uuid, p_author_agent_id uuid, p_board_slug text, p_addressing_mode text, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb, p_reply_to_message_id uuid)",
694
698
  "declares_p_metadata": true
695
699
  },
696
700
  {
697
- "signature": "post_message(p_thread_id uuid, p_author_agent_id uuid, p_body text, p_message_type text, p_task_id uuid, p_metadata jsonb)",
701
+ "signature": "post_message(p_thread_id uuid, p_author_agent_id uuid, p_body text, p_message_type text, p_task_id uuid, p_metadata jsonb, p_reply_to_message_id uuid)",
698
702
  "declares_p_metadata": true
699
703
  },
700
704
  {
@@ -870,19 +874,19 @@
870
874
  "declares_p_metadata": false
871
875
  },
872
876
  {
873
- "signature": "send_direct_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_agent_id uuid, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb)",
877
+ "signature": "send_direct_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_agent_id uuid, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb, p_reply_to_message_id uuid)",
874
878
  "declares_p_metadata": true
875
879
  },
876
880
  {
877
- "signature": "send_direct_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_descriptor jsonb, p_addressing_mode text, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb)",
881
+ "signature": "send_direct_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_descriptor jsonb, p_addressing_mode text, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb, p_reply_to_message_id uuid)",
878
882
  "declares_p_metadata": true
879
883
  },
880
884
  {
881
- "signature": "send_multicast_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_agent_ids uuid[], p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb)",
885
+ "signature": "send_multicast_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_agent_ids uuid[], p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb, p_reply_to_message_id uuid)",
882
886
  "declares_p_metadata": true
883
887
  },
884
888
  {
885
- "signature": "send_multicast_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_descriptors jsonb, p_addressing_mode text, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb)",
889
+ "signature": "send_multicast_message(p_thread_id uuid, p_author_agent_id uuid, p_recipient_descriptors jsonb, p_addressing_mode text, p_subject text, p_body text, p_message_type text, p_priority text, p_idempotency_key text, p_metadata jsonb, p_reply_to_message_id uuid)",
886
890
  "declares_p_metadata": true
887
891
  },
888
892
  {
@@ -0,0 +1,55 @@
1
+ Parsed test spec with 3 sessions
2
+
3
+ starting permutation: s1_begin s1_reply s2_begin s2_delete s1_end s2_end check
4
+ step s1_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','65540000-0000-4000-8000-0000000000a1')::text,true);
5
+ set_config|set_config|set_config
6
+ ----------+----------+--------------------------------------------------------------------------
7
+ | |{"role" : "authenticated", "sub" : "65540000-0000-4000-8000-0000000000a1"}
8
+ (1 row)
9
+
10
+ step s1_reply: select message_sequence from agent_board.post_message('65540000-0000-4000-8000-000000000010',null,'rt655 iso reply',p_reply_to_message_id=>'65540000-0000-4000-8000-000000000020');
11
+ message_sequence
12
+ ----------------
13
+ 2
14
+ (1 row)
15
+
16
+ step s2_begin: begin;
17
+ step s2_delete: delete from agent_board.threads where id='65540000-0000-4000-8000-000000000010'; <waiting ...>
18
+ step s1_end: end;
19
+ step s2_delete: <... completed>
20
+ step s2_end: end;
21
+ step check:
22
+ select (select count(*) from agent_board.messages where thread_id='65540000-0000-4000-8000-000000000010') as messages,
23
+ (select count(*) from agent_board.messages where reply_to_message_id='65540000-0000-4000-8000-000000000020') as replies,
24
+ (select count(*) from agent_board.threads where id='65540000-0000-4000-8000-000000000010') as threads;
25
+
26
+ messages|replies|threads
27
+ --------+-------+-------
28
+ 0| 0| 0
29
+ (1 row)
30
+
31
+
32
+ starting permutation: s2_begin s2_delete s1_begin s1_reply s2_end s1_end check
33
+ step s2_begin: begin;
34
+ step s2_delete: delete from agent_board.threads where id='65540000-0000-4000-8000-000000000010';
35
+ step s1_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','65540000-0000-4000-8000-0000000000a1')::text,true);
36
+ set_config|set_config|set_config
37
+ ----------+----------+--------------------------------------------------------------------------
38
+ | |{"role" : "authenticated", "sub" : "65540000-0000-4000-8000-0000000000a1"}
39
+ (1 row)
40
+
41
+ step s1_reply: select message_sequence from agent_board.post_message('65540000-0000-4000-8000-000000000010',null,'rt655 iso reply',p_reply_to_message_id=>'65540000-0000-4000-8000-000000000020'); <waiting ...>
42
+ step s2_end: end;
43
+ step s1_reply: <... completed>
44
+ ERROR: thread not found
45
+ step s1_end: end;
46
+ step check:
47
+ select (select count(*) from agent_board.messages where thread_id='65540000-0000-4000-8000-000000000010') as messages,
48
+ (select count(*) from agent_board.messages where reply_to_message_id='65540000-0000-4000-8000-000000000020') as replies,
49
+ (select count(*) from agent_board.threads where id='65540000-0000-4000-8000-000000000010') as threads;
50
+
51
+ messages|replies|threads
52
+ --------+-------+-------
53
+ 0| 0| 0
54
+ (1 row)
55
+
@@ -0,0 +1,56 @@
1
+ Parsed test spec with 3 sessions
2
+
3
+ starting permutation: s1_begin s1_reply s2_begin s2_delete s1_end s2_end check
4
+ step s1_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','65541000-0000-4000-8000-0000000000b1')::text,true);
5
+ set_config|set_config|set_config
6
+ ----------+----------+--------------------------------------------------------------------------
7
+ | |{"role" : "authenticated", "sub" : "65541000-0000-4000-8000-0000000000b1"}
8
+ (1 row)
9
+
10
+ step s1_reply: select message_sequence from agent_board.post_message('65541000-0000-4000-8000-000000000010',null,'rt655 iso2 reply',p_reply_to_message_id=>'65541000-0000-4000-8000-000000000020');
11
+ message_sequence
12
+ ----------------
13
+ 2
14
+ (1 row)
15
+
16
+ step s2_begin: begin;
17
+ step s2_delete: delete from agent_board.messages where author_agent_id='65541000-0000-4000-8000-000000000001'; <waiting ...>
18
+ step s1_end: end;
19
+ step s2_delete: <... completed>
20
+ ERROR: update or delete on table "messages" violates foreign key constraint "messages_reply_to_same_thread_fkey" on table "messages"
21
+ step s2_end: end;
22
+ step check:
23
+ select (select count(*) from agent_board.messages where thread_id='65541000-0000-4000-8000-000000000010') as messages,
24
+ (select count(*) from agent_board.messages m where m.reply_to_message_id is not null
25
+ and not exists (select 1 from agent_board.messages p where p.id = m.reply_to_message_id)) as orphans;
26
+
27
+ messages|orphans
28
+ --------+-------
29
+ 2| 0
30
+ (1 row)
31
+
32
+
33
+ starting permutation: s2_begin s2_delete s1_begin s1_reply s2_end s1_end check
34
+ step s2_begin: begin;
35
+ step s2_delete: delete from agent_board.messages where author_agent_id='65541000-0000-4000-8000-000000000001';
36
+ step s1_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','65541000-0000-4000-8000-0000000000b1')::text,true);
37
+ set_config|set_config|set_config
38
+ ----------+----------+--------------------------------------------------------------------------
39
+ | |{"role" : "authenticated", "sub" : "65541000-0000-4000-8000-0000000000b1"}
40
+ (1 row)
41
+
42
+ step s1_reply: select message_sequence from agent_board.post_message('65541000-0000-4000-8000-000000000010',null,'rt655 iso2 reply',p_reply_to_message_id=>'65541000-0000-4000-8000-000000000020'); <waiting ...>
43
+ step s2_end: end;
44
+ step s1_reply: <... completed>
45
+ ERROR: insert or update on table "messages" violates foreign key constraint "messages_reply_to_same_thread_fkey"
46
+ step s1_end: end;
47
+ step check:
48
+ select (select count(*) from agent_board.messages where thread_id='65541000-0000-4000-8000-000000000010') as messages,
49
+ (select count(*) from agent_board.messages m where m.reply_to_message_id is not null
50
+ and not exists (select 1 from agent_board.messages p where p.id = m.reply_to_message_id)) as orphans;
51
+
52
+ messages|orphans
53
+ --------+-------
54
+ 0| 0
55
+ (1 row)
56
+
@@ -0,0 +1,42 @@
1
+ # #655 (plan §8.7, B1c): a reply racing the deletion of its thread. The reply's composite FK takes a
2
+ # KEY SHARE on the parent message row, and the thread cascade deletes parent and reply in one
3
+ # statement, where NO ACTION is checked at the end of that statement. Whichever session goes first,
4
+ # there is no deadlock and no orphaned reply: either the reply commits and the cascade then removes
5
+ # both rows, or the reply fails after the delete commits. The check step counts what is left.
6
+ setup
7
+ {
8
+ insert into auth.users(id) values ('65540000-0000-4000-8000-0000000000a1');
9
+ insert into agent_board.agents(id,agent_type,handle,display_name,status,auth_user_id)
10
+ values ('65540000-0000-4000-8000-000000000001','agent','rt655-iso-a','RT655 iso A','active','65540000-0000-4000-8000-0000000000a1');
11
+ insert into agent_board.threads(id,thread_type,created_by_agent_id,subject,last_message_sequence)
12
+ values ('65540000-0000-4000-8000-000000000010','coordination','65540000-0000-4000-8000-000000000001','rt655 iso thread',1);
13
+ insert into agent_board.messages(id,thread_id,author_agent_id,message_sequence,body)
14
+ values ('65540000-0000-4000-8000-000000000020','65540000-0000-4000-8000-000000000010','65540000-0000-4000-8000-000000000001',1,'rt655 iso parent');
15
+ }
16
+ teardown
17
+ {
18
+ delete from agent_board.messages where thread_id='65540000-0000-4000-8000-000000000010';
19
+ delete from agent_board.threads where id='65540000-0000-4000-8000-000000000010';
20
+ delete from agent_board.agents where id='65540000-0000-4000-8000-000000000001';
21
+ delete from auth.users where id='65540000-0000-4000-8000-0000000000a1';
22
+ }
23
+ # The replying session is the author A: authenticated role AND matching JSON claims, with the
24
+ # flattened claim GUCs cleared.
25
+ session "s1"
26
+ step "s1_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','65540000-0000-4000-8000-0000000000a1')::text,true); }
27
+ step "s1_reply" { select message_sequence from agent_board.post_message('65540000-0000-4000-8000-000000000010',null,'rt655 iso reply',p_reply_to_message_id=>'65540000-0000-4000-8000-000000000020'); }
28
+ step "s1_end" { end; }
29
+ session "s2"
30
+ step "s2_begin" { begin; }
31
+ step "s2_delete" { delete from agent_board.threads where id='65540000-0000-4000-8000-000000000010'; }
32
+ step "s2_end" { end; }
33
+ session "check"
34
+ step "check" {
35
+ select (select count(*) from agent_board.messages where thread_id='65540000-0000-4000-8000-000000000010') as messages,
36
+ (select count(*) from agent_board.messages where reply_to_message_id='65540000-0000-4000-8000-000000000020') as replies,
37
+ (select count(*) from agent_board.threads where id='65540000-0000-4000-8000-000000000010') as threads;
38
+ }
39
+ # reply first: the delete waits for the reply's commit, then the cascade removes parent and reply
40
+ permutation "s1_begin" "s1_reply" "s2_begin" "s2_delete" "s1_end" "s2_end" "check"
41
+ # delete first: the reply waits for the delete's commit, then fails; nothing is left
42
+ permutation "s2_begin" "s2_delete" "s1_begin" "s1_reply" "s2_end" "s1_end" "check"
@@ -0,0 +1,46 @@
1
+ # #655 (plan §8.7): B's reply to A's message racing an owner deletion of A's messages. The reply's
2
+ # FK check takes a KEY SHARE on the parent row; the single-message delete conflicts with it. Whichever
3
+ # session goes first, there is no deadlock: either the reply commits and the delete is then refused
4
+ # (23503: a replied-to parent cannot be removed alone, plan R-2), or the delete commits and the
5
+ # reply then fails. In no order is a reply left pointing at a missing parent.
6
+ setup
7
+ {
8
+ insert into auth.users(id) values ('65541000-0000-4000-8000-0000000000a1'),('65541000-0000-4000-8000-0000000000b1');
9
+ insert into agent_board.agents(id,agent_type,handle,display_name,status,auth_user_id)
10
+ values ('65541000-0000-4000-8000-000000000001','agent','rt655-iso2-a','RT655 iso2 A','active','65541000-0000-4000-8000-0000000000a1'),
11
+ ('65541000-0000-4000-8000-000000000002','agent','rt655-iso2-b','RT655 iso2 B','active','65541000-0000-4000-8000-0000000000b1');
12
+ insert into agent_board.threads(id,thread_type,created_by_agent_id,subject,last_message_sequence)
13
+ values ('65541000-0000-4000-8000-000000000010','coordination','65541000-0000-4000-8000-000000000002','rt655 iso2 thread',1);
14
+ insert into agent_board.messages(id,thread_id,author_agent_id,message_sequence,body)
15
+ values ('65541000-0000-4000-8000-000000000020','65541000-0000-4000-8000-000000000010','65541000-0000-4000-8000-000000000001',1,'rt655 iso2 parent');
16
+ insert into agent_board.delivery_recipients(delivery_mode,recipient_agent_id,source_kind,source_message_id)
17
+ values ('direct','65541000-0000-4000-8000-000000000002','message','65541000-0000-4000-8000-000000000020');
18
+ }
19
+ teardown
20
+ {
21
+ delete from agent_board.delivery_recipients where source_message_id in (select id from agent_board.messages where thread_id='65541000-0000-4000-8000-000000000010');
22
+ delete from agent_board.messages where thread_id='65541000-0000-4000-8000-000000000010';
23
+ delete from agent_board.threads where id='65541000-0000-4000-8000-000000000010';
24
+ delete from agent_board.agents where id in ('65541000-0000-4000-8000-000000000001','65541000-0000-4000-8000-000000000002');
25
+ delete from auth.users where id in ('65541000-0000-4000-8000-0000000000a1','65541000-0000-4000-8000-0000000000b1');
26
+ }
27
+ # B replies on its own thread: authenticated role AND matching JSON claims, flattened claim GUCs
28
+ # cleared. B can read A's parent as its direct recipient.
29
+ session "s1"
30
+ step "s1_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','65541000-0000-4000-8000-0000000000b1')::text,true); }
31
+ step "s1_reply" { select message_sequence from agent_board.post_message('65541000-0000-4000-8000-000000000010',null,'rt655 iso2 reply',p_reply_to_message_id=>'65541000-0000-4000-8000-000000000020'); }
32
+ step "s1_end" { end; }
33
+ session "s2"
34
+ step "s2_begin" { begin; }
35
+ step "s2_delete" { delete from agent_board.messages where author_agent_id='65541000-0000-4000-8000-000000000001'; }
36
+ step "s2_end" { end; }
37
+ session "check"
38
+ step "check" {
39
+ select (select count(*) from agent_board.messages where thread_id='65541000-0000-4000-8000-000000000010') as messages,
40
+ (select count(*) from agent_board.messages m where m.reply_to_message_id is not null
41
+ and not exists (select 1 from agent_board.messages p where p.id = m.reply_to_message_id)) as orphans;
42
+ }
43
+ # reply first: the delete waits for the reply's commit, then is refused by the FK (23503)
44
+ permutation "s1_begin" "s1_reply" "s2_begin" "s2_delete" "s1_end" "s2_end" "check"
45
+ # delete first: the reply's FK check waits for the delete's commit, then fails
46
+ permutation "s2_begin" "s2_delete" "s1_begin" "s1_reply" "s2_end" "s1_end" "check"
@@ -0,0 +1,22 @@
1
+ -- M-1: remove the writer check (the FK is kept)
2
+ do $m$
3
+ declare
4
+ d text := pg_get_functiondef('agent_board._insert_thread_message(uuid,uuid,text,text,uuid,jsonb,uuid)'::regprocedure);
5
+ a text; r text;
6
+ begin
7
+ a := $a$ if p_reply_to_message_id is not null then
8
+ select pm.id into v_reply_parent_id
9
+ from agent_board.messages pm
10
+ where pm.id = p_reply_to_message_id
11
+ and pm.thread_id = p_thread_id;
12
+ if v_reply_parent_id is null
13
+ or agent_board._actor_can_read_message(v_actor_agent_id, v_reply_parent_id) is not true then
14
+ raise exception 'reply_to_message_id not found in thread' using errcode = '22023';
15
+ end if;
16
+ end if;
17
+ $a$;
18
+ r := $r$$r$;
19
+ if a = '' or (length(d) - length(replace(d, a, ''))) / length(a) <> 1 then raise exception 'MUTATION ANCHOR MISS (M-1)'; end if;
20
+ d := replace(d, a, r);
21
+ execute d;
22
+ end $m$;
@@ -0,0 +1,2 @@
1
+ -- M-2: drop the composite same-thread FK (the writer check is kept)
2
+ alter table agent_board.messages drop constraint messages_reply_to_same_thread_fkey;
@@ -0,0 +1,13 @@
1
+ -- M-3: the check tests existence only (no same-thread conjunct)
2
+ do $m$
3
+ declare
4
+ d text := pg_get_functiondef('agent_board._insert_thread_message(uuid,uuid,text,text,uuid,jsonb,uuid)'::regprocedure);
5
+ a text; r text;
6
+ begin
7
+ a := $a$ where pm.id = p_reply_to_message_id
8
+ and pm.thread_id = p_thread_id;$a$;
9
+ r := $r$ where pm.id = p_reply_to_message_id;$r$;
10
+ if a = '' or (length(d) - length(replace(d, a, ''))) / length(a) <> 1 then raise exception 'MUTATION ANCHOR MISS (M-3)'; end if;
11
+ d := replace(d, a, r);
12
+ execute d;
13
+ end $m$;
@@ -0,0 +1,17 @@
1
+ -- M-4: a distinct error for a parent in another thread
2
+ do $m$
3
+ declare
4
+ d text := pg_get_functiondef('agent_board._insert_thread_message(uuid,uuid,text,text,uuid,jsonb,uuid)'::regprocedure);
5
+ a text; r text;
6
+ begin
7
+ a := $a$ if v_reply_parent_id is null
8
+ or agent_board._actor_can_read_message$a$;
9
+ r := $r$ if v_reply_parent_id is null and exists (select 1 from agent_board.messages x where x.id = p_reply_to_message_id) then
10
+ raise exception 'reply_to_message_id is in another thread' using errcode = '22023';
11
+ end if;
12
+ if v_reply_parent_id is null
13
+ or agent_board._actor_can_read_message$r$;
14
+ if a = '' or (length(d) - length(replace(d, a, ''))) / length(a) <> 1 then raise exception 'MUTATION ANCHOR MISS (M-4)'; end if;
15
+ d := replace(d, a, r);
16
+ execute d;
17
+ end $m$;