Commit graph

2,495 commits

Author SHA1 Message Date
atlas
dfd159d1de refactor: drop Coordinator::ensure_runtime dead shim (no callers post #2290) 2026-07-10 01:12:04 +02:00
atlas
df44becd4a fix(#2290): update stale spawn_poll references in comments 2026-07-09 01:08:38 +02:00
atlas
66c6828359 fix(#2290): register_agent in handle_spawn (event-driven, replaces stale spawn_poll comment) 2026-07-09 01:08:38 +02:00
atlas
73f1020a7e refactor(#2290): replace mcp_sockets poll with event-driven register_agent
mara: the background worker is redundant if c0re knows when its own
sockets go missing. damocles: 10s poll latency and redundancy are two
faces of the same issue — poll adds a reconnect window and does
redundant work when c0re could react directly.

design: c0re owns the MCP listener lifecycle, so the only time a
listener disappears without c0re knowing is when c0re itself restarts.

- replace spawn_poll (recurring 10s loop) with sync_on_start (one-shot
  sweep at daemon boot): re-registers all running agents on startup
  after /run/hyperhive/agents/ is cleared by the tmpfs reset.
- run_reconcile (reconcile-start path): add coord.register_agent(name)
  immediately after start_with_fallback — event-driven, no poll delay.
- run_create already calls register_agent eagerly; kill/destroy paths
  already call unregister_agent — no changes needed there.

tracker: #2290
2026-07-09 01:08:38 +02:00
atlas
44dd9d45f0 docs(#2290): update mcp_sockets module doc — no eager register_agent after converge cleanup 2026-07-09 01:08:38 +02:00
atlas
afdd8c6c9f feat(#2290): converge unification cleanup — pull preamble into lifecycle
Collapse the scattered ensure_agent_runtime_dir calls into the lifecycle
functions themselves so callers have a single responsibility:

- lifecycle::spawn: calls ensure_agent_runtime_dir before write_dropins.
  Callers (handle_spawn, ensure_root_agent) no longer need a separate
  preamble step.

- lifecycle::rebuild_no_meta spawn path: calls ensure_agent_runtime_dir
  before write_dropins. apply_commit / merge_config_pr flows no longer
  need a manual ensure_agent_runtime_dir.

- run_create (job-queue): drops ensure_agent_runtime_dir + register_agent.
  The tail Reconcile's converge_start_preamble handles the runtime dir
  and mcp_sockets::spawn_poll handles the listener. Create stays purely
  'provision + create', not 'create + start'.

- handle_spawn (server.rs): drops manual preamble; lifecycle::spawn owns it.
  Drops unneeded unregister_agent on failure (supervisor handles listener).

- ensure_root_agent (auto_update.rs): drops manual ensure_agent_runtime_dir.

- actions.rs apply_commit / merge_config_pr: drop manual
  ensure_agent_runtime_dir; rebuild_no_meta's spawn path handles it.

Result: ensure_agent_runtime_dir lives in exactly two places —
lifecycle::spawn (direct spawn) and converge_start_preamble (start/reconcile
path). All other callers are clean call sites.
2026-07-09 01:08:38 +02:00
atlas
a45f65bd73 style: rustfmt 2026-07-09 01:08:38 +02:00
atlas
950a13bc69 feat(#2290): StartableAgent token — start_with_fallback requires preamble proof
- lifecycle::StartableAgent: opaque token produced only by
  converge_start_preamble. #[must_use] with a hint to call
  start_with_fallback(token).

- lifecycle::converge_start_preamble(name, hive, paths): runs
  ensure_agent_runtime_dir + write_dropins, returns StartableAgent.
  The only way to obtain a token.

- lifecycle::start_with_fallback(token: StartableAgent): public API
  now requires the token. Callers that skip the preamble get a compile
  error, not a runtime outage.

- lifecycle::start_with_fallback_inner(name): private; used internally
  by rebuild_no_meta where the preamble is already enforced structurally
  (write_dropins was called on the line above).

- exec.rs ReconcileAction::Start: migrated to converge_start_preamble
  + start_with_fallback(token). The write_dropins + start_with_fallback
  two-step is now a single typed pipeline.
2026-07-09 01:08:38 +02:00
atlas
15fc33d2e1 style: rustfmt 2026-07-09 00:58:51 +02:00
atlas
3d919b596f feat(#2290): split ensure_runtime — dirs to lifecycle, listeners to mcp_sockets supervisor
- lifecycle::ensure_agent_runtime_dir(name): pure filesystem op, no
  Coordinator dep. Creates /run/hyperhive/agents/<name> without touching
  the MCP listener map.

- workers/mcp_sockets::spawn_poll(coord): 10 s reconcile loop (same shape
  as agent_sockets::spawn_poll). Converges 'agent running => MCP listener
  bound'. First tick is immediate so hive-c0re restarts re-register all
  running agents without waiting a full interval. Fixes the dead-listener-
  after-daemon-restart gap.

- All ensure_runtime() call sites updated:
  - Prebuild/Swap/WriteDropin: Coordinator::agent_dir() (pure, no IO)
  - Reconcile-Start: ensure_agent_runtime_dir + agent_dir (dir may be
    missing after reboot; listener deferred to supervisor)
  - run_create / handle_spawn: ensure_agent_runtime_dir + register_agent
    (eager on first spawn so socket ready before harness first turn)
  - apply_commit / merge_config_pr: ensure_agent_runtime_dir + agent_dir
  - Manager (auto_update): ensure_agent_runtime_dir + agent_dir
    (manager has no MCP listener; socket_server::start_manager owns it)

- ensure_runtime() retained in Coordinator with updated doc pointing at
  the preferred split form. No callers remain outside tests.
2026-07-09 00:58:51 +02:00
atlas
b1243f149f fix(#2290): move use Write before statements, use writeln! in sync_agent_tmpfiles 2026-07-09 00:52:32 +02:00
atlas
ae3ecc1de2 fix(#2290): drop redundant async blocks around sync_tmpfiles spawn 2026-07-09 00:52:32 +02:00
atlas
949bab62d3 fix(#2290): use write! instead of push_str(format!()) to satisfy clippy 2026-07-09 00:52:32 +02:00
atlas
dce97f4826 style: rustfmt 2026-07-09 00:52:32 +02:00
atlas
14c2c6d4a5 feat(#2290): ConditionPathIsDirectory= in container service drop-in
Add a [Unit] section to hyperhive-limits.conf (the drop-in written by
write_resource_limits) with:

  ConditionPathIsDirectory=/run/hyperhive/agents/<name>

When this condition is not met, systemd skips the unit with result
"condition" — NOT a failure, so the start-limit counter is not
incremented. Belt-and-braces on top of the tmpfiles.d fix (subtask 2):
if a dir is somehow absent at start time, the container idles instead of
restart-looping into start-limit-hit.

Also promote AGENT_RUNTIME_ROOT to a module-level const (was duplicated
inside two functions) and remove the duplicates.
2026-07-09 00:52:32 +02:00
atlas
f32fba0238 fix(#2290): use 0777 for per-agent socket dirs in tmpfiles.d
systemd-tmpfiles d entries adjust mode+owner on existing dirs. Using
0755 root root would stomp live agents' socket dirs (owned by agent
uid:gid) on every sync_tmpfiles call, breaking the harness's ability
to bind new sockets until host_config rechowns them.

Fix: 0777 root root — matches the chmod_socket_dir(0o777) fallback
already used by host_config when the agent uid is unavailable. World-
writable dirs let the non-root harness bind sockets regardless of who
owns the dir. host_config's chown_socket_dir tightens ownership when
the agent uid is resolved.

Also add missing # Errors doc to priv_client::sync_agent_tmpfiles.
2026-07-09 00:52:32 +02:00
atlas
9d1f5ebe76 feat(#2290): maintain /etc/tmpfiles.d/hyperhive-agents.conf for boot safety
Root cause of the boot outage: container@h-* units try to start before
hive-c0re reaches ensure_runtime, so bind-mount source dirs are missing.

Fix: hive-c0re (via hive-priv, which runs as root) writes
/etc/tmpfiles.d/hyperhive-agents.conf whenever the agent set changes.
systemd-tmpfiles-setup.service (sysinit.target) reads it at every boot
BEFORE any container units start, pre-creating:

  /run/hyperhive/agents/<name>  — MCP socket dir (bind -> /run/hive)
  /run/hive-agent/<name>        — web socket dir (bind -> /run/hive-agent)

This alone removes the outage class: even if hive-c0re is slow to start,
the bind-mount sources exist and container units can activate.

Added:
- PrivRequest::SyncAgentTmpfiles { agents } in hive-sh4re
- sync_agent_tmpfiles() in hive-priv: generates content, writes atomically,
  calls systemd-tmpfiles --create to apply immediately
- priv_client::sync_agent_tmpfiles() wrapper
- lifecycle::sync_tmpfiles() best-effort helper (list + priv call)
- Call sites: hive-c0re startup, handle_spawn success, destroy success
2026-07-09 00:52:32 +02:00
atlas
9cd408de8b fix(#2290): reset-failed before nixos-container start in hive-priv
systemd will refuse to start a unit that has hit start-limit. nixos-
container start does not clear the counter first. Add a best-effort
  systemctl reset-failed container@h-<name>.service
before each StartContainer so an earlier lockout cannot block a now-
correct start. Ignoring the reset exit code is intentional: the unit
may not exist yet on first-time create, and reset-failed on a clean
unit is a harmless no-op.
2026-07-09 00:52:32 +02:00
atlas
8d2ebcf51f fix(clippy): wrap PermanentBringUpError in backticks in doc comment (main.rs:59) 2026-07-09 00:47:32 +02:00
atlas
7bdc3a827e ci: retrigger nix flake check (wasip2 path missing from lix db) 2026-07-09 00:47:32 +02:00
atlas
793f6ce185 fix(fmt): split method chain in bring_up_secondary_with_retry for treefmt 2026-07-09 00:47:32 +02:00
atlas
3de576141b refactor: extract bring_up_secondary_with_retry (fix clippy too_many_lines + needless_continue) 2026-07-09 00:47:32 +02:00
atlas
317e545d7c fix: wrap M_UNKNOWN_TOKEN in backticks in doc comment (clippy::doc_markdown) 2026-07-09 00:47:32 +02:00
atlas
a1cd50610a fix(#2095): retry secondary matrix account bring-up on transient failure
On a transient error (network blip, DNS not ready, homeserver 5xx) a
secondary account's bring-up was immediately skipped for the entire
daemon lifetime. This bit janet's catgirl account repeatedly when the
host DNS resolver wasn't ready at daemon start — the account would
silently disappear until the next restart.

Add a PermanentBringUpError sentinel in client.rs so callers can
distinguish M_UNKNOWN_TOKEN (stale/expired token — permanent, don't
retry) from transient network/homeserver errors.

In main.rs, replace the immediate skip with a bounded retry loop for
secondary accounts: up to 4 attempts with 2s/5s/15s/30s backoffs
(~52s total wait). On a transient error the daemon now stays alive
serving the primary and any other healthy accounts while the failing
secondary gets another chance. Permanent failures (PermanentBringUpError)
still skip immediately with no retry.

The primary account keep its existing behaviour: fatal on non-permanent
error so systemd restarts the whole daemon (systemd is the right retry
mechanism for primary bring-up failure).
2026-07-09 00:47:32 +02:00
atlas
6f3e400903 refactor(#1868): drop tokenised_repo_url — call forge_git_url directly 2026-07-09 00:45:13 +02:00
atlas
031edbd41f fix(#1868): use HIVE_FORGE_URL for internal forge calls
Replace the hardcoded FORGE_HTTP const with forge_http_base() which
reads HIVE_FORGE_URL from the environment (already set unconditionally
by hive-c0re.nix to http://<forge.domain>). Add forge_git_url() helper
that inserts core:<token> credentials between scheme and authority for
git push/clone URLs.

All call sites updated:
- forge/mod.rs: api() OnceLock + new forge_git_url/forge_http_base fns
- forge/repos.rs: push_meta, push_config, ensure_meta_remote
- forge/pr_merge.rs: tokenised_repo_url delegate + test loosened
- workers/knowledge.rs: clone + push URLs
- socket_server/mod.rs: clone_url in RepoCreated response

No new env var: HIVE_FORGE_URL was already the right knob (mara).

Closes #1868. Closes #2174 (this supersedes the operators-team fix from
the closed #2218, which is re-applied in the ensure_operators_team call
that was already merged separately).
2026-07-09 00:45:13 +02:00
damocles
05c91245c7 refactor(#2286): make transient set/clear private — RAII guard is the only door 2026-07-09 00:44:47 +02:00
atlas
9c3884e031 docs(ci): lint jobs are required and block merge 2026-07-08 23:43:29 +02:00
atlas
260dc7bb58 docs(ci): drop bullet descriptions, keep only link + one-liner
Per mara/argus feedback: no need to describe job contents inline,
just link to the workflow file.
2026-07-08 23:43:29 +02:00
atlas
7ef90996f6 docs(ci): replace YAML copy with link to .forgejo/workflows/ci.yml
Per mara's feedback: don't copy the YAML inline, just reference the file.
2026-07-08 23:43:29 +02:00
atlas
bfba148f76 docs(ci): update CI workflow section to reflect 3-job layout 2026-07-08 23:43:29 +02:00
atlas
39af2bad5d style: nix fmt hive-xdg-icons.nix (treefmt) 2026-07-08 23:37:09 +02:00
atlas
ba5a0e1a66 fix: add hyperhiveXdgIcons stub to nix/docs eval (fixes packages.docs check) 2026-07-08 23:37:09 +02:00
atlas
64eddfd0b6 feat(#2228): add XDG icon set and .desktop entries for hyperhive processes
Adds hive-xdg-icons package (nix/packages/hive-xdg-icons.nix) that
rasterizes the branding SVG to all standard hicolor sizes (16–256px)
and installs /usr/share/pixmaps/hyperhive.png as a flat fallback.
Ships .desktop entries for hive-c0re and hive-ag3nt with NoDisplay=true
so desktop environments can match running processes to their icon without
cluttering the application launcher.

Narrow drv input: only ./branding/hyperhive.svg, so unrelated source
changes don't bust the cache.

Wired into environment.systemPackages in hive-c0re.nix (host side)
so the icons are present wherever hive-c0re is deployed.

Closes #2228
2026-07-08 23:37:09 +02:00
atlas
fa944d1213 fix(#2284): replace nixos-container kill with machinectl kill SIGKILL
nixos-container has no kill verb. The KillContainer priv request was
calling nixos-container kill which always fails. Replace with:

  machinectl kill <name> --signal=SIGKILL

which sends SIGKILL to all processes in the container — the correct
semantics for a forced shutdown (called after graceful stop has been
attempted). Add a machinectl_run helper alongside container_run so
callers stay consistent.
2026-07-08 22:47:36 +02:00
müde
c7c156e57b fix(hive-c0re): converge /run bind sources + limits drop-in before reconcile-start 2026-07-08 21:48:37 +02:00
damocles
5027068e31 feat(#2109): harness-side idle watchdog to bail on anthropic api stall storms 2026-07-07 22:45:18 +02:00
damocles
244669f644 fix(hive-claude): exempt crate-doc block from comment-block lint 2026-07-07 18:16:50 +02:00
müde
261f02439b fix(forge): review fixes for the forgejo-api port 2026-07-07 14:42:43 +02:00
müde
5cfb33eeed docs(forge): note forgejo-api client + remaining raw-HTTP surfaces 2026-07-07 09:25:51 +02:00
müde
72415497aa style: treefmt reflow of time dep 2026-07-07 09:25:03 +02:00
müde
4636987469 refactor(hive-forge): port CLI verbs to forgejo-api 2026-07-07 09:24:53 +02:00
müde
b8a3927c43 refactor(hive-c0re): port forge module + knowledge hooks to forgejo-api 2026-07-07 09:11:15 +02:00
müde
4468e86e2d refactor(hive-ag3nt): port forge_notify to forgejo-api 2026-07-07 09:10:24 +02:00
müde
0f035ce1e9 build: add time + url deps for forgejo-api port 2026-07-07 08:50:35 +02:00
müde
39fe0f306a build: add forgejo-api workspace dep (sync feature for hive-forge) 2026-07-07 08:48:07 +02:00
müde
5b062dca55 refactor(hive-ag3nt): split hive bin into hive-agent / hive-agent-mcp / hive-agent-wake 2026-07-06 23:48:05 +02:00
müde
2486251b32 fix: close second review round on the queue-routed CLI
- subvol upgrade waits for the queued stop DAG before migrating (was
  snapshotting + swapping state under a live bind mount) and for the
  restart job after
- history trim gets a 5-min grace for fresh terminals so broad
  stop/start waits can't miss a failed DAG evicted by the per-template
  cap (cap still applies past the grace)
- restart-all returns its DAG ids so hivectl actually waits
- hard stops await their agent DAGs (bounded) before infra goes down,
  restoring the agents-before-infra invariant
- hivectl wait uses node-level terminality so the after-any recovery
  reconcile is watched to completion; infra render errors no longer
  skip watching already-queued agent DAGs
- fold hive-bash-mcp's last local now_unix into wire_time
2026-07-06 22:57:28 +02:00
müde
0e4b5a1120 refactor(hive-c0re): group src-root files into submodules
stores/ (sqlite-backed host stores + db helper), stats/, agent_config/,
workers/ — pure git-mv moves; crate-root re-exports keep every
crate::<module> path compiling. flake_check stays at root (synchronous
approval-flow validation, not a background worker)
2026-07-06 22:38:47 +02:00
müde
b489454dc2 feat(hivectl): queue-routed lifecycle verbs with wait + DAG progress
every agent lifecycle verb on the admin socket (rebuild / restart /
restart-all / kill / stop / start) now submits job-queue DAGs and
returns their ids; hivectl polls the new HostRequest::QueueDag and
prints a live node-chain progress line per DAG (fan-out children
included), exiting non-zero on failure — --no-wait opts out. DagView
and the queue wire enums move to hive_sh4re::jobs (wire types live in
the shared crate); the last fused rebuild path (lifecycle::rebuild)
is gone. tracker: #2166
2026-07-06 22:30:49 +02:00