Skip to content

Build Python components from prepared runtime assets - #4516

Draft
noise64 wants to merge 17 commits into
mainfrom
python-runtime
Draft

noise64 wants to merge 17 commits into
mainfrom
python-runtime

Conversation

@noise64

@noise64 noise64 commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Part of GOL-1850. This is the first Python PR in a stack: PY-03, PY-04 and PY-05 come next.

This PR adds the Golem side of the prepared Python runtime. It uses the prepare/assemble API of the golemcloud/componentize-py fork, at the revision that the workspace pins (fork PR #2, which builds on the merged #1).

  • sdks/python/wit/main.wit defines the guest world golem:python/agent-guest. sdks/python/wit/deps is one more mirror in cargo make wit, and cargo make check-wit checks it for drift.

  • sdks/python/src/golem holds the SDK bootstrap. golem._bootstrap registers the component's exports and imports the application's entry modules. It then finalizes the agent registry. Discovery constructs no agents. This PR does not add agent declarations. Discovery returns an empty list until PY-03.

  • golem-python-assembler reads the prepared assets and links them with the SDK and the application. It then pre-initializes the result on create_wasmtime_config_without_fs_cache. The fork does not copy engine settings: Golem supplies the store, the linker and its WASI context. The crate links the fork without the embedded-runtime feature, so the Golem build does not compile CPython or process WIT.

  • The C stack is 96 KiB. On the shared engine's 1 MiB max_wasm_stack, a 1 MiB C stack lets deep repr/json/pickle recursion exhaust the engine's stack before CPython raises RecursionError. With 96 KiB, CPython raises RecursionError first, at a lower depth. This PR does not change the shared engine.

  • The build captures pre-initialization stdout and stderr, at most 64 KiB each. An import error then keeps its original traceback.

  • Pre-initialization opens the SDK, application and runtime directories read-only, through InitPlan::wasi_builder of the fork. A write raises PermissionError in the guest, so a build does not change its inputs, also when the import fails after the write. A test checks this for appends, new files, new directories, renames and removals in the application and SDK directories.

  • The fork takes wit-component 0.258.3 from the golemcloud/wasm-tools fork, from its golem-2.0 branch. The root [patch.crates-io] pins wit-component to the same revision, so Golem and componentize-py resolve one wit-component. A comment in Cargo.toml says to keep the two revisions equal.

  • cargo make python-sdk-prepare installs the pinned fork revision and writes the prepared assets to sdks/python/target/prepared. The tests of golem-python-assembler read them. The task revision and the workspace dependency revision must be equal.

  • Pre-initialization sees host-independent file metadata. Stat results have no timestamps, and metadata hashes (from which the guest derives inode numbers) count the files in the order the guest first sees them. CPython keeps this metadata in the memory that the component saves. Without these overrides, two builds of the same input in new directories differ in 282 bytes. A test checks that the two builds are identical.

  • Tools.invoke takes the six arguments of golem:tool/guest.invoke, including stdout and stderr, so a call returns invalid-tool-name instead of raising TypeError.

Limits: the world does not import golem:api/retry-scope and does not export save-snapshot/load-snapshot, which the TypeScript, Go and Scala worlds have. Snapshotting is reported as disabled.

Open in this issue: builds on different file systems or hosts are not checked yet, because directory listing order and link counts still come from the host. Wasm exceptions wait for #4351.

Tests

The changed shared contract is the WIT that the Python guest world imports. Its only callers are the Python SDK and golem-python-assembler; the other SDKs and the executor do not read the Python mirror. The caller tests are the golem-python-assembler assemble tests, which build actual components from the prepared assets and run them on the shared engine, and, at the top of the stack, the python_agents CLI integration tests. check-wit fails when the Python mirror is stale.

Pull requests run no Golem tests, and no CI job builds the prepared assets yet.

@netlify

netlify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for golemcloud canceled.

Name Link
🔨 Latest commit 7a563ed
🔍 Latest deploy log https://app.netlify.com/projects/golemcloud/deploys/6b117990d302449e043b4908

The generated binding calls golem:tool/guest.invoke with six arguments,
so the five-parameter method raised TypeError instead of returning
invalid-tool-name.

componentize-py moves to 58d479e. Its lowering checks accept number
types such as numpy.int64, build entropy also covers the app name and
Python path files, prepared blobs with links are rejected, and the
initialization WIT digest normalizes line endings.
The dlopen symbol-count fix is merged into the golem-2.0 branch of
golemcloud/wasm-tools, and componentize-py cad25ee removed its vendored
copy and pins that commit. The workspace patch now pins the same
wasm-tools commit, and componentize-py moves to cad25ee. The sibling
crates of wit-component still come from crates.io.
# Conflicts:
#	Cargo.toml
The runtime now lowers the values that its type check converted, so a
number type with Python conversion code is converted once. The fork also
links the stub component with the requested stack size and leaves the
output out of the build digest.

This branch has not been deployed

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