Skip to content

Build Python components from prepared runtime assets - #4516

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

noise64 wants to merge 5 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 cad25ee (fork PR #2, stacked on #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.

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

  • The fork takes wit-component 0.258.3 from the golemcloud/wasm-tools fork at 801650b. 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.

Verification

This head, a0c4cb3, adds one commit to the previous head a50b51a. It pins componentize-py cad25ee, which removes its vendor copy of wit-component, and pins wit-component to wasm-tools 801650b. Cargo.lock changes only by three source lines (componentize-py, componentize-py-test-generator and wit-component 0.258.3). cargo metadata --locked succeeds, and no crate name and version has two sources. The history is not rewritten. Checks on this head:

  • cargo test -p golem-python-assembler --tests and --doc, cargo clippy -p golem-python-assembler --all-targets -- -D warnings and cargo fmt -p golem-python-assembler -- --check: pass. The assemble tests build actual components from the prepared assets and run them on the shared engine.
  • The prepared assets come from the componentize-py binary at cad25ee, built with the pinned SQLite tarball from a local cache (the same SHA-256). cargo make python-sdk-prepare did not run, because sqlite.org is not reachable from the build host. Two prepares gave the same manifest identity, a120875a…0234, and identical files.
  • ruff check: fails with the known finding I001 in _guest.py. ruff format --check fails, because sdks/python/tests does not exist at this head.

CI: pull requests run no Golem tests. A missing result is not a pass.

@netlify

netlify Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for golemcloud canceled.

Name Link
🔨 Latest commit a0c4cb3
🔍 Latest deploy log https://app.netlify.com/projects/golemcloud/deploys/6b08460e7077cb1b9601a26b

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.

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