Reference·The gatewayIndex

The gateway

The background gateway: its verbs, what it installs per platform, logout, automatic start and updates.

.mdllms.txt

The gateway is the local server that shells attach to. The background gateway keeps it and the organism, a running Nodecode, up with no shell open.

Verbs

a shell
nodecode gateway
nodecode gateway on
nodecode gateway off
nodecode gateway restart
nodecode gateway logs --follow
VerbDoes
none, statusPrints the state: off, serving, waiting, starting, stopped, restarting, failed or unavailable.
onWrites the unit. Enables it. Starts it. On Linux, asks logind to keep it running after logout.
offDisables the unit, removes its file and stops the process. Writes gateway-off. Refused from inside the gateway, see below.
off --forceThe same, from inside the gateway too.
restartRestarts on the current build with the current config. Refused while the gateway is off, and from inside it.
restart --forceThe same, from inside the gateway too.
logsPrints the last 60 log lines.
logs --follow, logs -fKeeps printing new lines. Command line only.
runRuns the gateway in the foreground. This is what the unit runs. Command line only.
help [VERB]Prints help.

/gateway does the same from a shell, its verbs as rows: where it stands, on, a restart, off, its log, and setting up Discord, Telegram or Slack. A shell is the terminal UI. /settings > System > Gateway > Run in the background turns it on or off: Off is off, and writes gateway-off. On is on.

For a profile, add -p NAME:

a shell
nodecode -p NAME gateway on

While it serves, the status adds the pid, the port, the uptime and the build. It also says whether the gateway starts at login, and lists the standing notices of cells.

What on installs

PlatformInstallsUnit file
LinuxA systemd user unit~/.config/systemd/user/nodecode-gateway.service
macOSA LaunchAgent~/Library/LaunchAgents/nodecode-gateway.plist
WindowsNothingNone

Windows: no background gateway. status, on, restart and logs say so. Run nodecode serve in a terminal you keep open.

On Linux the unit folder follows XDG_CONFIG_HOME when it is set.

HomeUnit name
~/.nodecode/nodecode-gateway
A profilenodecode-gateway-NAME
Another NODECODE_HOMEnodecode-gateway- plus 8 hex digits of the path's hash
Any home under a HOME that is not your account's ownThe same hashed name

The home is ~/.nodecode/ unless a profile or NODECODE_HOME names another. Your account's own home is the one the system's user database names. A link to it counts. A scratch HOME never takes the account's nodecode-gateway.

SettingLinuxmacOS
Runsnodecode gateway runThe same, through a launcher
Restart after any exitAfter 5 sYes, at most once per 5 s
Watchdog30 sNone
Stop timeout60 s60 s
LogThe user journal~/Library/Logs/nodecode/nodecode-gateway.log

While serving on Linux under an armed systemd watchdog, each heartbeat requires a successful local /healthz response without redirects, a read through the shared store connection and a newly completed background watcher pass. An idle gateway is healthy: no new tokens, messages or events are required. A blocked store or watcher stops the heartbeat. A failed HTTP probe stops heartbeats until restart, rather than accumulating requests against a stuck listener. The check does not contact a model provider. The systemd watchdog, not a forced unwind of a native call, bounds a stuck check. Foreground serving and a notification socket without an armed watchdog do not run these probes. A retired watcher's late completion cannot count for its successor. Waiting for another process to release the store retains its waiting heartbeat.

On macOS the launcher is copied once to ~/Library/Application Support/nodecode/launcher/1/nodecode.

on refuses to overwrite a unit file of that name that Nodecode did not write. off leaves such a file alone.

Shells and the gateway

SituationResult
A shell owns the store, then the gateway startsThe gateway waits. It takes the organism over when that shell closes.
The gateway serves, then a shell opensThe shell attaches. Its footer shows Gateway, colored by the connection. A click opens the web page on Sessions.
The gateway restarts: for an update, or after a clean exitOpen shells wait up to 60 s for it to take the store again, then attach. Meanwhile they start no organism of their own.
Turned off in /gateway, from an attached shellThe gateway stops. That shell takes the organism over.

See The organism.

Logout

PlatformBehaviour
Linux, linger onThe gateway starts at boot. It keeps running after logout.
Linux, linger offThe gateway starts at login. It stops at logout.
macOSThe agent starts at login. It stops at logout. launchd has no linger.

on runs loginctl enable-linger for your account. If your system refuses, the status says so. Then run once:

a shell
sudo loginctl enable-linger $USER

Run the same command when the status says systemd has no user manager.

Automatic start

The organism turns the gateway on at the first boot of ~/.nodecode/ or a named profile, when HOME is your account's own home. Any other home is left to you, or to a cell.

A cell is a folder of code under ~/.nodecode/cells/. Four cells also turn the gateway on by themselves:

CellWhen
ChannelsA bot starts.
CronA job is scheduled, or active jobs exist at start.
LinkThe link is on.
PrsThe pull request watch starts.

Every attached shell shows a notice when this happens. The organism's says nodecode's gateway keeps your sessions running after this shell closes, and comes up at every login · /settings turns it off.

Nothing turns the gateway on by itself in these cases:

  • ~/.nodecode/gateway-off exists.
  • The organism runs with --ephemeral.
  • The platform is Windows.

From inside the gateway

A process the gateway started inherits its NODECODE_HOME: an agent's tool shell, a script that shell runs, a tmux session it leaves behind. On Linux that is every process in the unit's control group. There nodecode gateway off and nodecode gateway restart are refused, because stopping the gateway would end the process part way.

The refusal names the unit and its home, and nothing is changed. A script meant for another home sets NODECODE_HOME first. --force stops or restarts the gateway anyway. The gateway's own web page and the installer always force.

gateway-off

nodecode gateway off writes the file ~/.nodecode/gateway-off.

While the file exists, neither the organism nor a cell turns the gateway on. Bots and cron jobs then run only while a shell is open.

nodecode gateway on deletes the file.

Updates

The unit names the installer's current link. A restart runs the build installed last.

EventResult
The installer finishes, gateway runningThe installer runs nodecode gateway restart for it.
The installer finishes, gateway stoppedNothing. The next start runs the new build.
nodecode update needs a restartThe organism restarts itself through the unit at an idle moment.
nodecode gateway restartRewrites the unit first if the binary path or PATH changed.

The installer restarts only units that Nodecode wrote. See Updates.

Bounded headless shutdown

A headless gateway starts its stop supervisor before waiting for the store or loading cells. If that thread cannot start, the gateway refuses startup. SIGTERM records a three-second monotonic deadline without creating another thread. The owner does normal cleanup; the already-running supervisor enforces the deadline even when endpoint publication or cleanup is blocked. Repeated ordinary stop requests do not extend it. A second SIGTERM asks for immediate exit. An error unwinding an already stopping owner exits directly before error reporting, rather than disarming the deadline while reporting might block.

The deadline exits directly, without unwinding, flushing output, or walking child processes. In-flight work may be lost; the kernel releases this process's store lock. The external service manager owns child cleanup and restart policy. A stop already admitted takes precedence over restart or image handoff. Before a saved image is made, the supervisor joins cooperatively; a signal during handoff exits as soon as Lisp dispatches its handler, and a new launch acquires a fresh supervisor. During snapshot/exec handoff the worker has joined: a blocked foreign call can defer that handler, so only external supervision bounds that span. A manually run, unsupervised gateway may leave child processes after forced exit.

This is not a substitute for external supervision: if all Lisp execution or GC is wedged, the in-process deadline may not run. No service-unit limits or restart policy are changed by this code.

Esc

    Loading the index…

    ↑↓ moveEnter openEsc close