Runtime Internals
This page documents how hooks execute in Zeptoz today.
Execution pipeline
- API triggers a hook event.
- Hook manager resolves active bindings for the event and collection.
- Input contract is built (
event,record,auth,meta). - Runtime adapter executes hook (
RustorQuickJSforJS/TS). - Result is evaluated by lifecycle rules (
before_*vsafter_*). - Execution status and duration are logged.
Runtime adapters
Rusthooks run via Rust runtime adapter.JavaScript/TypeScripthooks run in QuickJS.- TypeScript/JavaScript are transpiled so
export default function hookbecomesglobalThis.__zeptoz_hookin compiled artifact.
Timeouts and failure isolation
- Timeout controlled by
ZEPTOZ_HOOK_TIMEOUT_MS(default150). - Hook runtime runs in a blocking task with timeout guard.
- On timeout, Zeptoz returns
HOOK_RUNTIME_TIMEOUTforbefore_*hooks. - For
after_*hooks, timeout becomes warning metadata and main operation remains successful.
Guardrails
QuickJS source is blocked if it contains tokens like:
require(importprocess.fs.child_processfetch(
Hook source/artifact paths are validated to stay within configured hooks root.
Observability
Hook execution emits runtime logs including:
- event
- runtime
- status (
success,failure,timeout,panic) - duration
- request correlation ID
Add hooks at runtime
You can add hooks while the server is running:
bash
zeptoz hook add Task before_insert --lang ts --new normalizeWhat happens:
- hook source/artifact files are created (for JS/TS)
hook_definitionsandhook_bindingsrows are inserted- subsequent requests can resolve the new active binding
Remove/disable hooks at runtime (current state)
There is currently no dedicated zeptoz hook remove command.
Current options:
- disable binding in DB (
hook_bindings.active = false) - or disable definition in DB (
hook_definitions.enabled = false)
Hook resolution filters by active/enabled flags, so disabled hooks are skipped on subsequent requests.
Dev-mode hot reload details
In zeptoz dev, watcher loop runs every 2 seconds and:
- detects hook file changes
- recompiles changed TS/JS hook sources to
.compiled.js - refreshes runtime snapshot counters
- validates OpenAPI build as part of runtime refresh