Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
faf9e31
perf(node): poll a task again soon after submit and back off
TudorAndrei Nov 13, 2026
451bc66
fix(node): shut down gracefully on SIGTERM as well as Ctrl-C
TudorAndrei Nov 13, 2026
bd329e8
fix(node): do not log a broadcast with no receivers as a failure
TudorAndrei Nov 13, 2026
759da03
perf(node): use ring as the process-wide rustls provider
TudorAndrei Nov 13, 2026
a3a6eab
perf(hub): read from a read-only pool and sweep expired invites in ch…
TudorAndrei Nov 13, 2026
fe6367c
perf(hub): cache the directory, batch owner lookups, cache signed-req…
TudorAndrei Nov 13, 2026
69e578d
perf(node): cache prepared SQL statements in the store
TudorAndrei Nov 13, 2026
1541a39
perf(node): reuse store connections and remember verified signatures
TudorAndrei Nov 13, 2026
68d9cc4
Merge branch 't3/02041278' into t3/a1294d36
TudorAndrei Nov 13, 2026
35b9872
Merge branch 't3/f42d8b68' into t3/a1294d36
TudorAndrei Nov 13, 2026
50fc8e5
Merge branch 't3/d3690a72' into t3/a1294d36
TudorAndrei Nov 13, 2026
b11e196
fix(node): retry an exchange that the per-peer rate limit shed
TudorAndrei Nov 13, 2026
acacf29
fix(hub): drop the accounts(kind) index that slowed people search
TudorAndrei Nov 13, 2026
3cf5192
fix(hub): expire cached accounts and never store a copy a write overtook
TudorAndrei Nov 13, 2026
befbba8
fix(hub): back off after a failed directory build, 503 when the cache…
TudorAndrei Nov 13, 2026
34e3e5c
fix(node): retry rate-limited outbox sends and reopen kept stores
TudorAndrei Nov 13, 2026
4b5f2c8
docs: document retryAfterMs in the wire profile
TudorAndrei Nov 13, 2026
93d4891
Merge branch 't3/c4261a70' into t3/a1294d36
TudorAndrei Nov 13, 2026
1dda0fd
Merge branch 't3/e8ff94f5' into t3/a1294d36
TudorAndrei Nov 13, 2026
59ffe72
feat(hub): put the directory's unavailable error and cache time in th…
TudorAndrei Nov 13, 2026
cf1ad60
feat(agent-socket): let an agent say how many tasks it takes at once
TudorAndrei Nov 13, 2026
dad9c41
feat(node): run more than one task at a time, up to a limit that the …
TudorAndrei Nov 13, 2026
0bc4bce
Merge branch 't3/cfe3a2b8' into t3/a1294d36
TudorAndrei Nov 13, 2026
cb68105
fix(node): close the gaps that the review of parallel tasks found
TudorAndrei Nov 13, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions crates/aether-core/src/limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,84 @@

use crate::named;

/// The limits of the task queue and of the tasks that run from it.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
pub enum QueueLimitId {
/// How many tasks wait in all.
Global,
/// How many tasks wait for each caller endpoint.
PerPeer,
/// How many tasks this node runs at once, for all callers together.
Running,
}

named!(QueueLimitId {
Global => "queue_global",
PerPeer => "queue_per_peer",
Running => "running_tasks",
});

impl QueueLimitId {
/// Every limit, in the order that the node shows them.
pub const ALL: [Self; 3] = [Self::Global, Self::PerPeer, Self::Running];

/// The smallest value that the owner can set.
#[must_use]
pub const fn minimum(self) -> u32 {
1
}

/// The largest value that the owner can set. `None`: no fixed maximum.
#[must_use]
pub const fn maximum(self) -> Option<u32> {
match self {
Self::Global | Self::PerPeer => None,
Self::Running => Some(MAX_RUNNING_TASKS),
}
}

/// Whether the owner can set this limit to `value`.
#[must_use]
pub fn accepts(self, value: u32) -> bool {
value >= self.minimum() && self.maximum().is_none_or(|maximum| value <= maximum)
}
}

/// How many tasks a node runs at once unless its owner sets more. One keeps
/// the behavior of a node before the limit existed.
pub const DEFAULT_RUNNING_TASKS: u32 = 1;

