@consiliency/agent-board-schema 1.22.0 → 1.23.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 (60) hide show
  1. package/fixtures/already-applied.json +36 -0
  2. package/migrations/20260901000100_agent_board_atomic_fleet_onboarding.sql +1496 -0
  3. package/migrations/20260901000110_agent_board_fleet_onboarding_ceiling_lock.sql +604 -0
  4. package/migrations/20260901000120_agent_board_human_revocation_evidence_completeness.sql +78 -0
  5. package/migrations/20260901000130_agent_board_fedsession_human_revocation_gate.sql +74 -0
  6. package/migrations/20260901000140_agent_board_fedsession_board_owner_lock_order.sql +102 -0
  7. package/migrations/20260902000100_agent_board_outbox_wake_ordering.sql +184 -0
  8. package/migrations/20260903000100_agent_board_enroll_identity_board_owner_lock_order.sql +604 -0
  9. package/migrations/20260903000200_agent_board_fedsession_provider_absence_gate.sql +177 -0
  10. package/migrations/20260904000100_agent_board_wake_recovery_surface.sql +155 -0
  11. package/package.json +1 -1
  12. package/schema-manifest.json +84 -3
  13. package/src/tooling.test.mjs +2 -2
  14. package/tests/agent_board_atomic_fleet_onboarding.test.sql +623 -0
  15. package/tests/agent_board_atomic_fleet_onboarding_backfill.test.sql +142 -0
  16. package/tests/agent_board_atomic_fleet_onboarding_runtime.test.sql +1250 -0
  17. package/tests/agent_board_enroll_federated_identity.test.sql +3 -3
  18. package/tests/agent_board_enroll_pop_binding.test.sql +13 -3
  19. package/tests/agent_board_enrollment_audit_content.test.sql +11 -7
  20. package/tests/agent_board_federated_lock_order_class.test.sql +390 -0
  21. package/tests/agent_board_fedsession.test.sql +46 -2
  22. package/tests/agent_board_fedsession_provider_absence_gate.test.sql +170 -0
  23. package/tests/agent_board_inbox_reads.test.sql +16 -19
  24. package/tests/agent_board_outbox_wake_ordering.test.sql +452 -0
  25. package/tests/agent_board_portal_offline_invariant.test.sql +1 -1
  26. package/tests/agent_board_roomlink.test.sql +2 -2
  27. package/tests/agent_board_wake_recovery.test.sql +756 -0
  28. package/tests/isolation/expected/atomic_fedsession_fleet_lock_order.out +79 -0
  29. package/tests/isolation/expected/atomic_fedsession_human_revoke.out +87 -0
  30. package/tests/isolation/expected/atomic_fleet_authority_races.out +469 -0
  31. package/tests/isolation/expected/atomic_fleet_binding_revoke.out +103 -0
  32. package/tests/isolation/expected/atomic_fleet_board_archive.out +117 -0
  33. package/tests/isolation/expected/atomic_fleet_human_fresh_revoke.out +136 -0
  34. package/tests/isolation/expected/atomic_fleet_identity_disposition.out +61 -0
  35. package/tests/isolation/expected/atomic_fleet_lifecycle_races.out +1479 -0
  36. package/tests/isolation/expected/atomic_fleet_onboarding.out +75 -0
  37. package/tests/isolation/expected/atomic_fleet_subtree_lock_order.out +60 -0
  38. package/tests/isolation/expected/ceiling_setter_lock_before_upsert.out +95 -0
  39. package/tests/isolation/expected/enroll_identity_board_owner_lock_order.out +55 -0
  40. package/tests/isolation/expected/fedsession_provider_absent_owner_lock.out +37 -0
  41. package/tests/isolation/expected/onboarding_ceiling_lock_order.out +123 -0
  42. package/tests/isolation/expected/outbox_wake_ordering.out +86 -0
  43. package/tests/isolation/expected/wake_recovery_late_commit.out +89 -0
  44. package/tests/isolation/specs/atomic_fedsession_fleet_lock_order.spec +117 -0
  45. package/tests/isolation/specs/atomic_fedsession_human_revoke.spec +66 -0
  46. package/tests/isolation/specs/atomic_fleet_authority_races.spec +235 -0
  47. package/tests/isolation/specs/atomic_fleet_binding_revoke.spec +127 -0
  48. package/tests/isolation/specs/atomic_fleet_board_archive.spec +134 -0
  49. package/tests/isolation/specs/atomic_fleet_human_fresh_revoke.spec +142 -0
  50. package/tests/isolation/specs/atomic_fleet_identity_disposition.spec +118 -0
  51. package/tests/isolation/specs/atomic_fleet_lifecycle_races.spec +244 -0
  52. package/tests/isolation/specs/atomic_fleet_onboarding.spec +106 -0
  53. package/tests/isolation/specs/atomic_fleet_subtree_lock_order.spec +147 -0
  54. package/tests/isolation/specs/ceiling_setter_lock_before_upsert.spec +117 -0
  55. package/tests/isolation/specs/enroll_identity_board_owner_lock_order.spec +117 -0
  56. package/tests/isolation/specs/fedsession_provider_absent_owner_lock.spec +63 -0
  57. package/tests/isolation/specs/onboarding_ceiling_lock_order.spec +183 -0
  58. package/tests/isolation/specs/outbox_wake_ordering.spec +202 -0
  59. package/tests/isolation/specs/wake_recovery_late_commit.spec +207 -0
  60. package/tests/seeds/20260901000100_agent_board_atomic_fleet_onboarding.sql.pre.sql +110 -0
