Watch
0
0
Fork
You've already forked hyperhive
0

swarm: bash task status keys expire after 72 hours

Nothing deletes the key of a finished task, so the bucket would grow with every
task an agent runs. The shared bucket helper takes an optional max age, applied
when the bucket is created; a live task's republishing keeps its own key.
This commit is contained in:
iris 2026-11-15 17:54:03 +01:00 • committed by mara
commit 1a698f1a97
2 changed files with 35 additions and 3 deletions

View file

@ -32,16 +32,19 @@ pub(crate) fn output_config(
}
/// Open the status bucket, creating it if nothing has yet. `history: 1`: a
/// reader wants each task's current state, not every state it has been in.
/// reader wants each task's current state, not every state it has been in. A
/// key expires [`swarm_wire::bash_task::STATUS_MAX_AGE`] after its last write,
/// since nothing deletes the key of a finished task.
pub async fn open_status(
client: &async_nats::Client,
) -> Result<async_nats::jetstream::kv::Store, crate::Error> {
let js = async_nats::jetstream::new(client.clone());
crate::kv::open_or_create(
crate::kv::open_or_create_expiring(
&js,
swarm_wire::bash_task::BUCKET,
"bash-task-status",
"The state of each bash task, as its agent's bash MCP last published it".to_owned(),
Some(swarm_wire::bash_task::STATUS_MAX_AGE),
)
.await
}

View file

@ -9,6 +9,19 @@ pub(crate) async fn open_or_create(
bucket: &str,
label: &str,
description: String,
) -> Result<async_nats::jetstream::kv::Store, Error> {
open_or_create_expiring(js, bucket, label, description, None).await
}
/// [`open_or_create`] with a `max_age`: a key nobody writes for that long goes
/// away, for a bucket whose keys come from a publisher that never deletes. The
/// age applies to a bucket created here; one that already exists keeps its own.
pub(crate) async fn open_or_create_expiring(
js: &async_nats::jetstream::Context,
bucket: &str,
label: &str,
description: String,
max_age: Option<std::time::Duration>,
) -> Result<async_nats::jetstream::kv::Store, Error> {
match js.get_key_value(bucket).await {
Ok(store) => Ok(store),
@ -22,6 +35,7 @@ pub(crate) async fn open_or_create(
bucket: bucket.to_owned(),
description,
history: 1,
max_age: max_age.unwrap_or_default(),
..Default::default()
})
.await