repos / zmx

session persistence for terminal processes
git clone https://github.com/neurosnap/zmx.git

commit
35f56e6
parent
2d37a09
author
Ian Tay
date
2026-03-08 12:57:26 -0400 EDT
fix(wait): time out after 3 polls if no matching sessions are found

Follow-up to the upstream wait fix: the `total > 0` guard prevented
vacuous exit 0, but left a typo'd `zmx wait foo` polling forever —
trading a wrong answer for no answer. After 3 iterations (~3s) with
max_seen still at 0, exit 2 with "no matching sessions found".

3s is generous: `zmx run foo && zmx wait foo` is essentially sequential
(run blocks until the socket exists and the Run IPC is acked), so a
persistent zero is a typo, not slowness.
1 files changed,  +16, -1
M src/main.zig
+16, -1
 1@@ -650,8 +650,9 @@ fn wait(cfg: *Cfg, session_names: std.ArrayList([]const u8)) !void {
 2 
 3     // Highest match count seen so far. Lets us distinguish "sessions haven't
 4     // appeared yet" (keep polling) from "sessions we were tracking
 5-    // disappeared" (fail — daemon crashed or was killed).
 6+    // disappeared" (fail -- daemon crashed or was killed).
 7     var max_seen: i32 = 0;
 8+    var zero_match_iters: u32 = 0;
 9 
10     while (true) {
11         var sessions = try util.get_session_entries(alloc, cfg.socket_dir);
12@@ -706,6 +707,20 @@ fn wait(cfg: *Cfg, session_names: std.ArrayList([]const u8)) !void {
13             return;
14         }
15 
16+        if (max_seen == 0) {
17+            // `zmx run foo && zmx wait foo` is essentially sequential, so
18+            // matching sessions should be visible from the first poll. If
19+            // nothing appears after a few iterations it's almost certainly a
20+            // typo, not a slow start.
21+            zero_match_iters += 1;
22+            if (zero_match_iters >= 3) {
23+                try stdout.print("error: no matching sessions found\n", .{});
24+                try stdout.flush();
25+                std.process.exit(2);
26+                return;
27+            }
28+        }
29+
30         std.Thread.sleep(1000 * std.time.ns_per_ms);
31     }
32 }