@consiliency/agent-board-schema 1.81.0 → 1.84.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 (264) hide show
  1. package/README.md +11 -0
  2. package/fixtures/already-applied.json +12 -0
  3. package/migrations/20261202000100_agent_board_archive_board.sql +1238 -0
  4. package/migrations/20261203000100_agent_board_archive_board_reads.sql +391 -0
  5. package/migrations/20261203000200_agent_board_signed_seat_gates.sql +695 -0
  6. package/package.json +1 -1
  7. package/schema-manifest.json +30 -3
  8. package/src/tooling.test.mjs +8 -2
  9. package/tests/agent_board_667_history_class.test.sql +20 -3
  10. package/tests/agent_board_954_signed_seat_gates.test.sql +472 -0
  11. package/tests/agent_board_archive_board.test.sql +956 -0
  12. package/tests/agent_board_archive_board_reads.test.sql +785 -0
  13. package/tests/agent_board_archive_board_reads_plan.test.sql +56 -0
  14. package/tests/agent_board_atomic_fleet_onboarding.test.sql +2 -0
  15. package/tests/agent_board_board_claim_policy.test.sql +5 -3
  16. package/tests/agent_board_claimpolicy_race.test.sql +8 -6
  17. package/tests/agent_board_fk_lock_edges.test.sql +27 -3
  18. package/tests/agent_board_gatenull_membstate.test.sql +3 -1
  19. package/tests/agent_board_invite_no_downgrade.test.sql +2 -2
  20. package/tests/agent_board_ledger_authority.test.sql +3 -1
  21. package/tests/agent_board_role_guard.test.sql +4 -1
  22. package/tests/agent_board_rolereset.test.sql +5 -4
  23. package/tests/agent_board_room_roster.test.sql +2 -2
  24. package/tests/agent_board_step_up.test.sql +12 -7
  25. package/tests/agent_board_step_up_helper.test.sql +20 -17
  26. package/tests/agent_board_write_enforcement_class.test.sql +2 -1
  27. package/tests/catalog/function_execute_privileges.json +72 -0
  28. package/tests/catalog/p_metadata_parameters.json +32 -0
  29. package/tests/catalog/step_up_gated_closure.json +2 -0
  30. package/tests/isolation/expected/archive_vs_content.out +800 -0
  31. package/tests/isolation/specs/archive_vs_content.spec +128 -0
  32. package/tests/mutations/918/M01_any_role.sql +13 -0
  33. package/tests/mutations/918/M02_departed_owner.sql +13 -0
  34. package/tests/mutations/918/M03_no_fleet_recheck.sql +13 -0
  35. package/tests/mutations/918/M04_no_step_up.sql +13 -0
  36. package/tests/mutations/918/M04b_step_up_archive_only.sql +14 -0
  37. package/tests/mutations/918/M04c_step_up_change_only.sql +17 -0
  38. package/tests/mutations/918/M05_null_flag.sql +12 -0
  39. package/tests/mutations/918/M05b_null_board.sql +12 -0
  40. package/tests/mutations/918/M06_not_idempotent.sql +12 -0
  41. package/tests/mutations/918/M06b_wrong_flag_returned.sql +12 -0
  42. package/tests/mutations/918/M07_create_board_unarchives.sql +15 -0
  43. package/tests/mutations/918/M08_no_moderation.sql +12 -0
  44. package/tests/mutations/918/M08b_any_change.sql +12 -0
  45. package/tests/mutations/918/M09_bootstrap_archived.sql +12 -0
  46. package/tests/mutations/918/M10_drop_artifacts.sql +2 -0
  47. package/tests/mutations/918/M10_drop_board_authority_ceilings.sql +2 -0
  48. package/tests/mutations/918/M10_drop_board_invite_blocks.sql +2 -0
  49. package/tests/mutations/918/M10_drop_board_invite_tokens.sql +3 -0
  50. package/tests/mutations/918/M10_drop_board_memberships.sql +3 -0
  51. package/tests/mutations/918/M10_drop_boards.sql +2 -0
  52. package/tests/mutations/918/M10_drop_callback_subscriptions.sql +3 -0
  53. package/tests/mutations/918/M10_drop_claims.sql +3 -0
  54. package/tests/mutations/918/M10_drop_conflicts.sql +2 -0
  55. package/tests/mutations/918/M10_drop_delegations.sql +2 -0
  56. package/tests/mutations/918/M10_drop_delivery_recipients.sql +2 -0
  57. package/tests/mutations/918/M10_drop_escalations.sql +2 -0
  58. package/tests/mutations/918/M10_drop_fleet_receive_policies.sql +2 -0
  59. package/tests/mutations/918/M10_drop_messages.sql +2 -0
  60. package/tests/mutations/918/M10_drop_task_events.sql +2 -0
  61. package/tests/mutations/918/M10_drop_tasks.sql +2 -0
  62. package/tests/mutations/918/M10_drop_thread_memberships.sql +3 -0
  63. package/tests/mutations/918/M10_drop_threads.sql +2 -0
  64. package/tests/mutations/918/M10i_drop_insert_board_invite_tokens.sql +2 -0
  65. package/tests/mutations/918/M10i_drop_insert_board_memberships.sql +2 -0
  66. package/tests/mutations/918/M10i_drop_insert_callback_subscriptions.sql +2 -0
  67. package/tests/mutations/918/M10i_drop_insert_claims.sql +2 -0
  68. package/tests/mutations/918/M10i_drop_insert_thread_memberships.sql +2 -0
  69. package/tests/mutations/918/M10u_drop_update_board_invite_tokens.sql +2 -0
  70. package/tests/mutations/918/M10u_drop_update_board_memberships.sql +2 -0
  71. package/tests/mutations/918/M10u_drop_update_callback_subscriptions.sql +2 -0
  72. package/tests/mutations/918/M10u_drop_update_claims.sql +2 -0
  73. package/tests/mutations/918/M10u_drop_update_thread_memberships.sql +2 -0
  74. package/tests/mutations/918/M11_artifacts_no_message.sql +10 -0
  75. package/tests/mutations/918/M11_artifacts_no_task.sql +10 -0
  76. package/tests/mutations/918/M11_artifacts_no_task_event.sql +10 -0
  77. package/tests/mutations/918/M11_claims_no_resource_key.sql +10 -0
  78. package/tests/mutations/918/M11_claims_no_thread.sql +10 -0
  79. package/tests/mutations/918/M11_delivery_no_source_message.sql +10 -0
  80. package/tests/mutations/918/M11_delivery_no_source_task.sql +10 -0
  81. package/tests/mutations/918/M12_claims_all.sql +9 -0
  82. package/tests/mutations/918/M13_memberships_all.sql +9 -0
  83. package/tests/mutations/918/M14_tokens_all.sql +9 -0
  84. package/tests/mutations/918/M15_subscriptions_all.sql +9 -0
  85. package/tests/mutations/918/M15b_thread_memberships_all.sql +9 -0
  86. package/tests/mutations/918/M16_messages_update.sql +10 -0
  87. package/tests/mutations/918/M16b_task_events_update.sql +10 -0
  88. package/tests/mutations/918/M17_boards_old_only.sql +10 -0
  89. package/tests/mutations/918/M18_threads_insert_only.sql +10 -0
  90. package/tests/mutations/918/M18b_guard_disabled.sql +2 -0
  91. package/tests/mutations/918/M20_no_clamp_exemption.sql +14 -0
  92. package/tests/mutations/918/M20b_clamp_any_session.sql +14 -0
  93. package/tests/mutations/918/M20c_clamp_raise.sql +13 -0
  94. package/tests/mutations/918/M20d_clamp_other_columns.sql +13 -0
  95. package/tests/mutations/918/M20e_clamp_any_principal.sql +15 -0
  96. package/tests/mutations/918/M20f_clamp_any_identity_row.sql +13 -0
  97. package/tests/mutations/918/M21_ignore_old_row.sql +14 -0
  98. package/tests/mutations/918/M22_never_refuses.sql +12 -0
  99. package/tests/mutations/918/M22b_wrong_sqlstate.sql +12 -0
  100. package/tests/mutations/918/M23_delegate_execute.sql +2 -0
  101. package/tests/mutations/918/M23b_status_oracle.sql +2 -0
  102. package/tests/mutations/918/M24_new_writer.sql +2 -0
  103. package/tests/mutations/918/M24b_new_dynamic_writer.sql +2 -0
  104. package/tests/mutations/918/M24c_second_status_writer.sql +2 -0
  105. package/tests/mutations/918/M24d_new_relation.sql +2 -0
  106. package/tests/mutations/918/M24e_direct_grant.sql +2 -0
  107. package/tests/mutations/918/M25_memberships_dropped_on_archive.sql +10 -0
  108. package/tests/mutations/918/M27_departure_result_only.sql +10 -0
  109. package/tests/mutations/918/M27b_departure_any_role.sql +10 -0
  110. package/tests/mutations/918/M27c_claim_result_only.sql +10 -0
  111. package/tests/mutations/918/M27d_claim_any_thread.sql +10 -0
  112. package/tests/mutations/918/M27e_subscription_result_only.sql +10 -0
  113. package/tests/mutations/918/M28_token_update_not_expiry.sql +8 -0
  114. package/tests/mutations/918/M28_token_update_not_reanchor.sql +8 -0
  115. package/tests/mutations/918/M28_token_update_not_role.sql +8 -0
  116. package/tests/mutations/918/M28_token_update_not_uses.sql +8 -0
  117. package/tests/mutations/918/M28b_revocation_any_edit.sql +10 -0
  118. package/tests/mutations/918/M28c_unrevoke.sql +10 -0
  119. package/tests/mutations/918/M28d_thread_access_agent.sql +10 -0
  120. package/tests/mutations/918/M28e_thread_access_thread.sql +10 -0
  121. package/tests/mutations/918/M28f_thread_access_expiry.sql +10 -0
  122. package/tests/mutations/918/M28g_thread_access_unrevoke.sql +10 -0
  123. package/tests/mutations/918/M29_grant_no_refusal.sql +13 -0
  124. package/tests/mutations/918/M29b_grant_refuses_first.sql +18 -0
  125. package/tests/mutations/918/M30_redeem_no_status.sql +12 -0
  126. package/tests/mutations/918/M30b_redeem_distinct_text.sql +16 -0
  127. package/tests/mutations/918/M31_display_any_status.sql +7 -0
  128. package/tests/mutations/918/M31b_display_not_service.sql +2 -0
  129. package/tests/mutations/918/M32_status_before_authority.sql +15 -0
  130. package/tests/mutations/918/M33_retention_refused.sql +14 -0
  131. package/tests/mutations/918/M33b_retention_any_metadata.sql +14 -0
  132. package/tests/mutations/918/M34_guard_rewrites_board_id.sql +13 -0
  133. package/tests/mutations/918/M34_guard_rewrites_claim_policy.sql +13 -0
  134. package/tests/mutations/918/M34_guard_rewrites_status.sql +13 -0
  135. package/tests/mutations/918/M34d_guard_returns_null.sql +16 -0
  136. package/tests/mutations/918/M34e_guard_rewrites_uppercase.sql +13 -0
  137. package/tests/mutations/918/M34f_guard_select_into_uppercase.sql +13 -0
  138. package/tests/mutations/918/M35_new_resource_kind.sql +3 -0
  139. package/tests/mutations/918/M35b_new_fk_anchor.sql +2 -0
  140. package/tests/mutations/918/M35c_exempt_gains_writer.sql +2 -0
  141. package/tests/mutations/918/M35d_service_role_gains_update.sql +2 -0
  142. package/tests/mutations/918/M36_token_created_at.sql +10 -0
  143. package/tests/mutations/918/M36b_thread_access_created_at.sql +10 -0
  144. package/tests/mutations/918/M37_non_object_refused.sql +14 -0
  145. package/tests/mutations/918/M37b_non_object_any_edit.sql +13 -0
  146. package/tests/mutations/918/M37c_non_object_any_key.sql +13 -0
  147. package/tests/mutations/918/M37d_non_object_partial_mark.sql +13 -0
  148. package/tests/mutations/918/M37e_non_object_result_any_type.sql +13 -0
  149. package/tests/mutations/918/M37f_non_object_any_last_element.sql +13 -0
  150. package/tests/mutations/918/M38_claim_key_free.sql +10 -0
  151. package/tests/mutations/918/M38b_claim_key_verbatim.sql +10 -0
  152. package/tests/mutations/918/M38c_claim_key_canonical_only.sql +10 -0
  153. package/tests/mutations/918/equivalents/M37ef_grid.sql +42 -0
  154. package/tests/mutations/918/isolation/I1_guard_no_lock.sql +13 -0
  155. package/tests/mutations/918/isolation/I2_archive_no_key_update.sql +12 -0
  156. package/tests/mutations/918/isolation/I3_guard_for_update.sql +12 -0
  157. package/tests/mutations/918/isolation/I4_archive_any_isolation.sql +12 -0
  158. package/tests/mutations/918/isolation/I5_redeem_unlocked.sql +12 -0
  159. package/tests/mutations/918/isolation/I6_thread_membership_unlocked.sql +12 -0
  160. package/tests/mutations/918/isolation/I7_thread_membership_for_share.sql +12 -0
  161. package/tests/mutations/918/pr2/R01_inbox_no_filter.sql +9 -0
  162. package/tests/mutations/918/pr2/R01b_inbox_hides_boardless.sql +9 -0
  163. package/tests/mutations/918/pr2/R01d_inbox_requires_readable.sql +9 -0
  164. package/tests/mutations/918/pr2/R01e_inbox_active_too.sql +9 -0
  165. package/tests/mutations/918/pr2/R02_counts_no_filter.sql +9 -0
  166. package/tests/mutations/918/pr2/R02b_counts_hide_boardless.sql +9 -0
  167. package/tests/mutations/918/pr2/R03_dashboard_no_filter.sql +9 -0
  168. package/tests/mutations/918/pr2/R03b_dashboard_hides_boardless.sql +9 -0
  169. package/tests/mutations/918/pr2/R03c_dashboard_tasks.sql +9 -0
  170. package/tests/mutations/918/pr2/R03d_dashboard_calls_helper.sql +9 -0
  171. package/tests/mutations/918/pr2/R04_open_esc_no_filter.sql +9 -0
  172. package/tests/mutations/918/pr2/R04b_open_esc_no_task.sql +9 -0
  173. package/tests/mutations/918/pr2/R04c_open_esc_no_thread.sql +9 -0
  174. package/tests/mutations/918/pr2/R05_ops_esc_no_filter.sql +9 -0
  175. package/tests/mutations/918/pr2/R05b_ops_esc_no_task.sql +9 -0
  176. package/tests/mutations/918/pr2/R05c_ops_esc_no_thread.sql +9 -0
  177. package/tests/mutations/918/pr2/R06_stale_no_filter.sql +9 -0
  178. package/tests/mutations/918/pr2/R06b_stale_no_task.sql +9 -0
  179. package/tests/mutations/918/pr2/R06c_stale_no_thread.sql +9 -0
  180. package/tests/mutations/918/pr2/R06d_stale_no_key.sql +9 -0
  181. package/tests/mutations/918/pr2/R06e_stale_unguarded_cast.sql +9 -0
  182. package/tests/mutations/918/pr2/R07_memberships_filtered.sql +9 -0
  183. package/tests/mutations/918/pr2/R07b_memberships_constant.sql +9 -0
  184. package/tests/mutations/918/pr2/R08a_v_active_claims_filtered.sql +9 -0
  185. package/tests/mutations/918/pr2/R08b_v_board_feed_filtered.sql +9 -0
  186. package/tests/mutations/918/pr2/R08c_task_tree_filtered.sql +5 -0
  187. package/tests/mutations/918/pr2/R08d_thread_feed_filtered.sql +5 -0
  188. package/tests/mutations/918/pr2/R08e_callback_subs_filtered.sql +5 -0
  189. package/tests/mutations/918/pr2/R09_inbox_definer_view.sql +9 -0
  190. package/tests/mutations/918/pr2/R09b_view_grant.sql +2 -0
  191. package/tests/mutations/918/pr2/R09c_view_revoke.sql +2 -0
  192. package/tests/mutations/918/pr2/R09d_column_renamed.sql +2 -0
  193. package/tests/mutations/918/pr2/R10_new_view.sql +2 -0
  194. package/tests/mutations/918/pr2/R10b_new_routine.sql +2 -0
  195. package/tests/mutations/918/pr2/R10c_new_indirect_routine.sql +2 -0
  196. package/tests/mutations/918/pr2/R10d_predicate_returns_rows.sql +2 -0
  197. package/tests/mutations/918/pr2/R10e_overload.sql +3 -0
  198. package/tests/mutations/918/pr2/R10f_execute_root.sql +2 -0
  199. package/tests/mutations/918/pr2/R10g_predicate_array.sql +2 -0
  200. package/tests/mutations/918/pr2/R10h_predicate_domain.sql +2 -0
  201. package/tests/mutations/918/pr2/R10i_polymorphic.sql +2 -0
  202. package/tests/mutations/918/pr2/R10j_predicate_json.sql +2 -0
  203. package/tests/mutations/918/pr2/R10k_foreign_view.sql +2 -0
  204. package/tests/mutations/918/pr2/R10l_foreign_view_transitive.sql +2 -0
  205. package/tests/mutations/918/pr2/R10m_foreign_view_function.sql +2 -0
  206. package/tests/mutations/918/pr2/R10n_foreign_matview.sql +2 -0
  207. package/tests/mutations/918/pr2/R10o_ambiguous_overload.sql +6 -0
  208. package/tests/mutations/918/pr2/R10p_resolved_overload.sql +6 -0
  209. package/tests/mutations/918/pr2/R11_requests_no_filter.sql +9 -0
  210. package/tests/mutations/918/pr2/R11b_requests_hide_all.sql +9 -0
  211. package/tests/mutations/918/pr2/R11c_requests_no_creator.sql +11 -0
  212. package/tests/mutations/918/pr2/R11d_requests_no_pending.sql +9 -0
  213. package/tests/mutations/918/pr2/R11e_requests_any_state.sql +9 -0
  214. package/tests/mutations/918/pr2/R11f_requests_active_too.sql +9 -0
  215. package/tests/mutations/918/pr2/R12_helper_definer.sql +2 -0
  216. package/tests/mutations/918/pr2/R12b_helper_no_thread.sql +11 -0
  217. package/tests/mutations/918/pr2/R12c_helper_no_task.sql +11 -0
  218. package/tests/mutations/918/pr2/R12d_helper_any_board.sql +10 -0
  219. package/tests/mutations/918/pr2/R12e_helper_task_any_board.sql +10 -0
  220. package/tests/mutations/918/pr2/R12f_helper_null.sql +11 -0
  221. package/tests/mutations/918/pr2/R12g_helper_delegate.sql +2 -0
  222. package/tests/mutations/918/pr2/R12h_helper_public.sql +2 -0
  223. package/tests/mutations/918/pr2/R12i_no_generic_plan.sql +2 -0
  224. package/tests/mutations/918/pr2/R13_archive_columns.sql +2 -0
  225. package/tests/mutations/918/pr2/R13b_second_agents_fk.sql +2 -0
  226. package/tests/mutations/918/pr2/R13c_archive_column.sql +2 -0
  227. package/tests/mutations/918/pr2/R15_rls_narrowed.sql +2 -0
  228. package/tests/mutations/918/pr2/R15b_rls_widened.sql +2 -0
  229. package/tests/mutations/918/pr2/R15c_threads_rls_narrowed.sql +2 -0
  230. package/tests/mutations/918/pr2/R16_archive_deletes.sql +10 -0
  231. package/tests/mutations/918/pr2/R16b_archive_marks_read.sql +10 -0
  232. package/tests/mutations/918/pr2/R17_wake_bypasses_inbox.sql +8 -0
  233. package/tests/mutations/918/pr2/R18_directory_archived.sql +7 -0
  234. package/tests/mutations/918/pr2/R19_delegate_ids_active_only.sql +7 -0
  235. package/tests/mutations/918/run.sh +95 -0
  236. package/tests/mutations/954/MA1_resolver_ignores_signer.sql +15 -0
  237. package/tests/mutations/954/MA2_null_actor_resolves_to_signer.sql +22 -0
  238. package/tests/mutations/954/MB1_no_bind.sql +14 -0
  239. package/tests/mutations/954/MC1_context_any_role.sql +15 -0
  240. package/tests/mutations/954/MG1_has_board_access_service_bypass.sql +18 -0
  241. package/tests/mutations/954/MG2_can_send_to_board_service_bypass.sql +18 -0
  242. package/tests/mutations/954/MG3_can_access_thread_service_bypass.sql +18 -0
  243. package/tests/mutations/954/MG4_can_post_to_thread_service_bypass.sql +13 -0
  244. package/tests/mutations/954/MG5_can_access_task_service_bypass.sql +18 -0
  245. package/tests/mutations/954/MG6_can_mutate_task_service_bypass.sql +18 -0
  246. package/tests/mutations/954/MR1_post_board_message_no_release.sql +14 -0
  247. package/tests/mutations/954/MR2_send_direct_message_no_release.sql +14 -0
  248. package/tests/mutations/954/MR3_send_multicast_message_no_release.sql +14 -0
  249. package/tests/mutations/954/MR4_create_tasking_delivery_no_release.sql +14 -0
  250. package/tests/mutations/954/MR5_append_task_event_no_release.sql +14 -0
  251. package/tests/mutations/954/MR6_grant_board_role_no_release.sql +14 -0
  252. package/tests/mutations/954/MR7_set_board_authority_ceiling_no_release.sql +14 -0
  253. package/tests/mutations/954/MW1_post_board_message_unbound.sql +25 -0
  254. package/tests/mutations/954/MW2_send_direct_message_unbound.sql +25 -0
  255. package/tests/mutations/954/MW3_send_multicast_message_unbound.sql +25 -0
  256. package/tests/mutations/954/MW4_create_tasking_delivery_unbound.sql +25 -0
  257. package/tests/mutations/954/MW5_append_task_event_unbound.sql +25 -0
  258. package/tests/mutations/954/MW6_grant_board_role_unbound.sql +25 -0
  259. package/tests/mutations/954/MW7_set_board_authority_ceiling_unbound.sql +25 -0
  260. package/tests/mutations/954/MX1_bind_session_level.sql +13 -0
  261. package/tests/mutations/954/MX2_release_session_level.sql +13 -0
  262. package/tests/mutations/954/run.sh +93 -0
  263. package/tests/seeds/20261202000100_agent_board_archive_board.sql.pre.sql +24 -0
  264. package/tests/seeds/20261203000100_agent_board_archive_board_reads.sql.pre.sql +38 -0
