Skip to content

Latest commit

 

History

History
317 lines (245 loc) · 24.3 KB

AGENTS.md

File metadata and controls

317 lines (245 loc) · 24.3 KB

Golem Development Guide

Overview

Golem is a distributed computing platform built in Rust. It uses cargo-make for build orchestration.

Backward Compatibility

Golem development currently makes no backward-compatibility guarantees. Until this section is explicitly revised, do not perform backward-compatibility work.

  • Make breaking changes directly and update every in-tree producer, consumer, test, fixture, generated artifact, and document to the new contract in the same change.
  • Do not add compatibility shims, legacy aliases, deprecated variants, fallback parsing, dual serialization, version negotiation, migration paths, or support for old protocols, schemas, configuration shapes, persisted formats, APIs, or behavior.
  • When replacing a contract or representation, remove the old path instead of preserving both.
  • Do not expand the scope of a task to accommodate older clients, servers, deployments, or stored data. If a task appears to require backward compatibility, treat it as conflicting with this repository policy rather than implementing it.

Prerequisites

  • Rust: Latest stable toolchain via rustup, with wasm32-wasip2 target
  • cargo-make: Latest version (cargo install --force cargo-make)
  • cargo-test-r: Match the version CI installs, pinned in .github/actions/setup-main-validation/action.yml (cargo install --force --locked cargo-test-r@<VERSION>)
  • WASI SDK: Version pinned by the wasi-sdk-version default in .github/actions/setup-wasm-component-tools/action.yml, with WASI_SDK_PATH set to its install directory; cargo make build compiles C dependencies of the built-in tools for wasm32-wasip2 with it
  • Node.js and pnpm: An official Node.js 24 build (fnm, nvm, or nodejs.org), not Homebrew's, whose system zlib makes the built-in tools' npm pack provenance checks fail
  • redis-server: Required by worker-executor, service-integration, and CLI integration tests that use spawned test dependencies; not required by every unit test
  • docker: Required by tests that use containerized dependencies

Building

cargo make build          # Build all targets in the root Cargo workspace in debug mode
cargo make build-release  # Release build excluding integration-tests and the single-binary golem package
cargo build -p <crate>    # Build a specific root-workspace crate

Note: The SDKs in sdks/ are not part of the main build flow. Load sdk-development when working on the Rust or TypeScript SDKs, golem-scala-development when working on the Scala SDK, and golem-go-development when working on the Go SDK; see sdks/moonbit/AGENTS.md when working on the MoonBit SDK.

Note: The user-facing documentation site (deployed at learn.golem.cloud) lives under docs/ and is a Next.js / Nextra project built with Bun — see docs/AGENTS.md. It is built and deployed by a dedicated workflow (.github/workflows/docs.yaml); Main validation also checks documentation drift on its selected main source.

