Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .agents/skills/golem-scala-base-image/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ The current pipeline uses:

- Rust stable with `wasm32-wasip2`
- Preview 3 (`wasm-rquickjs --target wasi-p3`)
- `wasm-rquickjs-cli` **0.5.5**, matching `wasm-rquickjs-version` in `.github/actions/setup-main-validation/action.yml`
- `wasm-rquickjs-cli` **0.5.6**, matching `wasm-rquickjs-version` in `.github/actions/setup-main-validation/action.yml`
- ordinary `cargo build --target wasm32-wasip2 --release` on generated wrapper crates; it does not use `cargo-component`

```bash
rustup target add wasm32-wasip2
cargo install --locked wasm-rquickjs-cli@0.5.5
cargo install --locked wasm-rquickjs-cli@0.5.6

# Repository root
cargo make wit
Expand Down
2 changes: 1 addition & 1 deletion .github/actions/setup-main-validation/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ runs:
- uses: ./.validation-control/.github/actions/setup-js-wasm-tools
with:
node-version: '24'
wasm-rquickjs-version: '0.5.5'
wasm-rquickjs-version: '0.5.6'
install-cargo-component: 'true'
- uses: oven-sh/setup-bun@v2
- name: Install validation tooling for selected and control sources
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ permissions:
contents: read

env:
WASM_RQUICKJS_VERSION: "0.5.5"
WASM_RQUICKJS_VERSION: "0.5.6"
WASI_SDK_VERSION: "25"
WASI_SDK_PATH: /opt/wasi-sdk

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/prepare-golem-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ jobs:
- uses: ./.github/actions/check-published-sdks
with:
prepare-binaries: 'true'
wasm-rquickjs-version: '0.5.5'
wasm-rquickjs-version: '0.5.6'
moonbit-version: '0.10.18+6c83a7f62'
- uses: actions/upload-artifact@v4
if: always()
Expand All @@ -96,7 +96,7 @@ jobs:
env:
CARGO_BUILD_JOBS: 20
WASI_SDK_PATH: /opt/wasi-sdk
WASM_RQUICKJS_VERSION: '0.5.5'
WASM_RQUICKJS_VERSION: '0.5.6'
steps:
- uses: actions/checkout@v5
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-golem-effect.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ permissions:
contents: read

env:
WASM_RQUICKJS_VERSION: "0.5.5"
WASM_RQUICKJS_VERSION: "0.5.6"
WASI_SDK_VERSION: "25"
WASI_SDK_PATH: /opt/wasi-sdk
NPM_CONFIG_AUDIT: "false"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-golem-scala.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

env:
JDK_JAVA_OPTIONS: -XX:+PrintCommandLineFlags
WASM_RQUICKJS_VERSION: "0.5.5"
WASM_RQUICKJS_VERSION: "0.5.6"
WASI_SDK_VERSION: 25
WASI_SDK_PATH: /opt/wasi-sdk

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-golem-ts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ concurrency:

env:
CARGO_TERM_COLOR: always
WASM_RQUICKJS_VERSION: "0.5.5"
WASM_RQUICKJS_VERSION: "0.5.6"
WASI_SDK_VERSION: "25"
WASI_SDK_PATH: /opt/wasi-sdk

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/skill-harness.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ permissions:

env:
BUILD_TARGET: "x86_64-unknown-linux-gnu"
WASM_RQUICKJS_VERSION: "0.5.5"
WASM_RQUICKJS_VERSION: "0.5.6"
WASI_SDK_VERSION: "25"
WASI_SDK_PATH: /opt/wasi-sdk

Expand Down
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ warp = "0.3.7"
wasip2 = "1.0.2"
wasm-encoder = "0.251.0"
wasm-metadata = { version = "0.251.0", features = ["oci"] }
wasm-rquickjs = { version = "0.5.5", features = ["optimize", "use-golem-wasmtime"] }
wasm-rquickjs = { version = "0.5.6", features = ["optimize", "use-golem-wasmtime"] }
wasm-wave = "0.251"
wasmparser = "0.251.0"
wasmprinter = "0.251.0"
Expand Down
4 changes: 3 additions & 1 deletion cli/golem-cli/src/app/build/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub async fn execute_build_command(
execute_inject_to_prebuilt_quick_js(ctx, &base_build_dir, command)
}
app_raw::BuildCommand::PreinitializeJs(command) => {
execute_preinitialize_js(ctx, &base_build_dir, command).await
execute_preinitialize_js(ctx, component_name, &base_build_dir, command).await
}
}
}
Expand Down Expand Up @@ -114,6 +114,7 @@ fn execute_inject_to_prebuilt_quick_js(

async fn execute_preinitialize_js(
ctx: &BuildContext<'_>,
component_name: &ComponentName,
base_build_dir: &Path,
command: &PreinitializeJs,
) -> anyhow::Result<()> {
Expand Down Expand Up @@ -145,6 +146,7 @@ async fn execute_preinitialize_js(
.with_context(|| format!("Failed to read JS module from {js_module}"))?;
fs::create_dir_all(fs::parent_or_err(output.as_std_path())?)?;
let result = golem_common::javascript::preinitialize_js(
component_name,
&input,
&output,
source,
Expand Down
47 changes: 45 additions & 2 deletions golem-common/src/javascript.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Copyright 2024-2026 Golem Cloud
// Licensed under the Golem Source License v1.1 (http://license.golem.cloud/LICENSE).

use crate::model::component::ComponentName;
use crate::wasmtime_config::create_wasmtime_config_without_fs_cache;
use anyhow::Context;
use anyhow::{Context, anyhow};
use camino::Utf8Path;
use std::collections::BTreeMap;
use std::io::ErrorKind;
Expand All @@ -14,7 +15,14 @@ pub const JS_COMPILATION_CACHE_MAX_BYTES: u64 = 512 * 1024 * 1024;

/// Preinitializes the current JavaScript source in an unchanged guest template.
/// Only compiled native code is cached; each call initializes a fresh instance.
///
/// A failure names the component. When the initializer traps, the error keeps the guest's
/// diagnostics, such as a JavaScript exception and its stack, and the trap cause, such as
/// the qualified import that module-level code called. It drops the Wasm backtrace of the
/// guest runtime and the `unreachable` trap that follows a reported guest failure. Other
/// optimizer failures keep their original error.
pub async fn preinitialize_js(
component_name: &ComponentName,
input: &Utf8Path,
output: &Utf8Path,
source: String,
Expand Down Expand Up @@ -72,7 +80,42 @@ pub async fn preinitialize_js(
tracing::warn!(error = %error, "Failed to trim JavaScript compilation cache");
}
}
result
result.map_err(|error| preinitialization_error(component_name, error))
}

fn preinitialization_error(component_name: &ComponentName, error: anyhow::Error) -> anyhow::Error {
let failed = format!("Failed to pre-initialize component {component_name}");
if error.downcast_ref::<wasmtime::WasmBacktrace>().is_none() {
return error.context(failed);
}

// The optimizer adds the guest's stderr tail as the outermost context.
let guest_stderr = error
.chain()
.next()
.map(ToString::to_string)
.filter(|diagnostic| diagnostic.starts_with("Guest stderr"))
.map(|diagnostic| {
diagnostic
.split_once('\n')
.map_or("", |(_, stderr)| stderr)
.trim()
.to_string()
})
.filter(|diagnostic| !diagnostic.is_empty());

let root_cause = error.root_cause();
let reported_abort = guest_stderr.is_some()
&& matches!(
root_cause.downcast_ref::<wasmtime::Trap>(),
Some(wasmtime::Trap::UnreachableCodeReached)
);

match (guest_stderr, reported_abort) {
(Some(guest_stderr), true) => anyhow!("{failed}:\n{guest_stderr}"),
(Some(guest_stderr), false) => anyhow!("{failed}: {root_cause}\n{guest_stderr}"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test reaches this arm. Reproducer, which also works as a regression test:

#[test]
#[timeout("120s")]
async fn guest_stderr_before_host_call_keeps_cause_and_stderr() -> anyhow::Result<()> {
    let text = preinitialization_failure(
        "js-guest:stderr-host-call",
        r#"import { getConfigValue } from 'golem:agent/host@2.0.0';
process.stderr.write('raw stderr line\n');
const metadata = { doc: undefined, aliases: [], examples: [], deprecated: undefined, role: undefined };
const graph = { typeNodes: [{ body: { tag: 'bool-type' }, metadata }], defs: [], root: 0 };
export default getConfigValue(['greeting'], graph);"#,
    )
    .await?;
    assert_eq!(
        text,
        "Failed to pre-initialize component js-guest:stderr-host-call: wizer pre-initialization \
         called unknown import `golem:agent/host@2.0.0#get-config-value` — this import is not \
         available during pre-initialization\nraw stderr line"
    );
    Ok(())
}

This passes on dd35902. It fails if the arm drops the stderr, or if the arm is merged into the true arm, which would lose the import name. The current tests do not catch either change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I added this test as written in bc8a947 (guest_stderr_before_host_call_keeps_cause_and_stderr). I also checked your mutation claim: when the arm drops the stderr, the three earlier tests still pass and this test fails.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified on bc8a947: guest_stderr_before_host_call_keeps_cause_and_stderr passes against the 0.5.6 TS guest, together with the other four failure tests. This finding is fixed.

(None, _) => anyhow!("{failed}: {root_cause}"),
}
}

fn trim_compilation_cache(directory: &Path) -> anyhow::Result<()> {
Expand Down
11 changes: 10 additions & 1 deletion golem-js-guest-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,17 @@ eviction. Parallel builds can temporarily exceed the limit. The cache lives at
`<Golem config directory>/js-compilation-cache`; deleting it only makes the next
build cold. The output Wasm is standalone and does not need this cache or external JS.

The failure tests preinitialize small JavaScript sources, written inline in the Rust
tests, in the TypeScript guest. They check the error that `golem build` prints when
preinitialization fails: a module-level host call names the component and the
qualified import, also after the guest wrote to stderr; a module-level throw keeps its
JavaScript message and stack; and a corrupt input keeps the optimizer's original
error. A top-level `await` of a host call fails with `Host error: WouldBlock` and does
not name the import yet; its test records that behavior until module evaluation runs
on the async executor.

The tests do not call the agent's `get` method or cover worker execution, awaited
I/O or source-map diagnostic accuracy. Source maps accompany the build outputs for
I/O that completes or source-map diagnostic accuracy. Source maps accompany the build outputs for
inspection; dependency paths omit pnpm's virtual-store prefix and use forward slashes.
The separate CLI and worker-executor suites retain their existing coverage.

Expand Down
Loading
Loading