Skip to content

Drift & Branch Diff

Recon has two drift tools. recon drift compares three sources of truth: the routes and DTOs in your code, the requests in your .http files, and the responses in the Flight Recorder. recon diff-branch compares your workspace’s requests, contracts and environment keys with a Git ref. Use the first to catch an API that no longer matches its code. Use the second in a pull request to flag breaking changes.

Terminal window
recon drift
Three-Way Drift Radar: 5 breaking, 2 rename(s), 12 warning(s)
[ROUTE Warning] POST /v2/enrollments — Undocumented fastapi `/v2/enrollments` endpoint exists in code (py/main.py:10) but has no `.http` request
[ROUTE Warning] DELETE /v1/students/{id} — Undocumented axum `/v1/students/{id}` endpoint exists in code (server/src/routes.rs:17) but has no `.http` request
...
[ROUTE Breaking] POST {{base_url}}/v1/enrollments — `.http` request `Create Enrollment` (`POST {{base_url}}/v1/enrollments`) has no matching backend route in scanned code
[ROUTE Breaking] POST {{base_url}}/v1/enrollments — `.http` request `Stripe Prod Key Leak Check` (`POST {{base_url}}/v1/enrollments`) has no matching backend route in scanned code
[FIELD Warning] Create Enrollment ($.id) — Undocumented new field `id` (`string`) observed
...
[FIELD Breaking] List Students ($.students[].gpa) — Field `gpa` changed type incompatibly from `string` to `number`
[FIELD Breaking] List Students ($.students[].advisor) — Required field `advisor` missing from observed response
[FIELD RenameCandidate] List Students ($.students[].programme) — Probable rename: `programme` -> `program` (78% match)
...
[FIELD Warning] List Students ($.students[].ssn) — Undocumented new field `ssn` (`string`) observed
[FIELD Breaking] List Students ($.students[].gpa) — Field `gpa` changed type incompatibly from `string` to `number`
[FIELD RenameCandidate] List Students ($.students[].studentId) — Probable rename: `studentId` -> `student_id` (100% match)

In this workspace the Rust Student struct declares gpa: String, programme and advisor. The live List Students response has a numeric gpa, a field named program, and no advisor. The staging run used studentId where the local run uses student_id.

Fail a CI job on breaking drift:

Terminal window
recon drift --fail-on-breaking
echo $?
1

Every finding has a dimension that names the two sources compared.

Dimension Compares Produced
code_vs_collection Scanned routes and .http requests Yes
code_vs_live_wire Scanned DTOs and the latest recorded response Yes
baseline_vs_latest An earlier run and the latest run of the same request Yes
collection_vs_live_wire Defined in the output model but never produced

