Watch
0
0
Fork
You've already forked hyperhive
0

agents get a per-agent repo limit in their permissions record, orgs are locked

max_repos (default 0, 0..=100) lives in the agent's agent-permissions record and is edited on its permissions panel. The controller applies each agent's own value as max_repo_creation at CreateForgeUser and to existing accounts on change, restart and every five minutes; agent accounts may not create organizations.
This commit is contained in:
atlas 2026-11-15 20:47:21 +01:00 • committed by mara
commit 1edeb5c55d

View file

@ -393,7 +393,13 @@ async fn run_node_work(
.to_owned(),
),
Some(client) => {
match forge_node("create_forge_user", client.ensure_agent_user(&agent)).await {
let max_repos = agent_max_repos_limit(deps.queue.as_ref(), &agent).await;
match forge_node(
"create_forge_user",
client.ensure_agent_user(&agent, max_repos),
)
.await
{
Ok(()) => Outcome::Done,
Err(e) => Outcome::Failed(format!("{e:#}")),
}
@ -554,6 +560,26 @@ async fn mint_forge_token(
}
}
/// The repository limit a new agent account is created at: the `max_repos` of
/// the agent's permissions record, or none (0) when there is no queue or it
/// cannot be read. The forge pass in `forge::agent_max_repos` raises the
/// account to its limit once the queue answers.
async fn agent_max_repos_limit(queue: Option<&async_nats::Client>, agent: &str) -> u32 {
let Some(queue) = queue else {
return swarm_wire::agent_permissions::DEFAULT_MAX_REPOS;
};
crate::agent_permissions::max_repos(queue, agent)
.await
.unwrap_or_else(|e| {
tracing::warn!(
agent,
error = %format!("{e:#}"),
"swarm jobq: the agent's repository limit is unreadable; creating the account at none"
);
swarm_wire::agent_permissions::DEFAULT_MAX_REPOS
})
}
/// The `GrantDocsRead` arm, lifted out for the same reason.
pub(crate) async fn grant_docs_read(
forge: Option<Arc<forge::Client>>,
@ -2031,6 +2057,29 @@ mod tests {
}
}
/// A new agent's account is created at the limit of its own record, not
/// another agent's, and at none when it has no record or there is no queue.
#[tokio::test]
async fn a_new_account_is_created_at_its_agents_limit() {
let nats = crate::test_nats::TestNats::start();
let client = nats.client().await;
assert_eq!(agent_max_repos_limit(Some(&client), "iris").await, 0);
let store = swarm_queue_client::agent_permissions::open_or_create(&client)
.await
.expect("bucket");
store
.put("iris", br#"{"max_repos":4}"#.to_vec().into())
.await
.expect("written");
store
.put("atlas", br#"{"max_repos":9}"#.to_vec().into())
.await
.expect("written");
assert_eq!(agent_max_repos_limit(Some(&client), "iris").await, 4);
assert_eq!(agent_max_repos_limit(Some(&client), "sock").await, 0);
assert_eq!(agent_max_repos_limit(None, "iris").await, 0);
}
fn build_state(
sched: &hive_jobq::scheduler::Scheduler<SwarmNodeKind, super::SwarmResourceKind>,
rev: &str,