Add in-memory hosted engine and napi addon - #276
Merged
Merged
Conversation
Let hosts run hosted-mode patching without a working directory or network access. The new hosted_memory engine takes a map of repository files, finds every project root, looks up patches once across all roots through a pluggable PatchApi provider, and returns the rewritten lockfiles and redirect ledgers. Lockfile inventory now reads through a ProjectView, so the same parsers serve disk and in-memory projects; disk behavior is unchanged. The existing scan --mode hosted path keeps using ApiClient directly, which also implements PatchApi. Parity tests compare the engine against the real CLI binary across npm, pnpm, yarn, bun, pypi, cargo, composer, gem and golang fixtures. A hidden hosted-bundle command exposes the engine for debugging. Assisted-by: Claude Code:claude-opus-5-5
Expose the in-memory hosted engine to Node as a native addon, so a service can stream repository files into a scan session and serve patch lookups from its own data source instead of the Socket API. The package lives under crates/socket-patch-node/npm and is private, so the npm release tooling does not publish it. Release builds now build only the CLI crate, and a new CI job builds the addon and runs its Node smoke test. Assisted-by: Claude Code:claude-opus-5-5
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Export the scan session as an opaque External handle plus plain functions, not a napi class. The class wrapper's generated glue unwraps its native pointer through an FFI out-parameter, which CodeQL reports as a possible invalid pointer dereference. The public HostedScanSession in index.js is unchanged; it now calls the handle functions. Assisted-by: Claude Code:claude-opus-5-5
Mikola Lysenko (mikolalysenko)
marked this pull request as ready for review
September 27, 2026 00:51
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using high effort and found 2 potential issues.
Bugbot Autofix is ON. A cloud agent has been kicked off to fix the reported issues.
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 1f45298. Configure here.
Collaborator
Author
|
Claude (@claude) review |
Keep every directory with its own Cargo.lock as a project root during path selection. Whether a nested lock belongs to an enclosing workspace depends on that workspace's members and exclude lists, which only the engine can read. Crates the workspace excludes are independent projects and are now scanned; real members still have their unused lock ignored. Point the in-memory Pipenv warning at the pipenvMajor option, the only input the engine reads, instead of PATH or an environment variable. Assisted-by: Claude Code:claude-opus-5-5
Bring in the concurrent scan work from #257. The Cargo member walk keeps the tree abstraction the in-memory engine needs, and its disk tree reads manifests through the new parse memo; the memory tree parses directly. The in-memory Cargo.lock reader adopts the memoized Arc<DocumentMut> that read_lock now returns. Assisted-by: Claude Code:claude-opus-5-5
Wenxin Jiang (Wenxin-Jiang)
approved these changes
Sep 27, 2026
Mikola Lysenko (mikolalysenko)
deleted the
feat/napi-hosted-in-memory
branch
September 27, 2026 14:32
Mikola Lysenko (mikolalysenko)
added a commit
that referenced
this pull request
Sep 27, 2026
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Mikola Lysenko (mikolalysenko)
added a commit
that referenced
this pull request
Sep 27, 2026
#276 moved the lock inventory onto `ProjectView` (disk or the in-memory hosted engine's `MemoryProject`). The requirements.txt reader keeps the rewired-line fix on main's new signature, so it reaches the in-memory engine through the same function; the redirected-lines test now also reads the file through a `ProjectView::Memory` and expects the same packages. The order and js7 fixes touch `get` and vendored staging, neither of which the hosted-only in-memory engine copies. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Mikola Lysenko (mikolalysenko)
added a commit
that referenced
this pull request
Sep 27, 2026
Brings in #276 (the in-memory hosted engine and its napi addon) and wires vlt into it: - vlt-lock.json is a project-root marker. - The lock inventory and the in-memory flavor probe read vlt through the new ProjectView. - The in-memory rewrite passes bun.lockb presence and the vlt withholding to the rewriters, and confirms vlt deps the way the disk flow does. - The in-memory ledger merge rebases vlt edits like the disk merge. - The engine has no network for the vlt artifact preflight, so it judges every in-scope vlt artifact as --offline does: the dep is withheld (redirect_vlt_artifact_unverifiable), never pinned. The disk and memory preflights share one judge. The node_modules/.vlt-lock.json entry is only an install-state sentinel, as on disk. The lock-inventory conflicts are resolved onto #276's ProjectView readers, and REBASE_KINDS keeps the vlt kind now that it is shared. Assisted-by: Claude Code:claude-opus-5-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