Two parts of docs/ are auto-generated from in-tree sources of truth and have CI drift checks (unit-tests-and-checks task):

  • docs/src/content/next/rest-api/*.mdx ← openapi/golem-service.yaml. Regenerated by cargo make generate-openapi (or cargo make generate-docs-openapi if the YAML is already current). Drift is rejected by cargo make check-openapi.
  • docs/src/content/next/how-to-guides/ and docs/src/content/next/how-to-guides.mdx ← golem-skills/skills/. Regenerated by cargo make generate-docs-skills. Drift is rejected by cargo make check-docs-skills.

If you edit either source, commit the regenerated MDX files in the same PR.

Makefile.toml script conventions

Inline scripts in Makefile.toml must be written in duckscript (script_runner = "@duckscript"), not POSIX shell/bash, so the build works on all operating systems including Windows. Do not introduce bash/sh inline scripts for build/asset tasks.

When a task needs the cargo target directory (e.g. to invoke a freshly built binary), do not hardcode target/... or shell out to cargo metadata. Use the CARGO_MAKE_CRATE_TARGET_DIRECTORY environment variable, which cargo-make resolves cross-platform and which honors a redirected target dir (CARGO_TARGET_DIR, cargo config, or a cargo wrapper). Example:

script_runner = "@duckscript"
script = '''
golem = set "${CARGO_MAKE_CRATE_TARGET_DIRECTORY}/debug/golem"
exec --fail-on-error ${golem} build -P release --yes
'''

Wasmtime configuration compatibility

All production engines that compile, load, or inspect components must use the shared constructors in golem_common::wasmtime_config. This includes the component compilation service, worker executor, component metadata extraction, and any future component tools. Do not set Wasmtime features or tunables independently at those call sites; change the shared constructor instead and verify every consumer still uses it.

The component compilation service serializes precompiled .cwasm artifacts that the worker executor deserializes. Wasmtime validates artifact-affecting feature and tunable settings during deserialization. A mismatch makes the executor reject the cached artifact and compile the original component again, causing a severe cold-start regression. When changing the Wasmtime version or configuration, run:

cargo test -p golem-common precompiled_components_are_compatible_across_engines -- --report-time

Minimal Wasmtime engines in unit tests may use a local configuration only when they exercise an isolated host primitive and neither load production components nor produce or consume precompiled artifacts. Tests intended to mirror production component behavior must use the shared constructor.

Testing

Root-workspace Rust tests use test-r. Important: Each test crate or integration-test entry point using test-r must call test_r::enable!(), and test_r::test must be in lexical scope wherever #[test] is used; otherwise those tests will not be registered with test-r. Separate workspaces may use their own test harnesses.

Tests that directly execute external processes belong in the CLI integration test suite. This includes Golem binaries such as golem and golem-cli, as well as tools and compilers such as cargo, rustc, npm, npx, tsc, bun, sbt, scala-cli, and moon.

  • Unit tests and worker-executor tests must never spawn external processes.
  • Non-CLI integration tests must use golem-test-framework for all process-backed dependencies and must not spawn additional processes directly.
  • CLI integration tests may spawn the external processes required by the behavior they exercise.

Release-workflow fixtures are a separate exception. Keep them in the standalone workspace at .github/scripts/release-tooling-tests/, not in the CLI integration suite. They may execute release helpers and their tools against local fixtures. CI runs them in the Test release tooling step.

The unit-test CI task runs prebuilt test binaries and is intentionally kept fast; subprocess execution in unit tests bypasses that design and can make the job time out.

Worker executor tests, integration tests, and CLI integration tests may depend on built test components from test-components/. Generated .wasm artifacts are generally not checked into the repository, so build the specific components needed by the selected tests before running them. The two minimal concurrent-runtime fixtures are intentional checked-in exceptions. Use the modifying-test-components skill for targeted rebuilds, or rebuild-all-test-components when a full rebuild is needed.

Rebuilding a test component with the latest locally built Golem binary may migrate files in that component's source directory, including manifests and embedded skills. Treat migration edits produced by the rebuild as intentional outputs: review them, keep them, and include them in the changeset even when they are unrelated to the original reason for rebuilding. Do not revert or omit them merely to minimize the diff; test components are expected to evolve with current Golem.

Do not run cargo make test — it runs broad root-workspace unit, worker-executor, service, and CLI integration suites and takes a very long time. Start with the smallest test that exercises the changed behavior, then broaden when the impact cannot be isolated:

Scope Test Command
One Rust test or test module cargo test -p <crate> -- <test_name> --report-time
One crate's library tests cargo test -p <crate> --lib -- --report-time
Worker executor test group cargo make worker-executor-tests-group1, cargo make worker-executor-tests-group2, cargo make worker-executor-tests-group3, cargo make worker-executor-tests-group4, or cargo make worker-executor-tests-misc
One CLI integration area Use a targeted cargo-test-r filter; see the testing skill
Broad core logic or utilities cargo make unit-tests
Broad worker executor functionality cargo make worker-executor-tests
Broad service and CLI integration cargo make integration-tests
Broad CLI changes cargo make cli-integration-tests

For broad CLI integration test reruns, use cargo make cli-integration-tests. For faster local runs with dev-release binaries, use cargo make cli-integration-tests-dev-release. To isolate failures, run targeted cargo-test-r filters or lower local concurrency with CLI_TEST_THREADS=1 cargo make cli-integration-tests.

Whenever tests are modified, always run the affected tests to verify they still pass before considering the task complete.

Load the testing skill for detailed guidance on test filtering, debugging failures, test components, and timeouts.

  • For process-free TypeScript and Effect guest smoke tests, run cargo make js-guest-tests after building the SDK templates. It bundles fresh SDK sources before the Rust tests; do not commit generated bundles or maps. See golem-js-guest-tests/README.md for prerequisites, Rust-only iteration, coverage limits and Main validation ownership.

Running Locally

cargo run -p golem  # Build and run the single Golem executable

Skills

Load these skills for guided workflows on complex tasks:

Skill When to Use
modifying-http-endpoints Adding or modifying REST API endpoints (covers OpenAPI regeneration, golem-client rebuild, type mappings, docs MDX sync)
adding-dependencies Adding or updating crate dependencies (covers workspace dependency management, versioning, features)
testing Running and debugging tests (covers test filtering, debugging failures, test components, timeouts)
debugging-hanging-tests Diagnosing worker executor or integration tests that hang indefinitely
understanding-durable-execution Changing, reviewing, or debugging worker executor replay, oplog, durable host calls, RPC exactly-once, streaming invocations, tool/entity invocations, snapshots, or worker lifecycle
modifying-test-components Building or modifying test WASM components, or rebuilding after SDK changes
modifying-wit-interfaces Adding or modifying WIT interfaces and synchronizing across sub-projects
modifying-cli-manifest-schema Adding or changing application manifest JSON schema versions and aligning CLI schema references
modifying-cli-output-schema Adding or changing structured golem-cli output, StructuredOutput types, or the command output JSON schema
modifying-service-configs Changing service configuration structs, defaults, or adding new config fields
db-migration-scripts Writing PostgreSQL and SQLite migration scripts under a db/migration/ root
logging Adding or reviewing tracing statements and following the structured logging conventions
modifying-builtin-plugins Changing built-in plugin source, release artifacts, descriptors, versions, or provisioning
creating-new-builtin-plugins Adding a new externally released built-in WASM plugin provisioned by the registry service
developing-builtin-tools Creating or modifying externally released component-backed built-in tools
publishing-builtin-artifacts Publishing immutable built-in tool/plugin WASMs and updating their pinned URLs and checksums
sdk-development Working on the Rust, TypeScript, or MoonBit SDKs in sdks/
migrate-ts-decorator-sdk Porting a TypeScript agent from the removed decorator/BaseAgent API to defineAgent
golem-scala-development Compile, publish, and test the Golem Scala SDK in sdks/scala/
golem-go-development Build, test, lint, and release the Golem Go SDK modules in sdks/go/
golem-scala-integration-tests Running and debugging Scala SDK integration tests
golem-scala-base-image WIT folder structure and regenerating agent_guest.wasm for the Scala SDK
golem-scala-code-generation Writing Scala code generators for the Scala SDK
moonbit-agent-guide Writing, refactoring, and testing MoonBit projects, and using moon tooling
moonbit-refactoring Refactoring MoonBit code to be idiomatic without regressing test coverage
moonbit-c-binding Writing MoonBit bindings to C libraries with native FFI
moonbit-code-transform Source-to-source MoonBit transformations with moonbitlang/parser and formatter
moonbit-proof Writing proof-carrying MoonBit code with Why3-backed specifications
investigating-executor-performance Investigating worker-executor performance with OTLP tracing and Jaeger
investigating-benchmark-performance Profiling Golem benchmarks with OTLP tracing and Jaeger
analysing-ci-failures Diagnosing a GitHub Actions failure from a run or job URL and reproducing it locally
golem-skill-harness Developing, testing, and running Golem skill tests with the skill test harness
managing-docs-versions Cutting a new docs version, backporting fixes to older releases, and managing versioned content under docs/src/content/
pre-pr-checklist Final checks before submitting a pull request
verifying-merged-branches Checking a merge or rebase for reverted changes and building every project it touched

Before Submitting a PR

Validate the smallest dependency and behavior scope that fully covers the change. Use package-scoped, non-mutating format, lint, build, and test commands by default. Broaden checks when shared contracts, workspace configuration, generated artifacts, or multiple subsystems are affected.

When changing SDK code generation, guest bridge generation, canonical ABI wrappers, runtime retention, or release profiles, run cargo make component-size-report (add --optimize for the per-core wasm-opt comparison, which needs Binaryen). It runs the report subcommand of golem-size-analysis, which builds representative fixtures, checks the export and reflection retention contracts, and writes tmp/component-size-report/report.md plus machine-readable details. Compare reports only when the toolchain, lockfile, Cargo configuration, and environment are identical. This is a local analysis capability, not a CI size gate. To measure one component and its Rule 2 breakdown, use cargo run -p golem-size-analysis -- collect; see test-components/size-analysis/README.md.

Do not run cargo make fix by default. It mutates the entire root and dev-tools workspaces and does not validate the separately built SDKs. Use scoped auto-fix commands only when needed, and inspect their diff afterward.

Clippy's --all-targets covers Cargo targets, not operating systems. Before accepting an unused-import or dead-code fix, inspect references behind #[cfg], including test modules. When an item is used only on another platform, gate its import or definition to match its callers instead of deleting it or suppressing the lint. Review auto-fix deletions for this case. Changes to platform-specific code require compilation on the affected platform before landing; a passing host build is not evidence for code excluded on that host. If the user skips checks or the platform is unavailable, report that coverage gap explicitly.

Pull requests to main run no tests. The continuous Main validation workflow validates the latest main commit after merge. Maintenance branches retain full CI.

Before opening or merging a PR, run the smallest local checks that cover the changed behavior and its callers. After revisions, rerun the checks affected by those revisions. Report the checks run, their outcomes and remaining coverage limits; post-merge validation does not replace affected local checks.

Two checks apply whenever their condition holds, however small the PR is:

  • Lint the whole root workspace. When a PR changes root-workspace Rust code, run cargo make check-clippy on its final head. Main validation runs the same check. It compiles every root crate, so it finds a caller in another crate that the change did not update. It also finds a lint that the change raises in another crate, such as large_enum_variant after a shared type grows. Package-scoped clippy sees neither. Use the current stable toolchain (rustup update stable), as Main validation does, because the lints change between toolchains. When the check fails in a crate that the PR does not change, run cargo clippy --all-targets --keep-going -- --no-deps -Dwarnings, so that cargo still lints the other crates.
  • Smoke-test the callers of a changed shared contract. A shared contract is anything that code outside the changed crate depends on at run time: a gRPC, HTTP or WebSocket protocol, WIT, a serialized or persisted format, an SDK runtime or generated bridge, CLI commands and output, or a shared test fixture. A Rust item that another crate uses is not on this list, because the whole-workspace lint finds a caller that no longer compiles. When the behaviour of such an item changes, run the existing tests of its callers that exercise that behaviour. For a shared contract, select the closest existing tests that run the changed path, one for each affected area: the worker executor, the services, the CLI, and each SDK that the contract reaches. The usual form is an integration test that builds, deploys and invokes a component. Build the test components that the selected tests need. SDKs, generated bridges and test components are outside the root workspace, so clippy does not see them. Only building them and running their tests finds a break in them. When no existing test runs the changed path, say so in the PR description. The full suites and their edge cases stay with Main validation. Name the selected tests in the PR description, and name each one that could not run, so the reviewer can decide.

Both checks keep the cost of a break with the PR that causes it. Main validation reports a break hours after the merge. Until then, another author who works in the same area meets the failure first. Their build, their tests or their feature stops working, so they have to fix the break before they can go on.

Keep the broad suites (cargo make unit-tests, cargo make worker-executor-tests, cargo make integration-tests, cargo make cli-integration-tests) for changes whose impact cannot be isolated, or for a user request. The absence of PR tests is not a reason to run them.

Load the pre-pr-checklist skill for scope-specific commands.

Writing the PR description

Describe what the change does, then why, in enough detail that a reviewer understands the decisions behind it. The description exists to help someone read the diff, not to prove the work happened.

Write it in ASD-STE100 Simplified Technical English, in the ubiquitous language of the code it describes.

Simplified Technical English means one word for one meaning, and one meaning for one word. Use the active voice. Write short sentences that each carry one idea. Use the simple verb tenses. Keep the article: write "the blob at the path", not "blob at path". Do not build a noun cluster longer than three words. Prefer a plain verb to a participle.

The ubiquitous language is the vocabulary of the code itself. A blob is a blob in the trait, in the test and in the description. Do not invent a second name for a thing that already has one, and do not borrow a word that the code uses for something else. Where the domain has no word yet, choose one, use it everywhere, and put it in the code too.

Leave out:

  • Test and assertion counts, timings and pass/fail tallies. CI reports these, and a number tells a reviewer nothing about whether the change is right.
  • Verification transcripts: the fmt, clippy, build and test commands that were run, red proofs, mutation-gate results, CI run numbers and attempt histories.
  • Commit SHAs. A rebase or a squash merge invalidates them, and a stale hash is worse than none because it resolves to nothing.

Include, where they apply:

  • The reasoning a reviewer would otherwise have to reconstruct: why an approach was chosen over the obvious alternative, why a trait method is required rather than defaulted, why one backend needs a guard the others do not.
  • Behaviour changes, especially where a caller's failure mode changes rather than its return value.
  • Anything that makes the diff read as larger or stranger than it is, such as a file whose tests moved out of line, or a rename that touches many call sites.
  • Where the change sits in a stack, and what has to land before it.
  • For a changed shared contract, the names of the caller tests that ran and of each one that could not run. Leave out their commands and their output.

Prefer a claim a reviewer can check by opening a file over a number they have to take on trust. When a pull request is restacked or rebased, reread the description: anything naming a commit, a branch or another pull request may have gone stale with the move.

Deployment diff model versioning

Changes to the deployment diff representation or hashing under golem-common/src/model/diff/ or golem-common/src/base_model/diff/ require bumping DIFF_MODEL_VERSION in golem-common/src/base_model/diff/mod.rs. Generate a new golem-common/tests/goldenfiles/diff_model_fingerprint_v<N>.txt with diff_model_version_matches_diff_module_fingerprint, then rerun that test without golden-file updates enabled. Do not overwrite an existing version's fingerprint to make the test pass; preserve historical fingerprints. This version identifies the CLI/server diff contract and does not require compatibility parsing or migration support.

Code Style

  • Follow existing code conventions in the file you're editing
  • Do not add unnecessary comments
  • Comments must describe the code as it is, for a reader who has no other context. Never reference implementation plans, migration "phases", ticket/issue/PR numbers, or other transient process artifacts in code comments — describe the actual invariant, behavior, or rationale instead.
  • Use existing libraries and utilities from the codebase
  • Security: Never expose or log secrets/keys

Dependency Management

Dependencies of root Cargo workspace members must be declared centrally in the root Cargo.toml under [workspace.dependencies]. Workspace members must reference them using x = { workspace = true } rather than declaring them directly. Independently built Cargo workspaces under sdks/, test-components/, plugins/, and dev-tools/ manage dependencies in their own workspace manifests.

Project Structure

  • golem-worker-executor/ - Worker execution engine
  • golem-worker-service/ - Worker management service
  • golem-component-compilation-service/ - Component compiler
  • golem-shard-manager/ - Distributed shard management
  • golem-registry-service/ - Component registry
  • golem-common/ - Shared types and utilities
  • cli/ - CLI tools (golem-cli, golem)
  • sdks/ - Language-specific SDKs (Rust, TypeScript, Scala, MoonBit) - not part of main build flow, see SDK-specific AGENTS.md
  • docs/ - User-facing documentation site at learn.golem.cloud (Next.js / Nextra / Bun) - not part of main build flow, see docs/AGENTS.md
  • golem-skills/ - Skill definitions and skill testing harness
  • integration-tests/ - Integration test suite
  • test-components/ - Test WASM components
  • website/ - Marketing site for golem.cloud (Astro, deployed to Netlify) - separate from docs/
  • golem-cloud-billing/ - Billing app of the hosted Golem Cloud (TypeScript, Effect, Better Auth, pnpm) - not part of main build flow, see golem-cloud-billing/README.md