Skip to content

feat(mcp): kcore_rpc can call the kcore-provisioning API - #11

Merged
rtacconi merged 1 commit into
mainfrom
cursor/mcp-provisioning-rpc-64a3
Oct 13, 2026
Merged

rtacconi merged 1 commit into
mainfrom
cursor/mcp-provisioning-rpc-64a3

Conversation

@rtacconi

@rtacconi rtacconi commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Recovers uncommitted kcore-mcp work from the old kcorehypervisor-kcore clone.

  • kcore_rpc now accepts service: "provisioning". It loads provisioning.proto, which is identical to kcore-provisioning main, and calls the Provisioning service.
  • The endpoint is resolved from connection.provisioning, then KCORE_PROVISIONING, then the context's provisioning address. The connection is insecure by default; provisioningInsecure controls this.
  • The README and the kcore-operator skill document the new service.
  • The dist/ bundles for the server and the VS Code extension are rebuilt.

Testing:

  • npm run build passes.
  • npm test (tsc --noEmit plus tsx --test) passes 20/20.
  • The repo's pre-push cargo gates pass.

Load provisioning.proto and route service=provisioning to the endpoint
from connection.provisioning, KCORE_PROVISIONING or the context's
provisioning address. Document it in the README and operator skill.
@rtacconi
rtacconi marked this pull request as ready for review October 13, 2026 09:54
@rtacconi
rtacconi merged commit 717551e into main Oct 13, 2026
5 checks passed
rtacconi added a commit that referenced this pull request Oct 16, 2026
- ci/Makefile: run cargo kani -p kcore-node-agent so the two node-agent
  proofs (segment_validation_never_panics,
  segment_acceptance_implies_safe) are exercised in CI and local
  make kani, not just controller and kctl.
- crates/controller/src/db.rs: replace string-match on \"foreign\" in
  vm_insert_rejects_unknown_node_id with structured matching on
  rusqlite::Error::SqliteFailure where code == ConstraintViolation and
  extended_code == 787 (SQLITE_CONSTRAINT_FOREIGNKEY). The integer
  literal is used because rusqlite does not re-export the extended-code
  constant publicly.
- docs/formal-methods-and-verification.md:
  * Phase 3: collapse the stale \"Properties to verify / Why third /
    Effort estimate\" plan block; the section now lists shipped
    properties + run instructions only, matching Phase 2/4 style.
  * Phase 2: drop the now-stale \"add Kani proof for
    validate_safe_segment once the file lands\" follow-up (shipped),
    add the harness-deduplication note as a tracked follow-up, list
    node-agent under the per-crate run instructions.
rtacconi added a commit that referenced this pull request Oct 16, 2026
The kani job on PR #11 (run 24565742587) was cancelled mid-Install Kani
at ~9 minutes with no Kani output. Three hardening changes so the next
push is faster, fails fast on a hung install, and auto-cleans superseded
runs:

- concurrency: scope formal-checks to workflow + ref with
  cancel-in-progress: true so a re-push to the same PR cancels the
  previous in-flight run instead of letting two compete for the kani
  slot.
- Swatinem/rust-cache@v2: warm cargo registry, git checkouts, and
  target/ across runs so cargo install --locked kani-verifier inside
  the kani-github-action does not recompile from scratch every time.
- actions/cache@v4 on ~/.cargo/bin/cargo-kani, ~/.cargo/bin/kani,
  and ~/.kani: caches the CBMC + Kyanite payload that
  cargo kani setup downloads. Cold install: ~8 min; cached: ~30 s.
- timeout-minutes: 15 on the Install Kani step itself: a hung install
  now fails the step instead of consuming the entire 30-minute job
  budget and silently looking like a timeout.
rtacconi added a commit that referenced this pull request Oct 16, 2026
… bullet

Two CodeRabbit findings on PR #11.

