What API drift means
API drift is a difference between the behavior your application expects and the behavior an API now exhibits. Shape drift changes fields or types. Semantic drift changes meaning or value patterns even when the payload still satisfies a schema. Unknown means the available evidence does not support a more specific classification. These classes are separate from detector names such as Unit.
What the statistical guest detects
The embedded guest evaluates configured fields for numeric magnitude (Unit), enumeration, completeness, type and charset/format changes. Not every detector is eligible for every window. A finding says these configured windows differ under the detector’s rules; it does not establish a vendor migration’s intent or authorize repair. The demonstration’s Unit case uses 128 repeated synthetic documents per window to make the expected difference reproducible.
Choose comparable windows
A baseline is the earlier reference window; live is the current comparison window. Supply arrays of complete raw JSON documents, not individual extracted numbers. Select independent calls for the same tenant, connection, vendor, operation and segment. Match request/response side and field path. Mixing currencies, customers or API operations can create differences unrelated to API drift. The fixed demonstration windows demonstrate configuration, not production calibration.
Configure the selection
At SDK construction, selection supplies scope and fields. Each field has side (request or response), path, baseline, live and enumeration. Use a JSON Pointer such as /value for the selected field. The selection operation must match the guarded tool name. This selection is frozen for the engine instance; configure changes call policy, not the engine’s windows. Construct a new instance for a new reviewed selection. These SDKs do not automatically fetch baselines or refresh them from a dashboard.
Request and response inspection
Request inspection occurs before the callable; response inspection follows its result or error. A request finding uses the configured request-side windows, and response findings use response-side evidence. Keep these datasets separate. A response halt can follow a completed vendor write and cannot undo it. Whole malformed bodies, truncated inspection copies and transport failures are different evidence conditions.
When no finding is inconclusive
A default instance with no selection has no findings. Missing fields, ineligible detectors, insufficient samples, scope mismatch or exhausted inspection work can prevent a useful verdict. Different detector families have different eligibility requirements; 128 is the fixture window size, not a promise that every production dataset of that size is sufficient. The demonstration verifies that four samples do not produce its Unit finding. Check bypass and readiness separately before interpreting silence.
Run the complete statistical example
After installing the pinned SDK, use Node 22.6+ for the native TypeScript command. Save the TypeScript tab as detect.mts and run node --experimental-strip-types detect.mts, or save the Python tab as detect.py and run python detect.py. No vendor credentials or network call is used. This labelled local magnitude shift compares baseline value 1 with current value 100 and verifies a Unit finding. Unchanged, unconfigured and insufficient-window controls must not claim detection. These fixed windows demonstrate detector setup, not production calibration or applied repair. Replace them only with independently collected comparable JSON windows for your selected operation.
import { createAgindow } from 'agindow';
import type { Event, StatisticalSelection } from 'agindow';
/** Labelled simulated break: numeric magnitude shift (1 → 100). Not a vendor migration story. */
const documents = (value: number): string[] =>
Array.from({ length: 128 }, () => JSON.stringify({ value }));
function selectionFor(live: number): StatisticalSelection {
return {
tenant: 'demo',
connection: 'local',
vendor: 'synthetic',
operation: 'demo.detect',
segment: 'default',
fields: [{
side: 'request',
path: '/value',
baseline: documents(1),
live: documents(live),
enumeration: true,
}],
};
}
async function observe(label: string, selection?: StatisticalSelection, bodyValue = 100): Promise<readonly Event[]> {
const sdk = createAgindow(selection === undefined
? { mode: 'observe' }
: { mode: 'observe', selection });
await sdk.ready;
const body = { value: bodyValue };
const result = sdk.guard((input: { value: number }) => input, {
tool: 'demo.detect',
operation: 'read',
})(body);
if (result !== body) throw Error(`${label}: observe mutated the result (not an applied repair path)`);
if (sdk.recent().some((event: Event) => event.type === 'repair')) {
throw Error(`${label}: unexpected repair event`);
}
if (sdk.recent().some((event: Event) => event.type === 'bypass')) {
throw Error(`${label}: unexpected bypass; this sample is detection, not an availability fixture`);
}
return sdk.recent();
}
const changed = await observe('changed', selectionFor(100), 100);
const drift = changed.find((event: Event) => event.type === 'drift');
if (!drift?.verdict
|| drift.verdict.bypassed
|| drift.verdict.halt
|| drift.verdict.repair
|| drift.verdict.findings !== 1
|| drift.verdict.detectors !== 5
|| drift.verdict.class !== 'semantic'
|| !drift.verdict.eligibleDetectors?.includes('Unit')) {
throw Error('expected a real Unit finding for the labelled numeric magnitude shift');
}
const unchanged = await observe('unchanged', selectionFor(1), 1);
if (unchanged.some((event: Event) => event.type === 'drift')) {
throw Error('unchanged live window reported drift');
}
const withoutDetector = await observe('default');
if (withoutDetector.some((event: Event) => event.type === 'drift')) {
throw Error('default engine reported detection without an explicit selection');
}
const insufficient: StatisticalSelection = {
tenant: 'demo',
connection: 'local',
vendor: 'synthetic',
operation: 'demo.detect',
segment: 'default',
fields: [{
side: 'request',
path: '/value',
baseline: Array.from({ length: 4 }, () => '{"value":1}'),
live: Array.from({ length: 4 }, () => '{"value":100}'),
enumeration: true,
}],
};
const thin = await observe('insufficient', insufficient, 100);
if (thin.some((event: Event) => event.type === 'drift')) {
throw Error('insufficient windows reported a successful detection');
}
const observed = {
labelledChange: 'numeric magnitude shift',
detector: drift.verdict.eligibleDetectors.find(name => name === 'Unit'),
event: drift.type,
findings: drift.verdict.findings,
detectors: drift.verdict.detectors,
eligibleDetectors: drift.verdict.eligibleDetectors,
class: drift.verdict.class,
bypassed: Boolean(drift.verdict.bypassed),
halt: Boolean(drift.verdict.halt),
repairApplied: Boolean(drift.verdict.repair),
resultUnchanged: true, // observe() checked reference identity above.
};
console.log(JSON.stringify(observed, null, 2));
console.log('Variable per run (not part of the stable finding above): latencyUs and host timing.');
import json
from agindow import Agindow, Event
# Labelled local fixture: numeric magnitude shift, not live vendor traffic.
def selection_for(value: int, count: int = 128) -> dict[str, object]:
return {
"tenant": "demo", "connection": "local", "vendor": "synthetic",
"operation": "demo.detect", "segment": "default",
"fields": [{"side": "request", "path": "/value", "enumeration": True,
"baseline": [json.dumps({"value": 1}) for _ in range(count)],
"live": [json.dumps({"value": value}) for _ in range(count)]}],
}
def observe(selection: dict[str, object] | None, value: int = 100) -> tuple[Event, ...]:
sdk = Agindow(mode="observe", selection=selection)
try:
assert sdk.ready, sdk.load_error
payload = {"value": value}
@sdk.guard(tool="demo.detect", operation="read")
def read(body: dict[str, int]) -> dict[str, int]:
return body
assert read(payload) is payload
events = sdk.recent()
assert not any(event.type in ("bypass", "repair", "blocked") for event in events)
return events
finally:
sdk.close()
changed = observe(selection_for(100))
drift = next(event for event in changed if event.type == "drift")
verdict = drift.verdict
assert verdict is not None
assert verdict.findings == 1 and verdict.detectors == 5
assert verdict.drift_class == "semantic"
assert not verdict.bypassed and not verdict.halt and verdict.repair is None
assert not any(event.type == "drift" for event in observe(selection_for(1), 1))
assert not any(event.type == "drift" for event in observe(None))
assert not any(event.type == "drift" for event in observe(selection_for(100, 4)))
print(json.dumps({"event": drift.type, "findings": verdict.findings,
"detectors": verdict.detectors, "class": verdict.drift_class,
"bypassed": verdict.bypassed, "halt": verdict.halt,
"repairApplied": verdict.repair is not None,
"resultUnchanged": True}, indent=2))
Read the demonstration finding
Node prints the stable summary below; Python reports the same finding count, class and safety flags without Node detector-name arrays. Timing varies and is excluded. A finding records configured evidence of a difference; it does not prove a safe repair or persisted write correctness.
{
"labelledChange": "numeric magnitude shift",
"detector": "Unit",
"event": "drift",
"findings": 1,
"detectors": 5,
"eligibleDetectors": [
"Unit"
],
"class": "semantic",
"bypassed": false,
"halt": false,
"repairApplied": false,
"resultUnchanged": true
}