Round-Trip Verification: Forward → Reverse → Forward
This page describes COGANT's v0.6 roundtrip contract. The important change is
terminological and behavioral: role preservation is no longer called strict
isomorphism. cogant roundtrip --json reports a roundtrip_status derived
from an invariant ledger, plus the scalar role_preservation_score (s_role)
as a weaker similarity signal.
What Is A Roundtrip?
- Forward pass (program code → GNN):
cogant translateingests source code, builds a typed program graph, applies 22 translation rules, compiles A/B/C/D matrices, and emits a GNN package. - Reverse pass (GNN → program code):
cogant reverseparses the GNN markdown, plans a Python package structure, and synthesizes runnable code with matrix functions and anAgentRuntime. - Forward-again (synthesized code → GNN): the synthesized package is re-analyzed and compared against the original bundle.
Status Taxonomy
| Status | Meaning |
|---|---|
STRUCTURALLY_ISOMORPHIC |
The strict tier: node/edge counts, edge kinds, role preservation, state-space shapes, matrix shapes/values, GNN sections, and generated-code compile checks all pass. |
ROLE_PRESERVED |
The original Active Inference role population is preserved above the configured threshold, but at least one stricter structural, matrix, or generated-code invariant drifts. |
DRIFT |
The roundtrip completed, but role preservation is below threshold or non-fatal invariants diverge. |
FAILED |
The generated code, import/compile check, or re-forward run failed. |
The role-preservation score is:
s_role =
mean(
min(count_original[role], count_resynthesized[role])
/ max(count_original[role], count_resynthesized[role])
for role in roles_original ∪ roles_resynthesized
)
The default role-preserved threshold is s_role >= 0.5. This symmetric
multiset-overlap score penalizes both dropped and extra roles, but it is still
intentionally weaker than strict graph isomorphism, matrix equality, or textual
code recovery. Recorded evaluation notes sometimes call out a stricter
high-confidence 0.8 line; that is not the public CLI default.
JSON Contract
cogant roundtrip ./my_repo --json returns fields such as:
{
"schema_version": "2.0",
"roundtrip_status": "ROLE_PRESERVED",
"role_preservation_score": 1.0,
"role_preserved": true,
"structurally_isomorphic": false,
"matrix_preserved": false,
"gnn_sections_preserved": true,
"generated_code_ok": true,
"invariants": {
"role_preserved": true,
"graph_node_edge_preserved": false,
"edge_kinds_preserved": true,
"matrix_preserved": false,
"gnn_sections_preserved": true,
"generated_code_ok": true
}
}
The structurally_isomorphic and role_preservation_score constructor aliases are accepted
inside Python for compatibility, but CLI/server JSON emits the v0.6 field
names above.
Interpreting Drift
Synthesized packages commonly contain scaffolding absent from the original
source: constructors, getters, policy functions, constraint checks, or matrix helper
functions. Those extra nodes can preserve the role distribution while changing
node/edge totals. That is why ROLE_PRESERVED is a real success tier but not the
same claim as STRUCTURALLY_ISOMORPHIC.
The inspection dashboard and batch dashboard expose the same distinction: original vs regenerated graph counts, edge-kind deltas, role deltas, GNN-section diffs, matrix deltas, generated-code status, and the final status badge.
Further Reading
- ROUNDTRIP_EVAL.md records the native v0.6 role-preservation ledger.
- ROUNDTRIP_IMPROVEMENT.md explains the policy/context/constraint synthesizer improvements that made the role corpus stable.
cogant.reverseAPI documents the reverse synthesizer.- GNN format reference describes the GNN sections checked by
gnn_sections_preserved.