1. crates/kcore-sanitize/src/lib.rs — UTF-8 corruption (Major)

   nix_escape took &str but iterated over s.as_bytes() and used
   `bytes[i] as char` for the default branch. That cast interprets each
   continuation byte of a multi-byte UTF-8 scalar as an independent
   Latin-1 code point, producing mojibake whenever the input contained
   any non-ASCII character — e.g.

       nix_escape("café")        → "café"
       nix_escape("🦀")          → four mangled control bytes
       nix_escape("café\${x}")  → "café\\${x}"

   Operator-supplied strings that flow through this function (VM names,
   security-group names, DC labels, image labels) are valid UTF-8
   `&str`, so non-ASCII input is not a hypothetical: as soon as anyone
   names a VM "café-prod" the generated Nix expression would either
   evaluate against the wrong attribute key or fail to parse.

   The Kani proofs in `mod kani_proofs` only feed
   `any_ascii_str(&mut buf)` (bytes restricted to 0x20..=0x7E), so the
   bug was outside the proved domain.

   Fix: iterate over `s.chars().peekable()` and match on `char` instead
   of `u8`. Behaviour on ASCII input is bit-for-bit identical (verified
   by re-running the existing unit tests and the Kani harnesses, both
   of which pass unchanged), so this is a strict superset of the prior
   contract.

   Added regression test `nix_escape_preserves_non_ascii_utf8` covering
   Latin-1 (café, naïve), CJK (日本語), and astral-plane (🦀) input,
   plus the "🦀\${rust}" interpolation-after-emoji case that exercises
   the peek branch.

2. docs/formal-methods-and-verification.md — narrow stale follow-up

   The "Next-iteration follow-ups" list still said "Add Kani harnesses
   for validate_safe_segment / validate_path_under_root once
   crates/node-agent/src/path_safety.rs lands". Both the landing
   condition and the validate_safe_segment harness shipped in this
   branch (see segment_validation_never_panics and
   segment_acceptance_implies_safe in crates/kcore-sanitize/src/lib.rs).

   Narrowed the bullet to mention only the still-unproved
   validate_path_under_root, with a pointer to where the existing
   segment proofs live so a future contributor knows what "matching"
   means.

Quality gates (all green):
  * cargo fmt --check
  * cargo clippy --all-targets -- --deny warnings
  * cargo test --workspace — 416 tests pass; the new
    nix_escape_preserves_non_ascii_utf8 test would have failed against
    the old byte-wise implementation.
  * cargo test -p kcore-sanitize — 14 / 14 pass (was 13).
  * cargo audit (no new advisories)
  * nixfmt --check
rtacconi added a commit that referenced this pull request Oct 16, 2026
The `formal-checks / kani` job on PR #11 has been timing out at exactly
10 minutes. That mark is the `Run bounded Kani proofs` step's
`timeout-minutes: 10`, not anything in `cargo kani` itself — the 11
`#[kani::proof]` harnesses in `crates/kcore-sanitize/src/lib.rs` were
running sequentially, each taking ~30-60s in CBMC on the standard
4-vCPU `ubuntu-latest` runner, so the cumulative wall-clock landed in
the 10-12 minute range and tripped the step timeout.

Three coordinated changes so the gate becomes reliable instead of a
flaky 50/50:

1. Parallelise harness execution.

   The 11 harnesses are independent (each is a separate CBMC
   invocation; they share only the compiled goto-c artifact). Pass
   `--jobs $(nproc)` so all 4 vCPUs are used. Sequential ~10-12 min
   becomes parallel ~3-4 min.

   `--jobs` currently lives behind `-Z unstable-options` (Kani
   stabilisation in progress as of mid-2025 — model-checking/kani#4108
   is the tracking PR). When `--jobs` is stabilised the `-Z` flag can
   be dropped without other changes.

2. Bump step + job timeouts.

   - kani job: `timeout-minutes: 20` → `30`.
   - "Run bounded Kani proofs" step: `timeout-minutes: 10` → `25`.

   This is sized for a sequential cold run (worst case if `--jobs`
   regresses or the cache is fully cold), so a future increase in
   `MAX_INPUT_LEN`, harness count, or `unwind` bound has headroom
   without another workflow edit. The "Install kani-verifier" step
   keeps its own 15-min budget.

