Skip to content

fix(setup): deploy the system agent once /setup creates the admin (#3237) - #3261

Merged
vybe merged 2 commits into
devfrom
feature/3237-system-agent-after-setup
Oct 6, 2026
Merged

vybe merged 2 commits into
devfrom
feature/3237-system-agent-after-setup

Conversation

@dolho

@dolho dolho commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • On a browser-claimed install (DigitalOcean / AWS one-click, the hosted script) the only system-agent deploy ran at backend boot, before /setup had created the admin, and failed with Admin user 'admin' not found. Nothing retried it, so trinity-system stayed absent until a backend restart.
  • POST /api/setup/admin-password now schedules _deploy_system_agent_after_setup as a background task once the admin row exists. It calls the same idempotent system_agent_service.ensure_deployed() as boot, so the next restart is a no-op.
  • It runs before ensure_first_run_seeded, which is the boot order. The seeder hosts its failure alerts on trinity-system, and running the two in sequence keeps the system agent and Cornelius from racing for an SSH port.
  • The task never raises, because Starlette runs background tasks in sequence and a raise would also skip the seed and the operator intake. It skips when there is no Docker client, the same as the boot guard.

Changes

  • src/backend/routers/setup.py: the helper and the add_task call. Imports are lazy, which keeps the router's import isolation.
  • tests/unit/test_3237_system_agent_after_setup.py (new) and its tests/registry.json entry.
  • docs/memory/feature-flows/internal-system-agent.md: the second deploy trigger.

Trade-off

On a fresh install, Cornelius seeding now starts after the system-agent create, roughly 20–90s later (recreate plus readiness wait). Setup's response is unaffected because both are background tasks.

Out of scope

SYSTEM_AGENT_OWNER = "admin" is hard-coded, while /setup creates admin_username(), which honours ADMIN_USERNAME. With ADMIN_USERNAME set to anything else, the create still fails after this fix. That is a separate bug and gets its own issue.

Test Plan

Fixes #3237

🤖 Generated with Claude Code

)

On a browser-claimed install (every one-click / marketplace path) the
only system-agent deploy runs at boot, before /setup has created the
admin, and fails with "Admin user 'admin' not found". Nothing retried
it, so trinity-system stayed absent until a backend restart.

/setup now schedules ensure_deployed() as a background task after the
admin row is written, ahead of first-run seeding (the boot order; the
seeder hosts its alerts on trinity-system). The task never raises, since
Starlette runs background tasks in sequence, and skips without Docker.

Fixes #3237

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…p flow (#3237)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@vybe vybe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merge-train: batch validated on train/20261006-0833 (#3266)

@vybe
vybe merged commit 7787712 into dev Oct 6, 2026
24 checks passed
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