graphrt_wasm/limits.rs
1//! Resource limits for guest modules.
2
3use serde::{Deserialize, Serialize};
4
5/// Limits applied to every guest call. Operators set these; workflow documents cannot raise them.
6#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
7#[serde(default)]
8pub struct WasmLimits {
9 /// Fuel per call (roughly one unit per executed instruction). Bounds CPU
10 /// time deterministically. Default 1 000 000 000.
11 pub fuel: u64,
12 /// Maximum linear memory per instance, in bytes. Default 64 MiB.
13 pub memory_bytes: usize,
14 /// Maximum size of the `.wasm` module, in bytes. Default 32 MiB.
15 pub module_bytes: usize,
16 /// Maximum request JSON size written into guest memory. Default 8 MiB.
17 pub input_bytes: usize,
18 /// Maximum response / manifest JSON size read from guest memory. Default 8 MiB.
19 pub output_bytes: usize,
20 /// Maximum size of one log line, chunk or progress payload. Default 256 KiB.
21 pub message_bytes: usize,
22 /// Maximum number of log lines kept per run (surfaced in node metadata). Default 100.
23 pub max_logs: usize,
24 /// Maximum number of `chunk` + `progress` events per call. Default 10 000.
25 pub max_events: usize,
26 /// Maximum total bytes streamed through `chunk` + `progress` per call. Default 16 MiB.
27 pub max_stream_bytes: usize,
28 /// Maximum wasm call-stack depth. Default 1024.
29 pub max_recursion_depth: usize,
30 /// Hand plaintext secrets to the guest when its config references them.
31 /// Default `false`: secrets are masked. Enable only for plugins you trust.
32 pub expose_secrets: bool,
33}
34
35impl Default for WasmLimits {
36 fn default() -> Self {
37 Self {
38 fuel: 1_000_000_000,
39 memory_bytes: 64 * 1024 * 1024,
40 module_bytes: 32 * 1024 * 1024,
41 input_bytes: 8 * 1024 * 1024,
42 output_bytes: 8 * 1024 * 1024,
43 message_bytes: 256 * 1024,
44 max_logs: 100,
45 max_events: 10_000,
46 max_stream_bytes: 16 * 1024 * 1024,
47 max_recursion_depth: 1024,
48 expose_secrets: false,
49 }
50 }
51}
52
53impl WasmLimits {
54 pub fn with_fuel(mut self, fuel: u64) -> Self {
55 self.fuel = fuel;
56 self
57 }
58
59 pub fn with_memory_bytes(mut self, bytes: usize) -> Self {
60 self.memory_bytes = bytes;
61 self
62 }
63
64 pub fn with_output_bytes(mut self, bytes: usize) -> Self {
65 self.output_bytes = bytes;
66 self
67 }
68
69 pub fn with_expose_secrets(mut self, expose: bool) -> Self {
70 self.expose_secrets = expose;
71 self
72 }
73}