Skip to main content

Module backend

Module backend 

Source
Expand description

A plugin’s backend: one long-lived process the engine talks to in JSON lines (the wire format is in docs/plugins-backend.md).

Backend owns the process. It starts lazily on first use (an event or a request) on a thread of its own, so nothing here blocks the caller: messages queue until it runs. A writer thread feeds stdin, a reader thread reads stdout (lines over MAX_LINE are dropped with a fault), a third keeps the last STDERR_KEEP bytes of stderr. Replies go straight to the waiting Backend::request; everything else goes to the Sink (the engine’s inbox). A backend that exits is started again after a backoff (0.5 s, doubling to 30 s), at once when someone uses it, and given up on after MAX_CRASHES crashes in a row. Backend::stop (reload, switched off, removed, dropped) closes stdin and kills it if it doesn’t exit within half a second. A waiter thread notices the process exiting even when something it started still holds its stdout; on Unix it runs in a process group of its own, killed with it. Faults reach the sink at most once a second (the rest are counted). Every thread runs under catch_unwind.

Structs§

Backend
One plugin backend (see the module docs). Stops its process when dropped.
BackendTool
A tool a plugin’s backend serves ("run": "backend"): each call is a tool request.
Launch
How to start the process (worked out on the start thread: it may build a venv).
Status
A snapshot for status displays.

Enums§

Out
What a backend says that isn’t a reply, and its lifecycle.
Phase
Start
What a backend runs as: a process, or in-tree code on a thread (crate::native).

Constants§

CAPS
What the engine supports, sent in init.caps.
CARD_MSG
The sink message type of a tree card a backend tool attached to its step ({"type": "_tool_card", "view", "key", "tree"}): the engine caches it as a live view.
MAX_CRASHES
Crashes in a row after which it isn’t started again (until its plugin reloads).
MAX_FAULTS
Faults kept (the newest).
MAX_LINE
Longest line either way (one message).
NATIVE_STACK
Stack of a native backend’s thread. Native backends may recurse on untrusted input in libraries byob doesn’t control (IronCalc parses and evaluates formulas recursively), and running out of stack aborts the whole process rather than panicking; only the pages actually touched are committed.
REQUEST_TIMEOUT
How long a tool call waits for its reply.
STDERR_KEEP
Bytes of stderr kept.
WIRE_VERSION
The wire format’s version (init.v).

Functions§

last_lines
The last n lines of text, trimmed.

Type Aliases§

Prepare
Works out how to start it; its argument says the start was called off (the backend stopped), so a long preparation (a venv build) can give up.
Sink