From a9d9b34a4f67ffa835dd8948ba6ec06c95856eec Mon Sep 17 00:00:00 2001 From: therevoltingx <191371+therevoltingx@users.noreply.github.com> Date: Fri, 25 Sep 2026 10:55:03 -0700 Subject: [PATCH 1/3] fix(compliance): keep owner tests from re-arming the heartbeat schedule A full-suite owner_test published through recordComplianceRun advanced next_compliance_check_at by a full interval and cleared requeued_at, so it silently cancelled a pending requeue and could starve the independent heartbeat indefinitely. Gate the schedule_next CTE on triggered_by: owner_test runs still publish the verdict but leave the schedule untouched, and a first-ever owner test leaves the agent immediately eligible for a heartbeat. heartbeat, manual, and webhook runs keep advancing the cadence and consuming requeues. Closes #7680 Co-Authored-By: Claude Opus 5.5 --- server/src/db/compliance-db.ts | 9 +- .../compliance-run-publication.test.ts | 126 ++++++++++++++++++ 2 files changed, 133 insertions(+), 2 deletions(-) diff --git a/server/src/db/compliance-db.ts b/server/src/db/compliance-db.ts index 2691fe8b139..eb6856e6749 100644 --- a/server/src/db/compliance-db.ts +++ b/server/src/db/compliance-db.ts @@ -932,14 +932,18 @@ export class ComplianceDatabase { tracksSummary[t.track] = t.status; } - // 4. Upsert the materialized status and capture transition + // 4. Upsert the materialized status and capture transition. + // Owner-initiated runs publish the verdict but never touch the heartbeat + // schedule: they must not re-arm the eligibility gate, cancel a pending + // requeue, or displace the registry's independent check (#7680). const statusResult = await client.query( `WITH schedule_next AS ( INSERT INTO agent_registry_metadata (agent_url, next_compliance_check_at) - VALUES ($1, NOW() + INTERVAL '12 hours') + VALUES ($1, CASE WHEN $7 = 'owner_test' THEN NULL ELSE NOW() + INTERVAL '12 hours' END) ON CONFLICT (agent_url) DO UPDATE SET next_compliance_check_at = NOW() + make_interval(hours => agent_registry_metadata.check_interval_hours), requeued_at = NULL + WHERE $7 != 'owner_test' ) INSERT INTO agent_compliance_status ( agent_url, status, last_checked_at, @@ -996,6 +1000,7 @@ export class ComplianceDatabase { input.headline ?? null, input.requested_compliance_target ?? null, input.adcp_version ?? null, + input.triggered_by ?? 'heartbeat', ], ); diff --git a/server/tests/integration/compliance-run-publication.test.ts b/server/tests/integration/compliance-run-publication.test.ts index ead12121e3d..9735c20001f 100644 --- a/server/tests/integration/compliance-run-publication.test.ts +++ b/server/tests/integration/compliance-run-publication.test.ts @@ -188,6 +188,132 @@ describe.skipIf(!process.env.DATABASE_URL)('compliance publication transaction', } }); + describe('owner-initiated runs leave the heartbeat schedule alone (#7680)', () => { + const urls: string[] = []; + const freshAgent = async (options: { withMetadata?: boolean } = {}) => { + const url = `https://${randomUUID()}.example.test/mcp`; + urls.push(url); + if (options.withMetadata ?? true) await db.upsertRegistryMetadata(url, { lifecycle_stage: 'production' }); + return url; + }; + const schedule = async (url: string) => (await pool.query<{ + next_compliance_check_at: Date | null; requeued_at: Date | null; hours_until_next: number | null; + }>( + `SELECT next_compliance_check_at, requeued_at, + EXTRACT(EPOCH FROM next_compliance_check_at - NOW()) / 3600 AS hours_until_next + FROM agent_registry_metadata WHERE agent_url = $1`, + [url], + )).rows[0]; + const isDue = async (url: string) => + (await db.getAgentsDueForCheck(100000)).some(agent => agent.agent_url === url); + + afterAll(async () => { + for (const table of ['agent_compliance_step_diagnostics', 'agent_storyboard_status', 'agent_verification_badges', + 'agent_compliance_status', 'agent_compliance_runs', 'agent_registry_metadata']) { + await pool.query(`DELETE FROM ${table} WHERE agent_url = ANY($1::text[])`, [urls]); + } + }); + + it('keeps a pending requeue when a full-suite owner test publishes', async () => { + const url = await freshAgent(); + await db.requeueForHeartbeat(url); + await db.recordComplianceRun({ ...input, agent_url: url, triggered_by: 'owner_test' }); + + const after = await schedule(url); + expect(after.next_compliance_check_at).toBeNull(); + expect(after.requeued_at).not.toBeNull(); + expect(await isDue(url)).toBe(true); + // The owner verdict still publishes to the public card. + expect((await db.getComplianceStatus(url))?.status).toBe('passing'); + }); + + it('consumes the requeue when the heartbeat serving it publishes', async () => { + const url = await freshAgent(); + await db.requeueForHeartbeat(url); + await db.recordComplianceRun({ ...input, agent_url: url, triggered_by: 'heartbeat' }); + + const after = await schedule(url); + expect(after.requeued_at).toBeNull(); + expect(Number(after.hours_until_next)).toBeCloseTo(12, 1); + expect(await isDue(url)).toBe(false); + }); + + it.each(['manual', 'webhook'] as const)('advances the cadence and clears the requeue for %s runs', async (triggeredBy) => { + const url = await freshAgent(); + await db.requeueForHeartbeat(url); + await db.recordComplianceRun({ ...input, agent_url: url, triggered_by: triggeredBy }); + + const after = await schedule(url); + expect(after.requeued_at).toBeNull(); + expect(Number(after.hours_until_next)).toBeCloseTo(12, 1); + }); + + it('defaults an unlabelled run to heartbeat scheduling', async () => { + const url = await freshAgent(); + await db.requeueForHeartbeat(url); + expect(input.triggered_by).toBeUndefined(); + await db.recordComplianceRun({ ...input, agent_url: url }); + + const after = await schedule(url); + expect(after.requeued_at).toBeNull(); + expect(Number(after.hours_until_next)).toBeCloseTo(12, 1); + }); + + it('does not push a scheduled heartbeat further out when an owner test publishes', async () => { + const url = await freshAgent(); + await pool.query( + `UPDATE agent_registry_metadata SET next_compliance_check_at = NOW() + INTERVAL '2 hours' WHERE agent_url = $1`, + [url], + ); + const before = await schedule(url); + await db.recordComplianceRun({ ...input, agent_url: url, triggered_by: 'owner_test' }); + + expect((await schedule(url)).next_compliance_check_at).toEqual(before.next_compliance_check_at); + }); + + it('leaves an overdue heartbeat due after an owner test publishes', async () => { + const url = await freshAgent(); + await pool.query( + `UPDATE agent_registry_metadata SET next_compliance_check_at = NOW() - INTERVAL '1 hour' WHERE agent_url = $1`, + [url], + ); + await db.recordComplianceRun({ ...input, agent_url: url, triggered_by: 'owner_test' }); + + expect(await isDue(url)).toBe(true); + }); + + it('leaves a first-ever owner test immediately eligible for an independent heartbeat', async () => { + const url = await freshAgent({ withMetadata: false }); + await db.recordComplianceRun({ ...input, agent_url: url, triggered_by: 'owner_test' }); + + const after = await schedule(url); + expect(after).toBeDefined(); + expect(after.next_compliance_check_at).toBeNull(); + expect(await isDue(url)).toBe(true); + }); + + it('still schedules a first-ever heartbeat on the default cadence', async () => { + const url = await freshAgent({ withMetadata: false }); + await db.recordComplianceRun({ ...input, agent_url: url, triggered_by: 'heartbeat' }); + + expect(Number((await schedule(url)).hours_until_next)).toBeCloseTo(12, 1); + }); + + it('leaves scheduling untouched for a scoped (non-authoritative) owner test', async () => { + const url = await freshAgent(); + await db.requeueForHeartbeat(url); + await db.recordComplianceRun({ + ...input, agent_url: url, triggered_by: 'owner_test', + is_authoritative: false, replace_storyboard_statuses: false, + storyboard_statuses: [{ storyboard_id: 'first', status: 'passing', steps_passed: 1, steps_total: 1 }], + }); + + const after = await schedule(url); + expect(after.next_compliance_check_at).toBeNull(); + expect(after.requeued_at).not.toBeNull(); + }); + }); + it('uses only complete public profiles for version and specialism fallback', async () => { const complete = await db.recordComplianceRun(input); const epoch = Date.parse('2030-01-01T00:00:00Z'); From c9a91101057df96a8b3d0ca17cf5a975411cffe6 Mon Sep 17 00:00:00 2001 From: therevoltingx <191371+therevoltingx@users.noreply.github.com> Date: Fri, 25 Sep 2026 13:16:00 -0700 Subject: [PATCH 2/3] docs(compliance): note the TriggeredBy union guard on the schedule predicate Requested in #7691 review: the WHERE predicate on the schedule_next CTE relies on the TypeScript TriggeredBy union as its compile-time guard. A new union member opts into advancing the cadence and consuming requeues unless the predicate is updated alongside it, and the INSERT-branch CASE is keyed on the same literal and must move with it. Co-Authored-By: Claude Fable 5.1 --- server/src/db/compliance-db.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/server/src/db/compliance-db.ts b/server/src/db/compliance-db.ts index eb6856e6749..2b44be07bfc 100644 --- a/server/src/db/compliance-db.ts +++ b/server/src/db/compliance-db.ts @@ -943,6 +943,11 @@ export class ComplianceDatabase { ON CONFLICT (agent_url) DO UPDATE SET next_compliance_check_at = NOW() + make_interval(hours => agent_registry_metadata.check_interval_hours), requeued_at = NULL + -- $7 is TriggeredBy (compliance-db.ts): the TypeScript union is the + -- compile-time guard on this value space. A new TriggeredBy member + -- opts into advancing the cadence and consuming requeues by default + -- unless this predicate is updated alongside the union. The CASE + -- above is keyed on the same literal and must move with it. WHERE $7 != 'owner_test' ) INSERT INTO agent_compliance_status ( From 96f881960c655c7d7a002dc4fbdc57bccc7beee5 Mon Sep 17 00:00:00 2001 From: therevoltingx <191371+therevoltingx@users.noreply.github.com> Date: Thu, 8 Oct 2026 18:28:07 -0700 Subject: [PATCH 3/3] test(compliance): register #7680 fixture agents on the member profile The heartbeat due query now selects only agents with a registry source (#7844), so metadata-only fixture agents were never due regardless of the fix. Owner tests come from member-registered agents; register each fixture agent on the suite's member profile, as beforeAll already does. Co-Authored-By: Claude Opus 5.5 --- .../tests/integration/compliance-run-publication.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/tests/integration/compliance-run-publication.test.ts b/server/tests/integration/compliance-run-publication.test.ts index 150b9c4649f..e5724f59394 100644 --- a/server/tests/integration/compliance-run-publication.test.ts +++ b/server/tests/integration/compliance-run-publication.test.ts @@ -356,6 +356,13 @@ describe.skipIf(!process.env.DATABASE_URL)('compliance publication transaction', const freshAgent = async (options: { withMetadata?: boolean } = {}) => { const url = `https://${randomUUID()}.example.test/mcp`; urls.push(url); + // Owner tests come from member-registered agents, and the heartbeat only + // selects agents with a registry source, so register each one on the + // suite's member profile. + await pool.query( + 'UPDATE member_profiles SET agents = agents || $2::jsonb WHERE workos_organization_id = $1', + [ownerOrgId, JSON.stringify([{ url }])], + ); if (options.withMetadata ?? true) await db.upsertRegistryMetadata(url, { lifecycle_stage: 'production' }); return url; };