Watch
0
0
Fork
You've already forked hyperhive
0

nix: the bash daemon gets the agent's store identity so it can publish its tasks

This commit is contained in:
damocles 2026-11-21 12:34:11 +01:00 • committed by mara
commit 1302965ca7
2 changed files with 53 additions and 12 deletions

View file

@ -19,7 +19,18 @@ let
# opencode preset the provider key too. Either way it is handed the same # opencode preset the provider key too. Either way it is handed the same
# store identity ./queue-identity.nix hands the harness, under the same # store identity ./queue-identity.nix hands the harness, under the same
# switch. # switch.
subagentReadsStore = config.services.hyperhive.agent.bao.addr != null; # The bash and subagent daemons publish to the swarm queue as the agent, so
# each reads the agent's queue secret from the store with the agent's own
# identity. Paths and a name only. `%d` is the unit's own credentials
# directory, where `hive-agent-bao-server-ca` is loaded.
daemonsReadStore = config.services.hyperhive.agent.bao.addr != null;
storeIdentityEnv = {
HIVE_AGENT_NAME = userName;
BAO_ADDR = config.services.hyperhive.agent.bao.addr;
BAO_CLIENT_CERT = config.services.hyperhive.agent.bao.clientCertFile;
BAO_CLIENT_KEY = config.services.hyperhive.agent.bao.clientKeyFile;
BAO_CACERT = "%d/hive-agent-bao-server-ca";
};
in in
{ {
options.services.hyperhive.agent.extraMcpServers = lib.mkOption { options.services.hyperhive.agent.extraMcpServers = lib.mkOption {
@ -291,6 +302,8 @@ in
description = "bash task runner + MCP daemon for hive-bash"; description = "bash task runner + MCP daemon for hive-bash";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
before = [ "hive-agent.service" ]; before = [ "hive-agent.service" ];
# The live certificate pair exists once ./bao.nix's unit has run.
after = lib.optional daemonsReadStore "hive-agent-bao-identity.service";
# The daemon runs every bash task via `Command::new("bash")` and the # The daemon runs every bash task via `Command::new("bash")` and the
# commands themselves (hive-forge, git, jq, …) resolve from PATH. # commands themselves (hive-forge, git, jq, …) resolve from PATH.
# A standalone daemon has no inherited agent PATH, so without this # A standalone daemon has no inherited agent PATH, so without this
@ -317,7 +330,13 @@ in
# loose-ends dir paths; `hive_agent_sock::paths::harness_dir` # loose-ends dir paths; `hive_agent_sock::paths::harness_dir`
# panics loudly if HYPERHIVE_HARNESS_DIR is unset rather than # panics loudly if HYPERHIVE_HARNESS_DIR is unset rather than
# deriving a fallback, since every service here always gets it. # deriving a fallback, since every service here always gets it.
}; #
# The store identity is what lets the daemon publish each task's
# status and output to the swarm queue as this agent
# (`swarm_term.rs`): without it the daemon logs "bash tasks are not
# published" and the swarm UI's background-tasks list stays empty.
}
// lib.optionalAttrs daemonsReadStore storeIdentityEnv;
serviceConfig = { serviceConfig = {
ExecStart = "${config.services.hyperhive.agent.packages.hive-bash-daemon}/bin/hive-bash-daemon --http 127.0.0.1:${toString config.services.hyperhive.agent.mcp.bashHttpPort}"; ExecStart = "${config.services.hyperhive.agent.packages.hive-bash-daemon}/bin/hive-bash-daemon --http 127.0.0.1:${toString config.services.hyperhive.agent.mcp.bashHttpPort}";
SyslogIdentifier = "hive-bash-daemon"; SyslogIdentifier = "hive-bash-daemon";
@ -338,6 +357,11 @@ in
DelegateSubgroup = "daemon"; DelegateSubgroup = "daemon";
User = userName; User = userName;
Group = userName; Group = userName;
}
// lib.optionalAttrs daemonsReadStore {
# Bare id: inherits the credential the container manager passed in,
# the same form ./queue-identity.nix uses.
LoadCredential = [ "hive-agent-bao-server-ca" ];
}; };
}; };
@ -360,7 +384,7 @@ in
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
before = [ "hive-agent.service" ]; before = [ "hive-agent.service" ];
# The live certificate pair exists once ./bao.nix's unit has run. # The live certificate pair exists once ./bao.nix's unit has run.
after = lib.optional subagentReadsStore "hive-agent-bao-identity.service"; after = lib.optional daemonsReadStore "hive-agent-bao-identity.service";
# A subagent task runs its own nested `claude` invocation (via # A subagent task runs its own nested `claude` invocation (via
# `hive-claude`), which needs to resolve `claude` itself off PATH — # `hive-claude`), which needs to resolve `claude` itself off PATH —
# same reasoning as `hive-bash-daemon`'s `path` above, even though # same reasoning as `hive-bash-daemon`'s `path` above, even though
@ -408,14 +432,7 @@ in
# environment stays as is. # environment stays as is.
BASH_DEFAULT_TIMEOUT_MS = "1800000"; # 30 minutes BASH_DEFAULT_TIMEOUT_MS = "1800000"; # 30 minutes
} }
// lib.optionalAttrs subagentReadsStore { // lib.optionalAttrs daemonsReadStore storeIdentityEnv;
# Paths and a name only. `%d` is this unit's own credentials directory.
HIVE_AGENT_NAME = userName;
BAO_ADDR = config.services.hyperhive.agent.bao.addr;
BAO_CLIENT_CERT = config.services.hyperhive.agent.bao.clientCertFile;
BAO_CLIENT_KEY = config.services.hyperhive.agent.bao.clientKeyFile;
BAO_CACERT = "%d/hive-agent-bao-server-ca";
};
serviceConfig = { serviceConfig = {
ExecStart = "${config.services.hyperhive.agent.packages.hive-subagent-daemon}/bin/hive-subagent-daemon --http 127.0.0.1:${toString config.services.hyperhive.agent.mcp.subagentHttpPort}"; ExecStart = "${config.services.hyperhive.agent.packages.hive-subagent-daemon}/bin/hive-subagent-daemon --http 127.0.0.1:${toString config.services.hyperhive.agent.mcp.subagentHttpPort}";
SyslogIdentifier = "hive-subagent-daemon"; SyslogIdentifier = "hive-subagent-daemon";
@ -446,7 +463,7 @@ in
User = userName; User = userName;
Group = userName; Group = userName;
} }
// lib.optionalAttrs subagentReadsStore { // lib.optionalAttrs daemonsReadStore {
# Bare id: inherits the credential the container manager passed in, # Bare id: inherits the credential the container manager passed in,
# the same form ./queue-identity.nix uses. # the same form ./queue-identity.nix uses.
LoadCredential = [ "hive-agent-bao-server-ca" ]; LoadCredential = [ "hive-agent-bao-server-ca" ];

