Features

Drift detection and freshness scores

Use drift detection to compare two recording sessions for the same service. Gostly reports differences as drift events, summarizes recording recency, route coverage and open events in a 0–100 freshness score, and provides a 30-day event trend.

Compare recorded responses first, then run the affected consumer checks. A detected difference and a consumer compatibility decision answer different questions.

Review AI repair proposals

With the repair feature in your license and the proposal loop turned on (ENABLE_AI_MOCK_REPAIR=true; it is off by default), Gostly proposes a fixture change after drift. The proposal is a JSON Patch computed from the difference between the recorded response body and the observed one, with a computed safety score. Open the proposal in Quality, inspect the patch, then choose Approve and apply or Reject. Approve and apply saves the changed recording and publishes it to the proxy in one step; there is no separate apply action. The result says which happened: the proxy now serves the repaired response, the change is saved and the proxy has not yet confirmed it, the change was saved but could not be published, or the patch could not be applied.

Review what the changed fixture would return, then run the affected application checks. Approval does not verify the live provider or establish that your client handles the new response correctly.

Use drift detection

A recorded mock represents the upstream behavior captured at a point in time. If the upstream changes a field, removes a route or starts returning errors, tests against the older library can continue to pass. See How It Works for the LEARN → MOCK pipeline.

Re-record the upstream, then compare the stored recording sessions. A manual check reads existing observations; it does not fetch fresh upstream traffic. Detection runs in the control-plane API, outside the served-mock request path.

Before you begin

Drift is computed over recording sessions, not individual requests. Every recorded interaction carries a recording_session_id, which the proxy stamps at capture time. Select two distinct sessions for the same service: the baseline session used for the existing library and the current session from a fresh recording.

By default, the detector selects rows labelled recorded; curated source labels such as manual, MCP and OpenAPI are excluded. This is a provenance filter, not an independent check of upstream traffic. GOSTLY_DRIFT_LEARN_MODE_ONLY=false broadens eligible sources, but each selected session still needs matching rows. Fixture imports alone do not supply a pair of recorded upstream sessions.

Manual checks require a browser session with the member role or higher, or the system-managed service key for automation. Viewer sessions and user-generated API keys receive a typed 403. The API commands below use http://localhost:8000 and a system service key supplied in GHOST_API_KEY.

Keep the baseline available. A same-id upsert can update a recorded response and move its recording_session_id to the new session. A session ID is not an immutable historical snapshot. Verify that both selected sessions still contain the attributable rows and routes you intend to compare.

Re-record and compare

  1. Put the service back in LEARN mode and send representative traffic to the live upstream. Retain the intended baseline and verify that its rows and routes remain available.
  2. Select distinct baseline and current session IDs for the same service. Verify that each contains eligible rows, then submit the comparison below using your service and session IDs. An unknown or now-empty session returns 422; it is not an empty all-clear.
  3. Read the returned events and review request coverage. Run the affected client assertions, including business rules that response shape alone does not express. The worked example shows this distinction for one checkout.
  4. Choose a disposition. To adopt upstream changes, run the LEARN → MOCK transition against the fresher recording to rebuild the library. For expected changes you have handled, acknowledge the events. Acknowledgment changes the open-event count; it does not change the baseline or establish compatibility.
# Compare a fresh recording session against the baseline
curl -X POST http://localhost:8000/v1/drift/check \
  -H "X-API-Key: $GHOST_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{
        "service_id": "payments",
        "baseline_session_id": "sess-2026-05-01",
        "current_session_id":  "sess-2026-06-15"
      }'
# Example response shape: { "events": [ ... ], "count": 3 }

Each drift event is keyed on (tenant, service, baseline_session_id, current_session_id, route, method). Re-running the same session-pair comparison returns existing events without duplicating them. Comparing a different baseline with the same current session produces a distinct result. The Prometheus counter increments only for new drift. You can invoke the check from a script or a post-record transition hook.

See How It Works → Transition for the scrub-and-rebuild step. Use Record and replay → Replay in MOCK to verify the reviewed response's replay origin and run the affected application assertion.

Check admission and resource limits

The manual check is a mutating, CPU-bearing operation. The API admits one check per process. PostgreSQL also shares one slot across workers and replicas connected to the same primary. SQLite has no shared lock authority and is process-local for development and tests. A busy slot returns a typed 429 with Retry-After: 1.

