GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat(cargo): project-local [patch]-redirect backend + single fail-closed guard by mikolalysenko · Pull Request #102 · SocketDev/socket-patch

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Jun 4, 2026

Copy link
Copy Markdown
Collaborator

Project-local cargo [patch]-redirect backend + fail-closed guard

Patching a Rust dependency from the registry cache no longer mutates the shared
$CARGO_HOME registry in place. apply now writes a project-local patched copy
under .socket/cargo-patches/<name>-<version>/ and a managed [patch.crates-io]
entry (+ [env] SOCKET_PATCH_ROOT) into .cargo/config.toml, so patches are
project-scoped and the registry stays pristine for sibling projects. Vendored crates
(vendor/) and --global cargo keep the existing in-place .cargo-checksum.json
path.

Build-time guard — single fail-closed mode

socket-patch setup adds a tiny socket-patch-guard dependency (a normal
[dependencies] entry, so cargo always runs its build script) to each workspace
member. On every relevant cargo build it runs socket-patch apply --check:

  • in sync → proceed (cached no-op; zero steady-state overhead);
  • drift → heal (apply) then fail the build (the current build already
    compiled the stale copy; the re-run is clean) — recoverable reports
    "regenerated — re-run", unrecoverable reports "could NOT be reconciled";
  • missing / cargo-less CLI / unrecoverable → fail closed.

There is no warn/off mode and no SOCKET_PATCH_GUARD env. In normal use the
guard never fires, since changing a patch goes through get/apply, which
regenerate the copies. apply --check doubles as a read-only, offline, lock-free CI
gate and cross-checks Cargo.lock (catching a patched dep that resolved to an
unpatched version).

Ships with cargo enabled by default

default = ["cargo"] in both crates (npm + PyPI are unconditional), so released
binaries and cargo install socket-patch-cli patch Rust deps and run the guard out
of the box; golang/maven/composer/nuget/deno stay opt-in. A
--no-default-features binary's apply --check fails closed rather than reporting
"in sync".

R&D (not shipped): same-tick auto-heal

crates/socket-patch-guard/SAME_TICK_HEAL_RND.md + an #[ignore] experiment
(tests/same_tick_heal_experiment.rs) establish that a patched copy depending on the
guard heals in the same cargo build (verified on cargo 1.93.1), at zero
steady-state cost. It's publish-gated (copies need a portable guard ref) and
deliberately not wired into apply_cargo_redirect; the doc records the
productionization path.

Adversarial pre-push review

Before opening this PR I ran a multi-agent adversarial review of the full diff
(5 reviewers across guard logic / docs / R&D / backend / tests, each finding
independently verified). It surfaced 17 confirmed findings, all fixed in this
branch:

