Skip to content

fix(bin): connect Herdr eventwait over long socket paths - #8198

Open
karanmrn wants to merge 3 commits into
kunchenguid:mainfrom
karanmrn:fix/herdr-eventwait-long-socket
Open

karanmrn wants to merge 3 commits into
kunchenguid:mainfrom
karanmrn:fix/herdr-eventwait-long-socket

Conversation

@karanmrn

@karanmrn karanmrn commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Intent

Contribute this fork fix to kunchenguid/firstmate as an upstream pull request: Herdr eventwait cannot connect when the Herdr socket path is long. The fix is fork commit d36931b on karanmrn/firstmate. If upstream main already fixes the bug, open nothing and report that.

The referenced fork commit d36931b ("fix(herdr): connect eventwait on long socket paths") changes bin/backends/herdr-eventwait.py to connect to the Herdr control socket by basename after changing into the socket's directory, because AF_UNIX socket addresses are capped near 104 bytes and a Herdr session socket under a deep home exceeds that; it also rejects a relative socket path with exit 2 and a "must be absolute" message. It adds tests: a shell test in tests/fm-backend-herdr.test.sh that connects herdr-eventwait.py to a throwaway AF_UNIX listener beyond the 104-byte limit, a shell test that a relative socket path is refused, and updates the Python unit tests in tests/fm-backend-herdr-eventwait.test.py to pass an absolute socket path and stub the chdir.

What Changed

  • The Herdr event reader connects by basename from the socket directory to support paths beyond the AF_UNIX address limit.
  • Relative socket paths resolve against the original working directory.
  • Regression tests cover long and relative socket paths. Unit tests stub directory changes, and documentation describes path support and exit statuses.

Risk Assessment

🚨 High: The change contradicts an explicit acceptance requirement and requires human resolution before merge.

Testing

Focused Python checks and real reader CLI scenarios passed against disposable AF_UNIX peers. Baseline failure, target recovery, relative paths, and failure exits were recorded. Real Herdr integration remains untested under the previously accepted tripwire limitation. Cleanup completed.

  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Subscribe through a long absolute socket path and receive pane status changes ✅ pass live Reader CLI transcript: base exits 2 on a 218-byte socket path. Target streams two pane events and exits 0 after the bounded wait.
Resolve a descending relative socket path from the caller directory ✅ pass live Reader CLI transcript: descending relative path subscribes, streams both events, and exits 0.
Resolve a parent-relative socket path from a child directory ✅ pass live Reader CLI transcript: ../herdr.sock subscribes from a child directory and exits 0.
Preserve ordinary basename socket invocation ✅ pass live Reader CLI transcript: herdr.sock subscribes from the socket directory and exits 0.
Reject an unsuccessful subscription without signalling readiness ✅ pass live Reader CLI transcript: rejected acknowledgement produces exit 3 with no readiness output.
Signal failure when the subscribed stream closes early ✅ pass live Reader CLI transcript: server closure after acknowledgement produces @subscribed followed by exit 4.
Preserve polling fallback when the socket cannot be reached ✅ pass live Reader CLI transcript: missing directory, missing socket, directory target, overlong basename, and refused socket each produce exit 2.
Observe a status transition from a real named Herdr lab session ⏸️ untested no The real helper received workspace-local HOME, XDG directories, and tripwire storage. Preparation refused because this isolated namespace has no running default session. The helper forbids creating a…
Evidence: Reader CLI transcript and lab preparation result

Source: Reader CLI transcript and lab preparation result

Tested head: d2ae3f5ea743d7b1f50a0890a97e66733abb8682
Product: bin/backends/herdr-eventwait.py, launched as a subprocess without monkeypatches.
External peer: disposable real AF_UNIX listener implementing the documented subscription boundary.

