@consiliency/agent-board-schema 1.81.0 → 1.83.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.
- package/README.md +6 -0
- package/fixtures/already-applied.json +8 -0
- package/migrations/20261202000100_agent_board_archive_board.sql +1238 -0
- package/migrations/20261203000100_agent_board_archive_board_reads.sql +391 -0
- package/package.json +1 -1
- package/schema-manifest.json +21 -3
- package/src/tooling.test.mjs +6 -2
- package/tests/agent_board_667_history_class.test.sql +20 -3
- package/tests/agent_board_archive_board.test.sql +956 -0
- package/tests/agent_board_archive_board_reads.test.sql +785 -0
- package/tests/agent_board_archive_board_reads_plan.test.sql +56 -0
- package/tests/agent_board_atomic_fleet_onboarding.test.sql +2 -0
- package/tests/agent_board_board_claim_policy.test.sql +5 -3
- package/tests/agent_board_claimpolicy_race.test.sql +8 -6
- package/tests/agent_board_fk_lock_edges.test.sql +27 -3
- package/tests/agent_board_gatenull_membstate.test.sql +3 -1
- package/tests/agent_board_invite_no_downgrade.test.sql +2 -2
- package/tests/agent_board_ledger_authority.test.sql +3 -1
- package/tests/agent_board_role_guard.test.sql +4 -1
- package/tests/agent_board_rolereset.test.sql +5 -4
- package/tests/agent_board_room_roster.test.sql +2 -2
- package/tests/agent_board_step_up.test.sql +12 -7
- package/tests/agent_board_step_up_helper.test.sql +20 -17
- package/tests/agent_board_write_enforcement_class.test.sql +2 -1
- package/tests/catalog/function_execute_privileges.json +36 -0
- package/tests/catalog/p_metadata_parameters.json +16 -0
- package/tests/catalog/step_up_gated_closure.json +2 -0
- package/tests/isolation/expected/archive_vs_content.out +800 -0
- package/tests/isolation/specs/archive_vs_content.spec +128 -0
- package/tests/mutations/918/M01_any_role.sql +13 -0
- package/tests/mutations/918/M02_departed_owner.sql +13 -0
- package/tests/mutations/918/M03_no_fleet_recheck.sql +13 -0
- package/tests/mutations/918/M04_no_step_up.sql +13 -0
- package/tests/mutations/918/M04b_step_up_archive_only.sql +14 -0
- package/tests/mutations/918/M04c_step_up_change_only.sql +17 -0
- package/tests/mutations/918/M05_null_flag.sql +12 -0
- package/tests/mutations/918/M05b_null_board.sql +12 -0
- package/tests/mutations/918/M06_not_idempotent.sql +12 -0
- package/tests/mutations/918/M06b_wrong_flag_returned.sql +12 -0
- package/tests/mutations/918/M07_create_board_unarchives.sql +15 -0
- package/tests/mutations/918/M08_no_moderation.sql +12 -0
- package/tests/mutations/918/M08b_any_change.sql +12 -0
- package/tests/mutations/918/M09_bootstrap_archived.sql +12 -0
- package/tests/mutations/918/M10_drop_artifacts.sql +2 -0
- package/tests/mutations/918/M10_drop_board_authority_ceilings.sql +2 -0
- package/tests/mutations/918/M10_drop_board_invite_blocks.sql +2 -0
- package/tests/mutations/918/M10_drop_board_invite_tokens.sql +3 -0
- package/tests/mutations/918/M10_drop_board_memberships.sql +3 -0
- package/tests/mutations/918/M10_drop_boards.sql +2 -0
- package/tests/mutations/918/M10_drop_callback_subscriptions.sql +3 -0
- package/tests/mutations/918/M10_drop_claims.sql +3 -0
- package/tests/mutations/918/M10_drop_conflicts.sql +2 -0
- package/tests/mutations/918/M10_drop_delegations.sql +2 -0
- package/tests/mutations/918/M10_drop_delivery_recipients.sql +2 -0
- package/tests/mutations/918/M10_drop_escalations.sql +2 -0
- package/tests/mutations/918/M10_drop_fleet_receive_policies.sql +2 -0
- package/tests/mutations/918/M10_drop_messages.sql +2 -0
- package/tests/mutations/918/M10_drop_task_events.sql +2 -0
- package/tests/mutations/918/M10_drop_tasks.sql +2 -0
- package/tests/mutations/918/M10_drop_thread_memberships.sql +3 -0
- package/tests/mutations/918/M10_drop_threads.sql +2 -0
- package/tests/mutations/918/M10i_drop_insert_board_invite_tokens.sql +2 -0
- package/tests/mutations/918/M10i_drop_insert_board_memberships.sql +2 -0
- package/tests/mutations/918/M10i_drop_insert_callback_subscriptions.sql +2 -0
- package/tests/mutations/918/M10i_drop_insert_claims.sql +2 -0
- package/tests/mutations/918/M10i_drop_insert_thread_memberships.sql +2 -0
- package/tests/mutations/918/M10u_drop_update_board_invite_tokens.sql +2 -0
- package/tests/mutations/918/M10u_drop_update_board_memberships.sql +2 -0
- package/tests/mutations/918/M10u_drop_update_callback_subscriptions.sql +2 -0
- package/tests/mutations/918/M10u_drop_update_claims.sql +2 -0
- package/tests/mutations/918/M10u_drop_update_thread_memberships.sql +2 -0
- package/tests/mutations/918/M11_artifacts_no_message.sql +10 -0
- package/tests/mutations/918/M11_artifacts_no_task.sql +10 -0
- package/tests/mutations/918/M11_artifacts_no_task_event.sql +10 -0
- package/tests/mutations/918/M11_claims_no_resource_key.sql +10 -0
- package/tests/mutations/918/M11_claims_no_thread.sql +10 -0
- package/tests/mutations/918/M11_delivery_no_source_message.sql +10 -0
- package/tests/mutations/918/M11_delivery_no_source_task.sql +10 -0
- package/tests/mutations/918/M12_claims_all.sql +9 -0
- package/tests/mutations/918/M13_memberships_all.sql +9 -0
- package/tests/mutations/918/M14_tokens_all.sql +9 -0
- package/tests/mutations/918/M15_subscriptions_all.sql +9 -0
- package/tests/mutations/918/M15b_thread_memberships_all.sql +9 -0
- package/tests/mutations/918/M16_messages_update.sql +10 -0
- package/tests/mutations/918/M16b_task_events_update.sql +10 -0
- package/tests/mutations/918/M17_boards_old_only.sql +10 -0
- package/tests/mutations/918/M18_threads_insert_only.sql +10 -0
- package/tests/mutations/918/M18b_guard_disabled.sql +2 -0
- package/tests/mutations/918/M20_no_clamp_exemption.sql +14 -0
- package/tests/mutations/918/M20b_clamp_any_session.sql +14 -0
- package/tests/mutations/918/M20c_clamp_raise.sql +13 -0
- package/tests/mutations/918/M20d_clamp_other_columns.sql +13 -0
- package/tests/mutations/918/M20e_clamp_any_principal.sql +15 -0
- package/tests/mutations/918/M20f_clamp_any_identity_row.sql +13 -0
- package/tests/mutations/918/M21_ignore_old_row.sql +14 -0
- package/tests/mutations/918/M22_never_refuses.sql +12 -0
- package/tests/mutations/918/M22b_wrong_sqlstate.sql +12 -0
- package/tests/mutations/918/M23_delegate_execute.sql +2 -0
- package/tests/mutations/918/M23b_status_oracle.sql +2 -0
- package/tests/mutations/918/M24_new_writer.sql +2 -0
- package/tests/mutations/918/M24b_new_dynamic_writer.sql +2 -0
- package/tests/mutations/918/M24c_second_status_writer.sql +2 -0
- package/tests/mutations/918/M24d_new_relation.sql +2 -0
- package/tests/mutations/918/M24e_direct_grant.sql +2 -0
- package/tests/mutations/918/M25_memberships_dropped_on_archive.sql +10 -0
- package/tests/mutations/918/M27_departure_result_only.sql +10 -0
- package/tests/mutations/918/M27b_departure_any_role.sql +10 -0
- package/tests/mutations/918/M27c_claim_result_only.sql +10 -0
- package/tests/mutations/918/M27d_claim_any_thread.sql +10 -0
- package/tests/mutations/918/M27e_subscription_result_only.sql +10 -0
- package/tests/mutations/918/M28_token_update_not_expiry.sql +8 -0
- package/tests/mutations/918/M28_token_update_not_reanchor.sql +8 -0
- package/tests/mutations/918/M28_token_update_not_role.sql +8 -0
- package/tests/mutations/918/M28_token_update_not_uses.sql +8 -0
- package/tests/mutations/918/M28b_revocation_any_edit.sql +10 -0
- package/tests/mutations/918/M28c_unrevoke.sql +10 -0
- package/tests/mutations/918/M28d_thread_access_agent.sql +10 -0
- package/tests/mutations/918/M28e_thread_access_thread.sql +10 -0
- package/tests/mutations/918/M28f_thread_access_expiry.sql +10 -0
- package/tests/mutations/918/M28g_thread_access_unrevoke.sql +10 -0
- package/tests/mutations/918/M29_grant_no_refusal.sql +13 -0
- package/tests/mutations/918/M29b_grant_refuses_first.sql +18 -0
- package/tests/mutations/918/M30_redeem_no_status.sql +12 -0
- package/tests/mutations/918/M30b_redeem_distinct_text.sql +16 -0
- package/tests/mutations/918/M31_display_any_status.sql +7 -0
- package/tests/mutations/918/M31b_display_not_service.sql +2 -0
- package/tests/mutations/918/M32_status_before_authority.sql +15 -0
- package/tests/mutations/918/M33_retention_refused.sql +14 -0
- package/tests/mutations/918/M33b_retention_any_metadata.sql +14 -0
- package/tests/mutations/918/M34_guard_rewrites_board_id.sql +13 -0
- package/tests/mutations/918/M34_guard_rewrites_claim_policy.sql +13 -0
- package/tests/mutations/918/M34_guard_rewrites_status.sql +13 -0
- package/tests/mutations/918/M34d_guard_returns_null.sql +16 -0
- package/tests/mutations/918/M34e_guard_rewrites_uppercase.sql +13 -0
- package/tests/mutations/918/M34f_guard_select_into_uppercase.sql +13 -0
- package/tests/mutations/918/M35_new_resource_kind.sql +3 -0
- package/tests/mutations/918/M35b_new_fk_anchor.sql +2 -0
- package/tests/mutations/918/M35c_exempt_gains_writer.sql +2 -0
- package/tests/mutations/918/M35d_service_role_gains_update.sql +2 -0
- package/tests/mutations/918/M36_token_created_at.sql +10 -0
- package/tests/mutations/918/M36b_thread_access_created_at.sql +10 -0
- package/tests/mutations/918/M37_non_object_refused.sql +14 -0
- package/tests/mutations/918/M37b_non_object_any_edit.sql +13 -0
- package/tests/mutations/918/M37c_non_object_any_key.sql +13 -0
- package/tests/mutations/918/M37d_non_object_partial_mark.sql +13 -0
- package/tests/mutations/918/M37e_non_object_result_any_type.sql +13 -0
- package/tests/mutations/918/M37f_non_object_any_last_element.sql +13 -0
- package/tests/mutations/918/M38_claim_key_free.sql +10 -0
- package/tests/mutations/918/M38b_claim_key_verbatim.sql +10 -0
- package/tests/mutations/918/M38c_claim_key_canonical_only.sql +10 -0
- package/tests/mutations/918/equivalents/M37ef_grid.sql +42 -0
- package/tests/mutations/918/isolation/I1_guard_no_lock.sql +13 -0
- package/tests/mutations/918/isolation/I2_archive_no_key_update.sql +12 -0
- package/tests/mutations/918/isolation/I3_guard_for_update.sql +12 -0
- package/tests/mutations/918/isolation/I4_archive_any_isolation.sql +12 -0
- package/tests/mutations/918/isolation/I5_redeem_unlocked.sql +12 -0
- package/tests/mutations/918/isolation/I6_thread_membership_unlocked.sql +12 -0
- package/tests/mutations/918/isolation/I7_thread_membership_for_share.sql +12 -0
- package/tests/mutations/918/pr2/R01_inbox_no_filter.sql +9 -0
- package/tests/mutations/918/pr2/R01b_inbox_hides_boardless.sql +9 -0
- package/tests/mutations/918/pr2/R01d_inbox_requires_readable.sql +9 -0
- package/tests/mutations/918/pr2/R01e_inbox_active_too.sql +9 -0
- package/tests/mutations/918/pr2/R02_counts_no_filter.sql +9 -0
- package/tests/mutations/918/pr2/R02b_counts_hide_boardless.sql +9 -0
- package/tests/mutations/918/pr2/R03_dashboard_no_filter.sql +9 -0
- package/tests/mutations/918/pr2/R03b_dashboard_hides_boardless.sql +9 -0
- package/tests/mutations/918/pr2/R03c_dashboard_tasks.sql +9 -0
- package/tests/mutations/918/pr2/R03d_dashboard_calls_helper.sql +9 -0
- package/tests/mutations/918/pr2/R04_open_esc_no_filter.sql +9 -0
- package/tests/mutations/918/pr2/R04b_open_esc_no_task.sql +9 -0
- package/tests/mutations/918/pr2/R04c_open_esc_no_thread.sql +9 -0
- package/tests/mutations/918/pr2/R05_ops_esc_no_filter.sql +9 -0
- package/tests/mutations/918/pr2/R05b_ops_esc_no_task.sql +9 -0
- package/tests/mutations/918/pr2/R05c_ops_esc_no_thread.sql +9 -0
- package/tests/mutations/918/pr2/R06_stale_no_filter.sql +9 -0
- package/tests/mutations/918/pr2/R06b_stale_no_task.sql +9 -0
- package/tests/mutations/918/pr2/R06c_stale_no_thread.sql +9 -0
- package/tests/mutations/918/pr2/R06d_stale_no_key.sql +9 -0
- package/tests/mutations/918/pr2/R06e_stale_unguarded_cast.sql +9 -0
- package/tests/mutations/918/pr2/R07_memberships_filtered.sql +9 -0
- package/tests/mutations/918/pr2/R07b_memberships_constant.sql +9 -0
- package/tests/mutations/918/pr2/R08a_v_active_claims_filtered.sql +9 -0
- package/tests/mutations/918/pr2/R08b_v_board_feed_filtered.sql +9 -0
- package/tests/mutations/918/pr2/R08c_task_tree_filtered.sql +5 -0
- package/tests/mutations/918/pr2/R08d_thread_feed_filtered.sql +5 -0
- package/tests/mutations/918/pr2/R08e_callback_subs_filtered.sql +5 -0
- package/tests/mutations/918/pr2/R09_inbox_definer_view.sql +9 -0
- package/tests/mutations/918/pr2/R09b_view_grant.sql +2 -0
- package/tests/mutations/918/pr2/R09c_view_revoke.sql +2 -0
- package/tests/mutations/918/pr2/R09d_column_renamed.sql +2 -0
- package/tests/mutations/918/pr2/R10_new_view.sql +2 -0
- package/tests/mutations/918/pr2/R10b_new_routine.sql +2 -0
- package/tests/mutations/918/pr2/R10c_new_indirect_routine.sql +2 -0
- package/tests/mutations/918/pr2/R10d_predicate_returns_rows.sql +2 -0
- package/tests/mutations/918/pr2/R10e_overload.sql +3 -0
- package/tests/mutations/918/pr2/R10f_execute_root.sql +2 -0
- package/tests/mutations/918/pr2/R10g_predicate_array.sql +2 -0
- package/tests/mutations/918/pr2/R10h_predicate_domain.sql +2 -0
- package/tests/mutations/918/pr2/R10i_polymorphic.sql +2 -0
- package/tests/mutations/918/pr2/R10j_predicate_json.sql +2 -0
- package/tests/mutations/918/pr2/R10k_foreign_view.sql +2 -0
- package/tests/mutations/918/pr2/R10l_foreign_view_transitive.sql +2 -0
- package/tests/mutations/918/pr2/R10m_foreign_view_function.sql +2 -0
- package/tests/mutations/918/pr2/R10n_foreign_matview.sql +2 -0
- package/tests/mutations/918/pr2/R10o_ambiguous_overload.sql +6 -0
- package/tests/mutations/918/pr2/R10p_resolved_overload.sql +6 -0
- package/tests/mutations/918/pr2/R11_requests_no_filter.sql +9 -0
- package/tests/mutations/918/pr2/R11b_requests_hide_all.sql +9 -0
- package/tests/mutations/918/pr2/R11c_requests_no_creator.sql +11 -0
- package/tests/mutations/918/pr2/R11d_requests_no_pending.sql +9 -0
- package/tests/mutations/918/pr2/R11e_requests_any_state.sql +9 -0
- package/tests/mutations/918/pr2/R11f_requests_active_too.sql +9 -0
- package/tests/mutations/918/pr2/R12_helper_definer.sql +2 -0
- package/tests/mutations/918/pr2/R12b_helper_no_thread.sql +11 -0
- package/tests/mutations/918/pr2/R12c_helper_no_task.sql +11 -0
- package/tests/mutations/918/pr2/R12d_helper_any_board.sql +10 -0
- package/tests/mutations/918/pr2/R12e_helper_task_any_board.sql +10 -0
- package/tests/mutations/918/pr2/R12f_helper_null.sql +11 -0
- package/tests/mutations/918/pr2/R12g_helper_delegate.sql +2 -0
- package/tests/mutations/918/pr2/R12h_helper_public.sql +2 -0
- package/tests/mutations/918/pr2/R12i_no_generic_plan.sql +2 -0
- package/tests/mutations/918/pr2/R13_archive_columns.sql +2 -0
- package/tests/mutations/918/pr2/R13b_second_agents_fk.sql +2 -0
- package/tests/mutations/918/pr2/R13c_archive_column.sql +2 -0
- package/tests/mutations/918/pr2/R15_rls_narrowed.sql +2 -0
- package/tests/mutations/918/pr2/R15b_rls_widened.sql +2 -0
- package/tests/mutations/918/pr2/R15c_threads_rls_narrowed.sql +2 -0
- package/tests/mutations/918/pr2/R16_archive_deletes.sql +10 -0
- package/tests/mutations/918/pr2/R16b_archive_marks_read.sql +10 -0
- package/tests/mutations/918/pr2/R17_wake_bypasses_inbox.sql +8 -0
- package/tests/mutations/918/pr2/R18_directory_archived.sql +7 -0
- package/tests/mutations/918/pr2/R19_delegate_ids_active_only.sql +7 -0
- package/tests/mutations/918/run.sh +95 -0
- package/tests/seeds/20261202000100_agent_board_archive_board.sql.pre.sql +24 -0
- 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.';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@consiliency/agent-board-schema",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.83.0",
|
|
4
4
|
"description": "Canonical, immutable, exact-pinnable agent_board schema bundle: ordered SQL migrations, digest + compatibility manifest, and deterministic materialize/plan/check tooling for adopters.",
|
|
5
5
|
"repository": "https://github.com/Consiliency/message-board.git",
|
|
6
6
|
"type": "module",
|
package/schema-manifest.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"schema": "agent_board_schema_manifest.v1",
|
|
3
3
|
"interface": "IF-0-MBPLANE-BUNDLE-1",
|
|
4
4
|
"package": "@consiliency/agent-board-schema",
|
|
5
|
-
"packageVersion": "1.
|
|
5
|
+
"packageVersion": "1.83.0",
|
|
6
6
|
"schemaVersion": 8,
|
|
7
7
|
"minClientVersion": "1.1.0",
|
|
8
8
|
"source": {
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"usage": "upsert (retention/monitoring defaults; on conflict do nothing)"
|
|
47
47
|
}
|
|
48
48
|
],
|
|
49
|
-
"migrationCount":
|
|
50
|
-
"aggregateSha256": "
|
|
49
|
+
"migrationCount": 181,
|
|
50
|
+
"aggregateSha256": "be7779d1629fd834b24d4074ee24b9e69d5cf2f15c1cb9974237ecba200741f1",
|
|
51
51
|
"migrations": [
|
|
52
52
|
{
|
|
53
53
|
"order": 0,
|
|
@@ -1659,6 +1659,24 @@
|
|
|
1659
1659
|
"sourceRef": "message-board",
|
|
1660
1660
|
"bytes": 64189,
|
|
1661
1661
|
"sha256": "1687e08c4a24af412f10b99e031e0c5e7b592b9b0f74989abff65fa56d3cd00b"
|
|
1662
|
+
},
|
|
1663
|
+
{
|
|
1664
|
+
"order": 179,
|
|
1665
|
+
"id": "20261202000100_agent_board_archive_board",
|
|
1666
|
+
"filename": "20261202000100_agent_board_archive_board.sql",
|
|
1667
|
+
"origin": "message-board-forward",
|
|
1668
|
+
"sourceRef": "message-board",
|
|
1669
|
+
"bytes": 77518,
|
|
1670
|
+
"sha256": "e4e173ebe55e7af3ef392c31eea8b46dea338b3d177a31068e525d328088658f"
|
|
1671
|
+
},
|
|
1672
|
+
{
|
|
1673
|
+
"order": 180,
|
|
1674
|
+
"id": "20261203000100_agent_board_archive_board_reads",
|
|
1675
|
+
"filename": "20261203000100_agent_board_archive_board_reads.sql",
|
|
1676
|
+
"origin": "message-board-forward",
|
|
1677
|
+
"sourceRef": "message-board",
|
|
1678
|
+
"bytes": 23101,
|
|
1679
|
+
"sha256": "1c096c0ffc2da4717c8f88e4145b57a756eabe8cdbf6a414f897818c27af60f4"
|
|
1662
1680
|
}
|
|
1663
1681
|
],
|
|
1664
1682
|
"excludedBridge": {
|
package/src/tooling.test.mjs
CHANGED
|
@@ -41,9 +41,9 @@ describe('manifest integrity', () => {
|
|
|
41
41
|
expect(manifest.schemaVersion).toBe(8);
|
|
42
42
|
expect(manifest.minClientVersion).toMatch(/^\d+\.\d+\.\d+$/);
|
|
43
43
|
});
|
|
44
|
-
it('registers the four MBAUTHZ + four MBSENDAUTHZ + four MBSESSION + four MBDELEG + three MBFED + three MBHARDEN + two MBPORTALGATE + two MBPORTAL-PR32 + two ROOMOWN + two ROOMLINK + one ROOMDELEG + one LOCALAUTH + one ROOMUIAPI + one FEDSESSION + one FEDSESSION-AUTOJOIN + one GATENULL + one MEMBSTATE + one AGENTSDIR + one LEAVEIDEM + one ROLERESET + one MBROWID + one MBHYGIENE + one MBCONSENT-A + one MBCONSENT-B(a) + one MBCONSENT-B(i) + one MBCONSENT-B(ii) + one MBCONSENT-B(iii) + one MBHARDEN-#97 + one MBHARDEN-#118 + one INVITEPOLICY + one OBSGATE + one OBSGATE-2 + one OBSGATE-3 + one OBSGATE-4 + one FLEETMACHINERLS + one RESOLVENOOP + one ROOMDELEG-LANEB + one CLAIMKEY + two MINTHARDEN + one FLEETMACHINEHIJACK + one CLAIMGATE-SHADOW + one CLAIMGATE-ENFORCE + one FLEETMACHINEREACTIVATION + one DELEGCAPCEILING + one FLEETMACHINERECLAIM + one DELEGSOLEWRITER + one FLEETDOMAINRECLAIM + five ATOMICFLEETONBOARDING (onboarding + ceiling-lock + revocation-evidence + fedsession-gate + fedsession-lock-order) + one OUTBOXWAKE + one ENROLLLOCKORDER + one FEDPROVIDERABSENCE + one WAKERECOVERY + one CONSENTRECONCILE + one ENROLLRESUMPTION + one SIGNEDAUTHORITY + one SIGNERLIFECYCLE + one LEDGERAUTHORITY + one CEILINGLOCKCOMMENT + one LEDGERBOARDCREATE + one RECEIPTSUBJECTGATE + one TASKTHREADLOCKORDER + one CLAIMSUBJECTGATE + one FEDSESSIONIDENTITYGATE + one FEDIDENTITYSLUG + one INVITENODOWNGRADE + one SIGNEDWRITEFLAG + one SIGNEDWRITEMODEL + one RTCREDCLAIM + one ORIGINPOSTURE + one BOARDCLAIMPOLICY + one HEARTBEATPRESERVE + one LIVENESSDENOM + one OWNERLESSRENEWTTL + one OWNERLESSQUOTACENSUS + one FLEETDOMAINNODOWNGRADE + one OWNERLESSQUOTACONVERGE + one ADVISORYREVERTRESET + one CLAIMPOLICYRACE + one CLAIMPOLICYLOCKGRANT + one SESSIONCHALLENGESUPERSEDE + one ROOMCONTRACT + one CALLBACKCONSUMER + one ENROLLTOKENSINGLEUSE + one ROOMCONTRACT-ACTIVEFIRST + one ONBOARD + one HOSTED + one HOSTED-FOLLOWUPS + one OWNPOST + one SIDSCHEMA + one SIDOWNER + one GRANTTARGETROLE (#674) + one LASTOWNER (Consiliency/message-board#675) + one SESSIONPROVENANCE (Consiliency/message-board#665) + one REQUESTREMOVED (Consiliency/message-board#680) + one RLSCORRELATION (Consiliency/message-board#589) + one RESOLUTIONAUTHORITY (Consiliency/message-board#668) + one THREADASSOCIATION checkpoint (#667) + one SIDSERVER-MEASUREDMINT (Consiliency/message-board#653) + one REPLYDELIVERY (#661) + one DELIVERYWRITEREXEC (#717 F1) + one REPLAYSCOPE (#717 F2) + one MESSAGEREPLAYSCOPE (#717 F2b) + one SENDOUTCOME (#670) + one STEPUP-PR-A (#669) + one THREADKEYSERIALIZE (S-12) + one THREADKEYGUARDS (S-12 #815/#816) + one STEPUP-PR-B (#669) + one REMOVALSTATE (#906) + one REPLYTO (#655) forward migrations (migrationCount = prior 113 + 5 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 =
|
|
44
|
+
it('registers the four MBAUTHZ + four MBSENDAUTHZ + four MBSESSION + four MBDELEG + three MBFED + three MBHARDEN + two MBPORTALGATE + two MBPORTAL-PR32 + two ROOMOWN + two ROOMLINK + one ROOMDELEG + one LOCALAUTH + one ROOMUIAPI + one FEDSESSION + one FEDSESSION-AUTOJOIN + one GATENULL + one MEMBSTATE + one AGENTSDIR + one LEAVEIDEM + one ROLERESET + one MBROWID + one MBHYGIENE + one MBCONSENT-A + one MBCONSENT-B(a) + one MBCONSENT-B(i) + one MBCONSENT-B(ii) + one MBCONSENT-B(iii) + one MBHARDEN-#97 + one MBHARDEN-#118 + one INVITEPOLICY + one OBSGATE + one OBSGATE-2 + one OBSGATE-3 + one OBSGATE-4 + one FLEETMACHINERLS + one RESOLVENOOP + one ROOMDELEG-LANEB + one CLAIMKEY + two MINTHARDEN + one FLEETMACHINEHIJACK + one CLAIMGATE-SHADOW + one CLAIMGATE-ENFORCE + one FLEETMACHINEREACTIVATION + one DELEGCAPCEILING + one FLEETMACHINERECLAIM + one DELEGSOLEWRITER + one FLEETDOMAINRECLAIM + five ATOMICFLEETONBOARDING (onboarding + ceiling-lock + revocation-evidence + fedsession-gate + fedsession-lock-order) + one OUTBOXWAKE + one ENROLLLOCKORDER + one FEDPROVIDERABSENCE + one WAKERECOVERY + one CONSENTRECONCILE + one ENROLLRESUMPTION + one SIGNEDAUTHORITY + one SIGNERLIFECYCLE + one LEDGERAUTHORITY + one CEILINGLOCKCOMMENT + one LEDGERBOARDCREATE + one RECEIPTSUBJECTGATE + one TASKTHREADLOCKORDER + one CLAIMSUBJECTGATE + one FEDSESSIONIDENTITYGATE + one FEDIDENTITYSLUG + one INVITENODOWNGRADE + one SIGNEDWRITEFLAG + one SIGNEDWRITEMODEL + one RTCREDCLAIM + one ORIGINPOSTURE + one BOARDCLAIMPOLICY + one HEARTBEATPRESERVE + one LIVENESSDENOM + one OWNERLESSRENEWTTL + one OWNERLESSQUOTACENSUS + one FLEETDOMAINNODOWNGRADE + one OWNERLESSQUOTACONVERGE + one ADVISORYREVERTRESET + one CLAIMPOLICYRACE + one CLAIMPOLICYLOCKGRANT + one SESSIONCHALLENGESUPERSEDE + one ROOMCONTRACT + one CALLBACKCONSUMER + one ENROLLTOKENSINGLEUSE + one ROOMCONTRACT-ACTIVEFIRST + one ONBOARD + one HOSTED + one HOSTED-FOLLOWUPS + one OWNPOST + one SIDSCHEMA + one SIDOWNER + one GRANTTARGETROLE (#674) + one LASTOWNER (Consiliency/message-board#675) + one SESSIONPROVENANCE (Consiliency/message-board#665) + one REQUESTREMOVED (Consiliency/message-board#680) + one RLSCORRELATION (Consiliency/message-board#589) + one RESOLUTIONAUTHORITY (Consiliency/message-board#668) + one THREADASSOCIATION checkpoint (#667) + one SIDSERVER-MEASUREDMINT (Consiliency/message-board#653) + one REPLYDELIVERY (#661) + one DELIVERYWRITEREXEC (#717 F1) + one REPLAYSCOPE (#717 F2) + one MESSAGEREPLAYSCOPE (#717 F2b) + one SENDOUTCOME (#670) + one STEPUP-PR-A (#669) + one THREADKEYSERIALIZE (S-12) + one THREADKEYGUARDS (S-12 #815/#816) + one STEPUP-PR-B (#669) + one REMOVALSTATE (#906) + one REPLYTO (#655) + one ARCHIVEBOARD (#918) + one ARCHIVEBOARD-READS (#918 PR-2) forward migrations (migrationCount = prior 113 + 5 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 181)', () => {
|
|
45
45
|
expect(manifest.migrationCount).toBe(manifest.migrations.length);
|
|
46
|
-
expect(manifest.migrationCount).toBe(
|
|
46
|
+
expect(manifest.migrationCount).toBe(181);
|
|
47
47
|
// MBSESSION switched enforcement on (scoped-send re-grant): the client-visible
|
|
48
48
|
// schema version bumped to 8. MBDELEG tightens delegation and MBFED adds only
|
|
49
49
|
// enrollment-only additive surface (identity_providers registry, enrollment audit,
|
|
@@ -387,6 +387,10 @@ describe('manifest integrity', () => {
|
|
|
387
387
|
'20261126000100_agent_board_membership_removal_requires_active.sql',
|
|
388
388
|
// #655: reply to a specific message (reply_to_message_id, same-thread FK, feed columns).
|
|
389
389
|
'20261201000100_agent_board_reply_to_message.sql',
|
|
390
|
+
// #918: set_board_archived (sole writer of boards.status) and the archived-board write guard.
|
|
391
|
+
'20261202000100_agent_board_archive_board.sql',
|
|
392
|
+
// #918 PR-2: archived boards leave lists, inbox and ops counts; board_status.
|
|
393
|
+
'20261203000100_agent_board_archive_board_reads.sql',
|
|
390
394
|
]) {
|
|
391
395
|
expect(names.has(f)).toBe(true);
|
|
392
396
|
}
|
|
@@ -12,7 +12,7 @@ begin
|
|
|
12
12
|
execute 'create extension if not exists plpgsql_check with schema extensions';
|
|
13
13
|
end if;
|
|
14
14
|
end $$;
|
|
15
|
-
select plan(
|
|
15
|
+
select plan(64);
|
|
16
16
|
-- Procedure bodies and CALL edges are outside the function parsers below.
|
|
17
17
|
-- Fail closed on every non-extension application procedure until its complete
|
|
18
18
|
-- history and caller effects receive an explicit positive disposition.
|
|
@@ -314,8 +314,22 @@ select is((select string_agg(r.relid::regclass::text, ', ' order by r.relid::reg
|
|
|
314
314
|
where n.nspname<>'agent_board'), null::text, 'XB history relations outside the supported matcher schema name themselves');
|
|
315
315
|
select is((select string_agg(format('%s.%I -> %s',t.tgrelid::regclass,t.tgname,t.tgfoid::regprocedure), ', '
|
|
316
316
|
order by t.tgrelid::regclass::text,t.tgname)
|
|
317
|
-
from pg_trigger t join xb_history_relations r on r.relid=t.tgrelid where not t.tgisinternal
|
|
317
|
+
from pg_trigger t join xb_history_relations r on r.relid=t.tgrelid where not t.tgisinternal
|
|
318
|
+
and t.tgfoid<>'agent_board._archived_board_guard()'::regprocedure),
|
|
318
319
|
null::text, 'XB DML trigger entry points on history relations name themselves');
|
|
320
|
+
-- #918: the archived-board guard is the one reviewed entry point. It is a refusal: it reads the row's
|
|
321
|
+
-- anchors and writes nothing, so it opens no path into history. Asserted positively, by relation and by
|
|
322
|
+
-- the shared write matcher over every agent_board relation.
|
|
323
|
+
select is((select string_agg(distinct c.relname, ' ' order by c.relname)
|
|
324
|
+
from pg_trigger t join xb_history_relations r on r.relid=t.tgrelid join pg_class c on c.oid=t.tgrelid
|
|
325
|
+
where not t.tgisinternal and t.tgfoid='agent_board._archived_board_guard()'::regprocedure),
|
|
326
|
+
'artifacts claims conflicts delegations delivery_recipients escalations messages task_events tasks thread_memberships',
|
|
327
|
+
'XB #918: the archived-board guard sits on exactly these history relations');
|
|
328
|
+
select is((select string_agg(p.proname, ' ' order by p.proname) from pg_proc p
|
|
329
|
+
where p.oid in ('agent_board._archived_board_guard()'::regprocedure,'agent_board._assert_boards_not_archived(uuid[])'::regprocedure)
|
|
330
|
+
and not agent_board_test.stripped_body(p.oid) ~ agent_board_test.writes_any_re((select array_agg(relname::text) from pg_class
|
|
331
|
+
where relnamespace='agent_board'::regnamespace and relkind in ('r','p')))),
|
|
332
|
+
'_archived_board_guard _assert_boards_not_archived', 'XB #918: the archived-board guard and its assertion write no agent_board relation');
|
|
319
333
|
select is((select string_agg(format('%s.%I',rw.ev_class::regclass,rw.rulename), ', ' order by rw.ev_class::regclass::text,rw.rulename)
|
|
320
334
|
from pg_rewrite rw join xb_history_relations r on r.relid=rw.ev_class where rw.ev_type<>'1'),
|
|
321
335
|
null::text, 'XB DML rule entry points on history relations name themselves');
|
|
@@ -751,7 +765,10 @@ select is((select string_agg(distinct format('%s.%I -> %s [%s]',t.tgrelid::regcl
|
|
|
751
765
|
when t.dep_type='RELATION' then 'HISTORY-RELATION:'||t.dep_oid::regclass::text
|
|
752
766
|
else 'WRITER-CALL:'||t.dep_oid::regprocedure::text end))
|
|
753
767
|
from xb_trigger_deps t where t.problem is not null or t.opaque
|
|
754
|
-
|
|
768
|
+
-- #918: the guard READS history relations to resolve an anchor; it writes none (pinned above), and a
|
|
769
|
+
-- call from it that reached a writer would still be reported by the FUNCTION arm.
|
|
770
|
+
or (t.dep_type='RELATION' and t.dep_oid in (select relid from xb_history_relations)
|
|
771
|
+
and t.tgfoid<>'agent_board._archived_board_guard()'::regprocedure)
|
|
755
772
|
or (t.dep_type='FUNCTION' and t.dep_oid in (select oid from xb_reaches_writer))),
|
|
756
773
|
null::text, 'XB trigger paths to history or writers and unresolved triggers name themselves');
|
|
757
774
|
|