Skip to content

release: 1.8.1 - #1992

Merged
fujibee merged 4 commits into
mainfrom
integration/1.8.1
Nov 18, 2026
Merged

fujibee merged 4 commits into
mainfrom
integration/1.8.1

Conversation

@fujibee

@fujibee fujibee commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Release 1.8.1: delivery fixes for agmsgd under launchd and for grok-build.

Contents

Checked before release

Installed from this branch on a Mac with install.sh --update --cmd agmsg, which restarts the launchd-registered agmsgd the way a user's update does.

  • Antigravity (terminal-poke): an agy TUI opened by hand in a herdr pane received a message and replied (18 s and 33 s round trips on two daemon generations).
  • grok-build (grok-queue): a grok TUI with use_leader = true was switched with agmsg delivery agmsgd --type grok-build --project <dir>; the leader socket was found from the TUI's own child, status showed it addressable, and a message went out and a reply came back in 31 s.
  • With two grok-build registrations for one project, status named both and said how to resolve it.

Not yet checked on a real machine: the Windows (Git Bash) path of the agmsgd offer.

…1988)

## Problem

launchd starts agmsgd with `PATH=/usr/bin:/bin:/usr/sbin:/sbin` (measured on the running 1.8.0 agmsgd), and systemd `--user` has no `~/.local/bin` either. herdr and tmux installed in `~/.local/bin` or Homebrew are therefore not found by agmsgd's children. terminal-nudge.sh's readiness check (`terminal_team_input_ready`) answered every herdr/tmux-placed seat with `unknown:terminal_unreachable`, so the terminal-poke channel never delivered to an Antigravity seat in a herdr pane. Earlier real-machine checks ran agmsgd from a shell (`agmsg daemon start`, unregistered), which inherits the full PATH, so this path was never exercised.

## Change

- Each bundled terminal driver names its CLI in `terminal.conf` (`bin=herdr`, `bin=tmux`, `bin=orca`).
- `agmsg daemon start` (also run by `enable` and by `install --update`) records the directories those CLIs are found in, in `run/agmsgd-tool-path`. A directory recorded earlier is kept while it still exists, so a start from a shell that lacks one CLI does not drop it.
- agmsgd appends the recorded directories to its own PATH once at startup (`scripts/daemon/tool-path.mjs`), before the first poll, so every channel child inherits them. They are appended, not prepended, so the system directories keep precedence. Relative or missing entries are ignored. Windows is skipped.
- When the CLI is still missing, the readiness answer is now `unknown:<cli>_not_on_path`, and `agmsg daemon status` names the CLI and gives the steps that apply it (from a shell where it works, `agmsg daemon stop`, then `agmsg daemon start`), instead of a generic "readiness could not be checked (terminal_unreachable)".

There is no change to the launcher (bootstrap) or the install.db schema. An existing install gets the record at its next update, because the update restarts agmsgd through `daemon start`.

## Process spawns

`daemon start` runs these once per invocation (not per seat, not per poll):

- `$(_tool_path_file)`: one subshell.
- `bins`: the capture (one subshell) plus one `grep` and one `sed` over the bundled manifests.
- One `$(command -v …)` subshell per declared CLI (3 today; `command -v` itself is a builtin).
- `mkdir -p`, plus the `$(mktemp …)` capture and `mktemp`, then `mv`. On failure, one `rm` of the temp file mktemp created.
- The existing `$(_os)` capture, which runs `uname`.
- Measured on this Mac (bash 3.2): about 15 ms per call.
- The already-running path adds no process: it compares the record with `run/agmsgd-tool-path.applied` using builtins.

agmsgd adds no process. At startup only, it reads the record, stats each entry, and writes `.applied` (a file write plus rename). There is no new poll or timer.

## Failure reporting

- start: if the record cannot be written (the run dir, the temp file, the write, the replace, or a non-file at its path), start warns on stderr with the reason. start still succeeds, and agmsgd still starts. The only path ever removed is the temp file mktemp just created. If even that removal fails, it is added to the warning and does not end start under errexit.
- agmsgd: a record that exists but cannot be read (for example `EISDIR` or `EACCES`) is logged with the reason, not treated as "nothing recorded". A failure to write `.applied` is logged too. Neither stops agmsgd.
- If start finds agmsgd already running and the recorded directories differ from what it applied, start says the new directories take effect after `agmsg daemon stop`, then `agmsg daemon start`. agmsgd reads the record only at startup and is never restarted automatically.