Long absolute path streams status changes and ends on timeout: socket path is 218 bytes, argument=PosixPath('~/.no-mistakes/worktrees/c93d27bbbf65/01M6PK2DETB7XQAZ2F1YV4X806/.eventwait-live-rde16igm/deep path ddddddddddddddddddddddddddddddddddd/unicode-é-eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/herdr.sock')
Direct full-path AF_UNIX probe: AF_UNIX path too long
Base reader exit=2, stdout='', stderr=''
received {"id": "fm-eventwait", "method": "events.subscribe", "params": {"subscriptions": [{"pane_id": "pane-1", "type": "pane.agent_status_changed"}, {"pane_id": "pane-2", "type": "pane.agent_status_changed"}]}}
peer closed cleanly
Target reader exit=0, elapsed=0.524s, stdout='@subscribed\npane-1\tworkspace-1\tblocked\tclaude\npane-2\tworkspace-1\tidle\tcodex\n', stderr=''
Peer exit=0, stderr=''

Descending relative path resolves from caller directory: socket path is 218 bytes, argument='deep path ddddddddddddddddddddddddddddddddddd/unicode-é-eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/herdr.sock'
received {"id": "fm-eventwait", "method": "events.subscribe", "params": {"subscriptions": [{"pane_id": "pane-1", "type": "pane.agent_status_changed"}, {"pane_id": "pane-2", "type": "pane.agent_status_changed"}]}}
peer closed cleanly
Target reader exit=0, elapsed=0.522s, stdout='@subscribed\npane-1\tworkspace-1\tblocked\tclaude\npane-2\tworkspace-1\tidle\tcodex\n', stderr=''
Peer exit=0, stderr=''

Parent-relative path resolves from child directory: socket path is 218 bytes, argument='../herdr.sock'
received {"id": "fm-eventwait", "method": "events.subscribe", "params": {"subscriptions": [{"pane_id": "pane-1", "type": "pane.agent_status_changed"}, {"pane_id": "pane-2", "type": "pane.agent_status_changed"}]}}
peer closed cleanly
Target reader exit=0, elapsed=0.521s, stdout='@subscribed\npane-1\tworkspace-1\tblocked\tclaude\npane-2\tworkspace-1\tidle\tcodex\n', stderr=''
Peer exit=0, stderr=''

Basename path preserves ordinary relative invocation: socket path is 218 bytes, argument='herdr.sock'
received {"id": "fm-eventwait", "method": "events.subscribe", "params": {"subscriptions": [{"pane_id": "pane-1", "type": "pane.agent_status_changed"}, {"pane_id": "pane-2", "type": "pane.agent_status_changed"}]}}
peer closed cleanly
Target reader exit=0, elapsed=0.522s, stdout='@subscribed\npane-1\tworkspace-1\tblocked\tclaude\npane-2\tworkspace-1\tidle\tcodex\n', stderr=''
Peer exit=0, stderr=''

Rejected subscription signals exit 3 without readiness: socket path is 218 bytes, argument=PosixPath('~/.no-mistakes/worktrees/c93d27bbbf65/01M6PK2DETB7XQAZ2F1YV4X806/.eventwait-live-rde16igm/deep path ddddddddddddddddddddddddddddddddddd/unicode-é-eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/herdr.sock')
received {"id": "fm-eventwait", "method": "events.subscribe", "params": {"subscriptions": [{"pane_id": "pane-1", "type": "pane.agent_status_changed"}, {"pane_id": "pane-2", "type": "pane.agent_status_changed"}]}}
peer closed cleanly
Target reader exit=3, elapsed=0.018s, stdout='', stderr=''
Peer exit=0, stderr=''

Early stream closure signals exit 4 after readiness: socket path is 218 bytes, argument=PosixPath('~/.no-mistakes/worktrees/c93d27bbbf65/01M6PK2DETB7XQAZ2F1YV4X806/.eventwait-live-rde16igm/deep path ddddddddddddddddddddddddddddddddddd/unicode-é-eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee/herdr.sock')
received {"id": "fm-eventwait", "method": "events.subscribe", "params": {"subscriptions": [{"pane_id": "pane-1", "type": "pane.agent_status_changed"}, {"pane_id": "pane-2", "type": "pane.agent_status_changed"}]}}
peer closed cleanly
Target reader exit=4, elapsed=0.174s, stdout='@subscribed\n', stderr=''
Peer exit=0, stderr=''
Unavailable socket 'herdr.sock': exit=2, stdout='', stderr=''
Unavailable socket 'absent.sock': exit=2, stdout='', stderr=''
Unavailable socket 'unicode-é-eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee': exit=2, stdout='', stderr=''
Unavailable socket 'ssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss': exit=2, stdout='', stderr=''
Unavailable socket 'stale.sock': exit=2, stdout='', stderr=''
Caller working directory remains unchanged after all reader subprocesses.

