Skip to content

feat(capi): add owned Python and TypeScript host calls - #2742

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

chaliy merged 2 commits into
mainfrom
feat/c-runtime-host-functions

Conversation

@chaliy

@chaliy chaliy commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

What changed

C hosts can opt into embedded Python and TypeScript and register one ABI v1 dispatcher for named functions. Each callback receives an owned call handle that can be answered immediately or transferred to an I/O worker. Responses copy bounded JSON into the library; cancellation/deadline revokes the call and rejects late replies.

Callback-enabled handles return BUSY for concurrent blocking operations, and blocking callback reentry is rejected. Existing handles retain their serialization behavior. Runtime registration preserves the selected profile's VM limits. JSON conversion also rejects integer-overflow literals that serde_json would otherwise round into floating-point values.

Why

Complete native C callback parity after the JavaScript SDK (#2740).

Before / After

Before: ABI v1 had no embedded runtime or host-function callback API.
After: the C11 example dispatches Python lookup() and TypeScript await lookup(), producing 42 twice through the actual shared library. Local validation includes 19 existing ABI tests, 10 runtime tests, three shared codec tests, C/C++ header compilation, full pre-PR checks, feature-sliced Rust tests, all-feature Clippy and the parallel benchmark. Tests cover caller-thread affinity, cross-thread replies, eight concurrent instances, idle-handle migration between threads, cancellation/deadline/reuse, calls retained after handle destruction, invalid input, abandonment, reentry and hardened memory limits.

Risk

Medium: additive foreign ownership and callback lifetime contract. Hosts must free each call once, preserve callback/user-data lifetime, avoid destructor races/unwinding, and cooperate with cancellation. Existing symbols and ABI version remain unchanged; no Rust future or allocator ownership crosses the boundary.

Checklist

  • Tests added or updated
  • Backward compatibility considered

@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 31e9bef Commit Preview URL

Branch Preview URL
Oct 16 2026, 09:23 PM

Base automatically changed from feat/node-runtime-host-functions to main October 16, 2026 21:21
@chaliy
chaliy force-pushed the feat/c-runtime-host-functions branch from 8997cdb to 31e9bef Compare October 16, 2026 21:22
@chaliy
chaliy merged commit 3fa046a into main Oct 16, 2026
51 checks passed
@chaliy
chaliy deleted the feat/c-runtime-host-functions branch October 16, 2026 21:47
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.

1 participant