Skip to main content

Module host_control

Module host_control 

Source
Expand description

What a headless server’s registered external host asks of srv besides vouching for a connection: whether the workspace is in use, a graceful shutdown, and the notice that it is going to stop.

These are host routes, never RPCs: an RPC is a command an agent can call, and these must not be. Every agent on the machine holds the instance key, so the key does not open them. Each call is signed by the registered host (external_host::Host::check_call), for this workspace, over its operation and arguments, and answers 404 when no host is registered, so a desktop or a plain headless srv has none of these routes.

  • POST /api/v1/host/activity: { busy, agentsWorking, lastOutputAt, keepRunning }; keepRunning is the last thing an agent asked for (app_api::workspace_stop), for the host to honour or not. A turn counts only while its pane has written output in the last ten minutes (ACTIVE_WINDOW_MS), so a hung turn cannot keep a workspace up for ever; a pane process that wrote that recently counts as busy too.
  • POST /api/v1/host/shutdown: srv’s own graceful teardown (the one SIGTERM runs: interrupt turns, save final state) and the answer when it is done, within the deadline given.
  • POST /api/v1/host/notice: the stop time and why, as the fixed reason ids person, timer, credit and cap, never text: srv builds the phrase the page and the agents are shown, so nothing a person or an agent wrote can cross. stopAt and reason both null cancel it.

StructsΒ§

Activity πŸ”’
ActivityRequest πŸ”’
Held πŸ”’
The notice srv holds, what an agent has asked for since, and a counter that tells a reminder task whether it is still the current one.
KeepRunning πŸ”’
What an agent has asked for: the stop pushed back by minutes, recorded as the agent that asked.
NoticeRequest πŸ”’
Seen πŸ”’
What one pane’s controller says, for the activity answer.
ShutdownRequest πŸ”’
Stop πŸ”’
A notice as srv holds it: the stop time and why.

EnumsΒ§

KeepRefusal πŸ”’
Why a keep-running request was refused.
Notice πŸ”’
What the host sent, checked: a stop, or its cancelling.
Plan πŸ”’
What to do with a notice, given the one held.
Reason πŸ”’
Why a workspace is going to stop: the only reasons srv will say, as ids.

ConstantsΒ§

ACTIVE_WINDOW_MS πŸ”’
A turn or a pane process counts as working only if it wrote output this recently.
CANCEL_NOTE πŸ”’
The note when a stop is cancelled.
MAX_AHEAD_MS πŸ”’
The furthest ahead a stop may be set.
MAX_DEADLINE_SECS πŸ”’
The longest graceful shutdown a caller may ask for.
MAX_KEEP_MINUTES πŸ”’
The most an agent may ask to push a stop back at a time.
NOTE_KEY πŸ”’
The held-note key: a newer stop notice replaces an older one still waiting for an agent’s next turn.
REMIND_BEFORE_MS πŸ”’
The last reminder to the agents, this long before the stop.
SKEW_MS πŸ”’
How far in the past a stop time may be before it is refused (clock skew between host and srv).

StaticsΒ§

HELD πŸ”’

FunctionsΒ§

apply πŸ”’
Hold the notice, show it, tell the agents, and remind them a minute before; or take it back.
ask_keep_running πŸ”’
An agent asks to push the stop back (Held::ask_keep_running).
clock πŸ”’
HH:MM UTC of a unix-ms time.
current πŸ”’
The stop srv holds now, and what an agent has asked for since.
current_ms πŸ”’
handle_activity πŸ”’
POST /api/v1/host/activity.
handle_notice πŸ”’
POST /api/v1/host/notice.
handle_shutdown πŸ”’
POST /api/v1/host/shutdown: srv’s graceful teardown, and the answer once it is done (done: false when the deadline came first, with the teardown still running). Calling it again is harmless: what is closed is gone.
held πŸ”’
not_registered πŸ”’
parse_notice πŸ”’
The notice in a request, or why it is refused. A stop needs both a time and a reason id; neither cancels. idleMinutes goes with timer and with nothing else.
plan πŸ”’
publish πŸ”’
refused πŸ”’
remind_later πŸ”’
A minute before the stop, if it is still the stop that is held, the agents are reminded.
remind_note πŸ”’
The last reminder, sent a minute before.
running_panes πŸ”’
stop_note πŸ”’
The note every agent is given when a stop is set.
summarize πŸ”’
The workspace’s activity from its running panes. A turn that has been silent for ACTIVE_WINDOW_MS is not working (the guard against a stuck turn); a pane that wrote output within it is busy even with no turn.
tell_agents πŸ”’
text_of πŸ”’