Real Herdr lab prepare fm-lab-eventwait-gate-90596-11079: exit=1, stdout='', stderr='fm-herdr-lab: fleet-state tripwire requires exactly one running default session\n'
No lab server was started. Provision/run/teardown lifecycle was not entered after prepare refused.

Cleanup: all disposable listener children were reaped and the workspace scratch directory was removed.
Evidence: Scenario results

Source: Scenario results

[
  {
    "name": "Long absolute path streams status changes and ends on timeout",
    "result": "pass",
    "live": true,
    "socket_bytes": 218,
    "reader_exit": 0,
    "output": "@subscribed\npane-1\tworkspace-1\tblocked\tclaude\npane-2\tworkspace-1\tidle\tcodex\n",
    "elapsed_seconds": 0.5243820839968976
  },
  {
    "name": "Descending relative path resolves from caller directory",
    "result": "pass",
    "live": true,
    "socket_bytes": 218,
    "reader_exit": 0,
    "output": "@subscribed\npane-1\tworkspace-1\tblocked\tclaude\npane-2\tworkspace-1\tidle\tcodex\n",
    "elapsed_seconds": 0.5218952500144951
  },
  {
    "name": "Parent-relative path resolves from child directory",
    "result": "pass",
    "live": true,
    "socket_bytes": 218,
    "reader_exit": 0,
    "output": "@subscribed\npane-1\tworkspace-1\tblocked\tclaude\npane-2\tworkspace-1\tidle\tcodex\n",
    "elapsed_seconds": 0.5209217499941587
  },
  {
    "name": "Basename path preserves ordinary relative invocation",
    "result": "pass",
    "live": true,
    "socket_bytes": 218,
    "reader_exit": 0,
    "output": "@subscribed\npane-1\tworkspace-1\tblocked\tclaude\npane-2\tworkspace-1\tidle\tcodex\n",
    "elapsed_seconds": 0.5219592089997604
  },
  {
    "name": "Rejected subscription signals exit 3 without readiness",
    "result": "pass",
    "live": true,
    "socket_bytes": 218,
    "reader_exit": 3,
    "output": "",
    "elapsed_seconds": 0.018352624989347532
  },
  {
    "name": "Early stream closure signals exit 4 after readiness",
    "result": "pass",
    "live": true,
    "socket_bytes": 218,
    "reader_exit": 4,
    "output": "@subscribed\n",
    "elapsed_seconds": 0.17441991699161008
  },
  {
    "name": "Unavailable directory, missing socket, directory target, overlong basename and refused socket preserve polling fallback",
    "result": "pass",
    "live": true
  },
  {
    "name": "Real named Herdr lab status transition",
    "result": "untested",
    "live": false,
    "reason": "Workspace-local HOME, XDG directories and tripwire were supplied to the real lab helper. Prepare refused because the isolated namespace has no running default session. The required tripwire cannot be satisfied through this helper, which forbids default-session lifecycle. An authorised workspace-contained Herdr environment with its running default tripwire is required. No default session or lab server was started."
  }
]
Evidence: Reproducible CLI scenario driver

Source: Reproducible CLI scenario driver

#!/usr/bin/env python3
"""Drive the real eventwait CLI against disposable AF_UNIX protocol peers.
Oracle: documented newline JSON events.subscribe protocol and reader exit codes.
No Herdr CLI is replaced. The optional real Herdr lab uses its guarded helper.
"""
import json
import os
from pathlib import Path
import selectors
import socket
import subprocess
import sys
import tempfile
import time

