Skip to content

feat(adr-001): verifySparseSolution MCP tool — wire-callable witness - #52

Merged
ruvnet merged 1 commit into
mainfrom
adr/mcp-verify-tool
May 19, 2026
Merged

ruvnet merged 1 commit into
mainfrom
adr/mcp-verify-tool

Conversation

@ruvnet

@ruvnet ruvnet commented May 19, 2026

Copy link
Copy Markdown
Owner

Summary

PR #41 shipped the Rust witness (`verify_sparse_solution`); PR #42 added it to the `estimateComplexityClass` advertisement table. But there was no actual wire-callable MCP tool — clients couldn't audit their SubLinear orchestrator outputs over the wire.

This closes that gap with a pure-TypeScript handler. The residual math is straightforward enough that duplicating it in JS is cheaper than plumbing a new WASM binding. Matches Rust's `verify_sparse_solution` semantics exactly.

Math

```
r[i] = b[i] - Σ_j A[i,j] · x_new[j] for each (row, value) entry
x_new[j] = overlay[j] if entries contains j, else prev_solution[j]
threshold = tolerance · max(1, ‖b‖_∞)
ok ⟺ max_i |r_i| ≤ threshold
```

API

```json
{
"name": "verifySparseSolution",
"x-complexity": { "class": "SubLinear", "edgeSafe": true },
"inputSchema": {
"matrix": "...",
"prev_solution": "number[n]",
"vector": "number[n] (RHS b)",
"entries": "Array<{row: number, value: number}>",
"tolerance": "number, default 1e-6"
}
}
```

Returns: `{ok, max_residual, threshold, worst_row, note}`.

Wire contract

  • Supports both dense and sparse-COO matrix formats.
  • Out-of-bound entries silently dropped (no panic).
  • Malformed entries tolerated.
  • Failure on strict-DD input indicates real solver bug (not a tolerance miss).

Test plan

  • `npm run build` clean
  • Full CI (TS-only change)

🤖 Generated with claude-flow

PR #41 shipped the Rust witness (verify_sparse_solution); PR #42
added it to the estimateComplexityClass advertisement table. But
there was no actual wire-callable MCP tool — clients (RuView /
Cognitum agents) couldn't audit their SubLinear orchestrator
outputs over the wire.

This closes that gap with a pure-TypeScript handler. The residual
math is straightforward enough that duplicating it in JS is
cheaper than plumbing a new WASM binding. Matches Rust's
verify_sparse_solution semantics exactly:

  r[i] = b[i] - Σ_j A[i,j] · x_new[j]  for each (row, value) entry

  x_new[j] = overlay[j] if entries contains j, else prev_solution[j]
  threshold = tolerance · max(1, ‖b‖_∞)
  ok ⟺ max_i |r_i| ≤ threshold

Lands in src/mcp/server.ts:
  - New `verifySparseSolution` tool with x-complexity = SubLinear
  - Input schema: matrix, prev_solution, vector (b), entries: Array<{row, value}>, tolerance
  - Dispatch case + handleVerifySparseSolution method
  - Returns {ok, max_residual, threshold, worst_row, note}
  - Supports both dense and sparse-COO matrix formats

Wire contract matches the Rust function:
  - Out-of-bound entries silently dropped (no panic)
  - Malformed entries (non-numeric row/value) tolerated
  - Failure on strict-DD input indicates real solver bug

Cost: O(|entries| · avg_row_nnz). Independent of n for sparse DD
matrices — same complexity class as the orchestrator whose output
it verifies.

Co-Authored-By: claude-flow <ruv@ruv.net>
@ruvnet
ruvnet merged commit 45d1059 into main May 19, 2026
11 of 12 checks passed
@ruvnet
ruvnet deleted the adr/mcp-verify-tool branch May 19, 2026 19:26
ruvnet added a commit that referenced this pull request May 19, 2026
…trator

The SubLinear orchestrator shipped in Rust (PR #29) had MCP preview
primitives (coherenceScore, closureIndices, estimateComplexityClass)
and a wire-callable witness (PR #52). But the orchestrator itself
wasn't wire-callable — agents had to fall back to `solve` (which
returns the full n-vector) instead of the closure-restricted entries
the SubLinear path produces.

This closes the gap with a pure-TS handler that chains:

  1. closure_indices(matrix, delta.indices, closure_depth)
  2. for each closure entry: truncated Neumann iteration
     restricted to the closure (mirrors src/entry.rs math)
  3. return Vec<{row, value}>

Lands in src/mcp/server.ts:
  - New `solveOnChangeSublinear` tool with x-complexity = SubLinear
  - Input schema: matrix, vector (b_new), delta_indices: number[],
    closure_depth (default 4), max_terms (default 32), tolerance (default 1e-8)
  - Dispatch case + handleSolveOnChangeSublinear method
  - Returns {entries: Array<{row, value}>, closure_size, max_terms,
    closure_depth, note}
  - Supports both dense and sparse-COO matrix formats

Matches Rust solve_on_change_sublinear semantics exactly:
  - Early-exit when |delta_k[target]| < tolerance
  - Zero-diagonal in closure → InvalidParams
  - Empty closure → empty entries
  - note field warns when closure covers full matrix

This completes the wire surface for the change-driven inner loop.
Agents can now run the full pipeline over MCP:

  1. coherenceScore             (PR #53)  — is the matrix solvable?
  2. closureIndices             (PR #54)  — how wide is the work?
  3. estimateComplexityClass    (PRs #30, #42)  — what class?
  4. solveOnChangeSublinear     (THIS PR) — actual SubLinear solve
  5. verifySparseSolution       (PR #52)  — audit output

All 5 tools are pure-TS. No Rust/WASM bridge required for any of them.

Co-Authored-By: claude-flow <ruv@ruv.net>
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.

1 participant