/// The most tasks that the owner can let a node run at once.
///
/// Each running task is a turn of the agent (for Codex its own
/// `codex app-server` process and task folder) with a lease-renewal thread,
/// and every store write of the running tasks goes through one connection.
/// 32 is far above what one computer's agent runs well, and it keeps a
/// typing mistake from starting hundreds of processes.
pub const MAX_RUNNING_TASKS: u32 = 32;

#[cfg(test)]
mod tests {
use super::{MAX_RUNNING_TASKS, QueueLimitId};

#[test]
fn the_running_limit_has_a_floor_and_a_ceiling() {
assert!(!QueueLimitId::Running.accepts(0));
assert!(QueueLimitId::Running.accepts(1));
assert!(QueueLimitId::Running.accepts(MAX_RUNNING_TASKS));
assert!(!QueueLimitId::Running.accepts(MAX_RUNNING_TASKS.saturating_add(1)));
}

#[test]
fn a_queue_limit_has_only_a_floor() {
assert!(!QueueLimitId::Global.accepts(0));
assert!(QueueLimitId::PerPeer.accepts(u32::MAX));
}

#[test]
fn every_limit_has_its_own_name() {
for id in QueueLimitId::ALL {
assert_eq!(QueueLimitId::parse(id.as_str()), Some(id));
}
}
}
28 changes: 16 additions & 12 deletions crates/aether-store/src/access_groups.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use rusqlite::params;

use crate::CachedSql;
use crate::{NodeStore, StoreError};

