Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/src/addie/jobs/compliance-heartbeat.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { complianceRunProvenance } from '../../compliance/run-provenance.js';
import { isAuthoritativeComplianceRun } from '../../compliance/run-publication.js';
/**
* Compliance Heartbeat Job
Expand All @@ -19,6 +20,7 @@ import {
selectedComplianceTargetMatchesObservedProfile,
type ComplyOptions,
type ComplianceTargetSelection,
type ComplianceResult,
} from '../services/compliance-testing.js';
import { ComplianceDatabase, type LifecycleStage } from '../../db/compliance-db.js';
import { query, withDatabaseDeadline } from '../../db/client.js';
Expand Down Expand Up @@ -459,6 +461,7 @@ export async function runComplianceHeartbeatJob(options: HeartbeatOptions = {}):
triggered_by: 'heartbeat',
dry_run: false,
completeness: 'not_completed',
provenance_json: complianceRunProvenance({ adcp_version: runTarget.version, agent_profile: {} as ComplianceResult['agent_profile'] }),
is_authoritative: false,
replace_storyboard_statuses: true,
});
Expand Down
417 changes: 174 additions & 243 deletions server/src/addie/services/compliance-testing.ts

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions server/src/compliance/run-provenance.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { LIBRARY_VERSION } from '@adcp/sdk';
import type { ComplianceResult, ComplyOptions } from '@adcp/sdk/testing';

export interface ComplianceRunProvenance {
grading_policy_version: string;
compliance_bundle_version: string | null;
sdk_version: string;
agent_build_version: string | null;
agent_library_version: string | null;
test_session_id: string | null;
timeout_ms: number | null;
storyboard_start_offset: number | null;
auth_type: string | null;
}

export function complianceRunProvenance(
result: Pick<ComplianceResult, 'adcp_version' | 'agent_profile'>,
options?: ComplyOptions,
): ComplianceRunProvenance {
return {
grading_policy_version: 'hosted-compliance-v1',
compliance_bundle_version: result.adcp_version ?? null,
sdk_version: LIBRARY_VERSION,
// Agent-reported provenance; absent optional fields remain unknown.
agent_build_version: result.agent_profile?.adcp_build_version ?? null,
agent_library_version: result.agent_profile?.library_version ?? null,
test_session_id: options?.test_session_id ?? null,
timeout_ms: options?.timeout_ms ?? null,
storyboard_start_offset: options?.storyboard_start_offset ?? null,
auth_type: options?.auth?.type ?? null,
};
}
55 changes: 55 additions & 0 deletions server/src/compliance/step-disposition.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/** Hosted grading policy over SDK output; never derive a verdict from diagnostic prose. */
export type StepDisposition = 'passed' | 'failed' | 'not_applicable' | 'setup_gap' | 'dependency_failed';

type GradedStep = {
passed?: boolean;
skipped?: boolean;
task?: string;
step_id?: unknown;
skip_reason?: string;
requirement?: unknown;
skip?: { reason?: string; requirement?: unknown };
};

// @adcp/sdk 14.0.0-rc.33 projects detailed reasons but omits canonical skip.reason.
// Keep this exact compatibility list aligned with its DETAILED_SKIP_TO_CANONICAL.
const NOT_APPLICABLE = new Set([
'not_applicable', 'peer_branch_taken', 'peer_substituted',
'probe_skipped', 'not_in_only_vectors', 'grader_skipped',
'capability_profile_mismatch', 'transport_ungradable', 'mcp_mode_flattens_url_edges',
'oauth_not_advertised', 'rate_limit_not_triggered', 'force_scenario_unsupported',
'fixture_seed_unsupported', 'fixture_unsatisfied', 'capability_unsupported',
'capability_prerequisite_unavailable',
]);
const SETUP_GAPS = new Set([
'missing_test_controller', 'fixture_unavailable', 'unsatisfied_contract',
'rate_abuse_opt_out', 'live_side_effect_opt_in_required',
'operator_skip', 'controller_seeding_failed',
]);
export function classifyComplianceStep(step: GradedStep, scenario = ''): StepDisposition {
// The synthetic seeding phase evaluates harness setup, not production behavior.
// Retain its failed wire evidence separately for the owner/operator.
if (scenario.endsWith('/__controller_seeding__') && step.task === 'comply_test_controller') {
return step.passed && !step.skipped ? 'not_applicable' : 'setup_gap';
}
if (!step.skipped) return step.passed ? 'passed' : 'failed';
const reason = step.skip?.reason ?? step.skip_reason;
if (reason === 'missing_tool') {
// rc.33 omits step_id in the synthetic projection. If a producer supplies
// an identity, require it to agree with the reserved gate phase.
const syntheticGate = scenario.endsWith('/missing_tool') &&
(step.step_id === undefined || step.step_id === 'missing_tool');
return syntheticGate ? 'not_applicable' : 'failed';
}
if (NOT_APPLICABLE.has(reason ?? '')) return 'not_applicable';
// The detailed seeding reason is more specific than canonical prerequisite_failed.
if (SETUP_GAPS.has(reason ?? '') || step.skip_reason === 'controller_seeding_failed') return 'setup_gap';
const requirement = step.skip?.requirement ?? step.requirement;
if (reason === 'requirement_unmet' && typeof requirement === 'string' && requirement.trim()) {
return 'setup_gap';
}
// rc.33 drops causal IDs from ordinary prerequisite failures. A nearby neutral
// skip is not proof: a passed producer may still have omitted required state.
if (reason === 'prerequisite_failed') return 'dependency_failed';
return 'failed';
}
21 changes: 13 additions & 8 deletions server/src/db/compliance-db.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import type { ComplianceRunProvenance } from '../compliance/run-provenance.js';
import { isAuthoritativeComplianceRun, type RunCompleteness } from '../compliance/run-publication.js';
import { query, getClient } from './client.js';
import { decrypt as decryptToken } from './encryption.js';
Expand Down Expand Up @@ -131,6 +132,7 @@ export interface ComplianceRun {
completeness: RunCompleteness;
is_authoritative: boolean;
storyboard_statuses_json: StoryboardStatusEntry[] | null;
provenance_json: ComplianceRunProvenance | null;
notices_json: NoticeEntry[] | null;
}