View file

@ -114,6 +114,30 @@ let
# Control: the lookup finds the store identity's credential. # Control: the lookup finds the store identity's credential.
&& lib.elem "hive-agent-bao-server-ca" (credentials agentBao); && lib.elem "hive-agent-bao-server-ca" (credentials agentBao);
} }
{
# The bash daemon publishes each task to the queue as the agent, which
# takes the agent's name and store identity in its own environment; the
# swarm UI's background-tasks list is empty without them. Same
# identity and server CA as the subagent daemon, ordered after the
# login unit that writes the certificate.
name = "the bash daemon gets the agent's store identity to publish its tasks";
ok =
let
a = agentBao.services.hyperhive.agent;
u = agentBao.systemd.services.hive-bash-daemon;
e = u.environment;
in
e.HIVE_AGENT_NAME == a.user.name
&& e.BAO_ADDR == a.bao.addr
&& e.BAO_CLIENT_CERT == a.bao.clientCertFile
&& e.BAO_CLIENT_KEY == a.bao.clientKeyFile
&& e.BAO_CACERT == "%d/hive-agent-bao-server-ca"
&& lib.elem "hive-agent-bao-server-ca" u.serviceConfig.LoadCredential
&& lib.elem "hive-agent-bao-identity.service" u.after
# Control: with no store address the daemon names no identity.
&& !(agentNoBao.systemd.services.hive-bash-daemon.environment ? BAO_ADDR)
&& !(agentNoBao.systemd.services.hive-bash-daemon.serviceConfig ? LoadCredential);
}
{ {
# Both options are refused, naming where the address # Both options are refused, naming where the address
# comes from now, rather than dropped silently. # comes from now, rather than dropped silently.