Repository navigation
perf(sdk): probe and hash the authored Node once per CLI process - #681
Merged
Merged
Conversation
An authored run resolved the Node authority twice on the startup path: assertAuthoredRuntimeAvailable before root admission and runAuthoredInNode before spawning the body. Each call spawned a node probe and read and SHA-256 hashed the whole node executable (~110 MB). Reuse the previous authority for the same FLOWS_AUTHORED_NODE/PATH while a stat fingerprint (dev, ino, size, mtime, ctime) of the resolved executable is unchanged. The child still hashes the executable it runs and the parent still compares that report, so a binary swapped after the probe is refused. Measured with an instrumented darwin-arm64 standalone build: the second authority call drops from 64-76 ms to 0 ms per run. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
[Medium impact] The PR appears safe to merge; the stale symlink selection is fixed and no new actionable issue was found.
|
Review (#681): the memo keyed on FLOWS_AUTHORED_NODE/PATH and fingerprinted the previously resolved file, so a selection symlink retargeted while the old binary remained kept returning the old authority. Key reuse on the candidate spawnSync would run now (the override, or the first node on an all-absolute PATH) by both its path and its realpath. Any change re-probes; a PATH with a relative entry is never reused. Tests cover an override symlink retarget and a PATH node symlink retarget. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
An authored run resolved the Node authority twice on its startup path: once in
assertAuthoredRuntimeAvailable(before root admission) and again inrunAuthoredInNode(before spawning the body). Each call spawned anodeprobe and read and SHA-256 hashed the whole node executable (about 110 MB).This PR keeps the previous authority for the same
FLOWS_AUTHORED_NODE/PATHselection while a stat fingerprint of the resolved executable (dev, ino, size, mtimeNs, ctimeNs) is unchanged. The integrity check is unchanged: the child still hashes the executable it actually runs, and the parent still compares that report with the authority. A binary swapped after the probe is refused, never trusted.Why
This is part of the hosted Relayflows v2 startup work. In production, the time from CLI spawn to the first step is 2.7–3.2 s (runs 87945dd1, 58982337, aa813b41, 3f646c0f). An instrumented darwin-arm64 standalone build (temporary trace points, not in this PR) put the second authority call at 64–76 ms locally. With the memo it is 0 ms; the whole CLI spawn → first step went from about 780 ms to about 720 ms on the same machine. E2B boxes are slower per operation (the same path takes about 4x longer there), so the expected hosted saving is about 0.2–0.3 s. That figure is an estimate and has not been measured on E2B.
Verification
Commands were run in
packages/sdkwith Node 22.22.2 and Bun 1.4.2.Head b8dcf19 (first commit):
npm run typecheckandnpm run typecheck:testspass.npx vitest run tests/authored-node-authority.test.ts: 3/3 pass.RELAYFLOWD_BIN=<released 2.0.54 darwin relayflowd> npx vitest run tests/authored-node-runtime.test.ts tests/authored-node-admission.test.ts tests/authored-node-result.test.ts tests/authored-node-authority.test.ts(afternpm run build): 81/81 pass.Review fix baf849f (keys the memo on the selected executable's path plus its realpath):
npx vitest run tests/authored-node-authority.test.ts: 5/5 pass.npm run typecheckpasses.EPERM, andnpm run typecheck:testsfailed with missing TypeScript lib errors for that reason.Release and pin
This saving reaches hosted runs only through a flows release followed by a Cloud pin bump of the hosted runtime artifact and Surface authority.
🤖 Generated with Claude Code
Note
Medium Risk
Touches security-sensitive Node executable trust on the authored startup path; caching is guarded by fingerprint revalidation and unchanged child-side hash verification, but a wrong invalidation rule could trust a stale authority.
Overview
Memoizes the authored Node authority so a single CLI process no longer runs the expensive probe (spawn Node + SHA-256 of the full executable) twice on startup—once before root admission and again before spawning the body.
Reuse is keyed on
FLOWS_AUTHORED_NODEandPATH, and is invalidated when a stat fingerprint (dev, ino, size, mtimeNs, ctimeNs) of the resolved executable changes or the candidate vanishes. The child still reports and hashes the binary it runs; parent comparison is unchanged, and a rewrite during hashing is not cached.Adds
authoredNodeAuthorityForTest()and Vitest coverage for single-probe reuse, re-probe on executable change, and re-probe whenPATHchanges.Reviewed by Cursor Bugbot for commit b8dcf19. Bugbot is set up for automated code reviews on this repo. Configure here.
Need help on this PR? Tag
@codesmith-botwith what you need.Agent Relay sessions
claudesessiona9c94cac· opened viagh pr create· last active 2026-10-21