Expand Down Expand Up @@ -165,6 +167,7 @@ export interface AgentComplianceStatus {
last_triggered_by: TriggeredBy | null;
/** tracks_json from the most recent non-dry-run, used for current-run UI details */
track_details_json?: TrackSummaryEntry[] | null;
provenance_json?: ComplianceRunProvenance | null;
}

export interface ComplianceStatusWithStoryboardCounts {
Expand Down Expand Up @@ -294,6 +297,7 @@ export interface RecordComplianceRunInput {
dry_run?: boolean;
completeness?: RunCompleteness;
is_authoritative?: boolean;
provenance_json?: ComplianceRunProvenance | null;
/** Durable refresh operation that produced this run; makes lease recovery idempotent. */
refresh_operation_id?: string | null;
/** Lease token paired with refresh_operation_id for fenced persistence. */
Expand Down Expand Up @@ -617,8 +621,8 @@ export class ComplianceDatabase {
total_duration_ms, tracks_json, tracks_passed, tracks_failed,
tracks_skipped, tracks_partial, agent_profile_json,
observations_json, triggered_by, triggered_org_id, dry_run,
notices_json, refresh_operation_id, completeness, is_authoritative, storyboard_statuses_json
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22)
notices_json, refresh_operation_id, completeness, is_authoritative, storyboard_statuses_json, provenance_json
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17, $18, $19, $20, $21, $22, $23)
ON CONFLICT (refresh_operation_id) DO NOTHING
RETURNING *`,
[
Expand All @@ -644,6 +648,7 @@ export class ComplianceDatabase {
input.completeness ?? 'complete',
authoritative,
JSON.stringify(input.storyboard_statuses ?? []),
input.provenance_json ? JSON.stringify(input.provenance_json) : null,
],
);
let run = runResult.rows[0] as ComplianceRun | undefined;
Expand Down Expand Up @@ -1000,11 +1005,11 @@ export class ComplianceDatabase {
`SELECT s.*, COALESCE(m.lifecycle_stage, 'production') AS lifecycle_stage,
r.id AS last_run_id,
r.triggered_by AS last_triggered_by,
r.tracks_json AS track_details_json
r.tracks_json AS track_details_json, r.provenance_json
FROM agent_compliance_status s
LEFT JOIN agent_registry_metadata m ON m.agent_url = s.agent_url
LEFT JOIN LATERAL (
SELECT id, triggered_by, tracks_json FROM agent_compliance_runs
SELECT id, triggered_by, tracks_json, provenance_json FROM agent_compliance_runs
WHERE agent_url = s.agent_url AND dry_run = false AND is_authoritative = true
ORDER BY tested_at DESC LIMIT 1
) r ON true
Expand All @@ -1019,13 +1024,13 @@ export class ComplianceDatabase {
`SELECT s.*, COALESCE(m.lifecycle_stage, 'production') AS lifecycle_stage,
r.id AS last_run_id,
r.triggered_by AS last_triggered_by,
r.tracks_json AS track_details_json,
r.tracks_json AS track_details_json, r.provenance_json,
COALESCE(sb_counts.passing, 0)::int AS storyboards_passing,
COALESCE(sb_counts.total, 0)::int AS storyboards_total
FROM agent_compliance_status s
LEFT JOIN agent_registry_metadata m ON m.agent_url = s.agent_url
LEFT JOIN LATERAL (
SELECT id, triggered_by, tracks_json FROM agent_compliance_runs
SELECT id, triggered_by, tracks_json, provenance_json FROM agent_compliance_runs
WHERE agent_url = s.agent_url AND dry_run = false AND is_authoritative = true
ORDER BY tested_at DESC LIMIT 1
) r ON true
Expand Down Expand Up @@ -1080,11 +1085,11 @@ export class ComplianceDatabase {
`SELECT s.*, COALESCE(m.lifecycle_stage, 'production') AS lifecycle_stage,
r.id AS last_run_id,
r.triggered_by AS last_triggered_by,
r.tracks_json AS track_details_json
r.tracks_json AS track_details_json, r.provenance_json
FROM agent_compliance_status s
LEFT JOIN agent_registry_metadata m ON m.agent_url = s.agent_url
LEFT JOIN LATERAL (
SELECT id, triggered_by, tracks_json FROM agent_compliance_runs
SELECT id, triggered_by, tracks_json, provenance_json FROM agent_compliance_runs
WHERE agent_url = s.agent_url AND dry_run = false AND is_authoritative = true
ORDER BY tested_at DESC LIMIT 1
) r ON true
Expand Down
1 change: 1 addition & 0 deletions server/src/db/migrations/590_compliance_run_provenance.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE agent_compliance_runs ADD COLUMN provenance_json JSONB;
Loading
Loading