This repository has been archived on 2026-08-04. You can view files and clone it, but cannot push or open issues or pull requests.
orchestrator/agent-team/systemd/agent-team-coordinator.service
Adam Moussa 2d1dca0804
feat(agent-team): deploy-readiness — serve starts Slack listener + systemd + provisioning docs (#23)
* fix(agent-team): serve() starts the inbound Slack listener (D-1)

Coordinator.serve() now constructs and starts the SlackListener concurrently
with the tick/drain loop on a background daemon thread, but ONLY when the live
transport is a SlackTransport AND SLACK_APP_TOKEN is configured. When Slack is
not the transport or the app token is absent, serve() behaves exactly as before
(tick/recover only) — Slack is never made mandatory.

- New injectable build_listener seam + default_slack_listener_factory sharing
  the coordinator's own transport, ledger db_path, and resume_queue put.
- AUTHZ-01 owner-allowlist + open-status CAS untouched: serve() sources
  AGENT_TEAM_SLACK_OWNER_IDS in SlackListener.serve, which still fails closed.
- SlackListener.close() added for clean Socket Mode teardown on shutdown;
  serve() stops the listener + joins the thread in a finally.
- Tests: start-when-Slack+app-token, no-start otherwise, clean shutdown,
  idempotent start, serve start/stop around the loop, listener close().

* fix(agent-team): systemd unit loads ~/orchestrator/.env + uses venv python (D-2/D-7)

D-2: add EnvironmentFile=-/home/adam/orchestrator/.env (optional '-') so the P2
GPT-4.1 review loop's cross_reviewer sub-process can read the non-Claude provider
key once a task reaches REVIEW. Mirrors the sea-haven-secrev unit.

D-7: point ExecStart at the agent-team venv interpreter
(/home/adam/orchestrator/agent-team/.venv/bin/python) instead of
/usr/bin/env python3, which resolved the system interpreter without the
installed deps under systemd's PATH.

All hardening (NoNewPrivileges / ProtectSystem=full / ProtectHome=read-only /
ReadWritePaths) is retained unchanged (locked decision).

* docs(agent-team): land provisioning + operator runbooks under docs/provisioning

- PROVISIONING-RUNBOOK.md: merged final state (6 checkers, dep-bump fixer, P5
  intake-checker loop), SLACK_CHANNEL_ID, the gated P3-live flip steps (GitHub
  App + agent-apply env + gated_build_verify_wiring), and D-1/D-2/D-7 marked
  FIXED so the demo can use the live Slack answer path.
- P1-DEMO-SCRIPT.md: live Slack answer path now available (D-1 fixed); both the
  Slack and operator-CLI answer paths documented for all four exit criteria.
- DEPLOY-AUDIT.md: D-1/D-2/D-7 RESOLVED (this PR); D-4/D-5 dep pinning and the
  operator-CLI divergence kept as provisioning notes.
- OPERATOR-RUNBOOK.md (new): incident handling for pipeline stalls, parked tasks,
  failed HITL resumes, budget exhaustion, transport outages, and
  COMPLACENCY/COVERAGE alarms — each grounded in real run-team.py verbs, plus the
  re-alarm-backoff -> Jira-after-N-nights escalation ladder (design §5/§6.6).

* fix(agent-team): supervise the Slack listener thread — recurring ALARM + respawn

sh-security-review (logic) MEDIUM: a crashed listener thread was logged once,
then the daemon ran on 'deaf' — posting clarifier questions but receiving no
answers, every gate silently parking, process never exiting so systemd
Restart=on-failure never fired. serve() now calls _supervise_slack_listener()
each pass: when the listener is enabled but its thread is dead, it emits a
recurring ERROR ALARM and respawns via the idempotent starter (self-heal).
No-op when alive or disabled. +3 tests. (authz detector: wiring clean — AUTHZ-01
fail-closed allowlist + open-status CAS intact, dead listener fails SAFE.)
2026-06-18 16:56:21 -04:00

71 lines
3.7 KiB
Desktop File

# agent-team-coordinator.service - R720 Plane-2 coordinator daemon (sh-secrev VM, user adam).
#
# Long-running coordinator for the agent-team SDLC pipeline. Unlike the
# sea-haven-secrev sweep (a oneshot driven by a timer), this is an always-on
# service: it serves the LangGraph coordinator, the durable pending_questions
# ledger, and the Slack Socket Mode inbound listener that answers clarifier
# questions. ExecStart runs the `serve` subcommand of the operator CLI.
#
# Install (on the VM, as root):
# sudo cp agent-team-coordinator.service /etc/systemd/system/
# sudo systemctl daemon-reload
# sudo systemctl enable --now agent-team-coordinator.service
# systemctl status agent-team-coordinator.service
# journalctl -u agent-team-coordinator.service -e -f
#
# Secrets come from the EnvironmentFile(s) (leading '-' = optional, no failure if
# absent). Two files are loaded, mirroring the sea-haven-secrev unit:
#
# ~/secrev.env (mode 600, NOT in git) - the agent-team runtime keys:
# CLAUDE_CODE_OAUTH_TOKEN -> subscription OAuth (from `claude setup-token`).
# A raw ANTHROPIC_API_KEY must NOT be set on this
# box; it would silently win and meter to API
# rates. The billing seam pops it defensively.
# SLACK_BOT_TOKEN -> xoxb- bot token (chat:write) - posts questions.
# SLACK_APP_TOKEN -> xapp- app-level token (connections:write) -
# REQUIRED for Socket Mode; opens the inbound
# WebSocket that receives answers. Without it the
# coordinator can post but never hear replies.
# serve() starts the inbound SlackListener only when
# the transport is live Slack AND this token is set.
# SLACK_CHANNEL_ID -> target channel for clarifier questions.
# AGENT_TEAM_SLACK_OWNER_IDS -> comma-separated authorized answerer ids
# (AUTHZ-01). The listener FAILS CLOSED if unset.
#
# ~/orchestrator/.env (mode 600, NOT in git) - the P2 review-loop provider key:
# The production serve() wires the GPT-4.1 cross-review loop, which shells the
# local orchestrator run.py -> cross_reviewer once a task reaches REVIEW. That
# sub-process needs the non-Claude provider key from ~/orchestrator/.env (same
# file the sea-haven-secrev unit loads). Optional ('-') so the daemon still
# starts if it is absent; the review path then fails loudly only at REVIEW.
[Unit]
Description=Sea Haven agent-team Plane-2 coordinator daemon
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=adam
WorkingDirectory=/home/adam/orchestrator/agent-team
EnvironmentFile=-/home/adam/secrev.env
EnvironmentFile=-/home/adam/orchestrator/.env
# Use the agent-team venv interpreter (where the runtime deps are installed by
# the DEPLOY-R720 / PROVISIONING-RUNBOOK step), NOT the bare system python3 that
# `/usr/bin/env python3` would resolve under systemd's PATH (D-7).
ExecStart=/home/adam/orchestrator/agent-team/.venv/bin/python run-team.py serve
Restart=on-failure
RestartSec=5
# Hardening - matches the level the sea-haven-secrev unit relies on, scoped for a
# long-running daemon that must READ ~/secrev.env and WRITE the local ledger.
NoNewPrivileges=true
ProtectSystem=full
# ProtectHome cannot be `true`: the daemon reads /home/adam/secrev.env and writes
# the ledger under the working dir. read-only home + an explicit RW carve-out for
# the state/ dir keeps the rest of $HOME unreadable/unwritable to the service.
ProtectHome=read-only
ReadWritePaths=/home/adam/orchestrator/agent-team/state
Nice=10
[Install]
WantedBy=multi-user.target