LLM Description written by Claude Code:claude-opus-5-5
Summary
Adds a way for a service to run hosted-mode patching in-process, with no working directory and no network calls from the engine. depscan's new autopatch worker streams a repository's lockfiles into it and serves patch lookups straight from the patch database.
hosted_memoryengine (crates/socket-patch-cli/src/hosted_memory/): takes a map of repository files (text, binary, presence-only, symlinks), detects project roots, looks up patches once across all roots, and returns rewritten files plus per-root redirect ledgers. The rewrite, pnpm trust and npm allow-remote planning, confirmation and ledger-merge stages are copied as pure functions fromrun_redirect_selected. The diskscan --mode hostedpath is unchanged.PatchApitrait (appended inapi/client.rs): the five lookups the hosted path makes (batch, by-package, package references, view, artifact download).ApiClientimplements it by forwarding to its existing methods.ProjectViewseam (lock_inventory/view.rs): lockfile readers work over disk or memory. Disk wrappers call the same readers, so behavior is unchanged.hosted-bundlecommand: runs the engine on a JSON bundle from stdin, for debugging.socket-patch-nodenapi addon (crates/socket-patch-node, napi 3.13):HostedScanSession(pushChunk/endFile/markPresent/finish/cancel), backed by an opaqueExternalhandle rather than a napi class (the class glue tripped CodeQL's invalid-pointer rule),selectHostedScanPaths, and a JS provider callback that implementsPatchApi. The JS package is private and lives outside thenpm/socket-patch-*release glob.Scope and limits
members/exclude, so excluded crates are scanned as their own projects.bun.lockband Rush), pypi, cargo, golang, gem and composer. Maven and NuGet produceecosystem_unsupported_in_memory, because they have no lockfile inventory without crawlers.FACTS_MEMO); the in-memory engine walks the sameTreeabstraction over its supplied files and never reads or writes that memo. The engine's copiedrun_redirect_selectedstages still pass the parity suite against a CLI binary built from the merged code. Deduplicating them against Speed up hosted and vendored scans: concurrent API requests, parallel crawl, single-pass rewriters #257's disk path is a follow-up.Testing
redirectblock against the engine, across npm, pnpm v9, yarn classic and berry,bun.lock,bun.lockb, Rush, uv, requirements, poetry, Pipfile, cargo (including workspaces and[patch]paths), composer, Gemfile, golang and a nested monorepo.SOCKET_*environments, malformed and 200k-deep inputs, limits, cancellation, timeouts, no proxy fallback on 401, symlinks, a corrupt ledger and vendored takeover refusal.cargo clippy --workspace --all-features -- -D warningspasses. The addon has only been built on macOS arm64; Linux and Windows CI builds are the first run there.🤖 Generated with Claude Code
Note
Medium Risk
Large new hosted redirect path and N-API boundary with org-authenticated lookups; disk scan behavior is mostly shared via extracted logic and parity tests, but any engine drift could affect in-process consumers before the CLI path.
Overview
Introduces an in-memory hosted redirect engine so hosted-mode patching can run without touching the filesystem or spawning the CLI. Callers supply repo files (text, binary, presence-only, symlinks); the engine detects roots, deduplicates patch lookups across roots, and returns rewritten lockfiles plus redirect ledgers aligned with
scan --mode hosted --json.The engine lives under
crates/socket-patch-cli/src/hosted_memory/(discovery, ledger merge, path selection, redirect planning/rewrite). Diskscan --mode hostedis largely unchanged; many helpers incommands/scan/hosted.rsare widened topub(crate)so the engine can reuse the same pnpm/npm trust and JSON shapes. A hiddenhosted-bundlesubcommand runs the engine from a JSON stdin bundle for parity/debugging (requires org API token; no public proxy).Adds
socket-patch-node, a private N-API crate exposingHostedScanSession(streamed input),selectHostedScanPaths, and a JSPatchApiprovider. Workspacedefault-membersand release builds now target onlysocket-patch-cliso release artifacts skip the addon; CI gains anode-addonjob (build + Node smoke tests) and a dedicatedprofile.addonfor faster addon links.Reviewed by Cursor Bugbot for commit 1f45298. Configure here.