Skip to content

fix(coherence): honor native graph and obstruction contracts - #703

Merged
proffesor-for-testing merged 4 commits into
proffesor-for-testing:mainfrom
rudycelekli:fix/coherence-wasm-graph
Sep 22, 2026
Merged

proffesor-for-testing merged 4 commits into
proffesor-for-testing:mainfrom
rudycelekli:fix/coherence-wasm-graph

Conversation

@rudycelekli

@rudycelekli rudycelekli commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Connected coherence graphs fail in the real WASM engine because serialized edges omit the required restriction_map and dimension fields. The service catches the native parse error and returns its human-lane fallback. The existing unseeded integration fixture exposed this intermittently; an edge-free graph passes. The adapter also reads obstruction fields that the native engine does not return, which would discard contradictions after fixing serialization alone.

Translate both sides of the actual native contract: equal-dimensional sections receive an identity restriction map, and native source_node / target_node / magnitude become the domain contradiction fields. Rebuild endpoint indices from current node positions, including after removals, and keep confidence in its declared range. Preserve native energy values and ordering.

Dense restriction matrices need explicit resource limits. Native energy and obstructions are edge-additive, so process bounded batches and merge their results. Preflight the entire operation before allocating matrices or calling WASM: at most 4 Mi matrix cells per batch and 32 Mi cumulative cells per operation. Missing endpoints, incompatible dimensions or oversized work raise a diagnostic; the service retains its existing human-lane fallback. Energy and obstruction detection are separate operations. These limits bound matrix work, not total process RSS or wall-clock time.

CI follow-up

Includes the fork-comment guard from #701 and the runner/reporting correction from #704. Optional fork comments are skipped while artifacts remain available; nonzero runner exits and timeouts remain failures. Coverage uses valid reporters and produces a JSON summary, while JUnit remains a test report.

The 12 fork-comment regressions and nine runner-exit regressions pass. A real 18-test coverage control produces the expected reports with exit 0; an invalid-reporter control retains exit 1 despite all 18 tests passing. Earlier green coverage jobs did not establish completed coverage reporting: the old wrapper could mask the invalid coverage reporter's error. The current full run has now completed successfully with the corrected wrapper.

These reporting and exit-status failure modes are exercised by tests/unit/scripts/fork-pr-comments.test.ts, tests/unit/scripts/ci-vitest-run.test.ts, and the real reporter controls described in #704.

Verification

  • Final published head 607a00af: all 18 checks pass. Full coverage job: 23,614 tests passed / 62 skipped; 976 files passed / six skipped. Coverage artifacts upload successfully; measured line coverage is 65.46% (the existing 80% comparison is advisory). No reporter errors or exit normalization occur.

  • 183 passed across seven files, including real WASM regressions, existing coherence gates, fallback handling, threshold tuning and concurrency tests.

  • The identical final two-file, 23-case WASM regression suite on pristine main 29f0ed4f: 15 failed / 8 passed. Patched: 23 passed.

  • A connected 10-by-384 graph is compared directly with an unbatched native reference: equal energy and all thresholded obstruction IDs/order, with each adapter call respecting the matrix budget.

  • npm run typecheck, npm run build, and npx eslint src/integrations/coherence/engines/cohomology-adapter.ts: passed.

  • Independent built-service checks with all pairs connected (10-by-128 and 20-by-384): native results match the analytical energy and do not fall back. The dense 20-by-384 case takes approximately 3–4 seconds locally; this is a correctness/resource-bound change, not a speed claim.

  • Replace unseeded test vectors with deterministic connected inputs, including seed 67 that reproduces the original missing-map failure class. The performance test keeps its existing fallback and duration assertions.

npx vitest run \
  tests/integration/coherence-connected-wasm.test.ts \
  tests/integration/coherence-wasm-integration.test.ts \
  tests/integration/coherence-quality-gates.test.ts \
  tests/unit/integrations/coherence/wasm-fallback-handler.test.ts \
  tests/unit/integrations/coherence/threshold-tuner.test.ts \
  tests/integration/ruvector/coherence-concurrency.test.ts \
  tests/unit/integrations/ruvector/coherence-gate.test.ts --bail=0
npm run typecheck
npm run build
npx eslint src/integrations/coherence/engines/cohomology-adapter.ts

Failure modes

  • Connected graphs fall back on missing native edge fields: identical, differing, seeded 10-by-128 and multi-batch real-WASM cases; edge-free compatibility control.
  • Native obstructions disappear or get wrong IDs/order: real differing-section controls, removal and edge-before-node cases, plus unbatched native reference comparison.
  • Native magnitudes produce negative confidence: a magnitude-greater-than-one control.
  • Matrix allocation grows without a bound or yields partial results: single-map and total-budget controls assert human-lane fallback before any native energy call; batching test checks every native call's size.
  • Incompatible dimensions silently truncate data or evade validation when node order changes: both dimension orders tested at adapter and service boundaries.
  • Unknown edge endpoints reach native code: explicit rejection control.

  • Every failure mode mentioned in this PR description has either (a) a test that exercises it, or (b) a linked tracking issue.

  • Affects published API or CLI surface: the coherence adapter now accepts valid connected graphs through real WASM and reports their contradictions. Incompatible or oversized graphs use the existing service fallback response.

  • Touches the init flow / npm-publish workflow / init corpus: no.

@proffesor-for-testing proffesor-for-testing left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified every native-contract claim directly against the installed prime-radiant-advanced-wasm binary: edges without restriction_map/source_dim/target_dim fail to parse (so main never reached the engine for any connected graph), obstruction records use edge_index/source_node/target_node/magnitude, and endpoints are array positions, which makes the rebuild-on-serialize index fix correct. Energy is additive across edge subsets, so batching with cell budgets is sound. Build passes; the real-WASM suite passes (176/183 with 7 skipped; one heavy 10x384 case is load-sensitive and passes in isolation). Codex adversarial pass found no serialization or aggregation defect; its two findings concern the service's pre-existing catch-all fallback (ignores fallbackEnabled:false, does not update stats), which this PR does not touch.

@proffesor-for-testing
proffesor-for-testing merged commit ca8b863 into proffesor-for-testing:main Sep 22, 2026
22 checks passed
@proffesor-for-testing

Copy link
Copy Markdown
Owner

Thank you, @rudycelekli! This is a genuinely valuable fix: our adapter never actually reached the native sheaf engine for any connected graph (the serialized edges lacked the required restriction_map and dimension fields, and the obstruction field names were wrong), so every connected check silently fell to the human lane. I confirmed each contract claim against the installed WASM binary, and the batching with explicit cell budgets plus the position-based index rebuild are the right design given the engine's dense-matrix requirement. Merged.

Small follow-ups, none blocking:

  • The heaviest real-WASM case (10x384 dense) times out under CI-like load; an explicit it(..., 30_000) or a smaller dimension would make it robust.
  • Worth an ADR/README note that the identity restriction map is dim² per edge, so the 32 Mi cell budget caps 1536-dim graphs at about 14 edges.
  • Pre-existing, not this PR: CoherenceService.checkCoherence's catch-all returns a fallback result even when fallbackEnabled: false, and that path does not update stats or fallbackCount.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants