Repository navigation
Conversation
Move every wasm-rquickjs pin to 0.5.6: the root Cargo.toml and Cargo.lock, the wasm-rquickjs-cli version in the main validation action, the workflows that install it and the golem-scala-base-image skill. The TS, Effect and Scala generated declarations gain wasm-rquickjs-import-abort.d.ts for the new built-in module. Amp-Thread-ID: https://ampcode.com/threads/T-01a212e5-5b9a-77a5-841b-80e5ee08c3ad Co-authored-by: Amp <amp@ampcode.com>
When JavaScript preinitialization traps, golem build now prints one error that names the component and the cause. The error keeps the guest 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, with the component name as context. The qualified import name and the guest diagnostics without Rust panic framing come from wasm-rquickjs 0.5.6. Amp-Thread-ID: https://ampcode.com/threads/T-01a212e5-5b9a-77a5-841b-80e5ee08c3ad Co-authored-by: Amp <amp@ampcode.com>
✅ Deploy Preview for golemcloud canceled.
|
|
📖 Docs preview: https://docs-bne2j1v8w-golem-cloud.vercel.app Built from commit |
runtologist
left a comment
There was a problem hiding this comment.
Adversarial review of dd35902. I built the TS agent_guest.wasm with wasm-rquickjs-cli 0.5.6 and ran the three new tests; they pass. I also ran scratch cases through the same preinitialization_failure helper from golem-js-guest-tests/tests/js_guest.rs. The cleanup handles these cases well: a module-level throw, process.exit, an unhandled rejection (WRQJS_PREINITIALIZATION_ERROR), a non-awaited fetch (WRQJS_PREINITIALIZATION_IO), a non-awaited async import (it now names golem:durability/durability@1.6.0#begin-custom-durable-invocation-async) and fs.readFileSync. I found two problems.
1. A top-level await gives Host error: WouldBlock, not the import or I/O cause
When module-level code awaits something, the error does not name the import and does not explain the problem. This happens with an async Golem import, with fetch, and even with a timer. The same calls without await give the clear messages that this PR adds. await at module level is the usual way to call an async import there, so in practice Example 1 does not apply to async imports.
Reproducer (add it to js_guest.rs next to the new tests):
#[test]
#[timeout("120s")]
async fn module_level_await_of_async_import() -> anyhow::Result<()> {
let text = preinitialization_failure(
"repro:async-import-await",
r#"import { beginCustomDurableInvocationAsync } from 'golem:durability/durability@1.6.0';
const metadata = { doc: undefined, aliases: [], examples: [], deprecated: undefined, role: undefined };
const graph = { typeNodes: [{ body: { tag: 'bool-type' }, metadata }], defs: [], root: 0 };
export default await beginCustomDurableInvocationAsync('f', { graph, value: { valueNodes: [{ tag: 'bool-value', val: true }], root: 0 } }, { tag: 'read-local' });"#,
)
.await?;
println!("{text}");
Ok(())
}Actual output:
Failed to pre-initialize component repro:async-import-await:
Failed to finish module initialization:
Host error: WouldBlock
Without await (beginCustomDurableInvocationAsync(...); export default 1;) the same call gives:
Failed to pre-initialize component repro:async-import-no-await: wizer pre-initialization called unknown import `golem:durability/durability@1.6.0#begin-custom-durable-invocation-async` — this import is not available during pre-initialization
export default await fetch('http://example.com/') and await new Promise((resolve) => setTimeout(resolve, 10)) also give Host error: WouldBlock. Without await, fetch gives the WRQJS_PREINITIALIZATION_IO: cannot perform HTTP request ... diagnostic.
This is probably not new with 0.5.6. I did not check it against 0.5.5. The root cause is in wasm-rquickjs: finish() of the module promise fails while the promise is still pending. A possible fix is for the runtime to report a pending top-level await as its own diagnostic, for example module-level code awaited a promise that cannot settle during pre-initialization, or to run pending subtasks first so that the stub's unknown-import error comes out. Please add a js-guest case for it either way. If you keep this out of scope, please say so in the PR description, because Example 1 currently reads as if it applies to every module-level host call.
2. No test covers the stderr-plus-non-abort branch of preinitialization_error
The (Some(guest_stderr), false) arm runs when the guest wrote to stderr and then a trap that is not unreachable stopped it, for example the unknown-import stub. None of the three new tests reaches this arm. console.error goes through wasi logging, not the captured stderr, so test 1 has no guest stderr. A mutation that drops guest_stderr from this arm, or that sends it to the true arm and loses the import name, passes all three tests. See the inline comment for a reproducer that you can keep as a test.
I found no complexity problems that need a comment. The version pins are complete. I found no other 0.5.5 pins of wasm-rquickjs, and regenerating the TS d.ts files with 0.5.6 gives no diff, so the committed wasm-rquickjs-import-abort.d.ts matches the generator.
|
|
||
| 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}"), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Cover the branch that keeps both the trap cause and the guest stderr: without a test, the error could drop the stderr or lose the import name. Record that a top-level await of a host call fails with WouldBlock and does not name the import, until module evaluation runs on the async executor. Amp-Thread-ID: https://ampcode.com/threads/T-01a212e5-5b9a-77a5-841b-80e5ee08c3ad Co-authored-by: Amp <amp@ampcode.com>
|
Thanks for the careful review. Both findings are right. bc8a947 adds tests for both, and changes no production code. 1. Top-level GOL-1330 had host calls other than HTTP and timers out of scope, so after its fix your example would still have no defined error. I added this requirement to GOL-1330: an awaited host call that the optimizer does not provide fails the build with the same message as the call without In this PR:
2. The stderr-plus-trap arm had no test. Your test is in as written; see the inline reply. The JS guest tier passes 9/9 on the 0.5.6 guests, Effect included. |
|
Re-review of bc8a947 for finding 1 (top-level |
What this PR does
When
golem buildpre-initializes a JavaScript component and the module-level code fails, the build now prints one short error. The error says which component failed and why. Before this change, the build printed a long Wasm backtrace of the JavaScript runtime, and the real cause was hard to find. One case still gives an unclear error: a top-levelawaitof a host call (see "Not covered yet" below).To get this, the PR also moves wasm-rquickjs from 0.5.5 to 0.5.6 (Linear GOL-1331).
Example 1: a host call at module level
Module-level code runs once, at build time, when the build pre-initializes the component. Golem host functions are not available at that time. This code reads a config value at module level:
Before, the build printed only the bare function name, followed by a long backtrace:
After, the build prints one line with the component and the full import name:
The full name matters because many interfaces have a function called
get. A baregetdoes not tell you which import your code called.Example 2: a JavaScript exception at module level
Before, the JavaScript error was surrounded by Rust panic text, the runtime backtrace and the trap:
After, only the component and the JavaScript error with its stack remain:
The JavaScript error is still shown two times in the build output: once while the build runs, and once in the final error. The first copy is the live output of the component, which also shows
console.logoutput from module-level code when the build succeeds, so it stays.Example 3: other failures stay as they are
When pre-initialization fails for another reason, for example a damaged input file, the build keeps the original error and only adds the component name:
The cleanup only applies when the component itself stopped during pre-initialization. A broken file or a failed write never turns into a message about host calls.
Not covered yet: top-level
awaitThe examples above call the host function without
await. When module-level code awaits a host call, the build still fails with an error that does not name the import:The same happens with
await fetch(...), with an awaited timer and even withawait new Promise(() => {}). The cause is in wasm-rquickjs: it evaluates the module synchronously, so any pending promise at module level stops the evaluation before the host call runs. This is not new in 0.5.6.GOL-1330 fixes this: it runs module evaluation on the async executor. It now also requires that an awaited host call that is not available fails with the same message as Example 1, naming the full import. A test in this PR records today's
WouldBlocktext, so that change must update it.How it works
golem_common::javascript::preinitialize_js) now receives the component name fromgolem build. When the component stops with a trap, it keeps the JavaScript error and the cause, and removes the runtime backtrace and the trap line. For every other failure, it keeps the original error and adds the component name.The wasm-rquickjs bump
The version changes in the root
Cargo.tomlandCargo.lock, the main validation action, the workflows that installwasm-rquickjs-cli, and thegolem-scala-base-imageskill.0.5.6 also contains changes that this PR does not use yet:
wasm-rquickjs:import-abort, can cancel the async host calls that a function starts (golemcloud/wasm-rquickjs#241, for GOL-1053). Because of this module, the generated type declarations of the TS, Effect and Scala SDKs each get one new file,wasm-rquickjs-import-abort.d.ts.The SDK guest
.wasmfiles are build outputs that git ignores, so they are not in this PR.Tests
The in-process JS guest tests (
golem-js-guest-tests) get five new cases:awaitof a host call gives today'sHost error: WouldBlock(see "Not covered yet").Overlap
golemcloud/golem#4357 replaces
golem_common::javascript::preinitialize_jswith a direct optimizer call. The PR that merges second must keep the component name and the error cleanup.