Commit c654778

Eric Bower  ·  2026-04-25 21:08:53 -0400 EDT
parent 758a137
fix(run): ignore DA queries when no terminal client connected

`run` is not a real terminal client, it just tails the output and cannot
respond to shell QA queries so we have a special flag that ignores read-only
clients
1 files changed,  +9, -6
+9, -6
......@@ -539,6 +539,7 @@ const Daemon = struct {
539539 cwd: []const u8 = "",
540540 has_pty_output: bool = false,
541541 has_had_client: bool = false,
542+ has_terminal_client: bool = false, // true only after a real attach (.Init received)
542543 created_at: u64, // unix timestamp (ns)
543544 is_task_mode: bool = false, // flag for when session is run as a task
544545 task_exit_code: ?u8 = null, // null = running or n/a, set when task completes
......@@ -943,6 +944,7 @@ const Daemon = struct {
943944
944945 // Mark that we've had a client init, so subsequent clients get terminal state
945946 self.has_had_client = true;
947+ self.has_terminal_client = true;
946948
947949 std.log.debug("init resize rows={d} cols={d}", .{ resize.rows, resize.cols });
948950 }
......@@ -2408,12 +2410,13 @@ fn daemonLoop(daemon: *Daemon, server_sock_fd: i32, pty_fd: i32) !void {
24082410 try vt_stream.nextSlice(buf[0..n]);
24092411 daemon.has_pty_output = true;
24102412
2411- // When no clients are attached, respond to terminal
2412- // queries (e.g. DA1/DA2) on behalf of the terminal.
2413- // This prevents shells like from fish from waiting 2s
2414- // and then sending a no DA query response warning because
2415- // there's no client terminal to respond to the query.
2416- if (daemon.clients.items.len == 0 and
2413+ // When no real terminal client has attached yet, respond to
2414+ // terminal queries (e.g. DA1/DA2) on behalf of the terminal.
2415+ // This prevents fish from waiting 10s for unanswered queries.
2416+ // `has_terminal_client` is only set when a client sends .Init
2417+ // (a real zmx attach), not when a `zmx run` tail-only client
2418+ // connects.
2419+ if (!daemon.has_terminal_client and
24172420 daemon.pty_write_buf.items.len < Daemon.PTY_WRITE_BUF_MAX)
24182421 {
24192422 util.respondToDeviceAttributes(daemon.alloc, &daemon.pty_write_buf, buf[0..n]);