Parity

From optave/ops-codegraph-tool · View interactive version

Parity is an AI agent skill from the GitHub repository optave/ops-codegraph-tool. Audit WASM/native engine correctness parity across all resolution fixtures and fix any divergence at the root cause — both engines must produce identical graphs

How to use this skill

Skill file

/parity — Engine Correctness Parity Audit & Fix

Codegraph has two engines that MUST produce identical results (see CLAUDE.md):

orchestrator is skipped: forced full rebuilds, older addons)

This skill runs scripts/parity-compare.mjs, which builds every

resolution-benchmark fixture with each engine and compares the **full node and

edge multisets** (kind, name, file, line, confidence, dynamic flag). Any

difference is a bug in the less-accurate engine — never an acceptable gap, and

never something to document as expected. The skill finds the root cause, fixes

it, and re-verifies until the audit is clean.

Arguments

Phase 0 — Pre-flight

All steps run from the repo root.

  1. Confirm scripts/parity-compare.mjs exists. If not, this repo doesn't have

the parity tooling — stop and report.

  1. Build the TypeScript dist (the script imports dist/index.js, and extractor

changes in src/ are invisible until rebuilt):

```bash

npm run build

```

  1. Ensure the native addon reflects the local Rust source:

```bash

cd crates/codegraph-core && npx napi build --platform --release && cd ../..

```

On macOS, locally built binaries must be re-signed or Node kills the process

(exit 137):

```bash

codesign --sign - --force crates/codegraph-core/*.node

```

  1. Verify the loader picks up the locally built binary, not the published

package. First check which path is actually resolved:

```bash

node -e "

const { createRequire } = require('node:module');

const r = createRequire(require.resolve('./dist/index.js'));

try { console.log(r.resolve('codegraph-core')); } catch { console.log('not found via require'); }

"

```

If the resolved path points to

node_modules/@optave/codegraph-<platform>-<arch>/codegraph-core.node

(the installed package), copy your freshly built binary over it:

```bash

cp crates/codegraph-core/*.node node_modules/@optave/codegraph-<platform>-<arch>/codegraph-core.node

```

Then confirm the loader picks it up:

```bash

node -e "import('./dist/infrastructure/native.js').then(m => console.log(m.isNativeAvailable()))"

```

If false, stop and report — auditing parity without the native engine is

meaningless.

Phase 1 — Audit

Run the comparison (pass through --langs / --hybrid from $ARGUMENTS):

node scripts/parity-compare.mjs [--langs ...] [--hybrid] 2>/dev/null

[edge] diff line and any BUILD FAILED fixtures.

For machine-readable output (useful when many fixtures diverge), re-run with

--json and parse fixtures[].comparisons[].nodeDiffs/edgeDiffs.

If --audit-only was passed: report the diffs (Phase 4 format) and stop.

Phase 2 — Root-cause and fix

For each divergence, identify which engine is wrong — the one missing edges or

producing lower-quality resolution is usually the buggy one, but verify by

reading the fixture source and deciding what the correct graph is.

Localize the bug by which paths disagree:

| wasm | hybrid | native | Bug location |

|------|--------|--------|--------------|

| A | A | B | Rust pipeline prep (pipeline.rs) or Rust extractor (crates/.../extractors/) — the napi solver gets correct input from JS but the orchestrator's own input differs |

| A | B | B | Rust build_edges.rs solver (shared by hybrid + native) |

| A | B | A | JS↔napi boundary: NativeFileEntry plumbing in build-edges.ts or the wasm-worker protocol |

| B | A | A | JS extractor or JS resolution (src/extractors/, src/domain/graph/builder/stages/build-edges.ts) |

Fix rules (from CLAUDE.md — non-negotiable):

add comments, tests, or fixture exclusions that frame wrong output as

expected.

on both implementations, don't restrict the fix to one side.

— read the TS and Rust counterparts side by side (e.g.

src/domain/graph/builder/stages/build-edges.ts ↔

crates/.../domain/graph/builder/stages/build_edges.rs).

order, first-wins vs highest-wins rules. A 0.05 confidence difference is a

parity failure.

pins the behavior.

Gotchas that mask fixes:

sees them.

src/domain/wasm-worker-{protocol,entry,pool}.ts or they are silently

dropped at the Worker-thread boundary.

FileEdgeInput structs in crates/.../types.rs & build_edges.rs, the

NativeFileEntry assembly in build-edges.ts, and the orchestrator's own

assembly in pipeline.rs (build_and_insert_call_edges). Missing the last

one produces hybrid-OK/native-broken splits.

opportunities) → gh issue create immediately, then continue.

Phase 3 — Verify

Repeat until the audit is clean — never stop at "fewer diffs than before":

  1. Rebuild whichever side changed (npm run build / napi build + codesign).
  2. Re-run the Phase 1 audit command. Any remaining divergence → back to Phase 2.
  3. Once clean, run the full verification suite — all must pass:

```bash

cargo test --manifest-path crates/codegraph-core/Cargo.toml

npm test

npx vitest run tests/benchmarks/resolution/resolution-benchmark.test.ts

```

(From a .claude worktree, vitest needs the worktree override config —

check memory/project notes if no tests are found.)

  1. If any verification step cannot run, STOP and report it — never proceed

with unverified changes.

Phase 4 — Report

Print a summary:

PARITY AUDIT — <date>
Fixtures audited: N (wasm vs native[, hybrid])
Divergences found: M
Fixed: <file:line summary per fix, with engine + root cause>
Verification: cargo test ✓ | npm test ✓ | resolution benchmark ✓
Issues filed: #NNN (out-of-scope findings)

which engine was wrong, which layer, what semantic was mismatched.

wasm/hybrid/native localization table applied.

concern).

Rules

confidence is a failure.

is mandatory after any code change.

table before reading code.

other is a parity bug from day one. New resolution techniques must land in

src/ and crates/codegraph-core/src/ in the same PR.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.