A self-improving RLM agent for coding workflows and long-running autonomous tasks.
Rust
fix: preserve npm launcher during overlapping Rust upgrades (#3444)
kt4e599696aacb
diff --git a/install-rust.sh b/install-rust.shindex 6427f4bd92..c1c40224c4 100755--- a/install-rust.sh+++ b/install-rust.sh@@ -2779,7 +2779,17 @@ fi# is the Rust port's now (the TS tree itself was preserved above). An# UNOWNED regular file at the path is not silently destroyed: it is moved# aside first, so nothing this script did not write is ever lost.-if [ -e "$launcher" ] || [ -L "$launcher" ]; then+# Old npm TUIs may have captured `node <prefix>/bin/prime-agent` before+# updating. Keep that npm-owned JS symlink executable by Node when npm and+# Rust share a prefix. The bridge delegates directly to the native payload.+preserve_npm_launcher=no+if [ "${PRIME_AGENT_PRESERVE_NPM_BRIDGE:-0}" = 1 ] \+ && [ -n "${PRIME_AGENT_NPM_BRIDGE_ENTRYPOINT:-}" ] \+ && [ -L "$launcher" ] \+ && [ "$launcher" -ef "$PRIME_AGENT_NPM_BRIDGE_ENTRYPOINT" ]; then+ preserve_npm_launcher=yes+fi+if [ "$preserve_npm_launcher" != yes ] && { [ -e "$launcher" ] || [ -L "$launcher" ]; }; thenif [ -L "$launcher" ]; thensay "replacing the prime-agent command symlink (was: $(readlink "$launcher" 2>/dev/null || true));"say " the keyword is the Rust port's now"@@ -2836,8 +2846,16 @@ exec "$(dirname "$0")/../share/prime-agent/prime-agent" "$@"EOFfichmod 0755 "$launcher_tmp"-mv -f "$launcher_tmp" "$launcher"-launcher_tmp=""+if [ "$preserve_npm_launcher" = yes ]; then+ # Probing the public bridge while it holds its migration lock would+ # recurse into this install. Use the generated sibling wrapper for these+ # checks; its relative payload path is identical, and EXIT removes it.+ install_probe_launcher="$launcher_tmp"+else+ mv -f "$launcher_tmp" "$launcher"+ launcher_tmp=""+ install_probe_launcher="$launcher"+fiif [ "${PRIME_AGENT_USE_LEGACY_DAEMON_SOCKET:-0}" = 1 ]; thenmkdir -p "${PREFIX}/share/.prime-agent-npm-bridge"printf 'legacy\n' > "${PREFIX}/share/.prime-agent-npm-bridge/legacy-daemon-socket"@@ -3078,7 +3096,7 @@ if uv_on_path \|| { [ -n "$uv_bin_dir" ] && [ -x "${uv_bin_dir}/${uv_name}" ]; } \|| { [ "$uv_under_store" = "no" ] && [ -x "${HOME}/.local/bin/${uv_name}" ]; }; thenstep_start "Preparing the Python kernel"- if bootstrap_out="$("$launcher" --prime-agent-bootstrap 2>&1)"; then+ if bootstrap_out="$("$install_probe_launcher" --prime-agent-bootstrap 2>&1)"; thenstep_ok "Kernel ready"say "kernel pre-warmed: the first session's Python kernel is ready"say "$bootstrap_out"@@ -3099,7 +3117,7 @@ fi# failure prints the output plus a re-run hint instead of failing the# install over it.version_ok="yes"-if version_out="$("$launcher" --version 2>&1)"; then+if version_out="$("$install_probe_launcher" --version 2>&1)"; thensay "installed: ${version_out}"elseversion_ok="no"diff --git a/scripts/release/npm_bridge_assets/cli.cjs b/scripts/release/npm_bridge_assets/cli.cjsindex f6230e8bfd..4c8708a930 100644--- a/scripts/release/npm_bridge_assets/cli.cjs+++ b/scripts/release/npm_bridge_assets/cli.cjs@@ -292,6 +292,7 @@ async function main() {env: { ...nativeEnvironment, PRIME_AGENT_VERSION: metadata.version,PRIME_AGENT_RELEASE_CHANNEL: metadata.primeAgentReleaseChannel,PRIME_AGENT_RUST_PREFIX: prefix, PRIME_AGENT_PRESERVE_NPM_BRIDGE: "1",+ PRIME_AGENT_NPM_BRIDGE_ENTRYPOINT: path.join(packageRoot, "dist", "bundle", "cli.js"),PRIME_AGENT_USE_LEGACY_DAEMON_SOCKET: "1",PRIME_AGENT_DEFER_DAEMON_STOP: coordinator ? "1" : "0" },stdio: ["ignore", process.stderr, process.stderr],diff --git a/scripts/release/test_npm_bridge.py b/scripts/release/test_npm_bridge.pyindex 28df876c90..f6aca2debe 100644--- a/scripts/release/test_npm_bridge.py+++ b/scripts/release/test_npm_bridge.py@@ -91,6 +91,7 @@ set -eutest "$PRIME_AGENT_VERSION" = "${EXPECT_VERSION:-1.0.0}"test "$PRIME_AGENT_RELEASE_CHANNEL" = "stable"test "$PRIME_AGENT_PRESERVE_NPM_BRIDGE" = "1"+test -f "$PRIME_AGENT_NPM_BRIDGE_ENTRYPOINT"echo install >> "$INSTALL_LOG"echo "installer output stays on stderr"if [ "${FAIL_INSTALL:-0}" = 1 ]; then exit 23; fi@@ -318,6 +319,54 @@ child.on("exit",code=>{process.exitCode=code;});custom = self.launch("socket", PRIME_AGENT_DAEMON_SOCKET=str(self.root / "custom.sock"))self.assertEqual(custom.stdout.strip(), str(self.root / "custom.sock"))+ def test_real_installer_preserves_node_relaunch_only_for_its_npm_bridge(self):+ installer = (Path(__file__).resolve().parents[2] / "install-rust.sh").read_text()+ section = installer.split("# --- the launcher (the takeover lives here)", 1)[1]+ section = section.split("# The cmd/PowerShell launcher twin", 1)[0]+ # Reuse the real published launcher section, not the fixture installer:+ # an old TUI captures the public symlink path in Node's argv before npm+ # replaces the package. That path must still contain JavaScript later.+ section = "# --- the launcher (the takeover lives here)" + section+ self.env["PRIME_AGENT_RUST_PREFIX"] = str(self.npm_prefix)+ payload = self.npm_prefix / "share/prime-agent"+ payload.mkdir(parents=True)+ shutil.copyfile(self.fixture, payload / "prime-agent")+ (payload / "prime-agent").chmod(0o755)+ (payload / "version").write_text("1.0.0\n")+ receipt_dir = self.npm_prefix / "share/.prime-agent-npm-bridge"+ receipt_dir.mkdir()+ (receipt_dir / "1.0.0").write_text("installed\n")+ command = self.npm_prefix / "bin/prime-agent"+ foreign_entry = self.root / "unrelated.js"+ foreign_entry.write_text(self.entrypoint.read_text())+ for flag, target, preserved in (("1", self.entrypoint, True),+ ("1", foreign_entry, False),+ ("0", self.entrypoint, False)):+ with self.subTest(flag=flag, target=target):+ command.unlink(missing_ok=True)+ command.symlink_to(target)+ result = subprocess.run(["sh", "-eu"], input='''+PREFIX="$PRIME_AGENT_RUST_PREFIX"+bin_dir="$PREFIX/bin"+launcher="$bin_dir/prime-agent"+WINDOWS=no+say() { :; }; note() { :; }; die() { echo "$*" >&2; exit 1; }+trap '[ -z "${launcher_tmp:-}" ] || rm -f "$launcher_tmp"' EXIT+''' + section + '\n"$install_probe_launcher" --version\n',+ text=True, capture_output=True, timeout=10, env={**self.env,+ "PRIME_AGENT_PRESERVE_NPM_BRIDGE": flag,+ "PRIME_AGENT_NPM_BRIDGE_ENTRYPOINT": str(self.entrypoint),+ "PRIME_AGENT_USE_LEGACY_DAEMON_SOCKET": "1"})+ self.assertEqual(result.returncode, 0, result.stderr)+ self.assertEqual(result.stdout.strip(), "1.0.0")+ self.assertEqual(command.is_symlink(), preserved)+ invocation = ["node", str(command)] if preserved else [str(command)]+ relaunched = subprocess.run([*invocation, "--version"], env=self.env,+ text=True, capture_output=True, timeout=10)+ self.assertEqual(relaunched.returncode, 0, relaunched.stderr)+ self.assertEqual(relaunched.stdout.strip(), "1.0.0")+ self.assertEqual(list(command.parent.glob(".prime-agent.*")), [])+def test_stale_bridge_does_not_downgrade_newer_native_without_receipt(self):payload = self.prefix / "share/prime-agent"payload.mkdir(parents=True)