{"record":{"id":"75f70d2960197d9b","repo":"windmill-labs/windmill","slug":"clock-is-not-supported-75f70d","errorCode":null,"errorMessage":"clock is not supported","messagePattern":"clock is not supported","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"backend/parsers/windmill-parser-r/src/wasm_libc.rs","lineNumber":222,"sourceCode":"    }\n    0 // Return false (0)\n}\n\n#[no_mangle]\npub extern \"C\" fn iswlower(wc: wint_t) -> c_int {\n    // Check if the character is a lowercase letter ('a' to 'z')\n    if wc >= 'a' as wint_t && wc <= 'z' as wint_t {\n        return 1; // Return true (1)\n    }\n    0 // Return false (0)\n}\n// End of AI implemetation\n\n/* --------------------------------- time.h --------------------------------- */\n\n#[no_mangle]\npub unsafe extern \"C\" fn clock() -> u64 {\n    panic!(\"clock is not supported\");\n}\n\n/* --------------------------------- ctype.h -------------------------------- */\n\n#[no_mangle]\npub unsafe extern \"C\" fn isprint(c: c_int) -> bool {\n    c >= 32 && c <= 126\n}\n\n/* --------------------------------- stdio.h -------------------------------- */\n\n#[no_mangle]\npub unsafe extern \"C\" fn fprintf(_file: *mut c_void, _format: *const c_void, _args: ...) -> c_int {\n    panic!(\"fprintf is not supported\");\n}\n\n#[no_mangle]\npub unsafe extern \"C\" fn fputs(_s: *const c_void, _file: *mut c_void) -> c_int {","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/windmill-labs/windmill/blob/e474e8803ce2ff5c2df09a58dab51d45f5c922ca/backend/parsers/windmill-parser-r/src/wasm_libc.rs#L204-L240","documentation":"The windmill-parser-r WASM libc shim stubs clock() (from time.h) with a panic — the WASM sandbox intentionally provides no time source to the compiled C parser. If the tree-sitter C runtime or a custom scanner calls clock() (usually for profiling, timeouts, or debugging instrumentation), the shim panics with \"clock is not supported\" and the parse fails.","triggerScenarios":"The compiled C code calls clock(): a custom scanner.c containing timing/debug instrumentation guarded only by a runtime (not compile-time) flag, or a tree-sitter runtime build with profiling enabled (e.g. TREE_SITTER_DEBUG) that measures parse time via clock().","commonSituations":"A grammar build that left debug/profiling instrumentation compiled in; a scanner authored for native tree-sitter (where clock() exists) reused in the WASM build; a grammar upgrade that introduced timing code.","solutions":["Rebuild the grammar/scanner without profiling or debug instrumentation (disable TREE_SITTER_DEBUG or equivalent) so clock() is never called.","Implement clock() in the shim to return a monotonically increasing counter (e.g. a static AtomicU64 of elapsed ticks) instead of panicking, if the value is only used for measurement.","Patch scanner.c to remove or compile-out the clock() usage for WASM builds (#ifdef TREE_SITTER_WASM).","Report the grammar upstream so the WASM build drops the timing code."],"exampleFix":"// before (wasm_libc.rs)\n#[no_mangle]\npub unsafe extern \"C\" fn clock() -> u64 {\n    panic!(\"clock is not supported\");\n}\n\n// after — harmless monotonic counter\nstatic CLOCK_TICKS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);\n\n#[no_mangle]\npub unsafe extern \"C\" fn clock() -> u64 {\n    CLOCK_TICKS.fetch_add(1, std::sync::atomic::Ordering::Relaxed)\n}","handlingStrategy":"try-catch","validationCode":"// Cannot pre-detect the C call, but ensure the grammar build has no profiling:\n// at build time, verify the generated C/scanner does not reference clock():\n//   grep -n '\\bclock\\s*(' scanner.c src/parser.c  # must return nothing for WASM builds","typeGuard":null,"tryCatchPattern":"try {\n  return parser.parse(doc);\n} catch (e) {\n  if (String(e).includes('clock is not supported')) {\n    // rebuild the grammar without profiling/debug instrumentation and retry once\n    return null; // or trigger the rebuild pipeline\n  }\n  throw e;\n}","preventionTips":["Build grammar WASM artifacts with profiling and debug instrumentation disabled.","Add a build-time check (grep the generated C for clock() references) to CI so a regression fails the build, not the runtime.","Gate any timing code in scanner.c behind a non-WASM ifdef.","Test the full parse path in the WASM sandbox after every grammar upgrade."],"tags":["wasm","libc","time","tree-sitter","unsupported-function"],"backgroundTag":"wasm-libc-stub-panic","analyzedSha":"e474e8803ce2ff5c2df09a58dab51d45f5c922ca","analyzedAt":"2026-09-03T12:38:19.024Z","contentChangedAt":"2026-09-03T12:38:19.024Z","schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}