@@ -0,0 +1,391 @@
1
+ -- #918 ARCHIVEBOARD PR-2: an archived board leaves lists, the inbox and the ops counts. Nobody reads
2
+ -- more or less of the rows themselves: no policy, table grant or base relation read changes.
3
+ --
4
+ -- Owner decisions (2026-11-30): members keep READ-ONLY access to an archived board's history; boards
5
+ -- RLS is unchanged. Scope: #933.
6
+ --
7
+ -- THE RULE. A filter never tells a caller anything the caller cannot already select.
8
+ -- * Inbox, counts, dashboard inbox counts, wake recovery: a row is left out for a caller who can read
9
+ -- that board's STATUS (its boards row, under RLS), and for nobody else.
10
+ -- * Escalations and stale claims name a board only through a thread, so a row is left out for a caller
11
+ -- who can read BOTH the board's status AND that thread (or the task and the task's thread) under RLS.
12
+ -- A caller who reads the status but not the thread keeps the row: for example a thread nobody has
13
+ -- posted in, or a creator, invitee or pending requester who is not a member and reads no thread.
14
+ -- * list_my_board_requests is a definer, so it restates the boards policy.
15
+ -- The views are security_invoker and the one helper is SECURITY INVOKER; there is no new definer routine.
16
+ -- The cost: a former member keeps the inbox rows they were already keeping, because they cannot read
17
+ -- whether the board is archived.
18
+ --
19
+ -- WHAT CHANGES
20
+ -- EXPOSE v_board_memberships gains board_status (last column).
21
+ -- EXCLUDE v_agent_inbox (and v_agent_wake_recovery), v_agent_inbox_counts (and v_ops_inbox_backlog),
22
+ -- v_agent_dashboard's two inbox counts, v_open_escalations,
23
+ -- v_ops_open_escalations, v_ops_stale_claims, list_my_board_requests. The rows stay and
24
+ -- come back when the board is un-archived.
25
+ -- NOT DONE: v_agent_dashboard's open_task_count and assigned_open_escalation_count. A task or escalation
26
+ -- names its board only through threads, which agent_board_delegate cannot read, and that view is in its
27
+ -- frozen read closure (HOSTED D4: no threads, and no function call in a granted view).
28
+ -- STAYS READABLE: v_thread_feed, v_board_feed, v_task_tree, v_active_claims, the roster
29
+ -- (list_board_members, list_board_pending_memberships, v_board_memberships), boards. Every other
30
+ -- board-scoped view and read routine is classified, with its reason, in
31
+ -- tests/agent_board_archive_board_reads.test.sql.
32
+ --
33
+ -- DEPLOY. One transaction; lock_timeout is a transaction-local 5 s when the applier left it unset.
34
+ -- CREATE OR REPLACE VIEW takes ACCESS EXCLUSIVE on each of the seven views; no table is locked beyond
35
+ -- ACCESS SHARE (and one row of delegate_allowed_operations is updated). 55P03 or 40P01 aborts with
36
+ -- nothing applied. agent_board.schema_version stays 8 (additive).
37
+
38
+ do $s0$
39
+ begin
40
+ if current_setting('lock_timeout') in ('0', '0ms', '0s') then
41
+ perform set_config('lock_timeout', '5s', true);
42
+ end if;
43
+ end
44
+ $s0$;
45
+
46
+ -- =============================================================================
47
+ -- 1. The thread predicate
48
+ -- =============================================================================
49
+ -- "Is this thread (or this task's thread) on one of these boards?" The views pass the archived boards
50
+ -- the caller can read, computed once per query.
51
+ -- SECURITY INVOKER on purpose: threads and tasks are read under the caller's RLS, so it answers nothing
52
+ -- the caller could not select itself. A definer would be an oracle for a thread's board.
53
+ -- board_id = any(...) is leakproof, so the planner tests it BEFORE the threads policy: the policy's
54
+ -- sub-selects run only for a thread that IS on one of the boards, and not at all when there are none.
55
+ -- plpgsql with plan_cache_mode = force_generic_plan: the tasks and threads policies are expensive to PLAN,
56
+ -- and left to itself plpgsql keeps choosing a custom plan here, that is, re-plans both policies for every
57
+ -- row. The generic plan is planned once per session and role. It is the same plan for any caller of that
58
+ -- role: the policies read the caller's claims when it RUNS, and the plan cache re-plans when the role
59
+ -- changes, which needs the fix for CVE-2024-10976 (PostgreSQL 17.1, 16.5, 15.9, 14.14, 13.17 and 12.21, all
60
+ -- 2024-11-14): on an older minor a cached plan can apply another role's policies. Do not adopt this bundle
61
+ -- on one. Measured in plans/evidence/918/pr2-explain (table.txt; table-no-generic-plan.txt without it).
62
+ create function agent_board._thread_on_board(p_board_ids uuid[], p_thread_id uuid, p_task_id uuid default null)
63
+ returns boolean
64
+ language plpgsql
65
+ stable
66
+ security invoker
67
+ set search_path = ''
68
+ set plan_cache_mode = force_generic_plan
69
+ as $fn$
70
+ begin
71
+ if coalesce(cardinality(p_board_ids), 0) = 0 or (p_thread_id is null and p_task_id is null) then
72
+ return false;
73
+ end if;
74
+ if p_thread_id is not null
75
+ and exists (
76
+ select 1
77
+ from agent_board.threads th
78
+ where th.id = p_thread_id
79
+ and th.board_id = any (p_board_ids)) then
80
+ return true;
81
+ end if;
82
+ return p_task_id is not null
83
+ and exists (
84
+ select 1
85
+ from agent_board.tasks t
86
+ join agent_board.threads th on th.id = t.thread_id
87
+ where t.id = p_task_id
88
+ and th.board_id = any (p_board_ids));
89
+ end;
90
+ $fn$;
91
+
92
+ revoke all on function agent_board._thread_on_board(uuid[], uuid, uuid)
93
+ from public, anon, authenticated, service_role, agent_board_delegate;
94
+ grant execute on function agent_board._thread_on_board(uuid[], uuid, uuid)
95
+ to authenticated, service_role;
96
+ comment on function agent_board._thread_on_board(uuid[], uuid, uuid) is
97
+ 'Consiliency/message-board#918: whether the thread, or the task''s thread, is on one of the named boards, as far as the CALLER can read it: SECURITY INVOKER, so threads and tasks are read under the caller''s RLS and it answers nothing the caller could not select. False for an empty or NULL board list, and for a NULL, unknown, unreadable or board-less thread. The read views pass the archived boards the caller can read, to leave out work nobody can act on. plan_cache_mode = force_generic_plan is load-bearing for speed: without it the tasks and threads policies are re-planned for every row.';
98
+
99
+ -- =============================================================================
100
+ -- 2. Views
101
+ -- =============================================================================
102
+ -- Each is pg_get_viewdef of the 1.82.0 tree plus only the #918-marked edit. security_invoker is
103
+ -- restated because CREATE OR REPLACE VIEW resets reloptions; it keeps the owner, the grants and the
104
+ -- column order (a new column may only be appended).
105
+
106
+ -- 2a. The inbox. v_agent_wake_recovery selects from it and inherits the filter.
107
+ create or replace view agent_board.v_agent_inbox with (security_invoker = true) as
108
+ SELECT ii.id AS inbox_item_id,
109
+ ii.delivery_recipient_id,
110
+ ii.recipient_agent_id,
111
+ recipient.handle AS recipient_handle,
112
+ recipient.display_name AS recipient_display_name,
113
+ ii.board_id,
114
+ b.slug AS board_slug,
115
+ b.name AS board_name,
116
+ ii.delivery_mode,
117
+ ii.source_kind,
118
+ ii.source_message_id,
119
+ ii.source_task_id,
120
+ ii.source_delegation_id,
121
+ ii.subject,
122
+ ii.preview,
123
+ ii.priority,
124
+ ii.action_state,
125
+ ii.visible_in_board_feed,
126
+ ii.fetch_descriptor,
127
+ ii.created_at,
128
+ ii.updated_at
129
+ FROM agent_board.inbox_items ii
130
+ JOIN agent_board.agents recipient ON recipient.id = ii.recipient_agent_id
131
+ LEFT JOIN agent_board.boards b ON b.id = ii.board_id
132
+ WHERE ii.visible_in_inbox = true
133
+ -- #918: the archived boards the caller can read, computed once per query (InitPlan), not per row; a
134
+ -- condition on the joined boards row would evaluate boards RLS for every inbox row before a LIMIT.
135
+ -- A row with no board (direct, multicast, tasking to named recipients) is never in the list.
136
+ AND (ii.board_id = any (coalesce((select array_agg(b.id) from agent_board.boards b where b.status = 'archived'), '{}'::uuid[]))) is not true;
137
+ comment on view agent_board.v_agent_inbox is
138
+ 'Per-agent inbox triage rows. security_invoker. #918: a row whose board is archived is excluded for a caller who can read that board''s row (boards RLS); it returns when the board is un-archived. A row with no board is unaffected.';
139
+
140
+ -- 2b. The counts. v_ops_inbox_backlog selects from it and inherits the filter.
141
+ create or replace view agent_board.v_agent_inbox_counts with (security_invoker = true) as
142
+ SELECT recipient_agent_id,
143
+ count(*) FILTER (WHERE action_state = ANY (ARRAY['new'::text, 'restored'::text])) AS unread_count,
144
+ count(*) FILTER (WHERE action_state = ANY (ARRAY['new'::text, 'restored'::text, 'deferred'::text])) AS pending_action_count,
145
+ count(*) AS total_visible_count,
146
+ max(updated_at) AS latest_inbox_updated_at
147
+ FROM agent_board.inbox_items ii
148
+ WHERE visible_in_inbox = true
149
+ -- #918: the archived boards the caller can read, computed once per query (InitPlan), not per row.
150
+ AND (ii.board_id = any (coalesce((select array_agg(b.id) from agent_board.boards b where b.status = 'archived'), '{}'::uuid[]))) is not true
151
+ GROUP BY recipient_agent_id;
152
+ comment on view agent_board.v_agent_inbox_counts is
153
+ 'Per-agent inbox counts over exactly the rows v_agent_inbox returns to the same caller. security_invoker. #918: rows on an archived board the caller can read are not counted.';
154
+
155
+ -- 2c. The dashboard's two inbox counts. Not open_task_count / assigned_open_escalation_count (see NOT
156
+ -- DONE above), active_claim_count (a claim on an archived board still holds its resource and can still
157
+ -- be released) or latest_* (the agent's own last activity: history, not a list).
158
+ create or replace view agent_board.v_agent_dashboard with (security_invoker = true) as
159
+ SELECT a.id AS agent_id,
160
+ a.handle,
161
+ a.display_name,
162
+ a.status AS participant_status,
163
+ p.availability,
164
+ p.thread_id AS presence_thread_id,
165
+ p.last_heartbeat_at,
166
+ p.expires_at AS presence_expires_at,
167
+ COALESCE(open_tasks.open_task_count, 0::bigint) AS open_task_count,
168
+ COALESCE(active_claims.active_claim_count, 0::bigint) AS active_claim_count,
169
+ COALESCE(open_escalations.assigned_open_escalation_count, 0::bigint) AS assigned_open_escalation_count,
170
+ latest.task_id AS latest_task_id,
171
+ latest.event_sequence AS latest_task_event_sequence,
172
+ latest.event_type AS latest_task_event_type,
173
+ latest.payload ->> 'kind'::text AS latest_task_event_kind,
174
+ latest.updated_at AS latest_task_updated_at,
175
+ COALESCE(inbox_counts.inbox_unread_count, 0::bigint) AS inbox_unread_count,
176
+ COALESCE(inbox_counts.inbox_pending_action_count, 0::bigint) AS inbox_pending_action_count,
177
+ latest_sig.verification_status AS latest_signature_verification_status,
178
+ latest_sig.key_fingerprint AS latest_signature_key_fingerprint,
179
+ latest_sig.key_version AS latest_signature_key_version,
180
+ latest_sig.algorithm AS latest_signature_algorithm,
181
+ latest_sig.verified_at AS latest_signature_verified_at,
182
+ latest_sig.failure_class AS latest_signature_failure_class
183
+ FROM agent_board.agents a
184
+ LEFT JOIN agent_board.presence p ON p.agent_id = a.id
185
+ LEFT JOIN LATERAL ( SELECT count(*) AS open_task_count
186
+ FROM agent_board.tasks t
187
+ WHERE t.assigned_agent_id = a.id AND (t.status = ANY (ARRAY['pending'::text, 'in_progress'::text, 'blocked'::text]))) open_tasks ON true
188
+ LEFT JOIN LATERAL ( SELECT count(*) AS active_claim_count
189
+ FROM agent_board.claims c
190
+ WHERE c.agent_id = a.id AND c.status = 'active'::text AND c.released_at IS NULL AND c.lease_expires_at > now()) active_claims ON true
191
+ LEFT JOIN LATERAL ( SELECT count(*) AS assigned_open_escalation_count
192
+ FROM agent_board.escalations e
193
+ WHERE e.assigned_agent_id = a.id AND (e.status = ANY (ARRAY['open'::text, 'acknowledged'::text]))) open_escalations ON true
194
+ LEFT JOIN LATERAL ( SELECT count(*) FILTER (WHERE ii.action_state = ANY (ARRAY['new'::text, 'restored'::text])) AS inbox_unread_count,
195
+ count(*) FILTER (WHERE ii.action_state = ANY (ARRAY['new'::text, 'restored'::text, 'deferred'::text])) AS inbox_pending_action_count
196
+ FROM agent_board.inbox_items ii
197
+ WHERE ii.recipient_agent_id = a.id AND ii.visible_in_inbox = true
198
+ -- #918
199
+ AND (ii.board_id = any (coalesce((select array_agg(b.id) from agent_board.boards b where b.status = 'archived'), '{}'::uuid[]))) is not true) inbox_counts ON true
200
+ LEFT JOIN LATERAL ( SELECT t.id AS task_id,
201
+ te.id AS task_event_id,
202
+ te.event_sequence,
203
+ te.event_type,
204
+ te.payload,
205
+ t.updated_at
206
+ FROM agent_board.tasks t
207
+ LEFT JOIN agent_board.task_events te ON te.task_id = t.id
208
+ WHERE t.assigned_agent_id = a.id OR t.created_by_agent_id = a.id
209
+ ORDER BY t.updated_at DESC, te.event_sequence DESC NULLS LAST
210
+ LIMIT 1) latest ON true
211
+ LEFT JOIN LATERAL ( SELECT se.verification_status,
212
+ ask.fingerprint AS key_fingerprint,
213
+ se.key_version,
214
+ se.algorithm,
215
+ se.verified_at,
216
+ se.failure_class
217
+ FROM agent_board.signature_evidence se
218
+ LEFT JOIN agent_board.agent_signing_keys ask ON ask.id = se.signing_key_id
219
+ WHERE se.source_kind = 'task_event'::text AND se.source_task_event_id = latest.task_event_id
220
+ ORDER BY se.created_at DESC
221
+ LIMIT 1) latest_sig ON true;
222
+ comment on view agent_board.v_agent_dashboard is
223
+ 'One row per agent with work counts. security_invoker. #918: inbox_unread_count and inbox_pending_action_count leave out items on an archived board the caller can read, as v_agent_inbox_counts does. Task, claim and escalation counts and latest_* are unchanged.';
224
+
225
+ -- 2d. Open escalations.
226
+ create or replace view agent_board.v_open_escalations with (security_invoker = true) as
227
+ SELECT e.id AS escalation_id,
228
+ e.thread_id,
229
+ e.task_id,
230
+ e.raised_by_agent_id,
231
+ raised.handle AS raised_by_handle,
232
+ e.assigned_agent_id,
233
+ assigned.handle AS assigned_agent_handle,
234
+ e.escalation_type,
235
+ e.severity,
236
+ e.status,
237
+ e.summary,
238
+ e.details,
239
+ e.created_at,
240
+ e.updated_at,
241
+ e.acknowledged_at,
242
+ t.status AS task_status
243
+ FROM agent_board.escalations e
244
+ JOIN agent_board.agents raised ON raised.id = e.raised_by_agent_id
245
+ LEFT JOIN agent_board.agents assigned ON assigned.id = e.assigned_agent_id
246
+ LEFT JOIN agent_board.tasks t ON t.id = e.task_id
247
+ WHERE (e.status = ANY (ARRAY['open'::text, 'acknowledged'::text]))
248
+ -- #918: the escalation's thread, and its task's thread.
249
+ AND NOT agent_board._thread_on_board(coalesce((select array_agg(b.id) from agent_board.boards b where b.status = 'archived'), '{}'::uuid[]), e.thread_id, e.task_id);
250
+ comment on view agent_board.v_open_escalations is
251
+ 'Open and acknowledged escalations. security_invoker. #918: an escalation whose thread, or whose task''s thread, is on an archived board is excluded for a caller who can read both the board''s status and that thread (following a task needs the task row and its thread, both readable); it returns when the board is un-archived.';
252
+
253
+ -- 2e. Open escalations.
254
+ create or replace view agent_board.v_ops_open_escalations with (security_invoker = true) as
255
+ SELECT e.id AS escalation_id,
256
+ e.task_id,
257
+ e.thread_id,
258
+ e.severity,
259
+ e.status,
260
+ e.summary,
261
+ e.assigned_agent_id,
262
+ assignee.handle AS assigned_agent_handle,
263
+ round(EXTRACT(epoch FROM now() - e.created_at) / 3600.0, 2) AS age_hours,
264
+ e.created_at
265
+ FROM agent_board.escalations e
266
+ LEFT JOIN agent_board.agents assignee ON assignee.id = e.assigned_agent_id
267
+ WHERE (e.status = ANY (ARRAY['open'::text, 'acknowledged'::text]))
268
+ -- #918: the escalation's thread, and its task's thread.
269
+ AND NOT agent_board._thread_on_board(coalesce((select array_agg(b.id) from agent_board.boards b where b.status = 'archived'), '{}'::uuid[]), e.thread_id, e.task_id);
270
+ comment on view agent_board.v_ops_open_escalations is
271
+ 'Open and acknowledged escalations. security_invoker. #918: an escalation whose thread, or whose task''s thread, is on an archived board is excluded for a caller who can read both the board''s status and that thread (following a task needs the task row and its thread, both readable); it returns when the board is un-archived.';
272
+
273
+ -- 2f. Stale claims.
274
+ create or replace view agent_board.v_ops_stale_claims with (security_invoker = true) as
275
+ SELECT c.id AS claim_id,
276
+ c.task_id,
277
+ c.thread_id,
278
+ c.agent_id,
279
+ a.handle AS agent_handle,
280
+ c.resource_kind,
281
+ c.resource_key,
282
+ round(EXTRACT(epoch FROM now() - c.created_at) / 3600.0, 2) AS stale_hours,
283
+ c.lease_expires_at,
284
+ c.created_at
285
+ FROM agent_board.claims c
286
+ JOIN agent_board.agents a ON a.id = c.agent_id
287
+ WHERE c.status = 'active'::text AND c.released_at IS NULL AND c.lease_expires_at < now()
288
+ -- #918: the claim's thread, its task, and the task a 'task' claim names in resource_key, as
289
+ -- trg_archived_board_guard resolves them.
290
+ AND NOT agent_board._thread_on_board(coalesce((select array_agg(b.id) from agent_board.boards b where b.status = 'archived'), '{}'::uuid[]), c.thread_id, c.task_id)
291
+ AND NOT agent_board._thread_on_board(coalesce((select array_agg(b.id) from agent_board.boards b where b.status = 'archived'), '{}'::uuid[]), NULL::uuid,
292
+ CASE WHEN c.resource_kind = 'task'::text
293
+ AND c.resource_key ~ '^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$'::text
294
+ THEN c.resource_key::uuid END);
295
+ comment on view agent_board.v_ops_stale_claims is
296
+ 'Active claims past their lease. security_invoker. #918: a claim whose thread, task''s thread, or resource_key''s task''s thread is on an archived board is excluded for a caller who can read both the board''s status and that thread (following a task needs the task row and its thread, both readable); v_active_claims is not filtered, because such a claim still holds its resource.';
297
+
298
+ -- 2g. Memberships gain the board's status, last. No row is filtered: members keep their rooms.
299
+ create or replace view agent_board.v_board_memberships with (security_invoker = true) as
300
+ SELECT bm.id AS board_membership_id,
301
+ bm.board_id,
302
+ b.slug AS board_slug,
303
+ b.name AS board_name,
304
+ bm.agent_id,
305
+ a.handle AS agent_handle,
306
+ a.display_name AS agent_display_name,
307
+ bm.membership_state,
308
+ bm.created_by_agent_id,
309
+ creator.handle AS created_by_handle,
310
+ bm.left_at,
311
+ bm.created_at,
312
+ bm.updated_at,
313
+ bm.role,
314
+ -- #918
315
+ b.status AS board_status
316
+ FROM agent_board.board_memberships bm
317
+ JOIN agent_board.boards b ON b.id = bm.board_id
318
+ JOIN agent_board.agents a ON a.id = bm.agent_id
319
+ LEFT JOIN agent_board.agents creator ON creator.id = bm.created_by_agent_id;
320
+ comment on view agent_board.v_board_memberships is
321
+ 'Self-scoped board membership read model. security_invoker preserves base-table RLS; role and then board_status (#918: active or archived, the joined boards row''s own column) are appended after every pre-existing column. Rows on an archived board are returned.';
322
+
323
+ -- The delegate's allow set says why each base table is in its read closure: boards now serves this view too.
324
+ -- The set itself is unchanged.
325
+ update agent_board.delegate_allowed_operations
326
+ set reason = 'read closure: v_board_feed, v_agent_inbox, v_board_memberships, v_agent_dashboard'
327
+ where kind = 'read_table' and name = 'boards';
328
+
329
+ -- =============================================================================
330
+ -- 3. list_my_board_requests
331
+ -- =============================================================================
332
+ CREATE OR REPLACE FUNCTION agent_board.list_my_board_requests()
333
+ RETURNS TABLE(board_id uuid, board_name text, board_slug text, requested_at timestamp with time zone, membership_state text, expires_at timestamp with time zone, expired boolean)
334
+ LANGUAGE plpgsql
335
+ STABLE SECURITY DEFINER
336
+ SET search_path TO 'agent_board', 'public'
337
+ AS $function$
338
+ declare
339
+ v_actor uuid := agent_board.current_agent_id();
340
+ begin
341
+ if v_actor is null then
342
+ return;
343
+ end if;
344
+
345
+ return query
346
+ select
347
+ b.id,
348
+ b.name,
349
+ b.slug,
350
+ req.created_at,
351
+ coalesce(cur.membership_state, 'none'),
352
+ req.created_at + make_interval(days => b.join_request_ttl_days),
353
+ req.created_at < now() - make_interval(days => b.join_request_ttl_days)
354
+ from (
355
+ -- The latest request event per board, by seq (the ledger's total order).
356
+ select distinct on (e.board_id) e.board_id, e.created_at
357
+ from agent_board.board_membership_events e
358
+ where e.agent_id = v_actor
359
+ and e.provenance = 'target-authored'
360
+ and e.result_state = 'requested'
361
+ order by e.board_id, e.seq desc
362
+ ) req
363
+ join agent_board.boards b on b.id = req.board_id
364
+ left join lateral (
365
+ select bm.membership_state
366
+ from agent_board.board_memberships bm
367
+ where bm.board_id = req.board_id
368
+ and bm.agent_id = v_actor
369
+ order by case when bm.membership_state in ('joined', 'subscribed') then 0 else 1 end,
370
+ bm.created_at desc, bm.id desc
371
+ limit 1
372
+ ) cur on true
373
+ -- #918: a request for an archived board is left out for a caller who can read that board's row, by the
374
+ -- boards SELECT policy's own two conditions (its third admits only active boards). For anyone else
375
+ -- the row stays, so this list does not tell a former requester that the board was archived.
376
+ where not (
377
+ b.status = 'archived'
378
+ and (b.created_by_agent_id = v_actor
379
+ or exists (
380
+ select 1
381
+ from agent_board.board_memberships rm
382
+ where rm.board_id = b.id
383
+ and rm.agent_id = v_actor
384
+ and rm.membership_state in ('requested', 'invited', 'joined', 'subscribed'))))
385
+ order by req.created_at desc, b.id desc;
386
+ end;
387
+ $function$;
388
+ revoke all on function agent_board.list_my_board_requests() from public, anon, authenticated, service_role, agent_board_delegate;
389
+ grant execute on function agent_board.list_my_board_requests() to authenticated;
390
+ comment on function agent_board.list_my_board_requests() is
391
+ 'IF-0-ONBOARD-4: the caller''s own join requests as they stand now. Source is the consent ledger (board_membership_events: agent_id = caller, provenance target-authored, result_state requested), never board_memberships.created_by_agent_id, which later writers overwrite. Identity is current_agent_id() only; there is no parameter and a null identity returns nothing, so service_role (no caller identity) is refused EXECUTE. Per board: id, name, slug, the latest request event''s time, the current membership state chosen active-first (MBROWID 3a) or none, expires_at = requested_at + join_request_ttl_days, and expired (the request no longer counts as consent). Requests made before the ledger existed carry only a board-authored backfill_neutral event and are not returned. No per-row history. #918: a request for an archived board is not listed to a caller who can read that board''s row (creator, or a requested/invited/joined/subscribed membership); it returns when the board is un-archived.';