Skip to content

01a0343a - Discover Postgres.app binaries for the device daemon - #31

Open
TaprootFreak wants to merge 10 commits into
developfrom
01a0343a-follow-reconnect
Open

01a0343a - Discover Postgres.app binaries for the device daemon#31
TaprootFreak wants to merge 10 commits into
developfrom
01a0343a-follow-reconnect

Conversation

@TaprootFreak

Copy link
Copy Markdown
Contributor

EN:
The device daemon crash-loops when PostgreSQL lives in Postgres.app, because pg_ctl is not on the user-service PATH. This change searches those well-known extra bin directories and, when AGENT_PG_BIN is set at install time, writes it into the service unit so knock and sync --follow stay up.

DE:
Der Device-Daemon stürzt in einer Schleife ab, wenn PostgreSQL über Postgres.app läuft, weil pg_ctl nicht im PATH des User-Service liegt. Die Änderung sucht diese bekannten Extra-Bin-Verzeichnisse und schreibt AGENT_PG_BIN bei der Installation in die Service-Unit, damit knock und sync --follow laufen bleiben.

Details

Live watch on the hub needs the device daemon to keep agent sync --follow running. On a Mac using Postgres.app, launchd starts the daemon with a PATH that does not include /Applications/Postgres.app/Contents/Versions/.... Knock then exits pg_ctl is not installed, the supervisor dies, and the website terminal stays empty after the websocket drops.

_bin now also considers:

  • /Applications/Postgres.app/Contents/Versions/latest/bin
  • numbered version directories under that tree, newest first

install_and_start_service persists a non-empty AGENT_PG_BIN into the unit environment.

Tests: tests/test_pg.py, extra cases in tests/test_daemon.py.

@TaprootFreak

Copy link
Copy Markdown
Contributor Author

EN:
Ready after 2 review passes.
The device daemon finds Postgres.app pg_ctl and keeps AGENT_PG_BIN across reinstalls so live sync stays up.

DE:
Bereit nach 2 Review-Durchläufen.
Der Device-Daemon findet pg_ctl unter Postgres.app und behält AGENT_PG_BIN beim Reinstall, damit der Live-Sync stehen bleibt.

Details

Gates at head 26f4a81:

  • pytest SUCCESS
  • mergeable MERGEABLE, mergeStateStatus CLEAN
  • no issue comments, reviews, review comments, or unresolved threads
  • all four commits verified

Pass 1: extra-bin discovery needed numeric version sort, persist-on-reinstall, and PATH-before-extras. Those landed in follow-up commits.

Pass 2: 0 findings. Tests cover extra-dir fallback, PATH precedence, unit unescape, and reinstall keep.

@TaprootFreak
TaprootFreak marked this pull request as ready for review August 24, 2026 22:42
The user-service PATH often lacks Postgres.app, so knock exits and
sync --follow never stays up. Search well-known extra bins and persist
AGENT_PG_BIN in the service unit when it is set at install time.
Numbered extra bins now match dotted version names and sort as integer
tuples so 16 beats 9.6. Reinstall keeps a stored AGENT_PG_BIN unless the
variable is explicitly empty. Extra bin discovery runs only after PATH.
Add a PATH-miss extra-dir hit for _bin and an install/reinstall
pytest that keeps AGENT_PG_BIN in the written service unit.
…G_BIN

_bin now has a test that PATH wins when both PATH and extra dirs have
pg_ctl. Reading AGENT_PG_BIN back from the unit undoes XML escape and
shell quoting so a reinstall keeps the original path.
@TaprootFreakAI

Copy link
Copy Markdown
Collaborator

EN:
Rebased onto the current develop after #44: the two conflicts in daemon.py were resolved by merging both sides — service_extra_env() now keeps AGENT_PG_BIN (from the environment or the existing unit) and also forwards AGENT_PG_DSN into the service unit; the branch is force-pushed with --force-with-lease and the four lane verdicts are re-run on the new head.