Sev Fix
blocker A socket-patch built without the cargo feature returned 0 from apply --check, so the guard passed open. Now fails closed — and cargo ships by default, so the released binary supports it.
major verify_cargo_redirect_state now checks the [patch] entry path matches the desired version (new Drift::WrongEntryPath + regression test) — a stale-version entry no longer audits as in-sync.
major Wired guard_build_integration + e2e_cargo_coexist into the CI e2e matrix (the real fail-closed proofs were #[ignore] and never ran in CI).
major real_cargo_guard_fails_build_on_stale_patch asserted a message that never fires + an always-true || "socket-patch" escape; now asserts the real recoverable-drift message.
minor Corrupt/unreadable manifest in apply --check now fails closed (was exit 0).
minor Dropped the spurious || "socket-patch" escape in the unrecoverable-drift + missing-CLI integration tests; assert deterministic messages + sentinel.
minor/nit ×9 Documented duplicate-version + malformed-Cargo.lock cross-check limitations; doc/comment fixes (CHANGELOG "build-dependency", README "no warn" contradiction, R&D no_std caveat, .socket→., "runtime hook"→"build-time guard", stale "Default (strict)" comment).

Testing

  • cargo test green in both feature configs (default-with-cargo + --features cargo) and --no-default-features, for core + cli + guard.
  • The #[ignore] real-cargo proofs pass: guard_build_integration (4), e2e_cargo_coexist (incl. the fail-closed-on-stale-patch proof), same_tick_heal_experiment.
  • clippy clean on all changed files (cargo fmt intentionally not run — repo isn't rustfmt-1.8-clean; only touched lines formatted).

🤖 Generated with Claude Code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Mikola Lysenko (mikolalysenko) and others added 2 commits June 4, 2026 12:49
@mikolalysenko @claude
feat(cargo): project-local [patch]-redirect backend with fail-closed …
c151ee7
…guard

Local cargo patching no longer mutates the shared $CARGO_HOME registry. `apply`
now materialises a project-local patched copy under
`.socket/cargo-patches/<name>-<version>/`, points cargo at it with a managed
`[patch.crates-io]` entry in `.cargo/config.toml`, and reuses the hardened
`apply_package_patch` pipeline against the copy. Patches are project-scoped,
the `.cargo-checksum.json` rewrite disappears (a path-dep isn't checksum
verified), and removal is clean. Vendored crates and `--global` keep the
in-place sidecar path unchanged.

New `socket-patch-guard` crate (build-time) keeps committed patches honest. Its
build.rs runs `apply --check` and is FAIL-CLOSED: on drift it fails the build
rather than silently compiling stale/unpatched sources, so a one-shot CI build
can't ship an unpatched binary. The check inspects the static committed state,
so it's independent of cargo's build-script ordering. `SOCKET_PATCH_GUARD=warn`
heals-and-continues (one-build lag); `=off` disables it loudly.

`apply --check` is a read-only, lock-free, offline auditor (CI / GitHub-App
gate) that verifies copies vs manifest AND cross-checks Cargo.lock to catch a
patched dependency that resolved to an unpatched version. `setup` wires the
guard dep per workspace member + `[env] SOCKET_PATCH_ROOT` (never touching the
user's build.rs); that setup state is owned by setup/`setup --remove` and is
preserved by `rollback` (which removes only patch state).

Adds cargo_config + cargo_redirect (core), cargo_setup, the guard crate, and
unit + e2e coverage (e2e_cargo_coexist, setup_cargo_roundtrip,
guard_build_integration) incl. real-cargo fail-closed proofs.

Pre-GA: socket-patch-guard must be published to crates.io (in-repo path dep for
now).

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@mikolalysenko @claude
feat(cargo): single fail-closed guard, ship cargo by default, harden …
2fc84ae
…redirect audit

Finalizes the project-local cargo `[patch]`-redirect backend for review.

Guard — collapse to a single **fail-closed** mode: remove `warn`/`off` and the
`SOCKET_PATCH_GUARD` env entirely (warn could ship unpatched on a resolved-version
mismatch). The build script runs `apply --check`; in sync → proceed; on drift it
heals (`apply`) then fails the build (the current build already compiled the stale
copy — the re-run is clean); a missing/unrecoverable CLI fails closed.

Ship cargo by default — `default = ["cargo"]` in both crates (npm + PyPI stay
unconditional), so released binaries and `cargo install socket-patch-cli` patch
Rust deps and run the guard out of the box; golang/maven/composer/nuget/deno stay
opt-in. A `--no-default-features` binary's `apply --check` now fails closed instead
of reporting "in sync", so a cargo-less CLI can never make the guard pass vacuously.

Hardening from an adversarial pre-push review (17 confirmed findings):
- verify_cargo_redirect_state now checks the `[patch]` entry path matches the
  desired version (new `Drift::WrongEntryPath`, + regression test) — a stale-version
  entry no longer audits as in-sync while cargo links the unpatched crate.
- a corrupt/unreadable manifest in `apply --check` now fails closed (was exit 0).
- wire `guard_build_integration` + `e2e_cargo_coexist` into the CI e2e matrix; the
  real fail-closed proofs were `#[ignore]` and never ran in CI.
- tighten test assertions that passed spuriously on cargo's `failed to run custom
  build command for \`socket-patch-guard\`` boilerplate (recoverable-drift, missing
  CLI, unrecoverable-drift) + assert the sentinel.
- document the duplicate-version and malformed-`Cargo.lock` cross-check limitations;
  fix doc/comment drift (CHANGELOG "build-dependency", README "no warn"
  contradiction, R&D no_std caveat, `.socket`→`.`, "runtime hook"→"build-time guard").

R&D — same-tick auto-heal (tests/same_tick_heal_experiment.rs + SAME_TICK_HEAL_RND.md):
a patched copy depending on the guard heals in the SAME `cargo build` (verified on
cargo 1.93.1), at zero steady-state cost. Not shipped — publish-gated; documented as
a productionization path.

Tests green in both feature configs + guard; the `#[ignore]` real-cargo proofs pass;
clippy clean on all changed files.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@mikolalysenko
Mikola Lysenko (mikolalysenko) enabled auto-merge (squash) June 4, 2026 20:20
@mikolalysenko @claude
test(setup-matrix): add non-blocking known_regression allowlist
3d02523
The experimental (continue-on-error) setup-matrix job flags 9 pre-existing
failures as blocking "regression"s — present on main, unrelated to this branch:
the pnpm root-postinstall hook and the pip/uv/hatch `.pth` hook don't re-apply
the patch after `setup` + install (npm/yarn/bun work). Their baseline records
them as supported, so they classify as regression and red the job.

Add a temporary, explicit `known_regressions` allowlist (by `<eco>/<pm>/<scenario>`
id) in matrix.json. An allowlisted case that would be a `regression` is downgraded
to a new non-blocking `known_regression` class in BOTH consumers (the jq
orchestrator scripts/setup-matrix.sh and the Rust wrappers' shared mod.rs).

`baseline_supported` stays `true` (these SHOULD work — not unimplemented gaps), so
when a hook is fixed the case auto-recovers to `pass`/`progress` and is simply
removed from the list. Only a non-allowlisted `regression` still fails the job.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Wenxin-Jiang
Wenxin Jiang (Wenxin-Jiang) approved these changes Jun 4, 2026
View reviewed changes
@mikolalysenko
Mikola Lysenko (mikolalysenko) merged commit ed435b4 into main Jun 4, 2026
54 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the feat/cargo-local-patch-redirect branch June 4, 2026 21:42
@mikolalysenko Mikola Lysenko (mikolalysenko) mentioned this pull request Jun 5, 2026
feat(golang): project-local go.mod [replace]-redirect backend + fail-closed guard #104
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Wenxin-Jiang Wenxin Jiang (Wenxin-Jiang) Wenxin-Jiang approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@mikolalysenko @Wenxin-Jiang
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.