Before recursive fingerprinting, the API checks per-session and combined row, projected-byte, JSON-node and distinct-route ceilings. It checks the emitted-event ceiling before the first database write. A bounded rejection returns a typed 413 and persists no drift events.

LimitPer-session defaultCombined default
Rows5,0008,000
Projected bytes8 MiB12 MiB
JSON nodes16,00024,000
Distinct routes1,0001,500
Emitted events—500

Configure these ceilings with the GOSTLY_DRIFT_CHECK_MAX_* variables. Projected bytes include method, raw URI, pattern URI, response body and headers. The node default is conservative because wide objects retain substantially more fingerprint state than arrays with the same node count. After these checks, pure fingerprint CPU work moves to a worker thread. Python's GIL still applies, so concurrency remains one.

Review a changed order response

Use the response drift example to run four synthetic responses against one USD-only checkout contract. The example includes the downloadable packet, Node.js check, expected results and baseline decision worksheet. This local consumer check is separate from a Gostly recording-session comparison.

Understand comparison signals

Ordinary ID and timestamp variation need not be drift. For GET /charges/{id}, the detector compares schema and type information alongside value-derived profiles. A value change can affect cardinality, stable formats, selected headers or an opted-in enum set. Matching keys and types alone do not establish a consumer's business contract:

SignalCompared information
Schema shapethe field set per route, and a recursive type-shape string per field (object{id:integer,name:string}). Adding, removing, or restructuring a field shows up here; different ID values for the same shape do not.
Field typesthe dominant JSON type per field. An int|null union collapses to integer (null-tolerant). A field that flips integer → string is a type change.
Cardinality profileeach field's distinct-value count is bucketed (singleton / low / medium / high / unbounded) from value hashes — never raw values. A field that shifts from unbounded to singleton means the upstream stopped varying it; that's real change. The cardinality signal ignores different members within the same bucket; optional enum tracking is a separate signal.
Format profilefor string fields with a stable modal format (uuid, iso_datetime, url, email, ipv4, phone, numeric_string), a format break fires. Mixed-format or free-text values may not produce a stable format profile.
Enum value sets (opt-in)GOSTLY_DRIFT_ENUM_VALUE_ALLOWLIST defaults empty. Named top-level fields can expose hashed value-set changes only when eligible for the low-cardinality bucket; singleton fields are excluded. This does not compare arbitrary business values.
Selected response headersstable allowlisted headers, such as content-type and x-api-version, compare lowercased modal values; presence-only headers compare whether they occur. This is separate from body shape.
Status distributionthe fraction of responses in each HTTP status family (2xx/4xx/5xx). Can detect a status-family rate shift even when the single most-common status stays 200.
Empty-response ratethe fraction of responses that decoded to {}, null, or empty. A rising empty rate often signals upstream degradation that body-shape analysis alone misses.
Route topologyroutes present in one sampled session but absent from the other. Missing sampled traffic is not proof that the upstream removed an endpoint.
What the comparison retains. The detector reads recorded bodies and headers to derive structured summaries. Shape-change diffs use hashes, and cardinality profiles use buckets derived from value hashes; selected stable-header changes retain modal values. Opt-in enum tracking stores hashes that can reveal original values through guesses over a small domain. These representations do not anonymize the underlying recordings or guarantee that sensitive data is absent. Review captured data and configuration.

Distribution-based signals (status family, empty rate) need a minimum sample per side before they'll fire — GOSTLY_DRIFT_MIN_BEHAVIORAL_SAMPLES (default 10) — so a handful of recordings won't trip a rate-shift alert on noise. The field-level signals (shape, type, cardinality, format) work from the first recording.

Review and acknowledge drift events

Every drifted route produces one drift event. Each event records the route + method, the two session ids it compared, a headline change_type, a severity, the structured diff of which signals fired, and a detected_at timestamp.

