feat: per-agent CPU and memory limits
The hive applies one `agentCpuQuota` / `agentMemoryMax` to every
container. That's the right default and the wrong ceiling: a build-heavy
agent needs headroom the other twelve don't, and raising the hive-wide
value to suit it hands that headroom to everyone.
Adds a per-agent override, persisted host-side and resolved per-field
against the hive defaults.
Follows the existing `meta/*.json` pattern (`capabilities.json`,
`tool-groups.json`): a host-side map read by `hive-c0re`, staged and
committed in the meta repo so every change lands in the audit trail.
```json
{ "sock": { "cpu_quota": "400%", "memory_max": "8G" } }
```
Fallback is **per field**, not per agent: an entry with only
`memory_max` leaves that agent on the hive-wide CPU quota. Absent file,
absent agent and absent field all resolve to the hive default, so the
feature is inert until someone opts an agent in.
Unlike the other meta files this one is **not** injected into the
container — a limit is something done *to* an agent, not something it
reads about itself.
```
hivectl agents set-limits sock --cpu-quota 400% --memory-max 8G
hivectl agents set-limits sock --reset
```
Values are validated before they're persisted: they go into a systemd
drop-in verbatim, and a typo there makes the unit fail to *start* —
turning a fat-fingered quota into a container that won't come back.
The command is declarative: each call replaces the agent's whole entry.
That makes a forgotten flag a silent revert, so a bare `set-limits
<name>` is rejected at the clap layer and clearing needs an explicit
`--reset`.
`ContainerView` gains `cpu_quota` / `memory_max`, both always populated:
there's no "unset" state to render, only "same as everyone else". They
reflect what the drop-in *says* — what the next start will enforce — not
a live cgroup reading.
The write goes through `meta::commit_resource_limits` rather than the
bare setter, so it's staged and committed under `META_LOCK`. Writing
without committing would leave the meta working tree dirty for the next
`prepare_deploy` to trip over.
Docs: `persistence.md` (the new meta file, and why it isn't injected),
`tools/hivectl.md` (the prose guide), `tools/hivectl-cli.md`
(regenerated clap dump).
Closes: internal/requests issue 25
This commit is contained in:
parent
2cab121b35
commit
a6dc980700
15 changed files with 594 additions and 13 deletions
|
|
@ -32,6 +32,7 @@ This document contains the help content for the `hivectl` command-line program.
|
|||
* [`hivectl agents destroy`↴](#hivectl-agents-destroy)
|
||||
* [`hivectl agents rebuild`↴](#hivectl-agents-rebuild)
|
||||
* [`hivectl agents set-parent`↴](#hivectl-agents-set-parent)
|
||||
* [`hivectl agents set-limits`↴](#hivectl-agents-set-limits)
|
||||
* [`hivectl approvals`↴](#hivectl-approvals)
|
||||
* [`hivectl approvals pending`↴](#hivectl-approvals-pending)
|
||||
* [`hivectl approvals approve`↴](#hivectl-approvals-approve)
|
||||
|
|
@ -349,6 +350,7 @@ Lifecycle actions on managed agent containers. Needs the hive-c0re daemon runnin
|
|||
* `destroy` — Tear down a sub-agent container, keeping its state by default. No undo
|
||||
* `rebuild` — Apply pending config to a managed container
|
||||
* `set-parent` — Move an agent in the topology tree — under a new parent, or to root
|
||||
* `set-limits` — Declare an agent's CPU/memory limits, overriding the hive-wide defaults
|
||||
|
||||
|
||||
|
||||
|
|
@ -501,6 +503,26 @@ Move an agent in the topology tree — under a new parent, or to root
|
|||
|
||||
|
||||
|
||||
## `hivectl agents set-limits`
|
||||
|
||||
Declare an agent's CPU/memory limits, overriding the hive-wide defaults.
|
||||
|
||||
Replaces the agent's whole override entry rather than merging into it: any limit you don't pass returns to the hive-wide default. To change one and keep the other, pass both.
|
||||
|
||||
**Usage:** `hivectl agents set-limits [OPTIONS] <NAME>`
|
||||
|
||||
###### **Arguments:**
|
||||
|
||||
* `<NAME>` — Agent name
|
||||
|
||||
###### **Options:**
|
||||
|
||||
* `--cpu-quota <CPU_QUOTA>` — systemd `CPUQuota=` value, e.g. `400%` (100% = one full core)
|
||||
* `--memory-max <MEMORY_MAX>` — systemd `MemoryMax=` value, e.g. `8G`, `50%`, or `infinity`
|
||||
* `--reset` — Drop all overrides — the agent returns to the hive-wide defaults. Required to clear limits, so that a `set-limits` with a forgotten value can't silently reset the agent
|
||||
|
||||
|
||||
|
||||
## `hivectl approvals`
|
||||
|
||||
Operator approval queue: list, approve, or deny pending requests.
|
||||
|
|
|
|||
Loading…
Reference in a new issue