Watch
0
0
Fork
You've already forked hyperhive
0

swarm-controller: keep the known models in memory, and let the controller watch agent-inference

GET /api/models listed the agent-inference bucket on every request with
keys(), which needs the nameless ephemeral consumer subject
CONSUMER.CREATE.KV_agent-inference. The controller's NATS grant had that
subject for the status, permissions and bash task buckets but not for
this one, so NATS refused the create and the client waited out its
timeout: the request hung every time.

The controller now follows the bucket with a watch that replays each
key's current value first, keeps each agent's models in memory beside the
reported ones, and answers the request from there without reading the
bucket. The grant adds the one create subject the watch needs, with a
policy test like the other buckets'.
This commit is contained in:
iris 2026-11-23 21:01:31 +01:00 • committed by mara
commit 519ed2f134

View file

@ -857,6 +857,16 @@ impl Policy {
"$JS.API.CONSUMER.CREATE.{}",
swarm_wire::bash_task::STREAM
));
// The inference settings, followed by a watch: the controller keeps the
// list of models the swarm knows from every write to the bucket. A
// watch builds the same nameless ephemeral consumer as `keys()`, so
// the bare create subject is the one it needs. Without it the create
// request is refused and reaches the client as a timeout, which is
// how `GET /api/models` hung every time.
subjects.push(format!(
"$JS.API.CONSUMER.CREATE.{}",
swarm_wire::agent_inference::STREAM
));
subjects
}
}
@ -930,6 +940,23 @@ mod tests {
);
}
#[test]
fn the_reader_can_watch_the_agent_inference_bucket_and_no_other_stream() {
let subjects = policy().reader_subjects();
let s = swarm_wire::agent_inference::STREAM;
// The bare form is what a watch or `keys()` needs: its ephemeral
// consumer has no name.
assert!(subjects.contains(&format!("$JS.API.CONSUMER.CREATE.{s}")));
// Negative controls: the grant names this one stream, and holds no
// wildcard or `.>` form for it.
assert!(!subjects.contains(&"$JS.API.CONSUMER.CREATE.*".to_owned()));
assert!(!subjects.contains(&format!("$JS.API.CONSUMER.CREATE.{s}.>")));
assert!(
!subjects.contains(&"$JS.API.CONSUMER.CREATE.KV_unrelated".to_owned()),
"an unrelated stream must not be creatable"
);
}
#[test]
fn the_reader_can_list_the_bash_task_statuses_and_no_other_stream() {
let subjects = policy().reader_subjects();