Severity is one of two bands, rolled up as the max across every signal that fired. It is a detector classification, not a compatibility verdict for a particular client. Here, requiredness comes from observed baseline presence, not an OpenAPI declaration:

  • major (higher priority) — examples include a removed top-level field, a type or shape change in a field observed as required, a status-family change, a stable format break, a cardinality shift of ≥2 buckets, or a route absent from the current sample. A nested addition can change its parent's shape and receive major severity.
  • minor (lower priority) — examples include a new top-level field, a type change in a field not observed as required, a status shift within one family (200 → 201), a one-bucket cardinality shift, or a newly observed route. A consumer can still reject an additive or same-shape change.

When more than one signal fires for a route, the headline change_type is mixed and the full per-signal breakdown lives in the event's diff field. List events for the current tenant, newest first, and filter to the open ones:

# Open (unacknowledged) drift events for one service
curl "http://localhost:8000/v1/drift/events?service_id=payments&unacknowledged_only=true" \
  -H "X-API-Key: $GHOST_API_KEY"

# A single event by id
curl http://localhost:8000/v1/drift/events/42 \
  -H "X-API-Key: $GHOST_API_KEY"

After you triage an event, acknowledge it when it has been fixed or tracked for later work. The acknowledgment is append-only: it writes an audit row (optionally tagged with a user id and a reason like "tracked in JIRA-1234, fix planned Q3") and sets the event's acknowledged_at hint. Acknowledging again preserves the first timestamp but still records who silenced it again and why.

# Acknowledge an event (empty body is fine; richer payload optional)
curl -X POST http://localhost:8000/v1/drift/events/42/acknowledge \
  -H "X-API-Key: $GHOST_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"user_id": "jane", "reason_text": "expected v3 migration"}'
Effect on freshness. Unacknowledged events reduce the freshness score. Acknowledging an event removes its contribution to the open-event penalty; it does not replace the baseline or prove consumer compatibility.

Read the freshness score

The 0–100 freshness score combines recording recency, route coverage and open drift events to help you prioritize services for review. Read Freshness scores and trends for the weights, API command, no-data state and refresh behavior. The score is a triage signal; review coverage and affected client assertions before adopting a response.

Read the 30-day trend

The sparkline shows per-day drift event counts split by severity. See the 30-day trend reference for the API command and interpretation of missing days and event clusters. No events in the displayed series alone does not establish coverage or compatibility.

Monitor drift metrics

The control plane exposes a counter of drift events broken out by severity, so you can alert on the rate of new major drift across all services rather than polling each one:

curl http://localhost:8000/v1/drift/metrics \
  -H "X-API-Key: $GHOST_API_KEY"

# { "counters": {
#     "gostly_drift_events_total{severity=\"major\"}": 4,
#     "gostly_drift_events_total{severity=\"minor\"}": 11
# } }

The counter increments only on genuinely new events, never on idempotent re-checks — so the rate reflects real upstream movement, not how often your pipeline happens to run the comparison. The proxy's own request-path metrics (match-type counters, mock-library size) live on the agent's /metrics endpoint; see Configuration.

Scope and limits

Apply these limits when interpreting a comparison:

  • Response bodies must be JSON objects. Per-field signals are computed over top-level JSON objects. Top-level arrays and primitive bodies currently produce no per-field drift signal; the detector logs once per route so the gap is visible rather than silent.
  • Comparison is session-vs-session. Manual checks take the two sessions you select; background transition enrichment can compare the two newest recorded sessions. Pre-partition recordings (those captured before sessions were tracked) carry no session id and aren't mixed into a session-scoped comparison.
  • Detection is request-driven. A drift check runs when you invoke it (or when a transition-pipeline hook does). Each check that finds new or reopened drift sends one digest to the notification channels you configure (Slack, Teams, Mattermost, a webhook or email; GOSTLY_NOTIFY_URL or GOSTLY_NOTIFY_CONFIG in .env), with the findings at or above each channel’s minimum severity; the dashboard and the API show every event either way.
  • Admission authority has a named scope. The PostgreSQL advisory lock coordinates replicas only when they share one primary. A deployment split across independent databases has independent drift-check capacity.
  • Background hooks have a separate boundary. The synchronous manual endpoint owns the admission and resource policy described above. Transition hooks run as best-effort enrichment, outside the admission and resource policy above.

Related topics

  • How It Works — the LEARN → MOCK pipeline, match cascade and library transition.
  • Record and replay — verify replay origin and run the affected client assertion.
  • Configuration Reference — environment variables, including GOSTLY_DRIFT_* settings, and agent metrics.