3. Make the toolchain cache forward-compatible.

   - Bump cache key to `kani-toolchain-${{ runner.os }}-v2` so this
     PR seeds a fresh entry and stale `cargo-kani` binaries from the
     pre-`-Z unstable-options` era cannot mask a real regression.
   - Add a `restore-keys` fallback of `kani-toolchain-${{ runner.os }}-`
     so a future key bump (`-v3`, …) falls back to the most recent
     compatible cache instead of paying a full 8-min cold install on
     the first run after the bump.
   - Skip `cargo-kani setup` when `~/.kani` was restored from cache.
     `setup` re-downloads the CBMC + Kyanite payload (~1 min) every
     invocation even when the layout is already on disk; the `[ -d
     "$HOME/.kani" ] && [ -n "$(ls -A …)" ]` guard reclaims that
     minute on every warm run.

Local parity: `make kani` now passes the same `-Z unstable-options
--jobs $(nproc)` flags so a passing local run is a faithful predictor
of the CI gate. `nproc` is portable to GNU coreutils and falls back
to `sysctl -n hw.ncpu` on macOS, then to `4` if neither is available.

docs/formal-methods-and-verification.md: updated the local-run snippet
and the CI description to match the new flags and explain the
parallelisation rationale.

Validated locally:
  * actionlint .github/workflows/formal-checks.yml — clean
  * cargo fmt --all -- --check — clean
  * cargo clippy --all-targets -- --deny warnings — clean
  * nixfmt --check on every tracked .nix file — clean
  * (cargo kani not run locally — no Kani toolchain on this machine;
    the workflow change is purely flag/timeout/cache and does not
    touch any harness body.)
rtacconi added a commit that referenced this pull request Oct 16, 2026
Resolve conflicts created when PR #12 (Phase-2 property tests) landed
on main while this branch (formal phase 2/3) was open. Three files
needed manual resolution; the rest auto-merged cleanly.

crates/controller/Cargo.toml — both sides added a `proptest`
  dev-dependency. main pinned `1.11`, this branch pinned `1`. Took
  main's tighter pin (`1.11`) and kept this branch's `[lints]
  workspace = true` stanza (added by the kcore-sanitize refactor so
  `cfg(kani)` doesn't trip the workspace `unexpected_cfgs` lint).

crates/node-agent/Cargo.toml — main added `proptest = "1.11"` to
  `[dev-dependencies]`; this branch added `[lints] workspace = true`.
  Both kept.

Cargo.lock — kcore-kctl's resolved dependency list had `kcore-sanitize`
  (this branch) on one side and `proptest` (main) on the other, both
  added to the same alphabetical position. Both kept; alphabetical
  order maintained (`kcore-sanitize` < `proptest`). `cargo metadata
  --locked` and `cargo build --locked --workspace` both pass after the
  resolution, confirming the lockfile is internally consistent and no
  unrelated entries had to be regenerated.

Validated post-merge:
  * cargo metadata --locked exits 0
  * cargo build --locked --workspace builds clean
  * cargo fmt --all -- --check
  * cargo clippy --all-targets --locked -- --deny warnings
  * cargo test --workspace --locked — 552 / 552 pass (sum of all
    suites). This is the union of PR #11's Phase-2 Kani harnesses +
    Phase-3 DB proptests, PR #12's 111 Phase-2 helper proptests, and
    the UTF-8 regression in nix_escape from earlier in this branch.
rtacconi added a commit that referenced this pull request Oct 16, 2026
…b-proptests

Feat/formal phase 2 3 kani and db proptests
rtacconi added a commit that referenced this pull request Oct 16, 2026
feat(mcp): kcore_rpc can call the kcore-provisioning API
@rtacconi
rtacconi deleted the cursor/mcp-provisioning-rpc-64a3 branch October 16, 2026 07:42
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