Loading files
This file is pinned to the selected release. Download the original to open it in your design tool.
379833346This file is pinned to the selected release. Download the original to open it in your design tool.
# Kiln Safety Systems
Kiln lets AI agents control 3D printers safely. Every layer of the stack
enforces hard limits so that even a confused or hallucinating model cannot
damage your hardware, start a fire, or ruin a print without multiple
independent checks failing simultaneously.
---
## Defense in Depth
Kiln does not rely on a single safety gate. Five independent layers stand
between an AI-generated command and your printer:
1. **Pre-flight checks** -- validates printer state before every print.
2. **G-code validation** -- blocks dangerous commands before they reach firmware.
3. **Per-printer safety profiles** -- enforces model-specific temperature,
speed, and build-volume limits.
4. **Heater watchdog** -- auto-cools idle heaters to prevent thermal runaway.
5. **Adapter-level validation** -- each printer adapter re-checks temperatures
against its own safety profile before sending commands.
A command must pass *all* layers. Failing any one is enough to block it.
---
## Emergency Latch Model (E-stop)
Kiln uses a persistent emergency latch per printer. When tripped, the latch
remains active across process restarts until an operator explicitly clears it.
### What gets persisted
- `latched` state
- `reason` and `source`
- `triggered_at`, `cleared_at`
- `cleared_by`
- `ack_note`
### What is blocked while latched
- `start_print`
- `resume_print`
- queue/scheduler dispatch for that printer
- hazardous control paths (`send_gcode`, heating commands in `set_temperature`,
firmware resume)
Blocked calls return `E_STOP_LATCHED` with next-step guidance.
### Clear requirements
Clearing a latch requires all of the following:
1. all critical interlocks engaged
2. explicit acknowledgement note
3. explicit clear action (no implicit auto-resume)
CLI:
```bash
kiln emergency-stop --printer default --reason user_request --source cli
kiln emergency-status --printer default
kiln emergency-clear --printer default --ack-note "Area inspected, safe to resume"
```
MCP tools:
- `emergency_stop`
- `emergency_status`
- `clear_emergency_stop`
- `emergency_trip_input` (for external button/PLC bridges)
---
## Pre-flight Checks
Before every print, Kiln runs a mandatory pre-flight sequence. This cannot
be skipped -- `start_print`, `download_and_upload` (with auto-print),
`slice_and_print`, and `generate_and_print` all call `preflight_check()`
internally and abort if it fails.
### What gets checked
| Check | Blocks print? | Details |
|----------------------|:---:|---------|
| Printer connected | Yes | Printer must be reachable and responding. |
| Printer idle | Yes | State must be `idle` -- not printing, paused, or errored. |
| No error flags | Yes | Printer must not be in an error state. |
| Temperatures in range| Yes | Current hotend and bed temps must be within the safety profile limits. |
| Material match | Configurable | If an expected material is specified, it is checked against the loaded material and the printer intelligence database. Strict mode (default) blocks on mismatch. |
| Local file valid | Yes (if provided) | G-code file is scanned for blocked commands and temperature violations. |
| Remote file exists | Yes (if provided) | Verifies the file is present on the printer before starting. |
| Outcome history | No (advisory) | If past prints on this printer/material combo have a high failure rate, a warning is shown but the print is not blocked. |
By default, `KILN_STRICT_MATERIAL_CHECK=true` -- unknown materials block the
print. Set to `false` for advisory-only warnings.
---
## G-code Validation
Every G-code command -- whether sent via `send_gcode`, embedded in an uploaded
file, or generated by the slicer -- passes through the G-code safety validator
before reaching the printer.
### Blocking rules (command rejected)
These violations prevent the command from being sent at all:
- **Temperature above safe maximum** -- hotend, bed, and chamber temps are
checked against hard limits (per-printer or generic defaults of 300/130/80 C).
- **Negative temperatures** -- caught and blocked.
- **Unconditionally blocked commands:**
- `M112` (emergency stop) -- must use the dedicated `emergency_stop` tool.
- `M500/M501/M502` (EEPROM save/load/reset) -- agents must not modify
firmware settings.
- `M552/M553/M554` (network config) -- agents must not change network
settings.
- `M997` (firmware update trigger) -- must use the dedicated firmware tools.
- **Dialect-specific blocks** -- e.g., Klipper blocks M500/M501/M502
(use SAVE_CONFIG instead); Bambu blocks M600 during prints.
- **Unrecognised command formats** -- arbitrary text is never forwarded to the
printer firmware.
### Warning rules (command allowed with advisory)
These issues are logged and returned to the caller but do not block the
command:
- **Z below bed plane** (Z < 0) -- risk of nozzle crash.
- **Feedrate above recommended maximum** -- may cause missed steps.
- **Stepper disable** (M18/M84) -- part may shift.
- **Homing** (G28) -- bed should be clear.
- **Stepper current changes** (M906) -- incorrect values can damage hardware.
- **Arc commands without I/J/R parameters** -- undefined arc.
- **Cold extrusion risk** -- hotend below 150 C with extrusion active.
### File-level scanning
`scan_gcode_file()` streams through an entire file line by line without loading
it into memory, fails fast on the first blocked command, and caps warnings at
50. Files over 500 MB are rejected. The scanner auto-detects the target
printer from slicer header comments (PrusaSlicer, Cura, OrcaSlicer,
BambuStudio) and applies the matching safety profile automatically.
---
## Per-Printer Safety Profiles
Kiln ships a curated database of safety limits for 26+ printer models. Each
profile defines:
- **Max hotend temperature** (e.g., 260 C for PTFE-lined Ender 3, 300 C for
all-metal Prusa MK4)
- **Max bed temperature** (80--120 C depending on model)
- **Max chamber temperature** (where applicable)
- **Max feedrate** (mm/min)
- **Max volumetric flow** (mm^3/s)
- **Build volume** (X/Y/Z dimensions in mm)
- **Safety notes** (e.g., "PTFE-lined hotend -- exceeding 240 C risks toxic
fumes")
Profiles exist for printers from Creality, Prusa, Bambu Lab, Voron, Rat Rig,
Elegoo, AnkerMake, Artillery, Sovol, FlashForge, and QIDI. A conservative
generic/default profile (300 C hotend, 130 C bed) applies when no match is
found.
### How profiles are used
1. **G-code validator** -- `validate_gcode_for_printer()` loads the profile
and uses its limits instead of the generic defaults.
2. **Printer adapter** -- `PrinterAdapter._validate_temp()` cross-checks
temperature commands against the profile for defense-in-depth. Even if the
G-code validator is somehow bypassed, the adapter will reject unsafe temps.
3. **Pre-flight checks** -- current temperatures are compared against the
profile limits.
Set your printer model via `KILN_PRINTER_MODEL` to enable profile-aware
validation.
---
## Heater Watchdog
The heater watchdog is a background daemon that prevents heaters from being
left on indefinitely when no print is active.
### How it works
1. The watchdog starts automatically with the Kiln server.
2. It tracks the last time heaters were intentionally activated (via
`set_temperature` or print start).
3. Every 30 seconds, it checks whether:
- No print is currently running, AND
- The idle timeout has elapsed (default: 30 minutes), AND
- Heater targets are still above zero.
4. If all conditions are met, it sends cooldown commands (set hotend and bed
to 0 C) and emits a `TEMPERATURE_WARNING` event.
5. If the reading has no trustworthy targets (see *Temperatures Kiln cannot
vouch for* below), the watch stays armed and is checked again on the next
tick. An unknown target is never treated as an off heater.
### Configuration
Set `KILN_HEATER_TIMEOUT` to the number of minutes before auto-cooldown
(default 30, set to 0 to disable). The timer resets on print start/end and
`set_temperature` calls, so the watchdog never interferes during active
printing and gives you time to inspect a finished print.
---
## Temperatures Kiln Cannot Vouch For
A hotend or bed temperature is the one reading a person acts on with their
hands. Some printers (Bambu over MQTT, Elegoo over websocket, OctoPrint and
Moonraker when push monitoring is on) are read from a cache the printer
fills; if the printer stops reporting, the cache keeps answering with the
last numbers it was given. A cached 38 C beside a hotend that is really at
110 C is a burn, and a caveat next to the number does not prevent it -- the
number is what gets read.
So the rule is on the reading itself, not on any one screen:
- A reading that is **stale** (older than the printer's own reporting budget,
and unanswered when Kiln asked again) or **disconnected** carries **no
temperatures at all**. Every `*_temp_actual` and `*_temp_target` field is
empty, and a `temperature_note` says why: *Kiln does not know the hotend or
bed temperature ... The printer's own display is the only authority -- read
it before touching anything, and do not act on any earlier number.*
- `printer_status` mirrors that sentence as `temperature_warning`;
`monitor_print` and `kiln status` print *unknown* where the numbers would
be; `set_temperature` carries the sentence instead of comparing the new
target with one it cannot trust.
- Kiln never shows a "last known" temperature. Nothing that keeps a person
safe needs one -- unknown already means *assume hot* -- and a dated number is
still a number a reader will act on.
---
## Faults Kiln Can See
A fault the printer is reporting is the machine's **state**, not a field
underneath one. Measured on an A1 (2026-09-07): `printer_status` answered
`idle` while the same payload carried `print_error: 302022663` --
`1200-8007`, "failed to extrude the filament" -- and the printer's own screen
held a modal error dialog. Everything reading the headline saw a healthy,
ready machine.
So the rule is the same shape as the two above it: the fact that decides what
you should do next takes the headline, and the fact it displaces is kept.
- A printer reporting a fault nobody has cleared reads `error`, whatever it
was doing. A `fault_note` says what happened, in plain language with the
code beside it for lookup, and a `fault_remedy` says what clears it -- two
fields, so a surface with one line of room shows the half about your
printer. The raw `print_error` and the screen-form `print_error_code` are
unchanged.
- `faults` lists every code the firmware is reporting, each spelled as the
printer's own screen spells it (`1200-8001`; an HMS entry as four groups,
`1200-8000-0002-0001`) with exactly what came over the wire beside it.
Where the vendor publishes a sentence for the code, it rides along as
`screen_text` with its `source` named -- Kiln asks Bambu's own fault-text
service for it, the way Bambu's client does, and never ships or invents
one; where there is none, the field is absent. The six digits the screen
shows after the code (`[1200-8001 290420]`) are not part of the code and
not on the wire -- Bambu's own client stamps the wall clock there at
display time, and the printer's number changes with every occurrence --
so Kiln does not show one and does not invent one. Set
`KILN_OFFLINE=1` (or `KILN_NO_BAMBU_HMS_TEXT=1`) to keep the lookup off
the network; it never blocks a status read either way.
- What the machine was **doing** moves to `last_known_state`, and everything
asking that question reads through it. A fault raised mid-print does not
free the bed, end the watch, unlock a filament change, or get the print
recorded as failed. Two accessors, because the question splits: *has it
ended* looks through a fault but never through silence, since an expired
reading is not evidence anything finished; *might it be busy* looks through
both and fails closed.
- `preflight_check` refuses a faulted printer. `clear_printer_error`
acknowledges the latch, and refuses while a print is live.
- A stale reading still outranks a fault: Kiln cannot vouch for a fault code
in a reading it cannot vouch for, and the headline already says to go and
look at the machine.
Kiln notices a fault on any printer it is connected to, **including one it
did not start the job on**. The connection is already open and the code is
already parsed; staying quiet about it would be the same dishonesty as the
`idle` above. It reports and does not act -- every read shows the fault, and
the fault's leading edge raises one `printer.error` event -- because a job
started at the printer's own touchscreen is the operator's to stop. Only the
print watchdog stops a machine. A running Kiln server attaches one to every
print it starts -- from any tool, the queue or a pipeline -- and retires it
when it sees that print end, so it does not stay behind to police the next job
on that machine. When there is no ending to see, the watchdog leaves without
stopping anything in two cases: the printer takes up no job within 30 minutes
of accepting the print, or Kiln loses sight of the print -- no readable report
for more than 2 minutes, or a report that nothing is running -- and then
finds the printer running a print it can tell is a different one, by its name,
its job number or its start time. When Kiln cannot tell, the watchdog stays:
a print the printer reports under a name that does not match the file Kiln
sent is watched until Kiln sees it end, and a reprint of the same file begun
while Kiln could not see the printer looks like the same print. A pass
through idle in the middle of a print retires the watchdog and nothing
re-attaches it; nothing Kiln has measured shows a printer doing that. A print
started from the `kiln` command line gets no watchdog.
It stops a machine only for what the machine itself proves: a fault code it
keeps printing through, or a temperature that violates physics. A print
that has stopped moving is reported -- one `print.stalled` event, the same
sentence on every status surface -- and never stopped. A stall needs a
person, not an emergency halt.
The watchdog stops a machine only when the machine has not already acted.
A fault the printer paused or ended the job for -- filament runout, an AMS
problem, a clog -- is reported, never cancelled; the same code has to stand
for five seconds while the printer keeps printing before the watchdog stops
it (a code on your own HMS block list still stops it at once). The Bambu
emergency stop is read back, and when no report shows the job ending it says
plainly that it could not confirm the stop and that the machine must be
stopped at its own screen or power switch. A stop aimed at every printer
commands them all at once, so no machine waits for another to confirm, and
the `emergency_stop` tool names each printer it could not confirm.
---
## What Kiln Will NOT Do
The safety system actively prevents the following:
- **Send G-code that exceeds your printer's temperature limits.** Commands
like `M104 S350` on a 300 C-max printer are blocked before reaching firmware.
- **Start a print without pre-flight validation.** There is no code path that
bypasses `preflight_check()`.
- **Start a print nobody said yes to.** A print starts only after a person
says go -- in their AI app's approval dialog, by typing a code Kiln shows on
their screen, or at the terminal, or under an auto-print setting they
switched on themselves -- and an agent cannot supply that yes itself. Stopping, pausing and watching a print never need that yes. See
"Saying Go" in [PROJECT_DOCS.md](PROJECT_DOCS.md#saying-go).
- **Allow agents to modify firmware settings.** EEPROM writes (M500/M501/M502),
network configuration (M552-M554), and firmware updates (M997) are all
blocked at the G-code validation layer.
- **Send emergency stop via G-code.** M112 is blocked -- the dedicated
`emergency_stop` tool handles safety-stop behavior.
- **Leave heaters on indefinitely.** The watchdog auto-cools after the
configured timeout.
- **Forward unvalidated external data to the printer.** Every adapter
normalizes API responses to typed dataclasses. Raw dicts never reach the
MCP layer.
- **Silently swallow errors.** Every failure produces a structured error
response with a clear error code and message.
---
## Safety Audit Trail
Every safety-relevant action is logged and accessible via the `safety_audit`
MCP tool: tool executions, blocked commands, rate-limit violations, pre-flight
failures, and dry-run validations. Use `safety_status` for a real-time
dashboard and `safety_settings` to review current configuration.
---
## Reporting Safety Issues
If you discover a safety concern -- a command that should be blocked but isn't,
a temperature limit that seems wrong, or any behavior that could risk hardware
damage -- please report it on GitHub Issues with the `safety` label.
Safety reports are treated with the highest priority. We would rather
over-block than under-block.