Skip to content

Version Comparison

Compare the performance metrics of two policy versions side-by-side over a shared observation window. This is useful for validating that a newly deployed version performs at least as well as its predecessor before committing to full rollout.

Endpoint

GET /api/v1/audit/compare

Required Role

ADMIN

Headers

HeaderValueRequired
AuthorizationBearer <token>Yes
X-Tenant-IDTenant identifier stringYes

Query Parameters

ParameterTypeRequiredDescription
versionAstringYesIdentifier of the first policy version (typically the baseline or current version).
versionBstringYesIdentifier of the second policy version (typically the candidate or newer version).
daysintegerNoNumber of days of history to compare. Defaults to 30. Maximum: 90.

Time Window Limit

days must not exceed 90. Requests with a larger value will be rejected with 400 Bad Request.

Response Body

json
{
  "versionA": "v-abc123",
  "versionB": "v-def456",
  "windowDays": 30,
  "metrics": {
    "versionA": {
      "totalEvaluations": 18420,
      "avgExecutionTimeMs": 7.2,
      "p95ExecutionTimeMs": 18.1,
      "p99ExecutionTimeMs": 42.3,
      "failureRate": 0.008,
      "errorCount": 147
    },
    "versionB": {
      "totalEvaluations": 4310,
      "avgExecutionTimeMs": 6.8,
      "p95ExecutionTimeMs": 16.4,
      "p99ExecutionTimeMs": 38.9,
      "failureRate": 0.003,
      "errorCount": 13
    }
  },
  "comparison": {
    "avgExecutionTimeDeltaMs": -0.4,
    "avgExecutionTimeDeltaPct": -5.6,
    "failureRateDelta": -0.005,
    "failureRateDeltaPct": -62.5,
    "verdict": "VERSION_B_BETTER"
  }
}

Metric Fields

FieldTypeDescription
totalEvaluationsnumberTotal number of policy evaluations recorded for this version within the window.
avgExecutionTimeMsnumberMean wall-clock execution time in milliseconds.
p95ExecutionTimeMsnumber95th-percentile execution time in milliseconds.
p99ExecutionTimeMsnumber99th-percentile execution time in milliseconds.
failureRatenumberFraction of evaluations that resulted in an error (0.0 to 1.0).
errorCountnumberAbsolute number of failed evaluations.

Comparison Fields

FieldTypeDescription
avgExecutionTimeDeltaMsnumberDifference in average execution time: versionB.avg − versionA.avg. Negative means versionB is faster.
avgExecutionTimeDeltaPctnumberSame delta expressed as a percentage of versionA's average.
failureRateDeltanumberDifference in failure rate: versionB.failureRate − versionA.failureRate. Negative means versionB is more reliable.
failureRateDeltaPctnumberSame delta expressed as a percentage of versionA's failure rate.
verdictstringSummary judgment: VERSION_A_BETTER, VERSION_B_BETTER, or COMPARABLE.

HTTP Status Codes

StatusMeaning
200 OKComparison completed successfully.
400 Bad RequestMissing required parameters, identical version identifiers, or days exceeds the 90-day limit.
401 UnauthorizedMissing or invalid bearer token.
403 ForbiddenToken is valid but the caller lacks the ADMIN role.
404 Not FoundOne or both version identifiers do not exist.
500 Internal Server ErrorUnexpected engine failure.

Examples

bash
curl -X GET "https://policy.aster-lang.dev/api/v1/audit/compare?versionA=v-abc123&versionB=v-def456&days=30" \
  -H "Authorization: Bearer <token>" \
  -H "X-Tenant-ID: acme-corp"
js
const params = new URLSearchParams({
  versionA: 'v-abc123',
  versionB: 'v-def456',
  days:     '30',
});

const response = await fetch(
  `https://policy.aster-lang.dev/api/v1/audit/compare?${params}`,
  {
    headers: {
      Authorization: 'Bearer <token>',
      'X-Tenant-ID': 'acme-corp',
    },
  }
);

const comparison = await response.json();

if (comparison.comparison.verdict === 'VERSION_B_BETTER') {
  console.log('New version outperforms the baseline — safe to promote.');
}

Example Response

json
{
  "versionA": "v-abc123",
  "versionB": "v-def456",
  "windowDays": 30,
  "metrics": {
    "versionA": {
      "totalEvaluations": 18420,
      "avgExecutionTimeMs": 7.2,
      "p95ExecutionTimeMs": 18.1,
      "p99ExecutionTimeMs": 42.3,
      "failureRate": 0.008,
      "errorCount": 147
    },
    "versionB": {
      "totalEvaluations": 4310,
      "avgExecutionTimeMs": 6.8,
      "p95ExecutionTimeMs": 16.4,
      "p99ExecutionTimeMs": 38.9,
      "failureRate": 0.003,
      "errorCount": 13
    }
  },
  "comparison": {
    "avgExecutionTimeDeltaMs": -0.4,
    "avgExecutionTimeDeltaPct": -5.6,
    "failureRateDelta": -0.005,
    "failureRateDeltaPct": -62.5,
    "verdict": "VERSION_B_BETTER"
  }
}

Released under the MIT License.