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
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