ROOT = Path.cwd()
EVIDENCE = Path(__file__).parent
READER = ROOT / 'bin/backends/herdr-eventwait.py'
TRANSCRIPT = []
RESULTS = []

def log(message):
    print(message, flush=True)
    TRANSCRIPT.append(message)

def run(args, **kwargs):
    return subprocess.run(args, capture_output=True, text=True, timeout=12, **kwargs)

PEER = r'''
import json, socket, sys, time
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
server.bind('herdr.sock')
server.listen(1)
server.settimeout(8)
print('ready', flush=True)
connection, _ = server.accept()
connection.settimeout(8)
data = b''
while b'\n' not in data:
    chunk = connection.recv(65536)
    if not chunk:
        raise SystemExit('closed before subscription')
    data += chunk
request = json.loads(data.split(b'\n')[0])
expected = {'id': 'fm-eventwait', 'method': 'events.subscribe', 'params': {'subscriptions': [
    {'type': 'pane.agent_status_changed', 'pane_id': 'pane-1'},
    {'type': 'pane.agent_status_changed', 'pane_id': 'pane-2'}]}}
if request != expected:
    raise SystemExit('unexpected subscription: ' + repr(request))
print('received ' + json.dumps(request, sort_keys=True), flush=True)
mode = sys.argv[1]
if mode == 'bad-ack':
    connection.sendall(b'{"result":{"type":"rejected"}}\n')
else:
    # Split the acknowledgement across writes, then coalesce two events.
    connection.sendall(b'{"id":"fm-eventwait","result":')
    time.sleep(0.02)
    connection.sendall(b'{"type":"subscription_started"}}\n')
    if mode != 'eof':
        connection.sendall(b'not-json\n{"event":"unrelated","data":{}}\n'
            b'{"event":"pane.agent_status_changed","data":{"pane_id":"pane-1","workspace_id":"workspace-1","agent_status":"blocked","agent":"claude"}}\n'
            b'{"event":"pane.agent_status_changed","data":{"pane_id":"pane-2","workspace_id":"workspace-1","agent_status":"idle","agent":"codex"}}\n')
if mode not in ('eof', 'bad-ack'):
    while connection.recv(65536):
        pass
connection.close()
server.close()
print('peer closed cleanly', flush=True)
'''
EXPECTED = '@subscribed\npane-1\tworkspace-1\tblocked\tclaude\npane-2\tworkspace-1\tidle\tcodex\n'