## Tests

- `tests/agmsgd_tool_path.test.mjs` (new): appended after the minimal PATH; relative, missing, duplicate and already-present entries skipped; no record or Windows leaves PATH unchanged; an unreadable record (EISDIR) is reported; `.applied` records the line read.
- `tests/test_agmsgd_daemon_sh.bats`: start records the directory of a CLI found on PATH; an earlier entry is kept while its directory exists and dropped once it is gone; a record that cannot be written is warned about and start still succeeds; a failed replace whose temp cleanup also fails (mv and rm both failing, under `set -euo pipefail`) is reported and the caller continues; start on an already-running agmsgd with a newer record prints the stop/start steps.
- `tests/agmsgd_status_display.test.mjs`: the `herdr_not_on_path` status text.
- `tests/test_terminal_nudge.bats`: the herdr-not-on-PATH readiness case now expects `unknown:herdr_not_on_path`.

## Real-machine check (macOS)

Run on a throwaway install with all agmsg paths under a temporary directory (no change to the real home: 0 file differences), against real herdr panes, with this branch at 35db428.

- Before (agmsg 1.8.0, live): an Antigravity seat placed in a herdr pane was never nudged. agmsgd's log showed `terminal_poke ... unknown:terminal_unreachable` on every attempt, and agmsgd's PATH was `/usr/bin:/bin:/usr/sbin:/sbin`.
- `agmsg daemon start` from a normal shell wrote `run/agmsgd-tool-path` = `<home>/.local/bin:/opt/homebrew/bin` (herdr and tmux).
- `agmsg daemon stop`, then `env PATH=/usr/bin:/bin:/usr/sbin:/sbin bash agmsg daemon start`, the same PATH launchd gives it. agmsgd logged `startup: PATH += <home>/.local/bin:/opt/homebrew/bin (recorded terminal CLI directories)`.
- A message to an Antigravity seat running in a herdr pane:
  - First attempt: held as `input_box_not_found`, because the seat was on a file-access confirmation screen. That is the intended refusal, and it shows the herdr readiness and screen checks now run.
  - After the screen was dismissed, the retry at 00:19:55Z logged `sent ... accepted`, and the nudge text appeared in the pane at 00:19:56Z.

Not run: Linux under systemd `--user`, which goes through the same code path (the unit's PATH also lacks `~/.local/bin`).
…ld/terminal-poke types (#1989)

## What

Two 1.8.0 dogfooding findings, bundled into one PR:

**(A) An ambiguous grok-build seat resolution was silent.** When a project has
more than one grok-build registration, `agmsg_grok_resolve_seat` correctly
refuses to guess which one a session belongs to -- but both SessionStart and
Stop then did nothing at all: no witness (correct), but also no pending
reason, so `agmsg daemon status` could not tell this apart from a project
that simply never configured grok-build. Both hooks now go through a new
`agmsg_grok_resolve_seat_for_session`: when 2+ registrations exist, it first
checks whether exactly one candidate's own witness file already names this
exact session id (a confirmed fact from an earlier event, never a guess),
and only falls back to recording the ambiguity -- naming every candidate --
on each candidate's own pending-reason file when nothing distinguishes them.
That reason surfaces through the channel's existing pending-reason read path
(`grok-queue.mjs`), no changes needed there or in `status.mjs`.

**(B) `daemon.sh offer` refused every type except claude-code/codex.** This
was wrong for grok-build (has its own native channel, grok-queue) and for any
other type terminal-poke already reaches (antigravity, via its own
`input_prompt_marker`). The gate now mirrors the two checks
`terminal-poke-store.mjs`/`terminal-poke-types.mjs` already use to build
their own roster: a native type (claude-code/codex/grok-build) is always
offered; any other type is offered only when its `type.conf` has not turned
poke delivery off and names a verified input box, with a specific reason
otherwise. `delivery-cli.sh`'s own status line reads straight from this
offer, so it picks up the same fix with no separate change there.

**(B, review round 1)** the terminal-poke eligibility check's dynamic
`import()` URL was built as a literal `'file://' +` the native path in bash.
Any install path containing a URL-special character (a bare `#` reproduces
it) threw `ERR_MODULE_NOT_FOUND`, silently folded into the generic "agmsgd
does not deliver to `<type>` sessions". Node now takes the plain native
path as an argument and builds the URL itself via `pathToFileURL`, and any
import/check failure is reported through its own message instead of being
swallowed.

**(B, review round 2)** that still was not enough under Git Bash on
Windows: `SCRIPT_DIR`/`SKILL_DIR` there are MSYS paths (`/c/Users/...`),
which Windows Node's own path rules read as drive-relative rather than the
real location -- and `installRoot` needed the same conversion, since
`typeConfGet`'s `readFileSync` runs under the same native node and would
otherwise misread every type as having no verified input box. Both paths
are now converted to a native Windows form first (`cygpath -w` preferred,
`cd`+`pwd -W` fallback), the same way the existing codex/Windows branch in
this function already does it.

## Process count / time (§4)

- (A) adds no new process spawn on the common (single-registration) path.
  The ambiguous path (2+ registrations, expected rare) writes one
  pending-reason file per candidate -- O(n) in registration count, each a
  witness-hash computation plus one `agmsg_write_atomic` call, never polled.
  Measured: ~1.8s end to end for a 2-candidate `grok-stop.sh` run on this
  machine, including sourcing.
- (B) adds exactly one Node invocation per `daemon.sh offer <type>` call for
  a non-native type, on top of the `_resolve_node`/capture/`tr` cost already
  in this function, plus (Windows only) one `cygpath`/`pwd -W` call per path
  converted (2 total) -- same cost class as the existing storage-gate.mjs /
  Windows-codex checks. `offer` is called interactively from the
  delivery-choice screen, never polled or looped. Measured: ~0.2s per offer
  call end to end (non-Windows).

## §10 (automatic stop/refuse)

No new automatic stop/refuse. (A) makes an existing silent no-op visible as
a status reason; it still never guesses between candidates. (B) makes
agmsgd *available* where it previously refused for a type it can already
deliver to; the two URL/path fixes remove path-dependent false refusals
rather than adding any new one.

## Tests

- (A): six cases -- ambiguous records the reason on every candidate (both
  hooks), a matching witness narrows to exactly one, no regression on the
  existing "writes no witness" case.
- (B): eight cases -- grok-build offered, a verified-input-box type offered
  via terminal-poke, an unverified type's specific reason,
  `poke_delivery=no`'s specific reason, no-Node still disables a
  poke-eligible offer, a `#`-containing install path still offers correctly,
  a broken module reports its own import error, and (Windows) both the
  module path and installRoot are converted via a stubbed `cygpath -w`
  before reaching a node wrapper that captures the actual argv received.
- Mutation-confirmed: all fourteen go red against the prior behavior.
- Run scoped (`-f` against only the specific test names changed or added,
  never the whole file, `taskpolicy -b`); green under both the default
  toolchain and `/bin/bash` 3.2.
- Other CI gate scripts (including the kill-0-ownership gate) at their
  existing baselines.

## Real-machine check

None from this worktree -- the live install and the real `~/.grok` are out
of scope here; left to the usual real-machine round before this lands. The
Windows path-conversion fix is stub-tested only (bash's own `pwd` builtin
cannot be overridden via a PATH stub for the fallback branch) -- a real
Windows/Git Bash run is worth confirming before release.
…hild (#1991)

## Problem

`agmsg delivery agmsgd` for grok-build sets `use_leader = true` under `[cli]` in `~/.grok/config.toml`, and the user restarts the Grok session. The TUI then runs in leader mode: `grok --resume <id>` has a `grok agent leader` child, and `~/.grok/leader.sock` is listening. But it does not pass `GROK_LEADER_SOCKET` to its hooks. Measured on Grok Build 1.0.77: the variable is absent from the TUI, from its leader, and from the hook shell.

The hooks took the socket from that variable only, because of the fix that removed the blind default-path fallback. So the witness of every such seat recorded `"leader_socket": ""`. `agmsg daemon status` said "grok is not running in leader mode", and agmsgd never delivered to the seat. Earlier real-machine checks started the TUI with an explicit `--leader-socket`, which does pass the variable, so this path was not exercised.

## Change

`agmsg_grok_leader_socket_for <session_pid> <grok_home>` (scripts/internal/grok-session-witness.sh) answers with one of three verdicts: `found <socket>`, `none`, or `unknown <reason>`.

1. If `GROK_LEADER_SOCKET` is set, the verdict is found, with that value, as before.
2. Otherwise, `ps -A -o pid= -o ppid= -o comm=` lists the children of the session's own process (the pid from `active_sessions.json`). pid and ppid are separate columns, and the command comes last, so a path with spaces stays whole. A child counts only when:
   - the basename of its executable is exactly `grok`, and
   - its argv begins exactly `agent leader`. The argv is read from `/proc/<pid>/cmdline` where that exists (exact, NUL-separated). Elsewhere it comes from `ps -p <pid> -o args=`, checked against the exact executable path as its prefix.
3. The child's `--leader-socket` (either form) is read without splitting on spaces: from the cmdline on Linux, or on macOS from the leader's own bound unix socket (one `lsof -U` call, only when the flag is present). With no flag, the socket is `GROK_HOME/leader.sock`.
4. Any of these gives `unknown` with the reason, never "no leader": a ps failure, a `grok` child whose own argv cannot be read (`/proc` cmdline or `ps -p` failing or empty), or a `--leader-socket` whose path cannot be read.

Both hooks use it:

- SessionStart, once the session's pid is known.
- Stop, when it creates a witness.
- Stop also fills the socket into this session's existing witness when that witness was written empty. It clears or rewrites the pending reason only after the witness update succeeds. A failed update records why, in the same order the recovery branch uses.

When the verdict is `unknown`, the witness keeps an empty socket and the reason is written as the seat's pending reason. `agmsg daemon status` shows that reason instead of "grok is not running in leader mode". Only a confirmed `none` produces that message.

## What stays the same

- A TUI with no leader child keeps an empty socket. agmsgd's connect probe then never connects to it, and never has a leader started for it, which is what the earlier fallback removal was for.
- A leader started by an earlier TUI and merely shared by this one is not this session's child. It is not adopted, and that seat keeps the "not in leader mode" reason.
- No new stop or refusal; this removes a case where delivery silently never happened.
- Windows (MSYS) is unchanged.

## Process spawns

These run only while `GROK_LEADER_SOCKET` is unset, and in Stop only while the witness's socket is still empty. Once the socket is recorded, the per-turn cost is zero.

- One `ps` for the process table.
- Per `grok` child: one `ps -p`, or `tr` over its `/proc` cmdline plus two `sed`.
- With `--leader-socket`: `lsof`, `sed`, `sort` and `grep`.
- Reading the result: one `$(…)` capture plus two `sed` (`agmsg_grok_resolve_leader_socket`).
- Stop's fill-in path also has the `_wpid` sed/head capture and the JSON escape sed capture.
- Measured about 70 ms per lookup on macOS.

## Tests

`tests/test_grok_session_witness.bats` uses a stub `ps` (table plus `-p … -o args=`), a stub `lsof`, and a fake `/proc` through `AGMSG_GROK_PROC_DIR`:

- The session's own child leader gives `GROK_HOME/leader.sock`.
- An executable path with spaces is matched whole.
- A `--leader-socket` with spaces is read whole from the bound socket, in both flag forms (ps args path).
- `/proc` cmdline gives the exact argv, with a socket containing spaces, in both flag forms.
- `notgrok`, `grok agent stdio`, and a leader that is not this session's child are not adopted. The result is `none`, with no pending reason.
- `ps` exiting non-zero is `unknown`, recorded as the pending reason.
- `--leader-socket` with an unreadable path is `unknown`.
- Stop fills an empty socket once the leader is found, and clears the pending reason.
- A grok child whose argv cannot be read is `unknown`.
- When the socket is found but the witness update fails, the reason is recorded and the pending reason is not just cleared.
- Existing cases still pass.

`tests/agmsgd_status_display.test.mjs` covers `leader_socket_unknown:<reason>`, which shows the reason.

## Real-machine check

To be run on this Mac's live install after it lands in `integration/1.8.1`:

- agmsgd launched by launchd.
- The mode switched with `agmsg delivery agmsgd`.
- A Grok TUI in leader mode through `use_leader`, resumed the normal way.
- A message round trip.

The lookup itself was checked against the live process table: it returns `~/.grok/leader.sock` for a `use_leader` session and nothing for a non-leader Grok session.
VERSION, package.json and .claude-plugin/plugin.json set to 1.8.1, and the [1.8.1] section added to CHANGELOG.md. The Release notes are built from that section (#1987).
@fujibee
fujibee merged commit 6acb58a into main Nov 18, 2026
84 of 86 checks passed
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.

1 participant