Recon scans the code and then checks two things.

  1. Each scanned route needs a request with the same method and a matching path. If none exists, you get a warning: “Undocumented {framework} {path} endpoint exists in code (file:line) but has no .http request”.
  2. If the scan found at least one route, each request with a local URL needs a matching route. A URL counts as local when it starts with {{ or /, or contains 127.0.0.1 or localhost. If no route matches, you get a breaking finding: “.http request {name} (METHOD url) has no matching backend route in scanned code”.

Requests are matched to routes first by their # @handler tag, then by method and path. Path matching follows the rules in Path normalisation.

This check runs only when the scan found DTOs.

  1. For each request, Recon takes the latest run in the window (see Limits).
  2. It parses the response body as JSON and infers a schema from it, the same way contract infer does. Bodies that are not JSON are skipped.
  3. It picks a DTO. If the request matches a route that has a response_dto, it uses that DTO. Otherwise it uses the DTO that shares the most field names with the response, if it shares at least two.
  4. It compares the DTO’s fields (expected) with the response fields (observed).

This check needs at least two runs of the same request in the window. The latest run is compared with a reference run, chosen in this order:

  1. The most recent run pinned as baseline, if it is not the latest run.
  2. Otherwise, the most recent run from a different environment.
  3. Otherwise, the run just before the latest.

Both bodies must be JSON. In the example, the latest List Students run was in local, so the earlier staging run became the reference.

For each field:

Situation Severity Message
Present on both sides, type change is not a safe widening breaking Field x changed type incompatibly from a to b
Missing, and a new field has a similar name rename_candidate Probable rename: old -> new (N% match)
Missing and required breaking Required field x missing from observed response
Missing and optional warning Optional field x absent in observed response
New and not matched to a missing field warning Undocumented new field x (type) observed

Safe widenings are: the same type, any type to any, integer to number, and date to timestamp. Everything else is breaking, including any to a concrete type.

Name similarity works like this. Both names are lowercased and stripped to letters and digits. Equal results score 1.0, so studentId and student_id score 1.0. Otherwise the score is 1 minus the Levenshtein distance divided by the longer length. A score of 0.72 or more makes a rename candidate. Each new field can be matched to only one missing field. The stored similarity is rounded to three decimals.

The field_path is $.{field} for a plain object response. When the response wraps its rows in an array, for example {"students": [...]}, it is $.students[].{field}.

  • breaking_count: breaking route findings plus breaking field findings.
  • rename_count: rename candidates.
  • warning_count: warning route findings plus warning field findings.

The same problem can appear twice when two dimensions see it. In the example, the gpa type change shows up under both code_vs_live_wire and baseline_vs_latest.

  • recon drift and the HTTP routes read the 40 most recent runs. The MCP tool reads the 40 most recent runs with responses masked by the airlock.
  • Severity info exists in the output model but is never produced.
Terminal window
recon drift [PATH] [--fail-on-breaking] [--sarif PATH]
Argument Default Description
PATH the --workspace directory Directory to scan for routes and DTOs. Requests and runs always come from the workspace.
--fail-on-breaking off Exit 1 when breaking_count is greater than 0.
--sarif PATH none Write a SARIF 2.1.0 report. - prints it to stdout.

With --sarif -, only the SARIF JSON is printed. With a file path, Recon creates missing parent directories, writes the file, and still prints the normal report.

With --format json or --format agent, the report is printed as JSON:

{
"dimension": "code_vs_live_wire",
"severity": "rename_candidate",
"endpoint": "List Students",
"field_path": "$.students[].programme",
"message": "Probable rename: `programme` -> `program` (78% match)",
"baseline_type": "string",
"observed_type": "string",
"rename_from": "programme",
"rename_to": "program",
"similarity": 0.778,
"handler_location": {
"file": "server/src/routes.rs",
"line": 16,
"symbol": "list_students"
}
}

The top-level object has breaking_count, rename_count, warning_count, route_drifts and field_drifts.

Route finding field Description
dimension, severity See above. Severity is breaking, rename_candidate, warning or info.
method, path For a missing route, path is the request URL as written.
message Explanation.
handler_location file, line, symbol. Omitted when unknown.
Field finding field Description
dimension, severity, message See above.
endpoint Request name.
field_path Path of the field.
baseline_type, observed_type Logical types, when they apply.
rename_from, rename_to, similarity Only on rename candidates.
handler_location The matched handler, or the DTO location. Omitted when unknown.

Optional fields are left out of the JSON when they have no value.

Upload the SARIF file to any tool that reads SARIF 2.1.0, such as code scanning in a CI system.

Terminal window
recon drift --sarif out/drift.sarif

The report has $schema https://json.schemastore.org/sarif-2.1.0.json and version 2.1.0. It has one run. The tool driver is named Recon, has the Recon version (here 0.3.2) and informationUri https://github.com/robertguss/recon.

Rule ID Name Default level Used for
RECON-DRIFT-ROUTE-MISSING Missing Backend Route error Breaking route findings
RECON-DRIFT-ROUTE-UNDOCUMENTED Undocumented Backend Route warning Other route findings
RECON-DRIFT-FIELD-BREAKING Breaking API Schema Drift error Breaking field findings
RECON-DRIFT-FIELD-RENAME Probable Field Rename warning Rename candidates
RECON-DRIFT-FIELD-WARNING Non-Breaking API Schema Drift warning Field warnings

Each result’s level follows its severity: breaking is error, rename_candidate and warning are warning, and info would be note. The message text starts with the dimension in brackets.

When the handler is known, the result has a physical location relative to %SRCROOT%:

{
"level": "warning",
"locations": [
{
"physicalLocation": {
"artifactLocation": {
"uri": "server/src/routes.rs",
"uriBaseId": "%SRCROOT%"
},
"region": {
"startLine": 16
}
}
}
],
"message": {
"text": "[code_vs_live_wire] List Students ($.students[].programme) — Probable rename: `programme` -> `program` (78% match)"
},
"properties": {
"baseline_type": "string",
"dimension": "code_vs_live_wire",
"endpoint": "List Students",
"field_path": "$.students[].programme",
"observed_type": "string",
"rename_from": "programme",
"rename_to": "program",
"severity": "rename_candidate",
"similarity": 0.778
},
"ruleId": "RECON-DRIFT-FIELD-RENAME"
}

When it is not known, the result has a logical location instead. Its kind is endpoint for route findings and member for field findings. Field findings also get a fullyQualifiedName of endpoint field_path.

"locations": [
{
"logicalLocations": [
{
"kind": "endpoint",
"name": "POST {{base_url}}/v1/enrollments"
}
]
}
]

recon diff-branch compares the workspace on disk with a Git ref. It does not use the Flight Recorder or the code scanner.

Terminal window
recon diff-branch main
Recon Branch Diff: `main` -> `feature/rename` (breaking: 4, warnings: 1, added: 2)
[BREAKING] POST {{base_url}}/v1/enrollments (Create Enrollment) — Endpoint `Create Enrollment` (POST {{base_url}}/v1/enrollments) existed on base ref and was removed.
[BREAKING] GET {{base_url}}/v2/students (List Students) — Endpoint `List Students` signature changed: `GET {{base_url}}/v1/students` -> `GET {{base_url}}/v2/students`.
[ADDED] GET {{base_url}}/health (Health) — New endpoint `Health` (`GET {{base_url}}/health`) added.
[BREAKING] contracts/students.odcs.yaml `list_students.gpa` — ODCS field `gpa` logicalType changed: `"number"` -> `"string"`.
[BREAKING] contracts/students.odcs.yaml `list_students.email` — ODCS required field `email` added.
[ENV:removed] staging: DEV_API_TOKEN
[ENV:added] staging: STAGING_TOKEN
  1. Recon checks that the workspace is inside a Git repository and that the ref resolves to a commit.
  2. It lists the files in the ref and copies the relevant ones into a temporary directory with git show. When the workspace is a subdirectory of the repository, only files under it are used.
  3. It loads that copy as the base workspace, and the workspace on disk as the current one. The current side is your working tree, including uncommitted changes, not HEAD.

Relevant files are .recon.toml, *.http, *.odcs.yaml, *.odcs.yml, environments/*.toml, and .yaml, .yml or .json files whose path contains openapi or starts with contracts/. The base side is loaded as a workspace only when the ref contains .recon.toml.

Requests are matched by name.

Change Kind Severity
Name exists only on the base ref removed Breaking
Same name, different method or URL modified Breaking
Name exists only in the working tree added Non-breaking

Renaming a request therefore shows as one removal and one addition.

Contract files are *.odcs.yaml, *.odcs.yml, and .yaml, .yml or .json files whose path contains openapi or starts with contracts/. On the current side Recon walks the workspace for them and skips .git, target, node_modules and .recon.

Change Severity
File removed Breaking
File added Non-breaking
ODCS object removed Breaking
ODCS field removed Breaking
ODCS field logicalType changed Breaking
ODCS field became required Breaking
ODCS required field added Breaking
ODCS optional field added Non-breaking
OpenAPI path removed Breaking
OpenAPI operation removed from a path Breaking
OpenAPI path added Non-breaking

A changed file is first parsed as ODCS, then as OpenAPI. If neither works on both versions, the change is not reported. Only paths and operations are compared for OpenAPI. Schema changes inside an OpenAPI file are not detected.

Recon compares variable names per environment. It never reads or prints values. A removed key is a warning. An added key is non-breaking. Changed values are not reported.

--markdown prints a report you can paste into a pull request:

Terminal window
recon diff-branch main --markdown
### Recon Branch API Diff (`main` -> `feature/rename` @ `b48e971`)
- **Breaking:** 4 | **Warnings:** 1 | **Non-Breaking Additions:** 2
#### `.http` Collection Changes
| Severity | Type | Endpoint | Detail |
| --- | --- | --- | --- |
| BREAKING | `removed` | `POST {{base_url}}/v1/enrollments` (Create Enrollment) | Endpoint `Create Enrollment` (POST {{base_url}}/v1/enrollments) existed on base ref and was removed. |
...
#### ODCS / OpenAPI Contract Changes
| Severity | File | Target | Detail |
| --- | --- | --- | --- |
| BREAKING | `contracts/students.odcs.yaml` | `list_students.gpa` | ODCS field `gpa` logicalType changed: `"number"` -> `"string"`. |
...
#### Environment Variable Key Deltas (Values Redacted)
| Severity | Env | Key | Status |
| --- | --- | --- | --- |
| WARNING | `staging` | `DEV_API_TOKEN` | `removed` |
| ADDED | `staging` | `STAGING_TOKEN` | `added` |

The badges are BREAKING, WARNING and ADDED. In the human output a warning is tagged WARN.

Terminal window
recon diff-branch [BASE_REF] [--markdown] [--fail-on-breaking]
Argument Default Description
BASE_REF main Git ref to compare with, such as origin/main or HEAD~1.
--markdown off Print the PR Markdown report.
--fail-on-breaking off Exit 1 when breaking_count is greater than 0.

Only --format json prints JSON, and it takes precedence over --markdown. --format agent prints the human summary. The JSON report has base_ref, current_branch, head_short, breaking_count, warning_count, non_breaking_count, endpoint_changes, contract_changes and env_changes.

{
"base_ref": "main",
"current_branch": "feature/rename",
"head_short": "b48e971",
"breaking_count": 4,
"warning_count": 1,
"non_breaking_count": 2,
"endpoint_changes": [
{
"kind": "removed",
"method": "POST",
"url": "{{base_url}}/v1/enrollments",
"name": "Create Enrollment",
"severity": "breaking",
"detail": "Endpoint `Create Enrollment` (POST {{base_url}}/v1/enrollments) existed on base ref and was removed."
},
...

Severities in JSON are breaking, warning and non_breaking.

Command Exit code When
recon drift 0 Report printed, or breaking drift without --fail-on-breaking.
recon drift 1 --fail-on-breaking and at least one breaking finding.
recon diff-branch 0 Report printed.
recon diff-branch 1 --fail-on-breaking and at least one breaking change.
either 2 Runtime error, such as an unreadable workspace.

diff-branch errors carry the prefix invalid ODCS contract:, even when they have nothing to do with ODCS:

Terminal window
recon diff-branch nosuchref --format json
{
"code": "E_CLI_RUNTIME",
"message": "invalid ODCS contract: invalid git base ref `nosuchref`: fatal: Needed a single revision",
"fix_hint": "Check workspace `.recon.toml`, arguments, or network connectivity.",
"retryable": false
}

Outside a Git repository the message is invalid ODCS contract: `.` is not inside a Git repository. An empty ref gives base_ref cannot be empty.

HTTP (see HTTP API):

Route Returns
GET /api/v1/drift {"drift": report}
GET /api/v1/drift/sarif The SARIF document
GET /api/v1/git/diff-branch?base=main {"report": ..., "markdown": "..."}. base defaults to main.
GET /api/v1/git/status Branch and repository status

The drift routes reuse the last scan from POST /api/v1/scan. If there is none, they scan the workspace once and cache the result. The cache does not refresh by itself, so rescan after you change code.

MCP (see MCP Tools): recon_drift_report with an optional path. It returns drift and frameworks_detected.

Web Studio (see Web Studio):

  • The response panel’s “Drift & ODCS” tab shows the “Three-Way Drift Radar” with “Copy SARIF” and “Refresh Drift” buttons. “Refresh Drift” fetches the report again but does not rescan the code. Use the palette command “Scan Repository Codebase” for that.
  • The palette command “Open Git Workspace Status & Branch Diff” opens a dialog with a “Base Ref:” field, a “Compare Branch” button and “Copy PR Markdown”.