/// The default group of direct contacts. Migration 011 makes it.
Expand Down Expand Up @@ -28,7 +29,7 @@ pub struct AccessGroupMember {
impl NodeStore {
pub fn create_access_group(&self, name: &str) -> Result<(), StoreError> {
self.connection
.execute("INSERT INTO access_groups(name) VALUES (?1)", [name])?;
.execute_cached("INSERT INTO access_groups(name) VALUES (?1)", [name])?;
Ok(())
}

Expand All @@ -39,19 +40,19 @@ impl NodeStore {
identities: &[(String, String)],
) -> Result<(), StoreError> {
let transaction = self.connection.transaction()?;
let initialized: bool = transaction.query_row(
let initialized: bool = transaction.query_row_cached(
"SELECT EXISTS(SELECT 1 FROM configuration WHERE key=?1)",
[INITIALIZED_KEY],
|row| row.get(0),
)?;
if !initialized {
for (agent, endpoint) in identities {
transaction.execute(
transaction.execute_cached(
"INSERT OR IGNORE INTO access_group_members(group_name,agent_id,endpoint_id) VALUES (?1,?2,?3)",
params![FRIENDS_GROUP, agent, endpoint],
)?;
}
transaction.execute(
transaction.execute_cached(
"INSERT INTO configuration(key,value) VALUES (?1,'1')",
[INITIALIZED_KEY],
)?;
Expand All @@ -61,7 +62,9 @@ impl NodeStore {
}

pub fn delete_access_group(&self, name: &str) -> Result<(), StoreError> {
if self.connection.execute("DELETE FROM access_groups WHERE name=?1", [name])?
if self
.connection
.execute_cached("DELETE FROM access_groups WHERE name=?1", [name])?
== 0
{
return Err(StoreError::NotFound);
Expand All @@ -75,14 +78,14 @@ impl NodeStore {
agent_id: &str,
endpoint_id: &str,
) -> Result<(), StoreError> {
if !self.connection.query_row(
if !self.connection.query_row_cached(
"SELECT EXISTS(SELECT 1 FROM access_groups WHERE name=?1)",
[group],
|row| row.get::<_, bool>(0),
)? {
return Err(StoreError::NotFound);
}
self.connection.execute(
self.connection.execute_cached(
"INSERT OR IGNORE INTO access_group_members(group_name,agent_id,endpoint_id) VALUES (?1,?2,?3)",
params![group, agent_id, endpoint_id],
)?;
Expand All @@ -95,7 +98,7 @@ impl NodeStore {
agent_id: &str,
endpoint_id: &str,
) -> Result<(), StoreError> {
if self.connection.execute(
if self.connection.execute_cached(
"DELETE FROM access_group_members WHERE group_name=?1 AND agent_id=?2 AND endpoint_id=?3",
params![group, agent_id, endpoint_id],
)? == 0 {
Expand All @@ -109,17 +112,18 @@ impl NodeStore {
agent_id: &str,
endpoint_id: &str,
) -> Result<bool, StoreError> {
self.connection.query_row(
self.connection.query_row_cached(
"SELECT EXISTS(SELECT 1 FROM access_group_members WHERE agent_id=?1 AND endpoint_id=?2)",
params![agent_id, endpoint_id],
|row| row.get(0),
).map_err(StoreError::from)
}

pub fn access_groups(&self) -> Result<Vec<AccessGroup>, StoreError> {
let mut groups =
self.connection.prepare("SELECT name FROM access_groups ORDER BY name")?;
let mut members = self.connection.prepare(
let mut groups = self
.connection
.prepare_cached("SELECT name FROM access_groups ORDER BY name")?;
let mut members = self.connection.prepare_cached(
"SELECT agent_id,endpoint_id FROM access_group_members WHERE group_name=?1 ORDER BY agent_id,endpoint_id",
)?;
groups
Expand Down
25 changes: 13 additions & 12 deletions crates/aether-store/src/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::collections::BTreeMap;

use rusqlite::{Connection, OptionalExtension, params};

use crate::CachedSql;
use crate::{NodeStore, StoreError, config, now, sql_count, sql_named};

/// The kind of an admin change. The names are the
Expand Down Expand Up @@ -140,7 +141,7 @@ fn audit(
actor: AuditActor,
result: AuditResult,
) -> Result<i64, StoreError> {
connection.execute(
connection.execute_cached(
"INSERT INTO audit_records(actor_type,action,result,created_at) VALUES(?1,?2,?3,?4)",
params![actor, AuditAction::Change, result, now()],
)?;
Expand Down Expand Up @@ -177,13 +178,13 @@ fn keep_change(
fn delete_expired(transaction: &Connection) -> Result<(), StoreError> {
let expired = {
let mut statement = transaction
.prepare("SELECT id FROM pending_changes WHERE expires_at<=?1")?;
.prepare_cached("SELECT id FROM pending_changes WHERE expires_at<=?1")?;
statement
.query_map([now()], |row| row.get::<_, String>(0))?
.collect::<Result<Vec<_>, _>>()?
};
for id in expired {
transaction.execute("DELETE FROM pending_changes WHERE id=?1", [&id])?;
transaction.execute_cached("DELETE FROM pending_changes WHERE id=?1", [&id])?;
config::delete(transaction, &pending_revision_key(&id))?;
}
Ok(())
Expand Down Expand Up @@ -257,7 +258,7 @@ impl NodeStore {
) -> Result<(), StoreError> {
let transaction = self.connection.transaction()?;
delete_expired(&transaction)?;
transaction.execute(
transaction.execute_cached(
"INSERT INTO pending_changes(id,change_type,value,expires_at) VALUES(?1,?2,?3,?4)",
params![id, kind, value, expires_at],
)?;
Expand Down Expand Up @@ -286,7 +287,7 @@ impl NodeStore {

/// Marks the audit record `audit` as failed.
pub fn fail_change(&self, audit: i64) -> Result<(), StoreError> {
self.connection.execute(
self.connection.execute_cached(
"UPDATE audit_records SET result=?1 WHERE id=?2",
params![AuditResult::Failed, audit],
)?;
Expand Down Expand Up @@ -320,7 +321,7 @@ impl NodeStore {
None => config::delete(&transaction, CURRENT_WORKSPACE_KEY)?,
}
}
transaction.execute(
transaction.execute_cached(
"UPDATE audit_records SET result=?1 WHERE id=?2",
params![AuditResult::Failed, replaced.audit],
)?;
Expand All @@ -339,7 +340,7 @@ impl NodeStore {
) -> Result<Replaced, StoreError> {
let transaction = self.connection.transaction()?;
let (kind, value, expires_at): (ChangeKind, String, i64) = transaction
.query_row(
.query_row_cached(
"SELECT change_type,value,expires_at FROM pending_changes WHERE id=?1",
[id],
|row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)),
Expand All @@ -351,7 +352,7 @@ impl NodeStore {
transaction.commit()?;
return Err(StoreError::InvalidState);
}
transaction.execute("DELETE FROM pending_changes WHERE id=?1", [id])?;
transaction.execute_cached("DELETE FROM pending_changes WHERE id=?1", [id])?;
config::delete(&transaction, &pending_revision_key(id))?;
audit(&transaction, AuditActor::Ui, AuditResult::Confirmed)?;
let replaced =
Expand All @@ -361,7 +362,7 @@ impl NodeStore {
}

pub fn pending_changes(&self) -> Result<Vec<PendingChange>, StoreError> {
let mut statement = self.connection.prepare(
let mut statement = self.connection.prepare_cached(
"SELECT id,change_type,value FROM pending_changes WHERE expires_at>?1 ORDER BY id",
)?;
Ok(statement
Expand All @@ -375,7 +376,7 @@ impl NodeStore {
id: &str,
) -> Result<PendingChange, StoreError> {
self.connection
.query_row(
.query_row_cached(
"SELECT id,change_type,value FROM pending_changes WHERE id=?1",
[id],
PendingChange::from_row,
Expand Down Expand Up @@ -420,7 +421,7 @@ impl NodeStore {
skip: usize,
limit: usize,
) -> Result<Vec<AuditRecord>, StoreError> {
let mut statement = self.connection.prepare(
let mut statement = self.connection.prepare_cached(
"SELECT actor_type,action,result FROM audit_records ORDER BY id LIMIT ?1 OFFSET ?2",
)?;
Ok(statement
Expand All @@ -439,7 +440,7 @@ impl NodeStore {
&self,
) -> Result<usize, StoreError> {
self.connection
.execute(
.execute_cached(
"INSERT INTO audit_records(actor_type,action,result,created_at) VALUES('mcp','change','private-credential',0)",
[],
)
Expand Down
22 changes: 13 additions & 9 deletions crates/aether-store/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,21 @@

use rusqlite::{Connection, OptionalExtension, params};

use crate::CachedSql;
use crate::{NodeStore, StoreError};

pub fn get(connection: &Connection, key: &str) -> Result<Option<String>, StoreError> {
Ok(connection
.query_row("SELECT value FROM configuration WHERE key=?1", [key], |row| {
row.get(0)
})
.query_row_cached(
"SELECT value FROM configuration WHERE key=?1",
[key],
|row| row.get(0),
)
.optional()?)
}

pub fn put(connection: &Connection, key: &str, value: &str) -> Result<(), StoreError> {
connection.execute(
connection.execute_cached(
"INSERT INTO configuration(key,value) VALUES(?1,?2) ON CONFLICT(key) DO UPDATE SET value=excluded.value",
params![key, value],
)?;
Expand All @@ -26,7 +29,7 @@ pub fn put(connection: &Connection, key: &str, value: &str) -> Result<(), StoreE

/// Removing a key that is not there is not an error.
pub fn delete(connection: &Connection, key: &str) -> Result<(), StoreError> {
connection.execute("DELETE FROM configuration WHERE key=?1", [key])?;
connection.execute_cached("DELETE FROM configuration WHERE key=?1", [key])?;
Ok(())
}

Expand All @@ -35,15 +38,15 @@ pub fn values(
connection: &Connection,
prefix: &str,
) -> Result<Vec<String>, StoreError> {
let mut statement = connection.prepare(
let mut statement = connection.prepare_cached(
"SELECT value FROM configuration WHERE substr(key,1,length(?1))=?1 ORDER BY key",
)?;
Ok(statement.query_map([prefix], |row| row.get(0))?.collect::<Result<_, _>>()?)
}

/// How many keys start with `prefix`.
pub fn count(connection: &Connection, prefix: &str) -> Result<usize, StoreError> {
let count: i64 = connection.query_row(
let count: i64 = connection.query_row_cached(
"SELECT COUNT(*) FROM configuration WHERE substr(key,1,length(?1))=?1",
[prefix],
|row| row.get(0),
Expand Down Expand Up @@ -90,8 +93,9 @@ mod tests {
store.configuration_values("caller.card.").expect("values must load"),
["a", "b"]
);
assert!(
store.configuration_values("CALLER.").expect("values must load").is_empty()
assert_eq!(
store.configuration_values("CALLER.").expect("values must load"),
Vec::<String>::new()
);
}
}
Loading
Loading