@@ -0,0 +1,117 @@
1
+ # Consiliency/message-board#162 — fleet onboarding and /portal-session may
2
+ # share both a human owner and the provider's default board. Prove the routes
3
+ # agree on board -> owner and cannot form the old board/owner ABBA cycle.
4
+
5
+ setup
6
+ {
7
+ insert into agent_board.agents(id, agent_type, kind, handle, display_name, status)
8
+ values ('162a0000-0000-0000-0000-000000000001', 'agent', 'agent',
9
+ 'atomic-cross-owner', 'Atomic Cross Owner', 'active');
10
+
11
+ select count(*) from agent_board.create_board(
12
+ '162a0000-0000-0000-0000-000000000001',
13
+ 'atomic-cross-board', 'Atomic Cross Board',
14
+ 'Consiliency/message-board#162 cross-route lock proof', jsonb_build_object(), 'private'
15
+ );
16
+
17
+ insert into agent_board.fleet_trust_domains(
18
+ id, slug, display_name, domain_kind, owner_agent_id, lifecycle_state, approved_at
19
+ ) values (
20
+ '162a0000-0000-0000-0000-000000000002', 'atomic-cross-domain',
21
+ 'Atomic Cross Domain', 'tailnet', '162a0000-0000-0000-0000-000000000001',
22
+ 'active', now()
23
+ );
24
+ insert into agent_board.fleet_machines(
25
+ id, trust_domain_id, owner_agent_id, machine_label, machine_fingerprint,
26
+ lifecycle_state, enrollment_source, enrolled_at
27
+ ) values (
28
+ '162a0000-0000-0000-0000-000000000003',
29
+ '162a0000-0000-0000-0000-000000000002',
30
+ '162a0000-0000-0000-0000-000000000001',
31
+ 'claw', 'sha256:atomic-cross-machine', 'active', 'portal', now()
32
+ );
33
+ insert into agent_board.identity_providers(
34
+ issuer, audience, supported, policy_approved,
35
+ allowed_scopes, allowed_board_scopes, allowed_agent_kinds
36
+ ) values (
37
+ 'https://atomic-cross.test', 'message-board', true, true,
38
+ ARRAY['board:send'], ARRAY[]::text[], ARRAY['agent','human']
39
+ );
40
+
41
+ -- Materialize the shared human owner while auto-join is still disabled.
42
+ select count(*) from agent_board.enroll_federated_human(
43
+ 'https://atomic-cross.test', 'message-board', 'cross-human',
44
+ jsonb_build_object('sub','cross-human'), 'Cross Human'
45
+ );
46
+ update agent_board.identity_providers
47
+ set default_board_id=(select id from agent_board.boards where slug='atomic-cross-board')
48
+ where issuer='https://atomic-cross.test';
49
+
50
+ select count(*) from agent_board.create_fleet_onboarding_invite(
51
+ (select id from agent_board.boards where slug='atomic-cross-board'),
52
+ '162a0000-0000-0000-0000-000000000003',
53
+ 'codex', 'phase-loop', 'message-board', 'sha256:atomic-cross-repo',
54
+ 'worker', 'phase_worker', 'atomic-cross-agent', 1,
55
+ now() + interval '1 hour', '162a0000-0000-0000-0000-000000000001',
56
+ jsonb_build_object()
57
+ );
58
+ }
59
+
60
+ session "guard"
61
+ step "guard_begin" { BEGIN; }
62
+ step "guard_board_key_share" {
63
+ select slug from agent_board.boards
64
+ where slug='atomic-cross-board' for key share;
65
+ }
66
+ step "guard_commit" { COMMIT; }
67
+
68
+ session "fleet"
69
+ step "fleet_begin" { BEGIN; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
70
+ step "fleet_onboard" {
71
+ select identity_disposition, membership_disposition, binding_disposition
72
+ from agent_board.onboard_federated_fleet_agent(
73
+ 'https://atomic-cross.test', 'message-board', 'cross-human',
74
+ jsonb_build_object('iss','https://atomic-cross.test','aud','message-board','sub','cross-human','iat',100),
75
+ 'atomic-cross-agent',
76
+ 'eRHZmllEy_TZHAG2zB-Qe_a5BFLkaavMTazWWfaE3f0',
77
+ 'raw_ed25519_base64url',
78
+ 'sha256:z8d5LQPfBMYnfZfvu8wVz684_jkp578-SPDU2OMObS8',
79
+ true, null, 'agent', ARRAY['board:send'], ARRAY[]::text[],
80
+ (select code from agent_board.board_invite_tokens where created_by_agent_id='162a0000-0000-0000-0000-000000000001'),
81
+ (select id from agent_board.boards where slug='atomic-cross-board'),
82
+ '162a0000-0000-0000-0000-000000000003',
83
+ 'codex', 'phase-loop', 'message-board', 'sha256:atomic-cross-repo',
84
+ 'worker', 'phase_worker', 'atomic-cross-agent'
85
+ );
86
+ }
87
+ step "fleet_commit" { COMMIT; }
88
+
89
+ session "portal"
90
+ step "portal_begin" { BEGIN; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
91
+ step "portal_enroll" {
92
+ select status from agent_board.enroll_federated_human(
93
+ 'https://atomic-cross.test', 'message-board', 'cross-human',
94
+ jsonb_build_object('sub','cross-human','iat',200), 'Cross Human'
95
+ );
96
+ }
97
+ step "portal_commit" { COMMIT; }
98
+
99
+ session "check"
100
+ step "check" {
101
+ select
102
+ (select count(*) from agent_board.agents
103
+ where owner_user_id=(select auth_user_id from agent_board.agents
104
+ where metadata #>> ARRAY['federation','subject']='cross-human'
105
+ order by kind='human' desc limit 1)) as owned_agents,
106
+ (select count(*) from agent_board.board_memberships m
107
+ join agent_board.agents a on a.id=m.agent_id
108
+ where m.board_id=(select id from agent_board.boards where slug='atomic-cross-board')
109
+ and a.owner_user_id=(select auth_user_id from agent_board.agents
110
+ where metadata #>> ARRAY['federation','subject']='cross-human'
111
+ order by kind='human' desc limit 1)) as memberships,
112
+ (select count(*) from agent_board.fleet_machine_agents b
113
+ join agent_board.agents a on a.id=b.agent_id
114
+ where a.handle='atomic-cross-agent') as bindings;
115
+ }
116
+
117
+ permutation "guard_begin" "guard_board_key_share" "fleet_begin" "fleet_onboard" "portal_begin" "portal_enroll" "guard_commit" "fleet_commit" "portal_commit" "check"
@@ -0,0 +1,66 @@
1
+ # Consiliency/message-board#162 — /portal-session's enroll_federated_human RPC
2
+ # shares the deterministic auth.users owner lock with total-human revocation.
3
+ # Prove both orders: session first completes before revocation; revocation first
4
+ # commits the marker and the waiting session fails closed.
5
+
6
+ setup
7
+ {
8
+ insert into agent_board.agents(id, agent_type, kind, handle, display_name, status)
9
+ values ('16290000-0000-0000-0000-000000000001', 'agent', 'agent',
10
+ 'atomic-fedsession-revoker', 'Atomic Fedsession Revoker', 'active');
11
+ insert into agent_board.identity_providers(
12
+ issuer, audience, supported, policy_approved, allowed_scopes, allowed_board_scopes, allowed_agent_kinds
13
+ ) values (
14
+ 'https://atomic-fedsession.test', 'message-board', true, true,
15
+ ARRAY[]::text[], ARRAY[]::text[], ARRAY['human']
16
+ );
17
+ select count(*) from agent_board.enroll_federated_human(
18
+ 'https://atomic-fedsession.test', 'message-board', 'portal-human-race',
19
+ jsonb_build_object('sub','portal-human-race'), 'Portal Human Race'
20
+ );
21
+ }
22
+
23
+ teardown
24
+ {
25
+ delete from agent_board.enrollment_federation_audit where issuer='https://atomic-fedsession.test';
26
+ delete from agent_board.fleet_human_revocations where issuer='https://atomic-fedsession.test';
27
+ delete from agent_board.fleet_revocation_events
28
+ where revoked_by_agent_id='16290000-0000-0000-0000-000000000001'
29
+ or agent_id in (
30
+ select id from agent_board.agents
31
+ where metadata #>> ARRAY['federation','subject'] = 'portal-human-race'
32
+ );
33
+ delete from agent_board.agents where handle like 'fed-human-%' or id='16290000-0000-0000-0000-000000000001';
34
+ delete from agent_board.identity_providers where issuer='https://atomic-fedsession.test';
35
+ }
36
+
37
+ session "portal"
38
+ step "portal_begin" { BEGIN; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
39
+ step "portal_enroll" {
40
+ select status from agent_board.enroll_federated_human(
41
+ 'https://atomic-fedsession.test', 'message-board', 'portal-human-race',
42
+ jsonb_build_object('sub','portal-human-race','iat',200), 'Portal Human Race'
43
+ );
44
+ }
45
+ step "portal_commit" { COMMIT; }
46
+
47
+ session "revoke"
48
+ step "revoke_begin" { BEGIN; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
49
+ step "revoke_human" {
50
+ select revoked_agent_count from agent_board.revoke_human_subtree(
51
+ (select auth_user_id from agent_board.agents where metadata #>> ARRAY['federation','subject'] = 'portal-human-race'),
52
+ '16290000-0000-0000-0000-000000000001', 'portal race revoke'
53
+ );
54
+ }
55
+ step "revoke_commit" { COMMIT; }
56
+
57
+ session "check"
58
+ step "check" {
59
+ select
60
+ (select count(*) from agent_board.fleet_human_revocations where issuer='https://atomic-fedsession.test') as markers,
61
+ (select count(*) from agent_board.agents where metadata #>> ARRAY['federation','subject'] = 'portal-human-race' and status='active') as active_humans,
62
+ (select count(*) from agent_board.enrollment_federation_audit where issuer='https://atomic-fedsession.test') as audits;
63
+ }
64
+
65
+ permutation "portal_begin" "portal_enroll" "revoke_begin" "revoke_human" "portal_commit" "revoke_commit" "check"
66
+ permutation "revoke_begin" "revoke_human" "portal_begin" "portal_enroll" "revoke_commit" "portal_commit" "check"
@@ -0,0 +1,235 @@
1
+ # Consiliency/message-board#162 — an expired complete replay must serialize
2
+ # against the live membership and creator-authority rows that justify its narrow
3
+ # expiry/exhaustion bypass. Each public invalidator is exercised in both orders.
4
+ #
5
+ # Consiliency/message-board#186 adds set_board_authority_ceiling as a fourth
6
+ # invalidator. It is the one that cannot be covered by a row lock: the invalidating
7
+ # state is the INSERT of a first ceiling row, and until it commits there is no row
8
+ # to lock — absence is the normal default-owner state (_grant_within_ceiling
9
+ # coalesces a missing row to owner). Its omission from this hand-written
10
+ # invalidator list is exactly why the race shipped uncovered.
11
+ #
12
+ # WHAT THIS PINS (a TRACE plus a value): the two transactions SERIALIZE — the
13
+ # second one to reach the ceiling prints `<waiting ...>` and, when the ceiling wins,
14
+ # the expired replay COMPLETES with `ERROR: fleet onboarding invite is not usable`.
15
+ # It pins the PROPERTY, not any one instrument; read the mutation results before
16
+ # attributing the `<waiting ...>` to the advisory lock.
17
+ #
18
+ # MUTATION RESULTS (all three run):
19
+ # * remove ONLY `perform agent_board._lock_board_authority_ceiling(...)` from
20
+ # onboard_federated_fleet_agent -> this spec still PASSES, byte-identical. The
21
+ # advisory lock is NOT what serializes these two today.
22
+ # * remove ONLY the `for update` from onboarding's `select ... from boards` ->
23
+ # still PASSES (the advisory lock takes over; atomic_fleet_board_archive fails,
24
+ # which is that spec's business).
25
+ # * remove BOTH -> FAILS: no `<waiting ...>`, and retry_onboard returns
26
+ # reused/reused/reused under a committed observer ceiling — a `member` grant
27
+ # authorized by an authority the ceiling forbids.
28
+ # The load-bearing serializer today is onboarding's boards FOR UPDATE against the
29
+ # FOR KEY SHARE lock the ceiling INSERT takes on the same boards row through
30
+ # board_authority_ceilings' FK. The advisory lock is a proven-redundant second
31
+ # defense that becomes load-bearing if that incidental lock ever moves.
32
+ #
33
+ # NOT COVERED HERE: the ABBA deadlock between these same two functions (onboarding's
34
+ # advisory-vs-boards ORDER against the setter's advisory-then-FK order). Every
35
+ # permutation below runs each RPC to completion in one step, so neither can be
36
+ # paused between its two acquisitions and no cycle can form -- this spec passed
37
+ # while that deadlock was live. It is pinned instead by the catalog ordering
38
+ # assertion 'atomic onboarding takes the ceiling advisory lock BEFORE the boards row
39
+ # lock' in agent_board_atomic_fleet_onboarding.test.sql, which was verified to fail
40
+ # exactly when a two-session probe reproduces `deadlock detected`.
41
+
42
+ setup
43
+ {
44
+ -- The ceiling setter is owner-gated on current_agent_id(), so the creator needs a
45
+ -- resolvable auth identity to act as itself; the other invalidators run as
46
+ -- service_role and are unaffected by this linkage.
47
+ insert into auth.users (id) values ('16250000-0000-0000-0000-0000000000a1');
48
+ insert into agent_board.agents(id, agent_type, kind, handle, display_name, status, auth_user_id)
49
+ values ('16250000-0000-0000-0000-000000000001', 'agent', 'agent',
50
+ 'atomic-authority-owner', 'Atomic Authority Owner', 'active',
51
+ '16250000-0000-0000-0000-0000000000a1');
52
+
53
+ select count(*) from agent_board.create_board(
54
+ '16250000-0000-0000-0000-000000000001',
55
+ 'atomic-authority-board', 'Atomic Authority Board',
56
+ 'Consiliency/message-board#162 authority isolation proof',
57
+ jsonb_build_object(), 'private'
58
+ );
59
+ insert into agent_board.fleet_trust_domains(
60
+ id, slug, display_name, domain_kind, owner_agent_id, lifecycle_state, approved_at
61
+ ) values (
62
+ '16250000-0000-0000-0000-000000000002', 'atomic-authority-domain',
63
+ 'Atomic Authority Domain', 'tailnet', '16250000-0000-0000-0000-000000000001',
64
+ 'active', now()
65
+ );
66
+ insert into agent_board.fleet_machines(
67
+ id, trust_domain_id, owner_agent_id, machine_label, machine_fingerprint,
68
+ lifecycle_state, enrollment_source, enrolled_at
69
+ ) values (
70
+ '16250000-0000-0000-0000-000000000003',
71
+ '16250000-0000-0000-0000-000000000002',
72
+ '16250000-0000-0000-0000-000000000001',
73
+ 'claw', 'sha256:atomic-authority-machine', 'active', 'portal', now()
74
+ );
75
+ insert into agent_board.identity_providers(
76
+ issuer, audience, supported, policy_approved,
77
+ allowed_scopes, allowed_board_scopes, allowed_agent_kinds
78
+ ) values (
79
+ 'https://atomic-authority.test', 'message-board', true, true,
80
+ ARRAY['board:send'], ARRAY[]::text[], ARRAY['agent']
81
+ );
82
+ select count(*) from agent_board.create_fleet_onboarding_invite(
83
+ (select id from agent_board.boards where slug='atomic-authority-board'),
84
+ '16250000-0000-0000-0000-000000000003', 'codex', 'phase-loop',
85
+ 'message-board', 'sha256:atomic-authority-repo', 'worker', 'phase_worker',
86
+ 'atomic-authority-agent', 1, now() + interval '1 hour',
87
+ '16250000-0000-0000-0000-000000000001', jsonb_build_object()
88
+ );
89
+ select count(*) from agent_board.onboard_federated_fleet_agent(
90
+ 'https://atomic-authority.test', 'message-board', 'human-authority',
91
+ jsonb_build_object('iss','https://atomic-authority.test','aud','message-board','sub','human-authority'),
92
+ 'atomic-authority-agent',
93
+ 'yd_DIFGWGusVg3SbktDJQ1bE5UWvtR33xln4b05JIhk',
94
+ 'raw_ed25519_base64url',
95
+ 'sha256:NeVC2vx1MbTY56jUwJcLLr6YwB4IKCERsXWbUwhf5pA',
96
+ true, null, 'agent', ARRAY['board:send'], ARRAY[]::text[],
97
+ (select code from agent_board.board_invite_tokens where created_by_agent_id='16250000-0000-0000-0000-000000000001'),
98
+ (select id from agent_board.boards where slug='atomic-authority-board'),
99
+ '16250000-0000-0000-0000-000000000003', 'codex', 'phase-loop',
100
+ 'message-board', 'sha256:atomic-authority-repo', 'worker', 'phase_worker',
101
+ 'atomic-authority-agent'
102
+ );
103
+ update agent_board.board_invite_tokens
104
+ set expires_at = now() - interval '1 minute'
105
+ where created_by_agent_id='16250000-0000-0000-0000-000000000001';
106
+ }
107
+
108
+ teardown
109
+ {
110
+ delete from agent_board.fleet_machine_agents where machine_id='16250000-0000-0000-0000-000000000003';
111
+ delete from agent_board.fleet_repo_scopes where harness_registration_id in (
112
+ select id from agent_board.fleet_harness_registrations where machine_id='16250000-0000-0000-0000-000000000003'
113
+ );
114
+ delete from agent_board.fleet_harness_registrations where machine_id='16250000-0000-0000-0000-000000000003';
115
+ delete from agent_board.board_invite_redemptions where invite_id in (
116
+ select id from agent_board.board_invite_tokens where created_by_agent_id='16250000-0000-0000-0000-000000000001'
117
+ );
118
+ truncate agent_board.fleet_onboarding_invite_bounds;
119
+ delete from agent_board.board_invite_tokens where created_by_agent_id='16250000-0000-0000-0000-000000000001';
120
+ delete from agent_board.board_authority_ceilings where board_id in (
121
+ select id from agent_board.boards where slug='atomic-authority-board'
122
+ );
123
+ delete from agent_board.board_memberships where board_id in (
124
+ select id from agent_board.boards where slug='atomic-authority-board'
125
+ );
126
+ delete from agent_board.enrollment_federation_audit where agent_id in (
127
+ select id from agent_board.agents where handle='atomic-authority-agent'
128
+ );
129
+ delete from agent_board.agent_signing_keys where agent_id in (
130
+ select id from agent_board.agents where handle='atomic-authority-agent'
131
+ );
132
+ delete from agent_board.agents where handle='atomic-authority-agent';
133
+ delete from agent_board.boards where slug='atomic-authority-board';
134
+ delete from agent_board.fleet_machines where id='16250000-0000-0000-0000-000000000003';
135
+ delete from agent_board.fleet_trust_domains where id='16250000-0000-0000-0000-000000000002';
136
+ delete from agent_board.agents where id='16250000-0000-0000-0000-000000000001';
137
+ delete from auth.users where id='16250000-0000-0000-0000-0000000000a1';
138
+ delete from agent_board.identity_providers where issuer='https://atomic-authority.test';
139
+ }
140
+
141
+ session "retry"
142
+ step "retry_begin" { BEGIN; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
143
+ step "retry_onboard" {
144
+ select identity_disposition, membership_disposition, binding_disposition
145
+ from agent_board.onboard_federated_fleet_agent(
146
+ 'https://atomic-authority.test', 'message-board', 'human-authority',
147
+ jsonb_build_object('iss','https://atomic-authority.test','aud','message-board','sub','human-authority','iat',200),
148
+ 'atomic-authority-agent',
149
+ 'yd_DIFGWGusVg3SbktDJQ1bE5UWvtR33xln4b05JIhk',
150
+ 'raw_ed25519_base64url',
151
+ 'sha256:NeVC2vx1MbTY56jUwJcLLr6YwB4IKCERsXWbUwhf5pA',
152
+ true, null, 'agent', ARRAY['board:send'], ARRAY[]::text[],
153
+ (select code from agent_board.board_invite_tokens where created_by_agent_id='16250000-0000-0000-0000-000000000001'),
154
+ (select id from agent_board.boards where slug='atomic-authority-board'),
155
+ '16250000-0000-0000-0000-000000000003', 'codex', 'phase-loop',
156
+ 'message-board', 'sha256:atomic-authority-repo', 'worker', 'phase_worker',
157
+ 'atomic-authority-agent'
158
+ );
159
+ }
160
+ step "retry_commit" { COMMIT; }
161
+
162
+ session "invalidator"
163
+ step "invalidator_begin" { BEGIN; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
164
+ step "remove_member" {
165
+ select membership_state from agent_board.update_board_membership(
166
+ (select id from agent_board.boards where slug='atomic-authority-board'),
167
+ (select id from agent_board.agents where handle='atomic-authority-agent'),
168
+ 'removed', jsonb_build_object('reason','isolation member removal')
169
+ );
170
+ }
171
+ step "revoke_creator" {
172
+ select status from agent_board.revoke_agent(
173
+ '16250000-0000-0000-0000-000000000001', 'isolation creator revoke'
174
+ );
175
+ }
176
+ step "demote_creator" {
177
+ select role from agent_board.grant_board_role(
178
+ (select id from agent_board.boards where slug='atomic-authority-board'),
179
+ '16250000-0000-0000-0000-000000000001', 'observer',
180
+ '16250000-0000-0000-0000-000000000001'
181
+ );
182
+ }
183
+ step "invalidator_commit" { COMMIT; }
184
+
185
+ # The ceiling setter is owner-gated on current_agent_id(), so this session runs as
186
+ # the creator under `authenticated` (NOT service_role, whose current_agent_id() is
187
+ # null and which the owner gate rejects). Separate session because that role/claim
188
+ # setup differs from the service_role invalidator above.
189
+ session "ceiling"
190
+ step "ceiling_begin" {
191
+ BEGIN;
192
+ SET LOCAL ROLE authenticated;
193
+ SET LOCAL "request.jwt.claim.role" = 'authenticated';
194
+ SET LOCAL "request.jwt.claim.sub" = '16250000-0000-0000-0000-0000000000a1';
195
+ }
196
+ step "set_ceiling" {
197
+ select ceiling_max_grantable_role from agent_board.set_board_authority_ceiling(
198
+ (select id from agent_board.boards where slug='atomic-authority-board'),
199
+ 'observer'
200
+ );
201
+ }
202
+ step "ceiling_commit" { COMMIT; }
203
+
204
+ session "check"
205
+ step "check" {
206
+ select
207
+ (select status from agent_board.agents where id='16250000-0000-0000-0000-000000000001') as creator_status,
208
+ (select role || '/' || membership_state from agent_board.board_memberships
209
+ where board_id=(select id from agent_board.boards where slug='atomic-authority-board')
210
+ and agent_id='16250000-0000-0000-0000-000000000001'
211
+ and membership_state in ('joined','subscribed')) as creator_authority,
212
+ (select membership_state from agent_board.board_memberships
213
+ where board_id=(select id from agent_board.boards where slug='atomic-authority-board')
214
+ and agent_id=(select id from agent_board.agents where handle='atomic-authority-agent')
215
+ order by (membership_state in ('joined','subscribed')) desc, created_at desc, id desc limit 1) as member_state,
216
+ (select max_grantable_role from agent_board.board_authority_ceilings
217
+ where board_id=(select id from agent_board.boards where slug='atomic-authority-board')) as board_ceiling;
218
+ }
219
+
220
+ # Retry wins, then the invalidator commits.
221
+ permutation "retry_begin" "retry_onboard" "invalidator_begin" "remove_member" "retry_commit" "invalidator_commit" "check"
222
+ permutation "retry_begin" "retry_onboard" "invalidator_begin" "revoke_creator" "retry_commit" "invalidator_commit" "check"
223
+ permutation "retry_begin" "retry_onboard" "invalidator_begin" "demote_creator" "retry_commit" "invalidator_commit" "check"
224
+
225
+ # The invalidator wins; the expired retry must fail closed.
226
+ permutation "invalidator_begin" "remove_member" "retry_begin" "retry_onboard" "invalidator_commit" "retry_commit" "check"
227
+ permutation "invalidator_begin" "revoke_creator" "retry_begin" "retry_onboard" "invalidator_commit" "retry_commit" "check"
228
+ permutation "invalidator_begin" "demote_creator" "retry_begin" "retry_onboard" "invalidator_commit" "retry_commit" "check"
229
+
230
+ # #186 — the ceiling INSERT, in both orders. Retry first: the ceiling setter must
231
+ # WAIT on the advisory lock rather than slip its insert under a completed
232
+ # authorization. Ceiling first: the retry must WAIT and then fail closed against the
233
+ # committed observer ceiling instead of reading the pre-insert absence as owner.
234
+ permutation "retry_begin" "retry_onboard" "ceiling_begin" "set_ceiling" "retry_commit" "ceiling_commit" "check"
235
+ permutation "ceiling_begin" "set_ceiling" "retry_begin" "retry_onboard" "ceiling_commit" "retry_commit" "check"
@@ -0,0 +1,127 @@
1
+ # Consiliency/message-board#162 — exact binding revocation and composed retry use
2
+ # the same machine-before-binding order in both winner orderings. A committed
3
+ # tombstone is never replaced by a new active binding.
4
+
5
+ setup
6
+ {
7
+ insert into agent_board.agents(id, agent_type, kind, handle, display_name, status)
8
+ values ('16230000-0000-0000-0000-000000000001', 'agent', 'agent',
9
+ 'atomic-binding-owner', 'Atomic Binding Owner', 'active');
10
+ select count(*) from agent_board.create_board(
11
+ '16230000-0000-0000-0000-000000000001', 'atomic-binding-board',
12
+ 'Atomic Binding Board', 'Consiliency/message-board#162 isolation proof',
13
+ jsonb_build_object(), 'private'
14
+ );
15
+ insert into agent_board.fleet_trust_domains(
16
+ id, slug, display_name, domain_kind, owner_agent_id, lifecycle_state, approved_at
17
+ ) values (
18
+ '16230000-0000-0000-0000-000000000002', 'atomic-binding-domain',
19
+ 'Atomic Binding Domain', 'tailnet', '16230000-0000-0000-0000-000000000001',
20
+ 'active', now()
21
+ );
22
+ insert into agent_board.fleet_machines(
23
+ id, trust_domain_id, owner_agent_id, machine_label, machine_fingerprint,
24
+ lifecycle_state, enrollment_source, enrolled_at
25
+ ) values (
26
+ '16230000-0000-0000-0000-000000000003',
27
+ '16230000-0000-0000-0000-000000000002',
28
+ '16230000-0000-0000-0000-000000000001',
29
+ 'claw', 'sha256:atomic-binding-machine', 'active', 'portal', now()
30
+ );
31
+ insert into agent_board.identity_providers(
32
+ issuer, audience, supported, policy_approved,
33
+ allowed_scopes, allowed_board_scopes, allowed_agent_kinds
34
+ ) values (
35
+ 'https://atomic-binding.test', 'message-board', true, true,
36
+ ARRAY['board:send'], ARRAY[]::text[], ARRAY['agent']
37
+ );
38
+ select count(*) from agent_board.create_fleet_onboarding_invite(
39
+ (select id from agent_board.boards where slug='atomic-binding-board'),
40
+ '16230000-0000-0000-0000-000000000003', 'codex', 'phase-loop',
41
+ 'message-board', 'sha256:atomic-binding-repo', 'worker', 'phase_worker',
42
+ 'atomic-binding-agent', 1, now() + interval '1 hour',
43
+ '16230000-0000-0000-0000-000000000001', jsonb_build_object()
44
+ );
45
+ select count(*) from agent_board.onboard_federated_fleet_agent(
46
+ 'https://atomic-binding.test', 'message-board', 'human-binding',
47
+ jsonb_build_object('iss','https://atomic-binding.test','aud','message-board','sub','human-binding'),
48
+ 'atomic-binding-agent',
49
+ 'yd_DIFGWGusVg3SbktDJQ1bE5UWvtR33xln4b05JIhk',
50
+ 'raw_ed25519_base64url',
51
+ 'sha256:NeVC2vx1MbTY56jUwJcLLr6YwB4IKCERsXWbUwhf5pA',
52
+ true, null, 'agent', ARRAY['board:send'], ARRAY[]::text[],
53
+ (select code from agent_board.board_invite_tokens where created_by_agent_id='16230000-0000-0000-0000-000000000001'),
54
+ (select id from agent_board.boards where slug='atomic-binding-board'),
55
+ '16230000-0000-0000-0000-000000000003', 'codex', 'phase-loop',
56
+ 'message-board', 'sha256:atomic-binding-repo', 'worker', 'phase_worker',
57
+ 'atomic-binding-agent'
58
+ );
59
+ }
60
+
61
+ teardown
62
+ {
63
+ delete from agent_board.fleet_machine_agents where machine_id='16230000-0000-0000-0000-000000000003';
64
+ delete from agent_board.fleet_repo_scopes where harness_registration_id in (
65
+ select id from agent_board.fleet_harness_registrations where machine_id='16230000-0000-0000-0000-000000000003'
66
+ );
67
+ delete from agent_board.fleet_harness_registrations where machine_id='16230000-0000-0000-0000-000000000003';
68
+ delete from agent_board.board_invite_redemptions where invite_id in (
69
+ select id from agent_board.board_invite_tokens where created_by_agent_id='16230000-0000-0000-0000-000000000001'
70
+ );
71
+ truncate agent_board.fleet_onboarding_invite_bounds;
72
+ delete from agent_board.board_invite_tokens where created_by_agent_id='16230000-0000-0000-0000-000000000001';
73
+ delete from agent_board.board_memberships where board_id in (
74
+ select id from agent_board.boards where slug='atomic-binding-board'
75
+ );
76
+ delete from agent_board.enrollment_federation_audit where agent_id in (
77
+ select id from agent_board.agents where handle='atomic-binding-agent'
78
+ );
79
+ delete from agent_board.agent_signing_keys where agent_id in (
80
+ select id from agent_board.agents where handle='atomic-binding-agent'
81
+ );
82
+ delete from agent_board.agents where handle='atomic-binding-agent';
83
+ delete from agent_board.boards where slug='atomic-binding-board';
84
+ delete from agent_board.fleet_machines where id='16230000-0000-0000-0000-000000000003';
85
+ delete from agent_board.fleet_trust_domains where id='16230000-0000-0000-0000-000000000002';
86
+ delete from agent_board.agents where id='16230000-0000-0000-0000-000000000001';
87
+ delete from agent_board.identity_providers where issuer='https://atomic-binding.test';
88
+ }
89
+
90
+ session "retry"
91
+ step "retry_begin" { BEGIN; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
92
+ step "retry_onboard" {
93
+ select binding_disposition from agent_board.onboard_federated_fleet_agent(
94
+ 'https://atomic-binding.test', 'message-board', 'human-binding',
95
+ jsonb_build_object('iss','https://atomic-binding.test','aud','message-board','sub','human-binding','iat',200),
96
+ 'atomic-binding-agent','yd_DIFGWGusVg3SbktDJQ1bE5UWvtR33xln4b05JIhk',
97
+ 'raw_ed25519_base64url','sha256:NeVC2vx1MbTY56jUwJcLLr6YwB4IKCERsXWbUwhf5pA',
98
+ true,null,'agent',ARRAY['board:send'],ARRAY[]::text[],
99
+ (select code from agent_board.board_invite_tokens where created_by_agent_id='16230000-0000-0000-0000-000000000001'),
100
+ (select id from agent_board.boards where slug='atomic-binding-board'),
101
+ '16230000-0000-0000-0000-000000000003','codex','phase-loop',
102
+ 'message-board','sha256:atomic-binding-repo','worker','phase_worker','atomic-binding-agent'
103
+ );
104
+ }
105
+ step "retry_commit" { COMMIT; }
106
+
107
+ session "revoke"
108
+ step "revoke_begin" { BEGIN; SET LOCAL "request.jwt.claim.role" = 'service_role'; }
109
+ step "revoke_binding" {
110
+ select lifecycle_state from agent_board.revoke_fleet_machine_agent_binding(
111
+ (select id from agent_board.fleet_machine_agents where machine_id='16230000-0000-0000-0000-000000000003'),
112
+ '16230000-0000-0000-0000-000000000001','isolation proof',jsonb_build_object()
113
+ );
114
+ }
115
+ step "revoke_commit" { COMMIT; }
116
+
117
+ session "check"
118
+ step "check_binding" {
119
+ select count(*) filter (where lifecycle_state='active') as active,
120
+ count(*) filter (where lifecycle_state='revoked') as revoked,
121
+ count(*) as total
122
+ from agent_board.fleet_machine_agents
123
+ where machine_id='16230000-0000-0000-0000-000000000003';
124
+ }
125
+
126
+ permutation "retry_begin" "retry_onboard" "revoke_begin" "revoke_binding" "retry_commit" "revoke_commit" "check_binding"
127
+ permutation "revoke_begin" "revoke_binding" "retry_begin" "retry_onboard" "revoke_commit" "retry_commit" "check_binding"