DE:
Nach #44 auf das aktuelle develop rebased: die zwei Konflikte in daemon.py wurden durch Zusammenführen beider Seiten gelöst — service_extra_env() behält AGENT_PG_BIN (aus der Umgebung oder der bestehenden Unit) und gibt zusätzlich AGENT_PG_DSN in die Service-Unit weiter; der Branch wurde mit --force-with-lease gepusht, die vier Lane-Verdikte laufen auf dem neuen Head erneut.

@TaprootFreakAI
TaprootFreakAI force-pushed the 01a0343a-follow-reconnect branch from 26f4a81 to a28df87 Compare August 29, 2026 18:56
@TaprootFreakAI

Copy link
Copy Markdown
Collaborator

EN:
Two non-blocking observations for the author, surfaced by the logic gate after the rebase: AGENT_PG_BIN is now kept across reinstalls but AGENT_PG_DSN is still taken from the environment only (a reinstall without the variable drops it from the unit), and on Linux a malformed Environment=AGENT_PG_BIN= line falls back to the raw string instead of None.

DE:
Zwei nicht blockierende Hinweise an den Autor aus dem Logik-Gate nach dem Rebase: AGENT_PG_BIN bleibt jetzt über Reinstalls erhalten, AGENT_PG_DSN kommt aber weiterhin nur aus der Umgebung (ein Reinstall ohne die Variable entfernt sie aus der Unit), und unter Linux fällt eine fehlerhafte Environment=AGENT_PG_BIN=-Zeile auf den Rohstring statt auf None zurück.

Details
  • src/agent_cli/daemon.py, service_extra_env: BIN has env-wins / explicit-empty-clears / keep-from-unit semantics; DSN has env-only semantics (introduced by f07aaefa - Create the local cluster only in agent init #44, not by this PR). Mirroring the three-state logic for DSN, or documenting the asymmetry, would be a follow-up.
  • src/agent_cli/daemon.py, existing_service_agent_pg_bin, linux branch: except ValueError: return raw or None — returning None would match the darwin branch (malformed plist → None) and let discovery retry instead of persisting an unparseable value.
  • Tests cover & and spaces for the escaping round trip; <, >, ", a malformed plist and a missing key are untested.

@TaprootFreakAI

Copy link
Copy Markdown
Collaborator

EN:
Rebased onto develop (after #44) and taken through the four review gates; on head d7ed16a all four are approved (Grok quality, Grok logic, Codex quality, Codex logic), CI is green (560 tests) and the PR is mergeable. Six check-fix commits on top of the four author commits: plistlib for the launchd plist, adoption only from the unit that belongs to this home, token-wise last-wins parsing of systemd Environment= lines, and the kept AGENT_PG_BIN is now adopted for every command that reaches pg_ctlopen_store(), daemon --uninstall (before the unit is removed) and pg status|stop.

DE:
Auf develop (nach #44) rebased und durch die vier Review-Gates geführt; auf Head d7ed16a sind alle vier approved (Grok Qualität, Grok Logik, Codex Qualität, Codex Logik), CI ist grün (560 Tests) und der PR ist mergeable. Sechs Check-Fix-Commits über den vier Autor-Commits: plistlib für das launchd-Plist, Übernahme nur aus der Unit, die zu diesem Home gehört, tokenweises Last-wins-Parsing der systemd-Environment=-Zeilen, und das gespeicherte AGENT_PG_BIN wird jetzt für jeden Befehl übernommen, der pg_ctl erreicht — open_store(), daemon --uninstall (bevor die Unit entfernt wird) und pg status|stop.

Notes for the author / Hinweise an den Autor
  • AGENT_PG_BIN is kept across reinstalls; AGENT_PG_DSN is still taken from the environment only (pre-existing f07aaefa - Create the local cluster only in agent init #44 behaviour). Mirroring the three-state logic for the DSN, or documenting the asymmetry, would be a follow-up.
  • README/DESIGN do not mention the Postgres.app auto-discovery or the AGENT_PG_BIN persistence yet.
  • existing_service_agent_pg_bin (linux) and service_home each parse Environment= lines on their own; a shared helper would remove the duplication.

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