Skip to content

refactor: align self-hosted deployment scripts, configs, and docs with production operating patterns #504

Closed

Description

@vybe

Summary

The repo's self-hosted deployment surface (scripts under scripts/deploy/, .env.example, docker-compose.yml, docker-compose.prod.yml, and the user-facing docs/user-docs/guides/deploying-trinity.md + getting-started/setup.md) has accumulated drift against what actually runs Trinity in production. A first-time self-hoster following the current docs hits at least one blocker (agent creation fails) and several misleading-or-broken instructions. Meanwhile, the operational knowledge that keeps real instances alive — the upgrade sequence, the verification probes, the resource thresholds, the "never down/up" rule — lives only in our internal ops runbook and never reaches public users.

This issue is the umbrella to (a) fix the broken/misleading bits in code, scripts, and configs so they match reality, and (b) surface the operational patterns that actually work in production into public-safe form, so the next /generate-user-docs run can produce accurate, complete deployment guides.

Context

Triggered by an audit of the rollout/deployment guides that compared the public docs to the internal production-ops patterns. The comparison surfaced concrete bugs, drift, and gaps. Splitting into one umbrella so we can land the fixes coherently rather than as scattered one-offs.

Findings

A. Broken or misleading scripts

  • scripts/deploy/start.sh does not build the trinity-agent-base:latest image, but docs/user-docs/guides/deploying-trinity.md step 3 and getting-started/setup.md step 2 both claim it does. Without ./scripts/deploy/build-base-image.sh first, the very first Create Agent click fails because the base image is missing. This is the primary first-run blocker.
  • scripts/deploy/verify-platform.sh references trinity-audit-logger (removed), uses port 3000 for the frontend (current is 80), and shows admin/admin as the default login. It will fail on any current install.
  • scripts/deploy/validate.sh references a non-existent deployment/ directory, also references audit-logger and port 3000, and points users to port 3000 in its success message.

B. Drift between .env.example and Compose

These keys are documented in .env.example but are NOT forwarded into the backend container by the dev docker-compose.yml, so setting them in .env is silently inert in dev:

  • EXTRA_CORS_ORIGINS — drift in both compose files
  • PUBLIC_CHAT_URL — only present in docker-compose.prod.yml
  • SLACK_SIGNING_SECRET — only present in docker-compose.prod.yml
  • TRINITY_GIT_BASE_URL / TRINITY_GIT_API_BASE — only forwarded by the docker-compose.gitea.yml overlay
  • SSH_HOST — present in neither compose env block
  • FRONTEND_URL — only present in docker-compose.prod.yml

Either wire these through dev compose, or annotate .env.example to mark each as "prod-only / requires compose edit / overlay-only." Right now they look functional and aren't.

C. Documentation inaccuracies

  • guides/deploying-trinity.md step 4 instructs the user to /trinity:connect with URL + username + password. Per docs/user-docs/abilities/trinity-plugin.md and cli/trinity-cli.md, that skill expects email-verification or an MCP API key. The instruction is wrong for self-hosted local without email service configured.
  • getting-started/setup.md says "On your first visit, Trinity displays a setup wizard" — but database.py:_ensure_admin_user auto-creates the admin user when ADMIN_PASSWORD is set in .env, while routers/setup.py + main.py print a setup token to logs that's only used when ADMIN_PASSWORD is unset. Both paths exist and the docs explain neither well.
  • Neither guide mentions docker-compose.prod.yml, deploy.config.example, scripts/deploy/gcp-deploy.sh, --profile tunnel / TUNNEL_TOKEN, or scripts/deploy/build-base-image.sh.

D. Operational knowledge that never reaches public users

