Skip to content

Decouple multi-agent temporal networks and show the algorithms in examples - #8

Merged
sunsided merged 8 commits into
mainfrom
feature/multi-agent
Nov 28, 2026
Merged

sunsided merged 8 commits into
mainfrom
feature/multi-agent

Conversation

@sunsided

Copy link
Copy Markdown
Owner

Closes #7.

What and why

Several agents (rovers, an orbiter) share timing constraints but can rarely talk. This PR gives each agent a part of the plan it can dispatch and change alone, and lets agents that do get to communicate check changes together and redistribute slack without a central solver. It also adds three runnable examples for the crate's algorithms and bumps the dependency floors.

Multi-agent STNs (multiagent, alloc only)

  • Temporal decoupling — MultiAgentStn::decouple. Every non-reference point has one owner. For each shared distance-graph edge u -> v (weight w), it adds a cut t_u - z >= c to u's owner and t_v - z <= c + w to v's. c is the midpoint of the feasible interval, computed on an incremental minimal network. Any combination of locally consistent schedules is then a schedule of the plan.
    • Cuts are kept even for edges the joint windows already imply. Those windows may come from other agents' constraints, and dropping such cuts is unsound; one of the hand mutations below checks exactly this.
    • It is a greedy heuristic, not an optimal (LP) decoupling. The docs say so.
  • Local changes — Agent::add_constraint accepts a change that fits inside the cuts without any communication. Agent::propose records one that does not fit for the next contact.
  • Distributed consistency — Agent::summary projects an agent onto its shared points: minimal-network bounds, exact because the minimal network is decomposable. AgentGroup::new builds the same joint network on every member, whatever order the summaries arrive in. AgentGroup::check_consistency decides the group's consistency. A conflict names the shared constraints and the agents involved.
  • Re-decoupling — Agent::redecouple adopts the proposals, or drops them if the group is inconsistent. It recomputes the cuts of the group's shared constraints and keeps the cuts towards non-members.
    • With all agents in the group, the result equals a central decoupling, agent by agent.
    • Summaries carry the group and the agent's revision. Stale or mismatched sets are refused.
  • Communication windows — a contingent link in an Stnu. The module docs show the pattern, plus a deadline that breaks controllability.
  • Crossing process boundaries — AgentParts with Agent::from_parts / into_parts, and Summary::from_parts, rebuild both types from plain data and validate them. The wire format stays the integrator's.

Protocol limits, documented and not enforced:

  • Re-decoupling is safe only if every member adopts. No member may change between sending its summary and adopting.
  • One refusal returns every member to its old cuts. A clone of each agent is the rollback.
  • Points that already happened must be pinned as local constraints before summarising.
  • The acknowledgement round itself is not implemented (design doc section 9).

Examples (examples/, run as tests via test = true)

  • rover_relay — two rovers and an orbiter:
    • decouple the plan and uplink each part through AgentParts;
    • execute without talking (earliest/latest mixes), checked against the full plan;
    • absorb a delay locally and propose one that does not fit;
    • rebalance at a contact before the sol;
    • reject a conflicting proposal.
  • relay_pass — a lander downlinks through a relay pass with an uncertain opening:
    • DC check, and the explanation when "send by minute 80" cannot hold;
    • checksummed encoding, and a flipped bit rejected without changing the loaded dispatcher;
    • a heap-free Dispatcher<6, 64, u16> reacting to five combinations of contingent outcomes.
  • observation_campaign:
    • a telescope night planned request by request on IncrementalStn, with a rejected request naming its conflicts;
    • a 200-field survey checked with P³C (368 pairs instead of 40,401 cells), compared with Floyd-Warshall;
    • the filtered dispatchable night (12 edges instead of 42), run by the dispatcher.

Dependencies

  • criterion 0.8.2, proptest 1.12 and libfuzzer-sys 0.4.13 are now the minimum versions. Cargo.lock is not tracked, so a fresh resolve already picked these. proptest 1.12 needs Rust 1.88 for tests only. The MSRV job checks the library alone, so the comment there is updated.
  • The docs.rs mermaid script moves from 11.17.2 to 12.3.0.
    • Mermaid 12 defaults to ELK and the "neo" look; the script sets layout: "dagre" and look: "classic" to keep the existing diagrams.
    • Checked by rendering the multiagent page in a browser.
    • Mermaid 12 needs Safari 17.4+ / ES2024 to view the diagrams.
  • Every pinned GitHub Action, pre-commit hook and mermaid-cli is already the latest release outside the 7-day cooldown, so nothing changed there.

Public API changes

  • New module multiagent, re-exported at the root: MultiAgentStn, Agent, AgentParts, AgentId, AgentGroup, Summary, SharedConstraint, Cut, GroupVerdict, GroupConflict.
  • New Error variants UnknownAgent and MismatchedSummaries. Error is #[non_exhaustive], and cargo semver-checks passes.

README "Scope", "Who this is for" and the new "Examples" section are updated. In docs/design.md:

  • new section 3.4 (semantics and soundness argument);
  • new rows in sections 4 and 5 and in the section 8 testing table;
  • new entries in sections 9 and 11 and in the references.

Testing

  • Property tests in tests/it/multiagent.rs:
    • decouple verdict equals the central check;
    • independently picked local schedules combine;
    • the distributed check equals the central check with proposals;
    • re-decoupling with all agents equals the central decoupling;
    • a partial (2 of 3) re-decoupling stays sound and leaves the third agent untouched;
    • parts round-trip;
    • malformed and stale inputs are refused.
  • Hand mutations made them fail: (a) skipping cuts of implied edges, and (b) cuts outside the feasible interval.
  • task ci passes, as do task semver and task build:no-std (the no_std build without alloc is unaffected).
  • No new CI jobs. Kani was not re-run because src/dispatch is untouched.

Review order

  1. docs/design.md §3.4, for the argument.
  2. src/multiagent/cuts.rs (the cut rule and its proof).
  3. src/multiagent.rs.
  4. src/multiagent/agent.rs and group.rs.
  5. tests/it/multiagent.rs.
  6. The examples.

criterion 0.8.2, proptest 1.12 and libfuzzer-sys 0.4.13 are the newest
releases; the requirements now name them so a fresh resolve cannot pick
an older one. Cargo.lock is not tracked, so the resolved versions were
already current. The pinned GitHub Actions and pre-commit hooks are
already the latest releases outside the seven-day cooldown.

proptest 1.12 needs Rust 1.88. Only tests use it, and the MSRV job checks
the library alone, so the comment there now names proptest instead of
criterion.

The docs.rs mermaid script moves from 11.17.2 to 12.3.0 (12.4.0 is inside
the cooldown). Mermaid 12 switches the default layout to ELK and the
default look to "neo"; the script sets the dagre layout and the classic
look so the existing diagrams keep their shape. Checked by rendering the
multiagent module page in a browser.
Several agents (rovers, an orbiter) share timing constraints but can
rarely communicate. The new `multiagent` module (alloc only) gives each
agent a part of the plan it can dispatch alone:

- `MultiAgentStn::decouple` adds reference-relative cuts on both sides of
  every shared distance-graph edge, chosen greedily at the midpoint of
  the feasible interval on an incremental minimal network. Any family of
  locally consistent schedules then combines into a schedule of the plan.
  Cuts are kept even for edges the joint windows already imply: those
  windows may come from other agents' constraints.
- `Agent::add_constraint` accepts a local change inside the cuts without
  communication; `Agent::propose` records one that does not fit for the
  next communication window.
- `Agent::summary` projects an agent onto its shared points (minimal
  network bounds, exact by decomposability), and `AgentGroup` builds the
  same joint network on every member. `AgentGroup::check_consistency`
  decides the group's consistency without a central solver, and
  `Agent::redecouple` adopts the proposals and redistributes the slack,
  keeping cuts towards agents outside the group. Summaries carry the
  group and the agent's revision; mismatched or stale sets are refused
  with the new `Error::MismatchedSummaries`, unknown agents with
  `Error::UnknownAgent`.
