Skip to content

feat(js): add Python and TypeScript runtime host functions - #2740

Merged
chaliy merged 5 commits into
mainfrom
feat/node-runtime-host-functions
Oct 16, 2026
Merged

chaliy merged 5 commits into
mainfrom
feat/node-runtime-host-functions

Conversation

@chaliy

@chaliy chaliy commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What changed

Node/Bun/Deno applications can register synchronous or asynchronous host functions for embedded Python and TypeScript on Bash, BashTool, and all JavaScript agent adapters. Each execution preserves its caller's AsyncLocalStorage context and supplies an AbortSignal for host I/O. Reset preserves handlers; snapshot restoration accepts fresh callbacks.

Blocking instance access rejects active asynchronous execution, preventing event-loop deadlocks involving host functions, streaming output, and live filesystem handles. Added bounded JSON conversion and explicit callback rows to the capability parity contract; Rust BashTool gains the Python callback builder counterpart.

Why

Extend the shipped Python integration to the native JavaScript SDK and make cross-surface callback gaps explicit. Browser/WASM and C follow in separate PRs.

Before / After

Before: externalFunctions had no callable JavaScript dispatcher; TypeScript runtime options were unavailable. LangChain used synchronous execution internally.
After: Python lookup(21, multiplier=2) and TypeScript await double(21) return 42 through real host callbacks. Local verification: 656 AVA tests and 167 runtime compatibility tests pass, including HTTP request contexts, queued requests, cancellation, timeout/reuse, snapshots, recursive access, worker-thread environments and all agent adapters. A subprocess regression terminates workers with pending or CPU-bound host functions and verifies quiet native teardown; completed ScriptedTool worker shutdown is also covered. Shared JSON codec and Rust tool callback tests pass. CI adds targeted macOS/Windows callback coverage alongside the existing Linux Node/Bun/Deno matrix. just pre-pr, just test, all-target/all-feature Clippy and the parallel execution benchmark pass locally.

Risk

Medium: native callback lifetime and synchronization. Execution-local revocation, weak NAPI dispatchers, bounded queues and blocking-entry guards cover shutdown/cancellation/reentry. Host I/O must observe its signal; application side effects cannot be rolled back.

Checklist

  • Tests added or updated
  • Backward compatibility considered

Comment thread crates/bashkit-js/__test__/runtime-functions.spec.ts Fixed
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 16, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit c145267 Commit Preview URL

Branch Preview URL
Oct 16 2026, 08:57 PM

@chaliy
chaliy merged commit 6c14402 into main Oct 16, 2026
52 checks passed
@chaliy
chaliy deleted the feat/node-runtime-host-functions branch October 16, 2026 21:21
chaliy added a commit that referenced this pull request Oct 25, 2026
…2776)

`runtime-functions.ts` arrived in #2740 without being added to tsconfig's
`include`. tsc compiles a reachable import regardless, so it kept emitting
`runtime-functions.js` and every local build and `js.yml` run stayed green.

Two things broke on that omission. `publish-js.yml` ships a `js-stubs`
artifact whose file list is maintained by hand from `include`, so it never
gained the file; the test jobs download that artifact instead of running
tsc. And `scripts/tests/test_js_publish_files.py`, the guard added after
0.18.2 shipped without `langchain.js`, reads its notion of "tsc output" out
of the same `include` -- so the guard was blind to exactly the file missing
from it.

v0.20.0 therefore published to crates.io and PyPI while all fifteen
`Publish JS` test jobs failed on `ERR_MODULE_NOT_FOUND` for
runtime-functions.js, which `wrapper.js` (the package `main`) imports on its
first line. `release-js` is gated on those jobs, so npm was never reached and
both npm packages remain on 0.19.0.

Fixes the omission in both tsconfigs, adds the two outputs to the artifact,
and closes the guard's blind spot by checking `include` against the sources
on disk. Reproduced the failure locally and verified the fix; 181/181 script
tests pass, identical tsc error set before and after, all 34 checks green.

Does not republish 0.20.0: only a `refs/tags/vX.Y.Z` ref publishes as npm
`latest`, so npm needs a patch release. `Publish Web` failed separately on an
npm 404 for `@everruns/bashkit-wasm`, which needs an `NPM_TOKEN` rotation.

Claude-Session: https://claude.ai/code/session_01RE65s6DTUE7LzZgc1o6Hzi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants