Skip to content

Reason Network: your team's coding agents, talking to each other. The engine behind `reason network`.

Same-account joins wait for the person's own machine; README keeps the no-account path

Lars Taliand47dd9b262c5
diff --git a/README.md b/README.md
index 072ab70..a31c972 100644
--- a/README.md
+++ b/README.md
@@ -37,6 +37,16 @@ curl -fsSL https://reasonmachines.com/install.sh | bash -s -- network join '<lin
That's it. Ask any agent "who's on the team?", tell it to ask someone's agent something, or to send them a file.
+**Without an account**: install just this engine. It asks your name and a team name, and gives you a team link (on
+your clipboard). Teammates open it, paste one command, type their name, and they're in. Or they tell their agent
+"join my Reason Network team: <link>". Names aren't verified this way.
+
+```sh
+curl -fsSL https://github.com/reason-machines/reason-network/releases/latest/download/install.sh | sh
+```
+
+On Windows, in PowerShell: `irm https://github.com/reason-machines/reason-network/releases/latest/download/install.ps1 | iex`
+
**Coming from tincan?** Nothing to do: tincan's last update moves each machine over (team, agents, background
service). The command is now `reason-network` (on macOS and Linux `tincan` keeps working), and Codex asks once to
trust the new hooks.
diff --git a/src/daemon/teamops.rs b/src/daemon/teamops.rs
index 6b143df..7663483 100644
--- a/src/daemon/teamops.rs
+++ b/src/daemon/teamops.rs
@@ -283,16 +283,31 @@ impl Daemon {
owner_only: proof.is_some(),
};
// Another computer of an account that holds a name is best let in by one of that person's own machines, which
- // every build takes: ask for that first. Else any machine of this build lets it in on its proof.
- let res = match net::join(&endpoint, &peers, &req).await {
+ // every build takes: ask for that first, and once more shortly if a machine on the link couldn't be reached (it
+ // may be theirs, not found yet). Else any machine of this build lets it in on its proof, which builds before
+ // proofs don't take.
+ let same_account = |r: &Result<_>| matches!(r, Err(e) if e.to_string().contains(team::SAME_ACCOUNT));
+ let mut tried = net::join(&endpoint, &peers, &req).await;
+ if same_account(&tried.result) && tried.unreachable {
+ tokio::time::sleep(Duration::from_secs(5)).await;
+ let again = net::join(&endpoint, &peers, &req).await;
+ if again.result.is_ok() {
+ tried = again;
+ }
+ }
+ let res = match tried.result {
Err(e) if e.to_string().contains(team::SAME_ACCOUNT) => {
let any = JoinRequest { owner_only: false, ..req };
- net::join(&endpoint, &peers, &any).await.map_err(|again| if taken(&again) { e } else { again })
+ net::join(&endpoint, &peers, &any).await.result.map_err(|again| if taken(&again) { e } else { again })
}
r => r,
};
endpoint.close().await;
- let mut state = TeamState::verified(&res?)?;
+ let (state, by) = res?;
+ let mut state = TeamState::verified(&state)?;
+ let who =
+ state.member(&by).map_or_else(|| by.fmt_short().to_string(), |m| format!("{} on {}", m.person, m.machine));
+ log(&format!("joined team {} as {person}: let in by {who}", state.name()));
let me = self.key.public();
// A ticket names the team; a code can't (whoever answers on the code's key knows the code, so could make up a
// team), which is why a sign-in joins only with a link.
diff --git a/src/net.rs b/src/net.rs
index fe1348a..3eb36bc 100644
--- a/src/net.rs
+++ b/src/net.rs
@@ -213,10 +213,18 @@ async fn read_frame<T: DeserializeOwned>(recv: &mut RecvStream) -> Result<T> {
Ok(serde_json::from_slice(&buf)?)
}
+/// How a join went: the team and the machine that let this one in, or why not; and whether a machine on the link
+/// couldn't be reached (it may yet be, shortly).
+pub struct Joined {
+ pub result: Result<(TeamState, EndpointId)>,
+ pub unreachable: bool,
+}
+
/// Joins a team: asks each machine in turn (the ticket's, or the one an invite code points at) to let us in.
-pub async fn join(endpoint: &Endpoint, peers: &[EndpointAddr], req: &JoinRequest) -> Result<TeamState> {
+pub async fn join(endpoint: &Endpoint, peers: &[EndpointAddr], req: &JoinRequest) -> Joined {
let mut last = anyhow!("the invite lists no machines");
let mut refused = Refusals::default();
+ let mut unreachable = false;
for addr in peers {
let attempt = || async {
let conn = endpoint.connect(addr.clone(), JOIN_ALPN).await?;
@@ -239,13 +247,23 @@ pub async fn join(endpoint: &Endpoint, peers: &[EndpointAddr], req: &JoinRequest
}
};
match reply {
- Ok(Ok(JoinReply::Ok { state })) => return Ok(*state),
- Ok(Ok(JoinReply::Err { error })) => refused.add(req, error)?,
- Ok(Err(e)) => last = e,
- Err(_) => last = anyhow!("couldn't reach the machine that made the invite (is it online?)"),
+ Ok(Ok(JoinReply::Ok { state })) => return Joined { result: Ok((*state, addr.id)), unreachable },
+ Ok(Ok(JoinReply::Err { error })) => {
+ if let Err(e) = refused.add(req, error) {
+ return Joined { result: Err(e), unreachable };
+ }
+ }
+ Ok(Err(e)) => {
+ unreachable = true;
+ last = e;
+ }
+ Err(_) => {
+ unreachable = true;
+ last = anyhow!("couldn't reach the machine that made the invite (is it online?)");
+ }
}
}
- Err(refused.0.map_or(last, |r| anyhow!(r)))
+ Joined { result: Err(refused.0.map_or(last, |r| anyhow!(r))), unreachable }
}
/// What the machines asked so far refused a join with. A refusal is final: another machine would say the same. Except
diff --git a/tests/e2e/mixed_versions.py b/tests/e2e/mixed_versions.py
index b2f2f24..489df19 100644
--- a/tests/e2e/mixed_versions.py
+++ b/tests/e2e/mixed_versions.py
@@ -49,6 +49,11 @@ def until(who, args, ok, secs=45):
time.sleep(1)
+def logged(who):
+ p = os.path.join(D, who, "daemon.log")
+ return open(p, errors="replace").read() if os.path.exists(p) else ""
+
+
def link_of(out):
m = re.search(r"https://\S+/join/#\S+", out)
return m.group(0) if m else ""
@@ -89,11 +94,14 @@ try:
check("the older machine has all three, every signed entry checking out", three(out), out)
# nina's second computer, through the older machine's link: it asks the link's machines for one of nina's own,
# whose word the older machine takes too.
+ # (nina's machine is up and reachable: every machine sees it connected.)
+ until("alex", ["team"], lambda o: re.search(r"nina \(verified\)\s+desk\s+(direct|relay)", o))
old_link = link_of(cli("olga", "link")) # now listing nina's machine too
out = cli("nina2", "join", old_link, "--proof", proof("u_nina", "nina", ep["nina2"]), "--no-setup")
check("another computer of nina's account joins through the older machine's link", "Joined team mixed as nina on pad." in out, out)
+ check("…let in by nina's own machine", "joined team mixed as nina: let in by nina on desk" in logged("nina2"), logged("nina2")[-2000:])
out = until("olga", ["team"], lambda o: re.search(r"nina\s+pad\s+(direct|relay)", o))
- check("…let in by nina's own machine, so the older machine takes it too", re.search(r"nina\s+pad\s+(direct|relay)", out) is not None, out)
+ check("…so the older machine takes it too", re.search(r"nina\s+pad\s+(direct|relay)", out) is not None, out)
cli("nina2", "leave")
cli("nina2", "stop")
# With nina's machine off, the older machine first on its link says the name is taken; alex's machine, further
@@ -102,6 +110,7 @@ try:
until("olga", ["team"], lambda o: not re.search(r"nina\s+desk\s+(direct|relay)", o))
out = cli("nina3", "join", link_of(cli("olga", "link")), "--proof", proof("u_nina", "nina", ep["nina3"]), "--no-setup")
check("past the older machine's refusal, a machine of this build lets nina's computer in", "Joined team mixed as nina on tab." in out, out)
+ check("…alex's, on its proof", "joined team mixed as nina: let in by alex on laptop" in logged("nina3"), logged("nina3")[-2000:])
out = until("alex", ["team"], lambda o: re.search(r"nina \(verified\)\s+tab\s+(direct|relay)", o))
check("…which this build's machines take", re.search(r"nina \(verified\)\s+tab\s+(direct|relay)", out) is not None, out)
cli("nina3", "leave")