Add agent restart lifecycle command
Extends the existing CheckIn RPC with a one-shot AgentCommand (restart only -- stop/uninstall need real per-platform OS service-manager integration and stay deliberately out of scope), delivered at-most-once: cleared the instant it's handed to the agent in a response, since a restarting agent's process is gone before it could ever confirm receipt. On restart, the agent flushes whatever's buffered, aborts its source task, and exits cleanly, relying entirely on the host's own service manager to bring it back up. Issuing a command is gated at RoleAdmin (stricter than config editing's RoleEditor) and logged into the same audit_log table Phase 7's AI interactions use, via a new agent_command event type. A real bug was found and fixed during live verification: the first implementation tried to atomically read-and-clear pending_command in a single INSERT...ON CONFLICT statement using a sibling CTE referenced only from RETURNING, on the assumption that Postgres evaluates every part of a WITH query against one pre-statement snapshot. That's wrong specifically for FOR UPDATE, which always reads the latest row version including one written earlier in the same statement -- confirmed empirically (a restart command was always coming back empty even when genuinely pending, so the agent never received it). Fixed by splitting into two real, ordered statements inside one explicit transaction. See /docs/agent-management-design.md's "Lifecycle commands" section.
This commit is contained in:
@@ -505,6 +505,15 @@ export type Agent = {
|
||||
applied_override_version: string;
|
||||
pending: boolean;
|
||||
updated_by?: string;
|
||||
// pending_command/command_issued_at/by (real, restart only for now
|
||||
// -- see /docs/agent-management-design.md's punch list) have no
|
||||
// "delivered" signal to show the way config's `pending` does:
|
||||
// ingest clears pending_command the instant it hands the command to
|
||||
// the agent, not once the agent confirms it ran, so
|
||||
// command_issued_at is shown as a last-issued record instead.
|
||||
pending_command?: string;
|
||||
command_issued_at?: string;
|
||||
command_issued_by?: string;
|
||||
};
|
||||
|
||||
export function listAgents(): Promise<Agent[]> {
|
||||
@@ -525,3 +534,14 @@ export function setAgentConfig(host: string, override: ConfigOverride): Promise<
|
||||
export function clearAgentConfig(host: string): Promise<void> {
|
||||
return request(`/agents/${encodeURIComponent(host)}/config`, { method: 'DELETE' });
|
||||
}
|
||||
|
||||
// "restart" is the only supported value today -- server-validated
|
||||
// (400 on anything else), RoleAdmin-gated (403 for a Viewer/Editor
|
||||
// session), and audit-logged. See /docs/agent-management-design.md's
|
||||
// punch list for why stop/uninstall aren't here yet.
|
||||
export function issueAgentCommand(host: string, command: 'restart'): Promise<Agent> {
|
||||
return request(`/agents/${encodeURIComponent(host)}/command`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ command })
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user