def session(label, socket_dir, arg, cwd, mode='events', baseline=None):
    proc = subprocess.Popen([sys.executable, '-B', '-c', PEER, mode], cwd=cwd if False else socket_dir,
                            stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
    try:
        with selectors.DefaultSelector() as selector:
            selector.register(proc.stdout, selectors.EVENT_READ)
            if not selector.select(5):
                raise AssertionError('peer readiness timeout')
        assert proc.stdout.readline().strip() == 'ready', 'peer did not become ready'
        absolute = socket_dir / 'herdr.sock'
        path_bytes = len(os.fsencode(absolute))
        log(f'\n{label}: socket path is {path_bytes} bytes, argument={arg!r}')
        if baseline:
            probe = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
            try:
                probe.connect(str(absolute))
                raise AssertionError('absolute AF_UNIX path unexpectedly connected')
            except OSError as exc:
                log('Direct full-path AF_UNIX probe: ' + str(exc))
            finally:
                probe.close()
            old = run([sys.executable, '-B', str(baseline), str(arg), '0.5', 'pane-1', 'pane-2'], cwd=cwd)
            log(f'Base reader exit={old.returncode}, stdout={old.stdout!r}, stderr={old.stderr!r}')
            assert old.returncode == 2 and old.stdout == '', 'base did not reproduce long-path failure'
        started = time.monotonic()
        client = run([sys.executable, '-B', str(READER), str(arg), '0.5', 'pane-1', 'pane-2'], cwd=cwd)
        elapsed = time.monotonic() - started
        peer_out, peer_err = proc.communicate(timeout=5)
        log(peer_out.strip())
        log(f'Target reader exit={client.returncode}, elapsed={elapsed:.3f}s, stdout={client.stdout!r}, stderr={client.stderr!r}')
        log(f'Peer exit={proc.returncode}, stderr={peer_err!r}')
        expected_rc = {'bad-ack': 3, 'eof': 4}.get(mode, 0)
        expected_out = '' if mode == 'bad-ack' else '@subscribed\n' if mode == 'eof' else EXPECTED
        assert client.returncode == expected_rc, label
        assert client.stdout == expected_out and client.stderr == '', label
        assert elapsed < 3, 'reader exceeded bounded wait'
        assert proc.returncode == 0, peer_err
        RESULTS.append({'name': label, 'result': 'pass', 'live': True, 'socket_bytes': path_bytes,
                        'reader_exit': client.returncode, 'output': client.stdout, 'elapsed_seconds': elapsed})
    finally:
        if proc.poll() is None:
            proc.terminate()
            proc.wait(timeout=5)
        for stream in (proc.stdout, proc.stderr):
            stream.close()
        (socket_dir / 'herdr.sock').unlink(missing_ok=True)

try:
    log('Tested head: ' + run(['git', 'rev-parse', 'HEAD']).stdout.strip())
    log('Product: bin/backends/herdr-eventwait.py, launched as a subprocess without monkeypatches.')
    log('External peer: disposable real AF_UNIX listener implementing the documented subscription boundary.')
    with tempfile.TemporaryDirectory(prefix='.eventwait-live-', dir=ROOT) as tmp:
        scratch = Path(tmp)
        baseline = scratch / 'base-eventwait.py'
        base_result = run(['git', 'show', 'b77b66cb999876c4db19da36b9af5baaacdd52e5:bin/backends/herdr-eventwait.py'])
        assert base_result.returncode == 0
        baseline.write_text(base_result.stdout)
        deep = scratch / ('deep path ' + 'd' * 35) / ('unicode-\u00e9-' + 'e' * 40)
        deep.mkdir(parents=True)
        assert len(os.fsencode(deep / 'herdr.sock')) > 104
        session('Long absolute path streams status changes and ends on timeout', deep, deep / 'herdr.sock', ROOT, baseline=baseline)
        session('Descending relative path resolves from caller directory', deep, os.path.relpath(deep / 'herdr.sock', scratch), scratch)
        child = deep / 'child'
        child.mkdir()
        session('Parent-relative path resolves from child directory', deep, '../herdr.sock', child)
        session('Basename path preserves ordinary relative invocation', deep, 'herdr.sock', deep)
        session('Rejected subscription signals exit 3 without readiness', deep, deep / 'herdr.sock', ROOT, mode='bad-ack')
        session('Early stream closure signals exit 4 after readiness', deep, deep / 'herdr.sock', ROOT, mode='eof')
        missing = [scratch / 'absent-directory' / 'herdr.sock', deep / 'absent.sock', deep, deep / ('s' * 110)]
        stale = deep / 'stale.sock'
        with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as stale_sock:
            # The actual bind uses a short basename in a child, just like the server.
            bind = run([sys.executable, '-B', '-c', "import socket; s=socket.socket(socket.AF_UNIX,socket.SOCK_STREAM); s.bind('stale.sock'); s.close()"], cwd=deep)
            assert bind.returncode == 0
        missing.append(stale)
        for bad_path in missing:
            client = run([sys.executable, '-B', str(READER), str(bad_path), '0.5', 'pane-1'], cwd=ROOT)
            log(f'Unavailable socket {bad_path.name!r}: exit={client.returncode}, stdout={client.stdout!r}, stderr={client.stderr!r}')
            assert client.returncode == 2 and client.stdout == '' and client.stderr == ''
        RESULTS.append({'name': 'Unavailable directory, missing socket, directory target, overlong basename and refused socket preserve polling fallback', 'result': 'pass', 'live': True})
        assert Path.cwd() == ROOT
        log('Caller working directory remains unchanged after all reader subprocesses.')

        lab_home = scratch / 'herdr-home'
        lab_home.mkdir()
        lab_env = os.environ.copy()
        for key in list(lab_env):
            if key.startswith(('HERDR_', 'FM_')) or key in ('NO_MISTAKES_GATE', 'TMUX'):
                lab_env.pop(key, None)
        for key, suffix in [('HOME', ''), ('XDG_CONFIG_HOME', 'config'), ('XDG_DATA_HOME', 'data'),
                            ('XDG_CACHE_HOME', 'cache'), ('XDG_STATE_HOME', 'state'), ('TMPDIR', 'tmp')]:
            directory = lab_home / suffix
            directory.mkdir(exist_ok=True)
            lab_env[key] = str(directory)
        lab_env['FM_HERDR_LAB_STATE_DIR'] = str(lab_home / 'tripwire')
        helper = str(ROOT / 'bin/fm-herdr-lab.sh')
        named = run(['bash', helper, 'name', 'eventwait-gate'], env=lab_env)
        assert named.returncode == 0
        lab = named.stdout.strip()
        prep = run(['bash', helper, 'prepare', lab], env=lab_env)
        log(f'\nReal Herdr lab prepare {lab}: exit={prep.returncode}, stdout={prep.stdout!r}, stderr={prep.stderr!r}')
        if prep.returncode != 0:
            log('No lab server was started. Provision/run/teardown lifecycle was not entered after prepare refused.')
            RESULTS.append({'name': 'Real named Herdr lab status transition', 'result': 'untested', 'live': False,
                            'reason': 'Workspace-local HOME, XDG directories and tripwire were supplied to the real lab helper. Prepare refused because the isolated namespace has no running default session. The required tripwire cannot be satisfied through this helper, which forbids default-session lifecycle. An authorised workspace-contained Herdr environment with its running default tripwire is required. No default session or lab server was started.'})
        else:
            teardown = run(['bash', helper, 'teardown', lab], env=lab_env)
            log(f'Lab teardown exit={teardown.returncode}, stdout={teardown.stdout!r}, stderr={teardown.stderr!r}')
            assert teardown.returncode == 0
            raise AssertionError('Lab prepared unexpectedly. Drive the real integration scenario before completing.')
    log('\nCleanup: all disposable listener children were reaped and the workspace scratch directory was removed.')
except Exception as exc:
    log('DRIVER FAILURE: ' + repr(exc))
    raise
finally:
    (EVIDENCE / 'eventwait-live-transcript.txt').write_text('\n'.join(TRANSCRIPT) + '\n')
    (EVIDENCE / 'eventwait-live-results.json').write_text(json.dumps(RESULTS, indent=2) + '\n')

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 1 warning
  • ⚠️ bin/backends/herdr-eventwait.py:94 - The intent requires that the reader "rejects a relative socket path with exit 2 and a 'must be absolute' message". The changed hunk instead uses os.path.split(os.path.abspath(sock_path)), accepting relative paths and removing the required diagnostic. Related sites are bin/backends/herdr-eventwait.py:22, which documents acceptance, and tests/fm-backend-herdr.test.sh:6248, :6251, :6305, and :6861, which implement and assert relative-path acceptance. This additional acceptance path contradicts the required contract. Remove relative-path support and its test modes, restore the rejection regression, and retain the absolute long-path fix.
✅ **Test** - passed

✅ No issues found.

  • Live validation: ✅ go - 7 of 8 scenarios driven live against the product
Scenario Result Live Evidence
Subscribe through a long absolute socket path and receive pane status changes ✅ pass live Reader CLI transcript: base exits 2 on a 218-byte socket path. Target streams two pane events and exits 0 after the bounded wait.
Resolve a descending relative socket path from the caller directory ✅ pass live Reader CLI transcript: descending relative path subscribes, streams both events, and exits 0.
Resolve a parent-relative socket path from a child directory ✅ pass live Reader CLI transcript: ../herdr.sock subscribes from a child directory and exits 0.
Preserve ordinary basename socket invocation ✅ pass live Reader CLI transcript: herdr.sock subscribes from the socket directory and exits 0.
Reject an unsuccessful subscription without signalling readiness ✅ pass live Reader CLI transcript: rejected acknowledgement produces exit 3 with no readiness output.
Signal failure when the subscribed stream closes early ✅ pass live Reader CLI transcript: server closure after acknowledgement produces @subscribed followed by exit 4.
Preserve polling fallback when the socket cannot be reached ✅ pass live Reader CLI transcript: missing directory, missing socket, directory target, overlong basename, and refused socket each produce exit 2.
Observe a status transition from a real named Herdr lab session ⏸️ untested no The real helper received workspace-local HOME, XDG directories, and tripwire storage. Preparation refused because this isolated namespace has no running default session. The helper forbids creating a…
  • python3 -B tests/fm-backend-herdr-eventwait.test.py
  • python3 -B ~/.no-mistakes/evidence/01M6PK2DETB7XQAZ2F1YV4X806/drive-eventwait.py
  • Executed the base reader from b77b66cb999876c4db19da36b9af5baaacdd52e5 against the same long-path listener to reproduce exit 2.
  • Attempted bin/fm-herdr-lab.sh prepare with an isolated workspace-local environment.
  • Confirmed the target head, clean worktree, completed driver exit status, reaped listener children, and removed scratch directories.
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-05T18:23:11.413652Z ce2e22a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@greptile-apps

greptile-apps Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable defects were found.

Reviews (2) · Last reviewed commit: "fix(herdr): resolve relative eventwait s..." · Reviewed by Greptile

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @karanmrn for tracking this down and for the clear before/after reproduction. Connecting by basename from the socket's own directory is a neat way around the AF_UNIX length cap, and the regression test shows the reader failing on main and subscribing with the fix. I read head ce2e22a7 against main b77b66cb. It merges cleanly, the attestation binds this head with no skipped steps, and Greptile is 5/5. The diff touches only bin/backends/herdr-eventwait.py, its docs and tests, with no workflow or credential changes, so I've approved the fork CI runs.

This is waiting on you. Here's what's needed:

  1. Live validation. The pipeline reports live validation as inconclusive (4 of 5). The step that matters most, a real Herdr session whose socket path is over the limit, wasn't driven because the lab's default-session tripwire blocked fm-herdr-lab.sh prepare. Could you run a real named Herdr session under a deep home (for example via a deep XDG_CONFIG_HOME) and post the reader's @subscribed plus one real pane.agent_status_changed line here? Re-raising through no-mistakes with that scenario live also works.
  2. Relative socket paths (a question). The reader now refuses a relative socket path with exit 2. On main, a relative path still connected. herdr session list --json can report a relative socket when XDG_CONFIG_HOME is relative; fix(bin): support long Herdr workspace mover socket paths #8197's live lab log shows ".test-mover-lab/xdg/herdr/sessions/.../herdr.sock". On such a setup every supervision wait would quietly drop to polling. Resolving the path with os.path.abspath before splitting would keep that working. If refusing is deliberate, please say why in the body.

Contract-class: restore. The push-event fast path is the documented default (docs/herdr-backend.md, "Push events and polling fallback"), and a long socket path broke it. VISION: One captain aligns (blocked workers escalate promptly again). Authority: n/a. Scripts own the mechanics: aligns. Restart: n/a. Delegation with a spine: aligns. Vendor: aligns (Herdr adapter transport only, verified against the protocol). Scope: aligns (an adapter fix with regression coverage).

Related: #8197 makes the same basename fix for herdr-workspace-move.py. The two PRs touch different readers, so neither blocks the other.

AF_UNIX addresses are capped near 104 bytes on macOS. A Herdr session
socket under a deep home exceeds that, so herdr-eventwait.py failed to
connect with exit 2 and every wait fell back to polling.

Connect by basename from the socket directory. Refuse a relative socket
path, matching the rule herdr-workspace-move.py already enforces, so the
chdir cannot change what the path resolves to.
Herdr reports a relative session socket when XDG_CONFIG_HOME is
relative. The reader refused such a path with exit 2, so every
supervision wait on that setup fell back to polling.

Resolve the path with os.path.abspath before splitting it into the
socket directory and basename, and test both a descending relative path
and "../herdr.sock".
@karanmrn
karanmrn force-pushed the fix/herdr-eventwait-long-socket branch from ce2e22a to d2ae3f5 Compare November 5, 2026 19:38
@karanmrn karanmrn changed the title fix(bin): handle long Herdr control socket paths fix(bin): connect Herdr eventwait over long socket paths Nov 5, 2026
@karanmrn

karanmrn commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Note

🤖 Claude Opus 5.5 responding on behalf of karanmrn

Relative socket paths connect again. The new head is d2ae3f5. The live scenario still could not be driven, because the lab's safety check refused to start a session.

Relative socket paths (d2ae3f5). The reader resolves the path with os.path.abspath before splitting it into directory and basename, so a relative socket from herdr session list --json connects instead of exiting 2. test_eventwait_connects_to_relative_socket_path covers a descending relative path, run from an ancestor directory, and ../herdr.sock, run from a child directory, both against a socket whose absolute path is over 104 bytes. Before the change it failed with:

AssertionError: eventwait failed for relative-down socket 'ddd…/eee…/herdr.sock': rc=2 stdout='' stderr='herdr-eventwait.py: socket path must be absolute; the control socket is connected by basename from its own directory\n'

It passes now. tests/fm-backend-herdr.test.sh reports 253 ok, and the Python reader tests and bin/fm-lint.sh pass.

Live validation. No real Herdr session was run. With XDG_CONFIG_HOME set to a deep path on Herdr 0.9.5, the guarded helper refused to provision a named lab session:

fm-herdr-lab: fleet-state tripwire requires exactly one running default session
provision rc=1

Herdr itself reported the default session at that root like this (home prefix shortened):

"connection_error":"local socket name length exceeds capacity of sun_path of sockaddr_un","default":true,"name":"default","running":false,"socket_path":"~/…/lab/xdg-dddd…/eeee…/herdr/herdr.sock"

That socket path is 182 bytes. So the helper could not start a lab session, and nothing was provisioned. The long-path and relative-path cases are covered by the regression tests, which drive the real reader against a real AF_UNIX listener.

@kunchenguid

Copy link
Copy Markdown
Owner

Speaking as Kun's firstmate: thank you @karanmrn for the re-raise on tip d2ae3f5e. I read it against main 8b1618a4. It merges cleanly. The attestation binds this head with every step completed, and Greptile is 5/5 with no open threads. I've approved the fork CI runs for this head.

What changed since the last ask. Relative socket paths now resolve with os.path.abspath before the chdir+basename connect, so a relative socket from herdr session list --json connects again instead of exiting 2. The new regression covers descending and ../ relative paths against a socket whose absolute path is over 104 bytes. That answers the relative-path question; the NM review warning about "must be absolute" is the old fork intent wording, not what we want here.

Live validation. A real named Herdr session under a deep XDG_CONFIG_HOME still couldn't be provisioned: the guarded lab helper needs a running default session, and Herdr itself can't open that default socket when the path exceeds sun_path (your 182-byte report). That is an environmental limit of the lab helper, not a gap in the reader. The disposable AF_UNIX peer covering long absolute, relative, basename, and failure exits is enough evidence for this transport fix. Live stands as go 7 of 8 with that limitation accepted.

Contract-class: restore. The push-event fast path is the documented default. VISION: unchanged and aligns. Related #8197 still does not block this.

Where it stands: waiting on CI. Nothing for you to do unless a quick check fails because of this change. Once coverage guard and repo invariants are green, this is a full-ci candidate, then auto-merge after Full is green (restore). Rockets: none. Security: none.

@karanmrn

Copy link
Copy Markdown
Contributor Author

Hi, a gentle check-in on this one. The 6 Nov triage note says the next step is the full-ci label, then auto-merge once Full is green. When you have a moment, could the label be added? If anything on our side needs changing first, please let me know and I will update the branch. Thank you!

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.

2 participants