- Communication windows are contingent links of an STNU; the module docs
  show the pattern and a deadline that breaks controllability.

Property tests check that independently chosen local schedules combine,
that the distributed check and an all-agent re-decoupling equal the
central check and decoupling, and that a partial re-decoupling stays
sound. Dropping the cuts of implied edges, or choosing cuts outside the
feasible interval, makes them fail.

Closes #7
Three examples, each asserting its own results and run as a test
(`test = true`), so CI keeps them working:

- rover_relay: two rovers and an orbiter decouple a plan, execute it
  without talking, absorb a delay locally, rebalance in a relay pass, and
  reject a conflicting proposal naming the shared constraint.
- relay_pass: a lander downlinks through a relay pass with an uncertain
  opening: controllability, the explanation of a deadline that cannot
  hold, the checksummed uplink rejecting a flipped bit, and the heap-free
  u16 dispatcher reacting to each combination of contingent outcomes.
- observation_campaign: a telescope night planned request by request on
  the incremental STN with a named conflict, a 200-field survey checked
  with P3C against Floyd-Warshall, and the filtered dispatchable night.

The README lists them.
An agent lives on its own vehicle and a summary travels over a radio
link, but both could only be built inside this crate. `AgentParts` with
`Agent::from_parts` / `Agent::into_parts`, and `Summary::from_parts`,
rebuild them from plain data and validate the structure (sorted points
without the reference, constraints and cuts on own points, shared
constraints that involve the agent); `Agent::from_parts` also checks the
local network and explains an inconsistency. The wire format stays the
integrator's.

The docs now spell out the rest of the re-decoupling protocol: no member
may change between sending its summary and adopting, a single refusal
returns every member to its old cuts (a clone is the rollback), and
points that already happened are pinned as local constraints before
summarising. The rover example uplinks each part through `AgentParts`,
and its re-decoupling happens at a contact before the sol starts, when
nothing has executed yet.
@codecov

codecov Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.95960% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.72%. Comparing base (8df93d5) to head (e2217d2).

Files with missing lines Patch % Lines
src/multiagent/agent.rs 95.13% 13 Missing ⚠️
src/multiagent/group.rs 96.31% 7 Missing ⚠️
src/multiagent.rs 95.95% 4 Missing ⚠️
src/error.rs 0.00% 2 Missing ⚠️
src/multiagent/cuts.rs 98.48% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main       #8      +/-   ##
==========================================
- Coverage   95.80%   95.72%   -0.08%     
==========================================
  Files          28       32       +4     
  Lines        3192     3885     +693     
==========================================
+ Hits         3058     3719     +661     
- Misses        134      166      +32     
Files with missing lines Coverage Δ
src/budget.rs 100.00% <100.00%> (ø)
src/error.rs 0.00% <0.00%> (ø)
src/multiagent/cuts.rs 98.48% <98.48%> (ø)
src/multiagent.rs 95.95% <95.95%> (ø)
src/multiagent/group.rs 96.31% <96.31%> (ø)
src/multiagent/agent.rs 95.13% <95.13%> (ø)

... and 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kilo-code-bot

kilo-code-bot Bot commented Nov 28, 2026 •

Copy link
Copy Markdown

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files in incremental diff, 19 in PR)
  • examples/observation_campaign.rs - 0 issues
  • tests/it/multiagent.rs - 0 issues
Previous Review Summaries (2 snapshots, latest commit 0bf5485)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 0bf5485)

Status: No Issues Found | Recommendation: Merge

Files Reviewed (3 files in incremental diff, 19 in PR)
  • src/error.rs - 0 issues (new variants moved to the end, discriminants preserved)
  • src/multiagent/group.rs - 0 issues (missing origin now returns Error::Internal; every Stn constraint gets an origin via push)
  • src/multiagent/agent.rs - 0 issues (conflict computed before pending is cleared, so the agent is unchanged on error)

Previous findings: the examples/relay_pass.rs:138 warning was a false positive (ContingentId is pub usize and compares directly with position's usize), and the group.rs origin-fallback suggestion is resolved at 0bf5485. The semver break from the mid-enum insertion is fixed at 9950f6d.

Previous review (commit 9aec33d)

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
examples/relay_pass.rs 138 The check on the contingent-link index compares the tuple field against pass_link without matching the element's borrow/reference level, so the example (compiled in CI because it sets test = true) fails to type-check.

SUGGESTION

File Line Issue
src/multiagent/group.rs 301 The origin lookup falls through to None => {} when a cycle edge's constraint id does not resolve. Consider asserting or returning an explicit error instead of silently leaving the conflict without that shared constraint or agent.
Files Reviewed (19 files)
  • .github/instructions/ci.instructions.md - 0 issues
  • .github/workflows/ci.yml - 0 issues
  • Cargo.toml - 0 issues
  • README.md - 0 issues
  • docs/design.md - 0 issues
  • docs/mermaid.html - 0 issues
  • examples/observation_campaign.rs - 0 issues
  • examples/relay_pass.rs - 1 issue
  • examples/rover_relay.rs - 0 issues
  • fuzz/Cargo.toml - 0 issues
  • src/budget.rs - 0 issues
  • src/error.rs - 0 issues
  • src/lib.rs - 0 issues
  • src/multiagent.rs - 0 issues
  • src/multiagent/agent.rs - 0 issues
  • src/multiagent/cuts.rs - 0 issues
  • src/multiagent/group.rs - 1 issue
  • tests/it/main.rs - 0 issues
  • tests/it/multiagent.rs - 0 issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-v4.1-flash-1017 · Input: 25K · Output: 2.2K · Cached: 330K

UnknownAgent and MismatchedSummaries were inserted after
UnknownTimePoint, which shifted the discriminants of every later
variant. cargo-semver-checks reports that as a major change, because
code casting a variant with `as` would see a different value. The new
variants now come last, with a comment saying why.
AgentGroup::conflict skipped a negative-cycle edge whose constraint had
no recorded origin. Every constraint of the joint network gets one when
it is added, so a miss means a broken invariant, and skipping it would
hand back a conflict that silently leaves out part of the cycle. It is
now Error::Internal, as elsewhere in the crate. redecouple computes the
conflict before it drops the proposals, so the error leaves the agent
unchanged.
@sunsided

Copy link
Copy Markdown
Owner Author

Thanks for the review. Taking the two findings in turn:

WARNING, examples/relay_pass.rs:138: this compiles as written. links is a Vec<ContingentId>, so l is a &ContingentId. l.0 auto-dereferences to the usize field, and pass_link is a usize from Iterator::position. Both sides of == are usize. CI confirms it: the clippy (--all-targets) and test jobs on this PR built the example, and test = true ran it. No change.

SUGGESTION, src/multiagent/group.rs:301: fixed in 0bf5485. Every constraint of the joint network records its origin when it is added, so a missing origin is a broken invariant. Skipping it would silently drop part of the cycle from the conflict. conflict now returns Error::Internal, like the crate's other invariant checks. redecouple computes the conflict before it drops the proposals, so the error leaves the agent unchanged.

Separately, CI's semver job caught a real break: the two new Error variants had been inserted mid-enum, which shifted the later discriminants. Fixed in 9950f6d by moving them to the end.

The example's tick loop kept `t` unchanged when `next_wakeup` returned
None. A dispatcher left with points it can never execute would then
spin forever, and since the example runs as a test, CI would time out
instead of failing. The loop now stops once the plan is complete and
otherwise expects a wakeup.
pick() carried its own LCG next to the xorshift Rng in tests/it/sim.rs
that does the same job. It now draws from that Rng; the seed's low bit
is forced on because xorshift never leaves zero.
@sunsided
sunsided merged commit 37c226f into main Nov 28, 2026
23 checks passed
@sunsided
sunsided deleted the feature/multi-agent branch November 28, 2026 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Multi-agent temporal networks: decoupling, distributed consistency and communication windows

1 participant