The internal ops runbook captures rules and procedures that are load-bearing in production but absent from public docs. None of the following are exposed to self-hosters:

  1. Use docker compose restart, never down/up — preserves agent containers and the trinity-agent-network. Single most important rule.
  2. Rebuild only platform services, not the base image — docker compose build --no-cache backend frontend mcp-server scheduler. The base image is a separate manual step.
  3. Backup before every update — ~/trinity-data/trinity.db via volume-mounted alpine cp. Daily cron + 14-day retention is the standard.
  4. Six health probes after any change — backend /health, scheduler :8001/health, frontend HTTP 200, redis PONG, MCP /health, Vector :8686/health.
  5. /api/ops/fleet/health is the authoritative agent-side status surface for operators (not just the dashboard).
  6. Resource threshold table with warning/critical bands for: agent context %, host CPU/memory, disk %, error rate/hr, container restarts, DB size, log size.
  7. Common-recovery patterns: agent stuck >90% context → restart agent; "network not found" on agent start → docker rm agent-X; docker restart trinity-backend; database locked → check for multiple uvicorn writers.
  8. Update flow has an explicit rollback path: restore DB backup → git checkout <sha> → rebuild → restart.

E. Open product questions

These need a decision before we can land the doc rewrite cleanly:

  1. docker-compose.prod.yml and scripts/deploy/gcp-deploy.sh — keep or kill? They're parallel to the path real production instances actually take. If they're vestigial, delete; if they're the public self-hoster path, document them. Right now they're undocumented.
  2. scripts/deploy/verify-platform.sh and scripts/deploy/validate.sh — repair or delete? Both are broken against current state; both look replaceable by a single small "post-install verification" probe.
  3. Public guidance on production self-hosting: how opinionated do we want to be? (Resend for email, Cloudflare Tunnel for public access, daily DB-backup cron, etc.) The internal ops setup is opinionated; the public docs are silent.

Acceptance Criteria

Code / scripts / configs

  • scripts/deploy/start.sh either builds the base image automatically or aborts with a clear instruction to run build-base-image.sh first
  • scripts/deploy/verify-platform.sh and scripts/deploy/validate.sh are either repaired against current architecture or deleted (with replacement noted)
  • .env.example is annotated so every key clearly states whether it works in dev compose, prod compose, or requires a compose edit/overlay
  • docker-compose.prod.yml / gcp-deploy.sh / deploy.config.example decision made and acted on (documented or removed)
  • First-time setup story (env var vs setup-token wizard) documented in code comments and surfaced in setup.md

Documentation

  • guides/deploying-trinity.md restructured into a hub + spokes covering: local development, single-server self-hosted, public access (Cloudflare Tunnel), upgrading, backup/restore, monitoring
  • setup.md no longer duplicates install instructions from deploying-trinity.md
  • /trinity:connect step in deploying guide reflects actual flow (email verification or MCP API key, not username/password)
  • Public-safe distillation of the operational rules (the eight items in finding D) lands in guides/deploying/upgrading.md and guides/deploying/monitoring.md
  • Resource threshold table and six-probe verification checklist included as reusable reference

Skill

  • .claude/skills/generate-user-docs/SKILL.md updated so the next run reproduces the new structure: hub + spokes layout for guides/deploying/, an "operational guide" template extension (pre-flight → action → verify → rollback), and a step that reads internal ops patterns as a source while explicitly forbidding leakage of host-specific details, SSH/sshpass invocations, or instance names

Technical Notes

Files implicated:

  • scripts/deploy/start.sh, scripts/deploy/verify-platform.sh, scripts/deploy/validate.sh, scripts/deploy/build-base-image.sh
  • .env.example
  • docker-compose.yml, docker-compose.prod.yml, docker-compose.gitea.yml, deploy.config.example
  • src/backend/database.py (admin user init), src/backend/routers/setup.py, src/backend/main.py (setup token print)
  • docs/user-docs/guides/deploying-trinity.md, docs/user-docs/getting-started/setup.md, docs/user-docs/getting-started/quick-start.md
  • .claude/skills/generate-user-docs/SKILL.md

Source of truth for operational patterns: the private ops/runbook repo. Pattern transfer must be public-safe — never copy SSH/sshpass invocations, host IPs, instance names, or credentials.

Suggested order: (1) land code/script/config fixes; (2) update the skill; (3) regenerate docs by running the skill against the now-correct codebase.

Activity

  1. added
    priority-p2
    type-refactor
    on Apr 25, 2026
  2. vybe commented on Apr 25, 2026

    @vybe
    ContributorAuthor

    Parked — partial work on feature/504-deployment-alignment

    This issue is paused. A feature branch exists with one acceptance criterion already complete:

    Branch: feature/504-deployment-alignment
    Commit: 3899682 — docs(generate-user-docs): add hub-and-spokes deployment structure and ops-pattern import

    Status against acceptance criteria

    Skill — ✅ done (on the branch, awaits PR)

    • .claude/skills/generate-user-docs/SKILL.md updated for hub+spokes layout, operational-guide template, ops-pattern import step, and public-safety greps

    Code / scripts / configs — ⏸ not started

    • scripts/deploy/start.sh base-image build behavior
    • scripts/deploy/verify-platform.sh + validate.sh (repair or delete)
    • .env.example annotation against compose env blocks
    • docker-compose.prod.yml / gcp-deploy.sh / deploy.config.example decision
    • First-time setup story (env var vs setup-token wizard) docs

    Documentation — ⏸ not started (depends on skill regeneration after code/script fixes land)

    • guides/deploying-trinity.md → hub + spokes restructure
    • setup.md deduplicated against deploying guide
    • /trinity:connect step corrected
    • Operational rules surfaced in upgrading.md + monitoring.md
    • Resource threshold table + six-probe checklist

    Blockers — open product questions

    These need decisions before the docs spoke work can land cleanly (Section E in the issue body):

    1. E1 — docker-compose.prod.yml + scripts/deploy/gcp-deploy.sh + deploy.config.example: keep or kill?
    2. E2 — verify-platform.sh + validate.sh: repair against current architecture or delete + replace?
    3. E3 — Public production guidance: how opinionated? (Resend for email, Cloudflare Tunnel for public access, daily DB-backup cron, etc.)

    When picked up again

    1. Decide E1/E2/E3
    2. Resume from feature/504-deployment-alignment (rebase on latest dev first)
    3. Land code/scripts/configs in suggested order: (1) code/script/config fixes → (2) skill is already updated → (3) regenerate docs by running /generate-user-docs against the now-correct codebase
  3. added
    status-in-dev
    on Apr 27, 2026
  4. added a commit that references this issue on Apr 30, 2026
  5. AndriiPasternak31 commented on May 12, 2026

    @AndriiPasternak31
    Contributor

    Sub-finding: setup-token banner is swallowed before reaching docker logs

    The current AC frames the first-time-setup story as a documentation gap, but there's a runtime visibility bug underneath that the existing wording doesn't catch.

    Bug: src/backend/main.py:335-341 uses bare print() for the "TRINITY FIRST-TIME SETUP REQUIRED" banner and the setup token. Under uvicorn's --reload parent process, stdout is buffered, so even when the setup-token path is being exercised correctly, the token never reaches docker logs trinity-backend. Lines 343-358 have the same problem for the agent-enumeration / system-agent-deploy startup output.

    The pattern drift is obvious — lines 325/327 right above use logger.info() correctly.

    Repro (clean):

    1. Fresh Conductor worktree → its own compose project with empty named volumes (<worktree>_trinity-data), so system_settings.setup_completed is unset.
    2. ./scripts/deploy/start.sh
    3. docker logs trinity-backend | grep -i setup → no banner, no token.
    4. POST /api/token returns 403 setup_required, and there's no documented way to recover except manually INSERT INTO system_settings('setup_completed','true') against the DB.

    Suggested AC addition (one-line each):

    • src/backend/main.py:335-341 — replace bare print() with logger.info() so the setup-token banner reaches docker logs reliably (or set PYTHONUNBUFFERED=1 in docker/backend/Dockerfile as a less-targeted alternative).
    • Same pattern at main.py:346,348,350,355,357 (agent enumeration + system agent deploy output) for consistency.
    • Manually verify on a clean compose project: token appears in docker logs trinity-backend within 10s of boot.

    Discovered while running #474's new integration suite against a fresh phoenix worktree (Conductor) — the worktree-per-compose-project reality means new dev workspaces hit this every time.

  6. vybe commented on Jun 1, 2026

    @vybe
    ContributorAuthor

    Shipped in v0.6.0 (released via #998).

  7. added
    complexity-medium
    theme-infrastructure
    and removed
    status-in-dev
    on Jun 1, 2026
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

    complexity-mediumpriority-p2theme-infrastructuretype-refactor

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions