Skip to content

macOS: CSRF token auto-discovery fails (no /proc) — daemon auth blocked on agy 1.2.11 #2

Open

Description

@ralphsun73221

Environment:

  • macOS 27 (Apple Silicon), zsh
  • agy 1.2.11 (installed via mise, AGY_CLI_DISABLE_AUTO_UPDATE=true)
  • agy-reader: latest (supports agy 1.2.11 per COMPATIBILITY.md)

Summary:

On macOS, watch mode cannot authenticate against the CLI daemon. The 1.2.11 CSRF token discovery documented in the README relies on Linux /proc (reading the sidecar process environment / argv), which doesn't exist on macOS, so there appears to be no working discovery path here. Every tick fails with:

[cli] watch: authentication failed; sync blocked, retrying discovery next tick
(LoadTrajectory: daemon authentication failed: HTTP 401 on LoadTrajectory
(check CSRF token discovery or ANTIGRAVITY_CSRF_TOKEN))

Additional macOS-specific observations:

  1. Process name truncation: the daemon's listener shows up in lsof as antigravi (truncated from antigravity-style name), not agy, so any name-based matching (lsof | grep agy) misses it. Matching by PID (pgrep -x agy → lsof -p <pid>) works reliably.
  2. Two ports, roles observable: the daemon listens on two ports; the lower-numbered one speaks HTTPS (returns 400 "Client sent an HTTP request to an HTTPS server" when probed over http://), the higher-numbered one is the plain-HTTP JSON-RPC endpoint. A curl http://127.0.0.1:<port>/ probe can distinguish them automatically.
  3. Token not discoverable from the environment: ps eww on the main agy process shows no ANTIGRAVITY_CSRF_TOKEN; macOS also restricts reading other processes' environments.

Workaround (currently working for me):

Start agy with an explicit token and pass it through a file:

# terminal A
TOKEN="$(uuidgen)"
echo "$TOKEN" > ~/.agy-session
agy --csrf_token="$TOKEN"

# terminal B
TOKEN="$(head -1 ~/.agy-session)"
PID=$(pgrep -x agy | head -1)
PORT=$(lsof -iTCP -sTCP:LISTEN -anP -p "$PID" 2>/dev/null \
  | grep '(LISTEN)' | awk '{print $9}' | sed 's/.*://' | sort -un | tail -1)
export ANTIGRAVITY_CSRF_TOKEN="$TOKEN"
export ANTIGRAVITY_DAEMON_URL="http://127.0.0.1:$PORT"
agy-reader --watch

Feature request:

  • Support macOS for CSRF token discovery — e.g. accept agy --csrf_token=<user-supplied> sessions, or document the manual workaround in the README for non-Linux platforms.
  • Auto-detect the HTTP endpoint among the daemon's ports (curl probe / distinguish HTTPS vs HTTP), rather than assuming port ordering.

References

Activity

  1. mjacobs commented on Oct 27, 2026

    @mjacobs
    Owner

    Thanks for the detailed report. I reproduced the authentication failure on macOS 27.0.1 (Apple Silicon), using agy 1.4.0 and a fresh agy-reader build from main at e3d9580.

    The reader found the correct HTTP endpoint, but discovered no token, and LoadTrajectory returned HTTP 401. Starting agy with --csrf_token alone did not fix discovery. Passing that same token to the reader through ANTIGRAVITY_CSRF_TOKEN made authentication succeed.

    The current CLI token-discovery implementation is Linux-only, so this remains an open macOS support gap. There are two options available now:

    For transcript exports from supported SQLite sessions, the newer offline command bypasses daemon authentication entirely:

    agy-reader export-offline --format=md /path/to/session.db
    agy-reader export-offline --format=json /path/to/session.db

    It does not require a running agy process or a CSRF token. It exports one session; it does not provide continuous watch/sync or write sync sidecars. Legacy encrypted .pb files and unsupported SQLite projections are not supported.

    For watch/sync, the pair helper launches agy and the reader together, supplying a matching token and HTTP endpoint:

    scripts/agy-pair.py run \
      --agy=/path/to/agy \
      --reader=/path/to/agy-reader

    I verified that its default argv mode authenticated successfully and started the watcher on macOS. That test used an empty temporary store, so it confirms authentication and watcher startup, not conversation-sync completeness. This mode puts the token in agy’s process arguments; use it only on a single-user machine.

    I also confirmed separate HTTP and HTTPS listeners. The reader’s log fallback selects the port explicitly logged as for HTTP, rather than relying on port ordering. I did not reproduce the truncated process name in this environment.

    Keeping this issue open: these options provide ways forward, but standalone macOS CLI token discovery remains unfixed.

  2. mjacobs commented on Nov 18, 2026

    @mjacobs
    Owner

    Thanks for reporting the 401 and pointing out the separate HTTP and HTTPS listeners. The macOS fix is now on main in #14. Run these commands from your checkout to try it.

    git switch main
    git pull --ff-only
    make build

    Run plain agy and, in a separate terminal under the same macOS account, run ./bin/agy-reader --watch from the checkout. The first sync can wait until agy runs a readable external tool, such as a shell command. Short commands can finish between polls. I used --watch-interval=2s for the test. Once the watcher discovers the credential, it can sync later text-only turns after the tool exits. A fresh doctor process needs a running tool to check daemon authentication.

    I verified this on Apple Silicon with agy 1.5.10. The watcher saved a verified transcript from a fresh conversation, then synced a later text-only turn. ./bin/agy-reader doctor --root "$HOME/.gemini/antigravity-cli" reported the CLI store healthy while the tool was active. The README covers troubleshooting and launchd setup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions