Repository navigation
refactor(user-transformations): share V1 sandbox API injection and keep no-op log in-isolate - #5675
sivashanmukh wants to merge 1 commit into
Conversation
…ep no-op log in-isolate createIvm and the cached-isolate context reset each kept their own copy of the host APIs injected into the sandbox. The copies drifted once already: the reset path never set log, so cached V1 transformations failed with "log is not defined" until #5637. Both paths now call injectSandboxApis in src/util/ivmSandboxApis.js, so they expose the same globals. Outside test mode, log was a host callback that did nothing. isolated-vm still copied every argument into host memory before calling it, and threw "could not be cloned" for function or symbol arguments. The host now sets log only in test mode, where it captures output. Otherwise the bootstrap script defines a no-op log inside the isolate. The cache-hit regression test now asserts that a cache miss and a cache hit see the same globals, and that log accepts an uncloneable argument. Co-Authored-By: Claude Opus 5.5 <[email protected]> 🔒 Scanned for secrets using gitleaks 8.28.0
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #5675 +/- ##
========================================
Coverage 92.12% 92.13%
========================================
Files 713 714 +1
Lines 39591 39526 -65
Branches 9276 9201 -75
========================================
- Hits 36474 36416 -58
- Misses 2852 2925 +73
+ Partials 265 185 -80 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
lvrach
left a comment
There was a problem hiding this comment.
Approved. Both paths now call injectSandboxApis. The reset path re-runs the bootstrap, so cache hits also get the in-isolate no-op log, and test mode still captures logs through the host callback.
[praise] The cache-hit test compares Object.getOwnPropertyNames(globalThis) on a miss and a hit, which pins both paths to the same globals.
CI: only the live (hs) job in Live Integration Tests fails. That workflow is also red on unrelated PRs today.
|
This PR is considered to be stale. It has been open for 20 days with no further activity thus it is going to be closed in 7 days. To avoid such a case please consider removing the stale label manually or add a comment to the PR. |



What are the changes introduced in this PR?
Follow-up to #5637, covering two review findings on that PR.
createIvminsrc/util/ivmFactory.jsandinjectFreshApisinsrc/util/ivmCache/contextReset.jseach kept their own copy of the host APIs injected into the isolate (_ivm,_fetch,_fetchV2,_geolocation,_getCredential,log,extractStackTrace). The copies drifted: the reset path never setlog, so withUSE_IVM_CACHE=trueevery cache hit of a V1 transformation that calledlog()failed withReferenceError: log is not defined. That bug existed from feat: ivm cache #4675 until fix(user-transformations): preserve log in cached V1 contexts #5637. Both paths now callinjectSandboxApisin the newsrc/util/ivmSandboxApis.js, so they cannot drift again.logno longer crosses into the host. Outside test mode,logwas a host callback that did nothing.isolated-vmstill deep-copied every argument into host memory (outside the isolate'smemoryLimit) before calling it. It also threw... could not be clonedfor function or symbol arguments. The host now injectslogonly in test mode, where it captures output for the test API. Otherwise the bootstrap script definesglobal.log = function () {}inside the isolate.What is the related Linear task?
Follow-up to MAR-2930 (#5637).
Please explain the objectives of your changes below
The moved code is unchanged apart from two things. The credentials error message reads ids from
trTags.logis wrapped inif (testMode).contextReset.jsdrops about 130 lines of duplicated code.Sandbox exposure goes down. One fewer host function is reachable from customer code in production, and nothing new is added.
Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?
log(x)is now a pure in-isolate no-op. Calls that used to throw for uncloneable arguments, such aslog(fn), now succeed.testMode = true) still capturesLog: ...lines through the host callback. The existinguser_transformation_code_test_output.jsonfixture covers this and passes.GEOLOCATION_TIMEOUT_IN_MSonce at module load, the same as the fresh path, instead of on every context reset.Any new dependencies introduced with this change?
N/A
Any new generic utility introduced or modified. Please explain the changes.
src/util/ivmSandboxApis.jsexportsinjectSandboxApis(jail, { trTags, credentials, testMode, logs }). Both the fresh-isolate path and the cached-isolate reset path use it.Any technical or performance related pointers to consider with the change?
logcalls in production no longer copy their arguments to the host or block on a host round trip.Validation
log('...', () => 1)and returnsObject.getOwnPropertyNames(globalThis). It asserts that the cache-miss and cache-hit outputs are equal, which checks that both paths expose the same globals.logback on in production makes that test fail.NODE_OPTIONS='--no-node-snapshot' npx jest -c jest.default.config.js test/__tests__/ivmCache test/__tests__/user_transformation*.test.js src/util/ivm/scriptRunner.test.ts src/routerUtils.test.js src/services/eventTest/__tests__/eventTester.test.ts --runInBandpasses 246/246 on Node 22.lint-staged(eslint and prettier) passes.Developer checklist
My code follows the style guidelines of this project
No breaking changes are being introduced.
All related docs linked with the PR? N/A
All changes manually tested?
Any documentation changes needed with this change? No.
Is the PR limited to 10 file changes?
Is the PR limited to one linear task?
Are relevant unit and component test-cases added in new readability format?
Reviewer checklist
Is the type of change in the PR title appropriate as per the changes?
Verified that there are no credentials or confidential data exposed with the changes.
🤖 Generated with Claude Code